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

RingBuffer.h

Committer:
AkinoriHashimoto
Date:
2015-10-30
Revision:
1:8f2a3144902b
Parent:
0:5373472190f5
Child:
2:db4675083c8c

File content as of revision 1:8f2a3144902b:

#pragma once

#include "mbed.h"
#include <string>

#define MaxBufSize     1024

#ifdef RTOS_H
extern Mutex mutex;
#endif

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;
    unsigned short idxF, idxR;    // front, rear
    char *buf;
    unsigned int bufSize;
    // %
    bool isPowers2;
    void modulo(unsigned short &idx);
};

// eof