Ring Buffer reconciled with RTOS. If with using RTOS, this lib is enabled Mutex. Default RingBuffer size is 256 Bytes, Max size is 1024 Bytes.
Dependents: RN41 HC05 HC05 mySerial ... more
Diff: RingBuffer.h
- Revision:
- 1:8f2a3144902b
- Parent:
- 0:5373472190f5
- Child:
- 2:db4675083c8c
diff -r 5373472190f5 -r 8f2a3144902b RingBuffer.h --- a/RingBuffer.h Fri Oct 30 05:20:40 2015 +0000 +++ b/RingBuffer.h Fri Oct 30 06:34:07 2015 +0000 @@ -3,7 +3,7 @@ #include "mbed.h" #include <string> -//#define BufSize 256 +#define MaxBufSize 1024 #ifdef RTOS_H extern Mutex mutex; @@ -12,19 +12,25 @@ class RingBuffer { public: + // Reccomend 2^n: pow(2,n) RingBuffer(unsigned int size= 256); ~RingBuffer(); + bool empty(); + bool set(char chr); bool set(string &str); // Return Full、参照渡し string get(); - + private: - volatile bool empty; - volatile unsigned short idxF, idxR; // front, rear + volatile bool _empty; + unsigned short idxF, idxR; // front, rear char *buf; unsigned int bufSize; + // % + bool isPowers2; + void modulo(unsigned short &idx); }; // eof \ No newline at end of file