Optimizing bit memory ring buffer

This commit is contained in:
Andy CA6JAU 2018-07-04 23:42:07 -04:00
parent 1791efe6a5
commit 2e2d2b3004
2 changed files with 12 additions and 7 deletions

View file

@ -21,6 +21,11 @@ Boston, MA 02110-1301, USA.
#include "BitRB.h"
const uint8_t BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U};
#define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7])
#define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7])
CBitRB::CBitRB(uint16_t length) :
m_length(length),
m_bits(NULL),
@ -30,8 +35,8 @@ m_tail(0U),
m_full(false),
m_overflow(false)
{
m_bits = new uint8_t[length];
m_control = new uint8_t[length];
m_bits = new uint8_t[length / 8U];
m_control = new uint8_t[length / 8U];
}
uint16_t CBitRB::getSpace() const
@ -68,8 +73,8 @@ bool CBitRB::put(uint8_t bit, uint8_t control)
return false;
}
m_bits[m_head] = bit;
m_control[m_head] = control;
WRITE_BIT1(m_bits, m_head, bit);
WRITE_BIT1(m_control, m_head, control);
m_head++;
if (m_head >= m_length)
@ -86,8 +91,8 @@ bool CBitRB::get(uint8_t& bit, uint8_t& control)
if (m_head == m_tail && !m_full)
return false;
bit = m_bits[m_tail];
control = m_control[m_tail];
bit = READ_BIT1(m_bits, m_tail);
control = READ_BIT1(m_control, m_tail);
m_full = false;

View file

@ -24,7 +24,7 @@
#define VER_MAJOR "1"
#define VER_MINOR "4"
#define VER_REV "0"
#define VER_REV "1"
#define VERSION_DATE "20180705"
#if defined(ZUMSPOT_ADF7021)