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

Committer:
AkinoriHashimoto
Date:
Fri Oct 30 05:20:40 2015 +0000
Revision:
0:5373472190f5
Child:
1:8f2a3144902b
1st publish.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AkinoriHashimoto 0:5373472190f5 1 #pragma once
AkinoriHashimoto 0:5373472190f5 2
AkinoriHashimoto 0:5373472190f5 3 #include "mbed.h"
AkinoriHashimoto 0:5373472190f5 4 #include <string>
AkinoriHashimoto 0:5373472190f5 5
AkinoriHashimoto 0:5373472190f5 6 //#define BufSize 256
AkinoriHashimoto 0:5373472190f5 7
AkinoriHashimoto 0:5373472190f5 8 #ifdef RTOS_H
AkinoriHashimoto 0:5373472190f5 9 extern Mutex mutex;
AkinoriHashimoto 0:5373472190f5 10 #endif
AkinoriHashimoto 0:5373472190f5 11
AkinoriHashimoto 0:5373472190f5 12 class RingBuffer
AkinoriHashimoto 0:5373472190f5 13 {
AkinoriHashimoto 0:5373472190f5 14 public:
AkinoriHashimoto 0:5373472190f5 15 RingBuffer(unsigned int size= 256);
AkinoriHashimoto 0:5373472190f5 16 ~RingBuffer();
AkinoriHashimoto 0:5373472190f5 17
AkinoriHashimoto 0:5373472190f5 18 bool set(char chr);
AkinoriHashimoto 0:5373472190f5 19 bool set(string &str); // Return Full、参照渡し
AkinoriHashimoto 0:5373472190f5 20
AkinoriHashimoto 0:5373472190f5 21 string get();
AkinoriHashimoto 0:5373472190f5 22
AkinoriHashimoto 0:5373472190f5 23 private:
AkinoriHashimoto 0:5373472190f5 24 volatile bool empty;
AkinoriHashimoto 0:5373472190f5 25 volatile unsigned short idxF, idxR; // front, rear
AkinoriHashimoto 0:5373472190f5 26 char *buf;
AkinoriHashimoto 0:5373472190f5 27 unsigned int bufSize;
AkinoriHashimoto 0:5373472190f5 28 };
AkinoriHashimoto 0:5373472190f5 29
AkinoriHashimoto 0:5373472190f5 30 // eof