Ringbuffer class
RingBuffer.h@0:fed94e516719, 2016-01-11 (annotated)
- Committer:
- chris215
- Date:
- Mon Jan 11 04:46:57 2016 +0000
- Revision:
- 0:fed94e516719
- Child:
- 1:fa4c2377a741
Simple RingBuffer class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris215 | 0:fed94e516719 | 1 | |
chris215 | 0:fed94e516719 | 2 | #ifndef FIFO_H |
chris215 | 0:fed94e516719 | 3 | #define FIFO_H |
chris215 | 0:fed94e516719 | 4 | |
chris215 | 0:fed94e516719 | 5 | #include <stdint.h> |
chris215 | 0:fed94e516719 | 6 | #include <string.h> |
chris215 | 0:fed94e516719 | 7 | |
chris215 | 0:fed94e516719 | 8 | template <typename T> |
chris215 | 0:fed94e516719 | 9 | class RingBuffer |
chris215 | 0:fed94e516719 | 10 | { |
chris215 | 0:fed94e516719 | 11 | private: |
chris215 | 0:fed94e516719 | 12 | T *m_buf; |
chris215 | 0:fed94e516719 | 13 | T *m_LatchedBuf; |
chris215 | 0:fed94e516719 | 14 | volatile uint32_t m_wloc; |
chris215 | 0:fed94e516719 | 15 | volatile uint32_t m_rloc; |
chris215 | 0:fed94e516719 | 16 | volatile uint32_t m_ActualCapacity; |
chris215 | 0:fed94e516719 | 17 | uint32_t m_size; |
chris215 | 0:fed94e516719 | 18 | bool m_SetBufferToReadOnly; //Put ring buffer into readonly mode, this way we can acces the underlying raw data with less |
chris215 | 0:fed94e516719 | 19 | //risk of behing overriten (Deprecated ... to be removed) |
chris215 | 0:fed94e516719 | 20 | public: |
chris215 | 0:fed94e516719 | 21 | RingBuffer(uint32_t size = 128); |
chris215 | 0:fed94e516719 | 22 | void clear(void); |
chris215 | 0:fed94e516719 | 23 | uint32_t getSize(); //Return the size of the ring buffer |
chris215 | 0:fed94e516719 | 24 | |
chris215 | 0:fed94e516719 | 25 | uint32_t getCapacity(); //Return the number of elements stored in the buffer |
chris215 | 0:fed94e516719 | 26 | |
chris215 | 0:fed94e516719 | 27 | |
chris215 | 0:fed94e516719 | 28 | T* LatchBuffer(void); |
chris215 | 0:fed94e516719 | 29 | T* LatchBufferPartial(uint32_t SizeToLatch); |
chris215 | 0:fed94e516719 | 30 | |
chris215 | 0:fed94e516719 | 31 | ~RingBuffer(); |
chris215 | 0:fed94e516719 | 32 | |
chris215 | 0:fed94e516719 | 33 | void put(T data); |
chris215 | 0:fed94e516719 | 34 | |
chris215 | 0:fed94e516719 | 35 | T get(void); |
chris215 | 0:fed94e516719 | 36 | |
chris215 | 0:fed94e516719 | 37 | |
chris215 | 0:fed94e516719 | 38 | |
chris215 | 0:fed94e516719 | 39 | }; |
chris215 | 0:fed94e516719 | 40 | |
chris215 | 0:fed94e516719 | 41 | #endif |