mirror of
https://github.com/juribeparada/MMDVM_HS.git
synced 2025-12-06 07:12:08 +01:00
Optimizing memory for bit ring buffer
This commit is contained in:
parent
1f2ae86612
commit
1fec6e5f77
13
BitRB.cpp
13
BitRB.cpp
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
TX fifo control - Copyright (C) KI6ZUM 2015
|
TX fifo control - Copyright (C) KI6ZUM 2015
|
||||||
Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
||||||
Copyright (C) 2016,2017 by Andy Uribe CA6JAU
|
Copyright (C) 2016,2017,2018 by Andy Uribe CA6JAU
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Library General Public
|
modify it under the terms of the GNU Library General Public
|
||||||
|
|
@ -21,6 +21,11 @@ Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
#include "BitRB.h"
|
#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]) >> (7 - ((i)&7)))
|
||||||
|
|
||||||
CBitRB::CBitRB(uint16_t length) :
|
CBitRB::CBitRB(uint16_t length) :
|
||||||
m_length(length),
|
m_length(length),
|
||||||
m_bits(NULL),
|
m_bits(NULL),
|
||||||
|
|
@ -30,7 +35,7 @@ m_tail(0U),
|
||||||
m_full(false),
|
m_full(false),
|
||||||
m_overflow(false)
|
m_overflow(false)
|
||||||
{
|
{
|
||||||
m_bits = new uint8_t[length];
|
m_bits = new uint8_t[length / 8U];
|
||||||
m_control = new uint8_t[length];
|
m_control = new uint8_t[length];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,7 +73,7 @@ bool CBitRB::put(uint8_t bit, uint8_t control)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_bits[m_head] = bit;
|
WRITE_BIT1(m_bits, m_head, bit);
|
||||||
m_control[m_head] = control;
|
m_control[m_head] = control;
|
||||||
|
|
||||||
m_head++;
|
m_head++;
|
||||||
|
|
@ -86,7 +91,7 @@ bool CBitRB::get(uint8_t& bit, uint8_t& control)
|
||||||
if (m_head == m_tail && !m_full)
|
if (m_head == m_tail && !m_full)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bit = m_bits[m_tail];
|
bit = READ_BIT1(m_bits, m_tail);
|
||||||
control = m_control[m_tail];
|
control = m_control[m_tail];
|
||||||
|
|
||||||
m_full = false;
|
m_full = false;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue