Skip to content

Commit

Permalink
Full memory optimization for ring buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
juribeparada committed Jul 16, 2018
1 parent 1fec6e5 commit ab929d2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
6 changes: 3 additions & 3 deletions BitRB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ m_full(false),
m_overflow(false)
{
m_bits = new uint8_t[length / 8U];
m_control = new uint8_t[length];
m_control = new uint8_t[length / 8U];
}

uint16_t CBitRB::getSpace() const
Expand Down Expand Up @@ -74,7 +74,7 @@ bool CBitRB::put(uint8_t bit, uint8_t control)
}

WRITE_BIT1(m_bits, m_head, bit);
m_control[m_head] = control;
WRITE_BIT1(m_control, m_head, control);

m_head++;
if (m_head >= m_length)
Expand All @@ -92,7 +92,7 @@ bool CBitRB::get(uint8_t& bit, uint8_t& control)
return false;

bit = READ_BIT1(m_bits, m_tail);
control = m_control[m_tail];
control = READ_BIT1(m_control, m_tail);

m_full = false;

Expand Down
18 changes: 8 additions & 10 deletions DMRRX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,21 @@
#include "Globals.h"
#include "DMRRX.h"

CDMRRX::CDMRRX()
CDMRRX::CDMRRX() :
m_control_old(0U)
{
}

void CDMRRX::databit(bool bit, const uint8_t control)
{
switch (control) {
case MARK_SLOT1:
m_slotRX.start(false);
break;
case MARK_SLOT2:
if (control != m_control_old) {
m_control_old = control;
if (control)
m_slotRX.start(true);
break;
default:
break;
else
m_slotRX.start(false);
}

io.setDecode(m_slotRX.databit(bit));
}

Expand Down
1 change: 1 addition & 0 deletions DMRRX.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class CDMRRX {

private:
CDMRSlotRX m_slotRX;
uint8_t m_control_old;
};

#endif
Expand Down
18 changes: 11 additions & 7 deletions DMRTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ m_poBuffer(),
m_poLen(0U),
m_poPtr(0U),
m_frameCount(0U),
m_abort()
m_abort(),
m_control_old(0U)
{
::memcpy(m_newShortLC, EMPTY_SHORT_LC, 12U);
::memcpy(m_shortLC, EMPTY_SHORT_LC, 12U);
Expand Down Expand Up @@ -218,21 +219,24 @@ void CDMRTX::writeByte(uint8_t c, uint8_t control)
{
uint8_t bit;
uint8_t mask = 0x80U;
uint8_t control_tmp;
uint8_t control_tmp = m_control_old;

for (uint8_t i = 0U; i < 8U; i++, c <<= 1) {
if ((c & mask) == mask)
bit = 1U;
else
bit = 0U;

control_tmp = MARK_NONE;

if( i == 7U || i == 6U)
control_tmp = control;
if(i == 7U) {
if (control == MARK_SLOT2)
control_tmp = true;
else if (control == MARK_SLOT1)
control_tmp = false;

io.write(&bit, 1, &control_tmp);
m_control_old = control_tmp;
}

io.write(&bit, 1, &control_tmp);
}
}

Expand Down
1 change: 1 addition & 0 deletions DMRTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class CDMRTX {
uint16_t m_poPtr;
uint32_t m_frameCount;
bool m_abort[2U];
uint8_t m_control_old;

void createData(uint8_t slotIndex);
void createCACH(uint8_t txSlotIndex, uint8_t rxSlotIndex);
Expand Down

0 comments on commit ab929d2

Please sign in to comment.