d
Fork of RingBuffer by
RingBuffer.h@3:8e9292ecb56c, 2016-06-07 (annotated)
- Committer:
- palmdotax
- Date:
- Tue Jun 07 03:14:41 2016 +0000
- Revision:
- 3:8e9292ecb56c
- Parent:
- 2:ea6d02ba96ae
5555+;
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:ea6d02ba96ae | 17 | unsigned char* sp; |
ykuroda | 2:ea6d02ba96ae | 18 | unsigned char* ep; |
ykuroda | 2:ea6d02ba96ae | 19 | |
ykuroda | 2:ea6d02ba96ae | 20 | |
ykuroda | 1:1c3a10f2eb04 | 21 | int bufsize; |
ykuroda | 0:db7fa84ff50e | 22 | |
ykuroda | 0:db7fa84ff50e | 23 | public: |
ykuroda | 0:db7fa84ff50e | 24 | RingBuffer(int _bufsize=100); |
ykuroda | 0:db7fa84ff50e | 25 | ~RingBuffer(); |
ykuroda | 0:db7fa84ff50e | 26 | |
ykuroda | 1:1c3a10f2eb04 | 27 | int save(unsigned char c); |
ykuroda | 0:db7fa84ff50e | 28 | unsigned char read(void); |
ykuroda | 0:db7fa84ff50e | 29 | int check(void); |
palmdotax | 3:8e9292ecb56c | 30 | int buffersize(void){return bufsize;} |
palmdotax | 3:8e9292ecb56c | 31 | int full(void){ return (check()>=bufsize-1 ? 1 : 0); } |
ykuroda | 0:db7fa84ff50e | 32 | }; |
ykuroda | 0:db7fa84ff50e | 33 | |
ykuroda | 0:db7fa84ff50e | 34 | |
ykuroda | 0:db7fa84ff50e | 35 | #endif /* _RINGBUFFER_H */ |
ykuroda | 0:db7fa84ff50e | 36 | |
ykuroda | 0:db7fa84ff50e | 37 |