Buffer no longer volatile, not needed

This commit is contained in:
Geoffrey Merck 2020-05-10 00:03:32 +02:00
parent 55df5fe04c
commit 16c3d418eb
2 changed files with 19 additions and 8 deletions

View File

@ -47,15 +47,17 @@
template <typename TDATATYPE> template <typename TDATATYPE>
class CRingBuffer { class CRingBuffer {
public: public:
CRingBuffer(uint16_t length); CRingBuffer(uint16_t length = 370U);
uint16_t getSpace() const; uint16_t getSpace() const;
uint16_t getData() const; uint16_t getData() const;
bool put(const volatile TDATATYPE item) volatile; bool put(TDATATYPE item) volatile;
bool get(volatile TDATATYPE& item) volatile; bool get(TDATATYPE& item);
TDATATYPE get();
TDATATYPE peek() const; TDATATYPE peek() const;
@ -65,7 +67,7 @@ public:
private: private:
uint16_t m_length; uint16_t m_length;
volatile TDATATYPE* m_buffer; TDATATYPE* m_buffer;
volatile uint16_t m_head; volatile uint16_t m_head;
volatile uint16_t m_tail; volatile uint16_t m_tail;
volatile bool m_full; volatile bool m_full;

View File

@ -56,14 +56,14 @@ template <typename TDATATYPE> uint16_t CRingBuffer<TDATATYPE>::getData() const
return m_length - m_tail + m_head; return m_length - m_tail + m_head;
} }
template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::put(const TDATATYPE sample) volatile template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::put(TDATATYPE item) volatile
{ {
if (m_full) { if (m_full) {
m_overflow = true; m_overflow = true;
return false; return false;
} }
m_buffer[m_head] = sample; m_buffer[m_head] = item;
m_head++; m_head++;
if (m_head >= m_length) if (m_head >= m_length)
@ -80,7 +80,7 @@ template <typename TDATATYPE> TDATATYPE CRingBuffer<TDATATYPE>::peek() const
return m_buffer[m_tail]; return m_buffer[m_tail];
} }
template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::get(volatile TDATATYPE& item) volatile template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::get(TDATATYPE& item)
{ {
if (m_head == m_tail && !m_full) if (m_head == m_tail && !m_full)
return false; return false;
@ -111,4 +111,13 @@ template <typename TDATATYPE> void CRingBuffer<TDATATYPE>::reset()
m_tail = 0U; m_tail = 0U;
m_full = false; m_full = false;
m_overflow = false; m_overflow = false;
} }
template <typename TDATATYPE> TDATATYPE CRingBuffer<TDATATYPE>::get()
{
TDATATYPE value;
if(get(value))
return value;
//return 0U;
}