An implementation of a circular array allowing direct write and read.
CircularArray.h@1:5036a532fe62, 2014-02-12 (annotated)
- Committer:
- GLemasson
- Date:
- Wed Feb 12 15:51:51 2014 +0000
- Revision:
- 1:5036a532fe62
- Parent:
- 0:28766f5a758e
change to char version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GLemasson | 0:28766f5a758e | 1 | |
GLemasson | 0:28766f5a758e | 2 | #ifndef _CIRCULAR_ARRAY_H_ |
GLemasson | 0:28766f5a758e | 3 | #define _CIRCULAR_ARRAY_H_ |
GLemasson | 1:5036a532fe62 | 4 | #include <stdint.h> |
GLemasson | 0:28766f5a758e | 5 | |
GLemasson | 1:5036a532fe62 | 6 | class CircularArray |
GLemasson | 0:28766f5a758e | 7 | { |
GLemasson | 0:28766f5a758e | 8 | private: |
GLemasson | 0:28766f5a758e | 9 | unsigned int m_capacity; |
GLemasson | 0:28766f5a758e | 10 | volatile unsigned int w; |
GLemasson | 0:28766f5a758e | 11 | volatile unsigned int r; |
GLemasson | 0:28766f5a758e | 12 | volatile bool m_full; |
GLemasson | 0:28766f5a758e | 13 | volatile bool m_empty; |
GLemasson | 1:5036a532fe62 | 14 | volatile uint8_t * data; |
GLemasson | 1:5036a532fe62 | 15 | volatile uint8_t * readerBuffer; |
GLemasson | 1:5036a532fe62 | 16 | uint16_t sizeRB; |
GLemasson | 1:5036a532fe62 | 17 | volatile uint8_t * writerBuffer; |
GLemasson | 1:5036a532fe62 | 18 | uint16_t sizeWB; |
GLemasson | 0:28766f5a758e | 19 | |
GLemasson | 0:28766f5a758e | 20 | public: |
GLemasson | 0:28766f5a758e | 21 | CircularArray(unsigned int capacity); |
GLemasson | 0:28766f5a758e | 22 | ~CircularArray(); |
GLemasson | 1:5036a532fe62 | 23 | uint8_t * getWritePointer(); |
GLemasson | 1:5036a532fe62 | 24 | uint8_t * getReadPointer(uint16_t num); |
GLemasson | 0:28766f5a758e | 25 | void writeElements(unsigned int num); |
GLemasson | 0:28766f5a758e | 26 | void readElements(unsigned int num); |
GLemasson | 0:28766f5a758e | 27 | unsigned int fillCapacity(); |
GLemasson | 0:28766f5a758e | 28 | unsigned int freeSpace(); |
GLemasson | 0:28766f5a758e | 29 | unsigned int size(); |
GLemasson | 0:28766f5a758e | 30 | unsigned int readable(); |
GLemasson | 0:28766f5a758e | 31 | bool full(); |
GLemasson | 0:28766f5a758e | 32 | bool empty(); |
GLemasson | 0:28766f5a758e | 33 | }; |
GLemasson | 0:28766f5a758e | 34 | |
GLemasson | 0:28766f5a758e | 35 | #endif |