Versión de Firmware con funciones de RAM incorporadas.
Dependencies: mbed
Fork of VmRecorderV1dot1 by
RingBuffer/Buffering.cpp@2:e818c80e6d5c, 2015-07-14 (annotated)
- Committer:
- JuanManuelAmador
- Date:
- Tue Jul 14 08:34:11 2015 +0000
- Revision:
- 2:e818c80e6d5c
- Parent:
- 0:3d456b8ce449
Funciones de memoria RAM introducidas.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JuanManuelAmador | 0:3d456b8ce449 | 1 | #include "Buffering.h" |
JuanManuelAmador | 0:3d456b8ce449 | 2 | |
JuanManuelAmador | 0:3d456b8ce449 | 3 | Buffering::Buffering() |
JuanManuelAmador | 0:3d456b8ce449 | 4 | { |
JuanManuelAmador | 0:3d456b8ce449 | 5 | for(int i = 0; i < BUFFERSIZE; i++){ |
JuanManuelAmador | 0:3d456b8ce449 | 6 | data[i] = 0; |
JuanManuelAmador | 0:3d456b8ce449 | 7 | } |
JuanManuelAmador | 0:3d456b8ce449 | 8 | windex = 0; |
JuanManuelAmador | 0:3d456b8ce449 | 9 | rindex = 0; |
JuanManuelAmador | 0:3d456b8ce449 | 10 | full = false; |
JuanManuelAmador | 0:3d456b8ce449 | 11 | empty = true; |
JuanManuelAmador | 0:3d456b8ce449 | 12 | bufSize = BUFFERSIZE; |
JuanManuelAmador | 0:3d456b8ce449 | 13 | } |
JuanManuelAmador | 0:3d456b8ce449 | 14 | |
JuanManuelAmador | 0:3d456b8ce449 | 15 | void Buffering::put(int16_t val) |
JuanManuelAmador | 0:3d456b8ce449 | 16 | { |
JuanManuelAmador | 0:3d456b8ce449 | 17 | if(!full) |
JuanManuelAmador | 0:3d456b8ce449 | 18 | { |
JuanManuelAmador | 0:3d456b8ce449 | 19 | data[windex] = val; |
JuanManuelAmador | 0:3d456b8ce449 | 20 | windex++; |
JuanManuelAmador | 0:3d456b8ce449 | 21 | empty = false; |
JuanManuelAmador | 0:3d456b8ce449 | 22 | if(windex >= bufSize) |
JuanManuelAmador | 0:3d456b8ce449 | 23 | { |
JuanManuelAmador | 0:3d456b8ce449 | 24 | windex = 0; |
JuanManuelAmador | 0:3d456b8ce449 | 25 | } |
JuanManuelAmador | 0:3d456b8ce449 | 26 | if(getDif() >= bufSize - 1){ |
JuanManuelAmador | 0:3d456b8ce449 | 27 | full = true; |
JuanManuelAmador | 0:3d456b8ce449 | 28 | } |
JuanManuelAmador | 0:3d456b8ce449 | 29 | /*if(windex >= rindex) |
JuanManuelAmador | 0:3d456b8ce449 | 30 | { |
JuanManuelAmador | 0:3d456b8ce449 | 31 | full = true; |
JuanManuelAmador | 0:3d456b8ce449 | 32 | }*/ |
JuanManuelAmador | 0:3d456b8ce449 | 33 | } |
JuanManuelAmador | 0:3d456b8ce449 | 34 | } |
JuanManuelAmador | 0:3d456b8ce449 | 35 | |
JuanManuelAmador | 0:3d456b8ce449 | 36 | int16_t Buffering::get() |
JuanManuelAmador | 0:3d456b8ce449 | 37 | { |
JuanManuelAmador | 0:3d456b8ce449 | 38 | int16_t temp = 0; |
JuanManuelAmador | 0:3d456b8ce449 | 39 | if(!empty) |
JuanManuelAmador | 0:3d456b8ce449 | 40 | { |
JuanManuelAmador | 0:3d456b8ce449 | 41 | temp = data[rindex]; |
JuanManuelAmador | 0:3d456b8ce449 | 42 | data[rindex] = 0; |
JuanManuelAmador | 0:3d456b8ce449 | 43 | full = false; |
JuanManuelAmador | 0:3d456b8ce449 | 44 | rindex++; |
JuanManuelAmador | 0:3d456b8ce449 | 45 | if(rindex >= bufSize) |
JuanManuelAmador | 0:3d456b8ce449 | 46 | { |
JuanManuelAmador | 0:3d456b8ce449 | 47 | rindex = 0; |
JuanManuelAmador | 0:3d456b8ce449 | 48 | } |
JuanManuelAmador | 0:3d456b8ce449 | 49 | if(getDif() == 0){ |
JuanManuelAmador | 0:3d456b8ce449 | 50 | empty = true; |
JuanManuelAmador | 0:3d456b8ce449 | 51 | } |
JuanManuelAmador | 0:3d456b8ce449 | 52 | /*if(rindex >= windex) |
JuanManuelAmador | 0:3d456b8ce449 | 53 | { |
JuanManuelAmador | 0:3d456b8ce449 | 54 | empty = true; |
JuanManuelAmador | 0:3d456b8ce449 | 55 | }*/ |
JuanManuelAmador | 0:3d456b8ce449 | 56 | } |
JuanManuelAmador | 0:3d456b8ce449 | 57 | return temp; |
JuanManuelAmador | 0:3d456b8ce449 | 58 | } |
JuanManuelAmador | 0:3d456b8ce449 | 59 | |
JuanManuelAmador | 0:3d456b8ce449 | 60 | bool Buffering::isFull() |
JuanManuelAmador | 0:3d456b8ce449 | 61 | { |
JuanManuelAmador | 0:3d456b8ce449 | 62 | return full; |
JuanManuelAmador | 0:3d456b8ce449 | 63 | } |
JuanManuelAmador | 0:3d456b8ce449 | 64 | |
JuanManuelAmador | 0:3d456b8ce449 | 65 | bool Buffering::isEmpty() |
JuanManuelAmador | 0:3d456b8ce449 | 66 | { |
JuanManuelAmador | 0:3d456b8ce449 | 67 | return empty; |
JuanManuelAmador | 0:3d456b8ce449 | 68 | } |
JuanManuelAmador | 0:3d456b8ce449 | 69 | |
JuanManuelAmador | 0:3d456b8ce449 | 70 | int Buffering::getSize() |
JuanManuelAmador | 0:3d456b8ce449 | 71 | { |
JuanManuelAmador | 0:3d456b8ce449 | 72 | return bufSize; |
JuanManuelAmador | 0:3d456b8ce449 | 73 | } |
JuanManuelAmador | 0:3d456b8ce449 | 74 | |
JuanManuelAmador | 0:3d456b8ce449 | 75 | unsigned int Buffering::getWritingIndex() |
JuanManuelAmador | 0:3d456b8ce449 | 76 | { |
JuanManuelAmador | 0:3d456b8ce449 | 77 | return windex; |
JuanManuelAmador | 0:3d456b8ce449 | 78 | } |
JuanManuelAmador | 0:3d456b8ce449 | 79 | |
JuanManuelAmador | 0:3d456b8ce449 | 80 | unsigned int Buffering::getReadingIndex() |
JuanManuelAmador | 0:3d456b8ce449 | 81 | { |
JuanManuelAmador | 0:3d456b8ce449 | 82 | return rindex; |
JuanManuelAmador | 0:3d456b8ce449 | 83 | } |
JuanManuelAmador | 0:3d456b8ce449 | 84 | |
JuanManuelAmador | 0:3d456b8ce449 | 85 | unsigned int Buffering::getDif() |
JuanManuelAmador | 0:3d456b8ce449 | 86 | { |
JuanManuelAmador | 0:3d456b8ce449 | 87 | unsigned int dif = 0; |
JuanManuelAmador | 0:3d456b8ce449 | 88 | if((int)(windex-rindex)>=0) { dif = windex-rindex; } |
JuanManuelAmador | 0:3d456b8ce449 | 89 | else { dif = bufSize+windex-rindex; } |
JuanManuelAmador | 0:3d456b8ce449 | 90 | return dif; |
JuanManuelAmador | 0:3d456b8ce449 | 91 | } |