General purpose ring buffer library

Dependents:   iSerial DGWWebServer iSerial Dumb_box_rev2 ... more

Committer:
ykuroda
Date:
Fri Aug 31 17:13:40 2012 +0000
Revision:
1:1c3a10f2eb04
Parent:
0:db7fa84ff50e
Child:
2:ea6d02ba96ae
bug fix

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ykuroda 1:1c3a10f2eb04 1 //
ykuroda 1:1c3a10f2eb04 2 // RingBuffer.h ... General purpose ring buffer library
ykuroda 1:1c3a10f2eb04 3 //
ykuroda 1:1c3a10f2eb04 4 // Copyright 2012 Yoji KURODA
ykuroda 1:1c3a10f2eb04 5 //
ykuroda 1:1c3a10f2eb04 6 // 2009.11.13 ... Originally written in C by Y.Kuroda for Renesas H83664
ykuroda 1:1c3a10f2eb04 7 // 2012.08.31 ... Code convert for mbed in C++
ykuroda 1:1c3a10f2eb04 8 //
ykuroda 1:1c3a10f2eb04 9
ykuroda 0:db7fa84ff50e 10 #ifndef _RINGBUFFER_H
ykuroda 0:db7fa84ff50e 11 #define _RINGBUFFER_H
ykuroda 0:db7fa84ff50e 12
ykuroda 0:db7fa84ff50e 13 class RingBuffer {
ykuroda 0:db7fa84ff50e 14
ykuroda 0:db7fa84ff50e 15 protected:
ykuroda 0:db7fa84ff50e 16 unsigned char* buf;
ykuroda 0:db7fa84ff50e 17 unsigned int sp;
ykuroda 0:db7fa84ff50e 18 unsigned int ep;
ykuroda 1:1c3a10f2eb04 19 int bufsize;
ykuroda 0:db7fa84ff50e 20
ykuroda 0:db7fa84ff50e 21 public:
ykuroda 0:db7fa84ff50e 22 RingBuffer(int _bufsize=100);
ykuroda 0:db7fa84ff50e 23 ~RingBuffer();
ykuroda 0:db7fa84ff50e 24
ykuroda 1:1c3a10f2eb04 25 int save(unsigned char c);
ykuroda 0:db7fa84ff50e 26 unsigned char read(void);
ykuroda 0:db7fa84ff50e 27 int check(void);
ykuroda 1:1c3a10f2eb04 28 int buffersize(void){return bufsize;};
ykuroda 1:1c3a10f2eb04 29 int full(void){ return (check()>=bufsize-1 ? 1 : 0); };
ykuroda 0:db7fa84ff50e 30 };
ykuroda 0:db7fa84ff50e 31
ykuroda 0:db7fa84ff50e 32
ykuroda 0:db7fa84ff50e 33 #endif /* _RINGBUFFER_H */
ykuroda 0:db7fa84ff50e 34
ykuroda 0:db7fa84ff50e 35