Ringbuffer class

Committer:
chris215
Date:
Wed Jan 13 05:31:28 2016 +0000
Revision:
2:959aad917307
Parent:
1:fa4c2377a741
Removed templates usage and moved to byte pointers. This makes the ring buffer more generic and removes the requirement to know all templates in .cpp

Who changed what in which revision?

UserRevisionLine numberNew 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 2:959aad917307 8 class RingBuffer
chris215 2:959aad917307 9 {
chris215 2:959aad917307 10 private:
chris215 2:959aad917307 11 uint8_t* m_buf;
chris215 2:959aad917307 12 uint8_t* m_latchingbuffer;
chris215 2:959aad917307 13 volatile uint32_t m_wloc;
chris215 2:959aad917307 14 volatile uint32_t m_rloc;
chris215 2:959aad917307 15 volatile uint32_t m_ActualCapacity;
chris215 2:959aad917307 16 uint32_t m_size;
chris215 2:959aad917307 17 uint32_t m_ElementSize;
chris215 2:959aad917307 18
chris215 2:959aad917307 19 public:
chris215 2:959aad917307 20 RingBuffer(uint32_t NumberOfElements = 128,uint32_t SizeOfElement = 1);
chris215 2:959aad917307 21 ~RingBuffer();
chris215 2:959aad917307 22
chris215 2:959aad917307 23 void put(void* data);
chris215 2:959aad917307 24 int get(void* data);
chris215 2:959aad917307 25
chris215 2:959aad917307 26 void clear(void);
chris215 2:959aad917307 27 uint32_t GetSize(){return m_size;}; //Return the size of the ring buffer
chris215 2:959aad917307 28
chris215 2:959aad917307 29 uint32_t GetCapacity(){return m_ActualCapacity;}; //Return the number of elements stored in the buffer
chris215 2:959aad917307 30
chris215 2:959aad917307 31 uint32_t GetElementSize(){return m_ElementSize;};
chris215 2:959aad917307 32
chris215 2:959aad917307 33 void LatchBuffer(void* DstBuffer);
chris215 2:959aad917307 34 };
chris215 2:959aad917307 35 /*
chris215 0:fed94e516719 36 template <typename T>
chris215 0:fed94e516719 37 class RingBuffer
chris215 0:fed94e516719 38 {
chris215 0:fed94e516719 39 private:
chris215 0:fed94e516719 40 T *m_buf;
chris215 0:fed94e516719 41 T *m_LatchedBuf;
chris215 0:fed94e516719 42 volatile uint32_t m_wloc;
chris215 0:fed94e516719 43 volatile uint32_t m_rloc;
chris215 0:fed94e516719 44 volatile uint32_t m_ActualCapacity;
chris215 0:fed94e516719 45 uint32_t m_size;
chris215 0:fed94e516719 46 bool m_SetBufferToReadOnly; //Put ring buffer into readonly mode, this way we can acces the underlying raw data with less
chris215 0:fed94e516719 47 //risk of behing overriten (Deprecated ... to be removed)
chris215 0:fed94e516719 48 public:
chris215 0:fed94e516719 49 RingBuffer(uint32_t size = 128);
chris215 0:fed94e516719 50 void clear(void);
chris215 0:fed94e516719 51 uint32_t getSize(); //Return the size of the ring buffer
chris215 0:fed94e516719 52
chris215 0:fed94e516719 53 uint32_t getCapacity(); //Return the number of elements stored in the buffer
chris215 0:fed94e516719 54
chris215 0:fed94e516719 55
chris215 1:fa4c2377a741 56 void LatchBuffer(T* DstBuffer);
chris215 0:fed94e516719 57
chris215 0:fed94e516719 58 ~RingBuffer();
chris215 0:fed94e516719 59
chris215 0:fed94e516719 60 void put(T data);
chris215 0:fed94e516719 61
chris215 0:fed94e516719 62 T get(void);
chris215 0:fed94e516719 63
chris215 0:fed94e516719 64
chris215 0:fed94e516719 65
chris215 0:fed94e516719 66 };
chris215 2:959aad917307 67 */
chris215 0:fed94e516719 68 #endif