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:
- 0:5373472190f5
- Child:
- 1:8f2a3144902b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RingBuffer.h Fri Oct 30 05:20:40 2015 +0000 @@ -0,0 +1,30 @@ +#pragma once + +#include "mbed.h" +#include <string> + +//#define BufSize 256 + +#ifdef RTOS_H +extern Mutex mutex; +#endif + +class RingBuffer +{ +public: + RingBuffer(unsigned int size= 256); + ~RingBuffer(); + + bool set(char chr); + bool set(string &str); // Return Full、参照渡し + + string get(); + +private: + volatile bool empty; + volatile unsigned short idxF, idxR; // front, rear + char *buf; + unsigned int bufSize; +}; + +// eof \ No newline at end of file