skeleton for lab1
Dependencies: AvailableMemory mbed-rtos mbed
Fork of helloaabbc by
RingBuffer.h@1:55e99f6e2aa5, 2014-04-04 (annotated)
- Committer:
- mbed36372
- Date:
- Fri Apr 04 21:31:22 2014 +0000
- Revision:
- 1:55e99f6e2aa5
- Parent:
- 0:1c8f2727e9f5
SP14_lab1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
y7jin | 0:1c8f2727e9f5 | 1 | #ifndef _RING_BUFFER_H |
y7jin | 0:1c8f2727e9f5 | 2 | #define _RING_BUFFER_H |
y7jin | 0:1c8f2727e9f5 | 3 | |
y7jin | 0:1c8f2727e9f5 | 4 | #include "mbed.h" |
y7jin | 0:1c8f2727e9f5 | 5 | |
y7jin | 0:1c8f2727e9f5 | 6 | class RingBuffer{ |
y7jin | 0:1c8f2727e9f5 | 7 | private: |
y7jin | 0:1c8f2727e9f5 | 8 | |
y7jin | 0:1c8f2727e9f5 | 9 | /*buf is the maximum size of the ring buffer; start is the beginning of first valid element, end is the next available position |
y7jin | 0:1c8f2727e9f5 | 10 | to write*/ |
y7jin | 0:1c8f2727e9f5 | 11 | int bufSize, start, end; |
y7jin | 0:1c8f2727e9f5 | 12 | public: |
y7jin | 0:1c8f2727e9f5 | 13 | /*buf is the pointer to actual buffer start, bufEnd is the actual end of the buffer, |
y7jin | 0:1c8f2727e9f5 | 14 | end is the current available position to insert (no element is at end yet), start is the first full position*/ |
y7jin | 0:1c8f2727e9f5 | 15 | int *buf; |
y7jin | 0:1c8f2727e9f5 | 16 | /*cur is used in next() method, denoting the current position in a sequential read, count is the number of elements*/ |
y7jin | 0:1c8f2727e9f5 | 17 | int cur,count; |
y7jin | 0:1c8f2727e9f5 | 18 | |
mbed36372 | 1:55e99f6e2aa5 | 19 | RingBuffer(int *data=NULL, int bs=0):bufSize(bs),start(0),end(0),buf(data),cur(0),count(0){} |
y7jin | 0:1c8f2727e9f5 | 20 | ~RingBuffer(){buf=NULL;} |
y7jin | 0:1c8f2727e9f5 | 21 | void insert(int sample); |
y7jin | 0:1c8f2727e9f5 | 22 | int next(); |
y7jin | 0:1c8f2727e9f5 | 23 | int getCount()const{return count;} |
y7jin | 0:1c8f2727e9f5 | 24 | void dump(FILE *fp)const; |
y7jin | 0:1c8f2727e9f5 | 25 | }; |
y7jin | 0:1c8f2727e9f5 | 26 | |
y7jin | 0:1c8f2727e9f5 | 27 | #endif |