From d9b5f5753eea0adafad0a83924a0734f5cdb92ad Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Thu, 14 Jan 2016 19:15:39 +0000 Subject: [PATCH] Set up ring buffer overflow signalling and a little debugging. --- DMRIdleRX.cpp | 2 +- DMRSlotRX.cpp | 5 +++++ IO.cpp | 10 ++++++++++ IO.h | 5 ++++- SampleRB.cpp | 18 +++++++++++++++--- SampleRB.h | 3 +++ SerialPort.cpp | 8 +++++++- 7 files changed, 45 insertions(+), 6 deletions(-) diff --git a/DMRIdleRX.cpp b/DMRIdleRX.cpp index 039d720..5b4adbd 100644 --- a/DMRIdleRX.cpp +++ b/DMRIdleRX.cpp @@ -112,7 +112,7 @@ void CDMRIdleRX::processSample(q15_t sample) errs += countBits8((sync[i] & DMR_SYNC_BYTES_MASK[i]) ^ DMR_MS_DATA_SYNC_BYTES[i]); if (errs <= MAX_SYNC_BYTES_ERRS) { - DEBUG4("DMRIdleRX: data sync found pos/centre/threshold", m_dataPtr, centre, threshold); + DEBUG3("DMRIdleRX: data sync found centre/threshold", centre, threshold); m_maxCorr = corr; m_centre = centre; m_threshold = threshold; diff --git a/DMRSlotRX.cpp b/DMRSlotRX.cpp index 577e12e..2545a1d 100644 --- a/DMRSlotRX.cpp +++ b/DMRSlotRX.cpp @@ -246,6 +246,11 @@ void CDMRSlotRX::correlateSync(q15_t sample) void CDMRSlotRX::samplesToBits(uint16_t start, uint8_t count, uint8_t* buffer, uint16_t offset, q15_t centre, q15_t threshold) { for (uint8_t i = 0U; i < count; i++, start += DMR_RADIO_SYMBOL_LENGTH) { + if (m_control == 0x20U || m_control == 0x40U) { + if (i == 77U) + DEBUG4("DMRSlotRX: slot/frame pos/sample pos", m_slot ? 2U : 1U, i, start); + } + q15_t sample = m_buffer[start] - centre; if (sample < -threshold) { diff --git a/IO.cpp b/IO.cpp index d6d6e21..cd88049 100644 --- a/IO.cpp +++ b/IO.cpp @@ -401,3 +401,13 @@ bool CIO::hasADCOverflow() return overflow; } +bool CIO::hasTXOverflow() +{ + return m_txBuffer.hasOverflowed(); +} + +bool CIO::hasRXOverflow() +{ + return m_rxBuffer.hasOverflowed(); +} + diff --git a/IO.h b/IO.h index f4cbff9..ed0905b 100644 --- a/IO.h +++ b/IO.h @@ -41,7 +41,10 @@ public: void setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rxLevel, uint8_t txLevel); - bool hasADCOverflow(); + bool hasADCOverflow(); + + bool hasTXOverflow(); + bool hasRXOverflow(); private: #if defined(__MBED__) diff --git a/SampleRB.cpp b/SampleRB.cpp index ff1a7ae..8095d41 100644 --- a/SampleRB.cpp +++ b/SampleRB.cpp @@ -27,7 +27,8 @@ m_samples(NULL), m_control(NULL), m_head(0U), m_tail(0U), -m_full(false) +m_full(false), +m_overflow(false) { m_samples = new uint16_t[length]; m_control = new uint8_t[length]; @@ -65,8 +66,10 @@ void CSampleRB::put(uint16_t sample, uint8_t control) if (m_head >= m_length) m_head = 0U; - if (m_head == m_tail) - m_full = true; + if (m_head == m_tail) { + m_overflow = true; + m_full = true; + } } void CSampleRB::get(uint16_t& sample, uint8_t& control) @@ -81,3 +84,12 @@ void CSampleRB::get(uint16_t& sample, uint8_t& control) m_tail = 0U; } +bool CSampleRB::hasOverflowed() +{ + bool overflow = m_overflow; + + m_overflow = false; + + return overflow; +} + diff --git a/SampleRB.h b/SampleRB.h index 0ac2fbe..49a0207 100644 --- a/SampleRB.h +++ b/SampleRB.h @@ -39,6 +39,8 @@ public: void get(uint16_t& sample, uint8_t& control); + bool hasOverflowed(); + private: uint16_t m_length; volatile uint16_t* m_samples; @@ -46,6 +48,7 @@ private: volatile uint16_t m_head; volatile uint16_t m_tail; volatile bool m_full; + bool m_overflow; }; #endif diff --git a/SerialPort.cpp b/SerialPort.cpp index 9f32de8..d176cff 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -56,7 +56,7 @@ const uint8_t MMDVM_DEBUG4 = 0xF4U; const uint8_t MMDVM_DEBUG5 = 0xF5U; const uint8_t MMDVM_SAMPLES = 0xF8U; -const uint8_t HARDWARE[] = "MMDVM 20160113 (D-Star/DMR/System Fusion)"; +const uint8_t HARDWARE[] = "MMDVM 20160114 (D-Star/DMR/System Fusion)"; const uint8_t PROTOCOL_VERSION = 1U; @@ -120,6 +120,12 @@ void CSerialPort::getStatus() const if (io.hasADCOverflow()) reply[5U] |= 0x02U; + if (io.hasRXOverflow()) + reply[5U] |= 0x04U; + + if (io.hasTXOverflow()) + reply[5U] |= 0x08U; + if (m_dstarEnable) reply[6U] = dstarTX.getSpace(); else