Ringbuffer class

RingBuffer.h

Committer:
chris215
Date:
2016-01-11
Revision:
0:fed94e516719
Child:
1:fa4c2377a741

File content as of revision 0:fed94e516719:


#ifndef FIFO_H
#define FIFO_H

#include <stdint.h>
#include <string.h>

template <typename T>
class RingBuffer
{
    private:
    T   *m_buf;
    T   *m_LatchedBuf;
    volatile uint32_t   m_wloc;
    volatile uint32_t   m_rloc;
    volatile uint32_t   m_ActualCapacity;
    uint32_t            m_size;
    bool                m_SetBufferToReadOnly;      //Put ring buffer into readonly mode, this way we can acces the underlying raw data with less
                                                    //risk of behing overriten (Deprecated ... to be removed)                                            
    public:
    RingBuffer(uint32_t size = 128);
    void clear(void);
    uint32_t getSize(); //Return the size of the ring buffer
    
    uint32_t getCapacity(); //Return the number of elements stored in the buffer
    
    
    T* LatchBuffer(void);
    T* LatchBufferPartial(uint32_t SizeToLatch);
    
    ~RingBuffer();
    
    void put(T data);
    
    T get(void);
    
    
    
};

#endif