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 06:34:07 2015 +0000
Revision:
1:8f2a3144902b
Parent:
0:5373472190f5
Child:
2:db4675083c8c
include empty(), buf limit 1kB, modulo Speed up.

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 1:8f2a3144902b 6 #define MaxBufSize 1024
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 1:8f2a3144902b 15 // Reccomend 2^n: pow(2,n)
AkinoriHashimoto 0:5373472190f5 16 RingBuffer(unsigned int size= 256);
AkinoriHashimoto 0:5373472190f5 17 ~RingBuffer();
AkinoriHashimoto 0:5373472190f5 18
AkinoriHashimoto 1:8f2a3144902b 19 bool empty();
AkinoriHashimoto 1:8f2a3144902b 20
AkinoriHashimoto 0:5373472190f5 21 bool set(char chr);
AkinoriHashimoto 0:5373472190f5 22 bool set(string &str); // Return Full、参照渡し
AkinoriHashimoto 0:5373472190f5 23
AkinoriHashimoto 0:5373472190f5 24 string get();
AkinoriHashimoto 1:8f2a3144902b 25
AkinoriHashimoto 0:5373472190f5 26 private:
AkinoriHashimoto 1:8f2a3144902b 27 volatile bool _empty;
AkinoriHashimoto 1:8f2a3144902b 28 unsigned short idxF, idxR; // front, rear
AkinoriHashimoto 0:5373472190f5 29 char *buf;
AkinoriHashimoto 0:5373472190f5 30 unsigned int bufSize;
AkinoriHashimoto 1:8f2a3144902b 31 // %
AkinoriHashimoto 1:8f2a3144902b 32 bool isPowers2;
AkinoriHashimoto 1:8f2a3144902b 33 void modulo(unsigned short &idx);
AkinoriHashimoto 0:5373472190f5 34 };
AkinoriHashimoto 0:5373472190f5 35
AkinoriHashimoto 0:5373472190f5 36 // eof