From b8457aed4c6f3432ac19e750f05c7b42a5a46930 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 6 Jun 2016 18:04:03 +0100 Subject: [PATCH] Disassociate the ADC overload detection from the DCD LED. --- DMRSlotRX.cpp | 29 +++++++++++++++++++++-------- DMRSlotRX.h | 1 + DStarRX.cpp | 7 +++++++ IO.cpp | 8 +++++++- IO.h | 2 ++ YSFRX.cpp | 4 ++++ 6 files changed, 42 insertions(+), 9 deletions(-) diff --git a/DMRSlotRX.cpp b/DMRSlotRX.cpp index eee9088..353b489 100644 --- a/DMRSlotRX.cpp +++ b/DMRSlotRX.cpp @@ -48,6 +48,7 @@ m_buffer(), m_bitPtr(0U), m_dataPtr(0U), m_syncPtr(0U), +m_startPtr(0U), m_endPtr(NOENDPTR), m_delayPtr(0U), m_maxCorr(0), @@ -83,6 +84,7 @@ void CDMRSlotRX::reset() m_control = CONTROL_NONE; m_syncCount = 0U; m_state = DMRRXS_NONE; + m_startPtr = 0U; m_endPtr = NOENDPTR; } @@ -92,6 +94,15 @@ bool CDMRSlotRX::processSample(q15_t sample) if (m_delayPtr < m_delay) return m_state != DMRRXS_NONE; + if (m_state != DMRRXS_NONE) { + if (m_dataPtr > m_startPtr && m_dataPtr < m_endPtr) + io.setADCDetection(true); + else + io.setADCDetection(false); + } else { + io.setADCDetection(false); + } + // Ensure that the buffer doesn't overflow if (m_dataPtr > m_endPtr || m_dataPtr >= 900U) return m_state != DMRRXS_NONE; @@ -285,10 +296,11 @@ void CDMRSlotRX::correlateSync(bool first) m_averagePtr = 0U; } - m_maxCorr = corr; - m_control = CONTROL_DATA; - m_syncPtr = m_dataPtr; - m_endPtr = m_dataPtr + DMR_SLOT_TYPE_LENGTH_SAMPLES / 2U + DMR_INFO_LENGTH_SAMPLES / 2U - 1U; + m_maxCorr = corr; + m_control = CONTROL_DATA; + m_syncPtr = m_dataPtr; + m_startPtr = m_dataPtr - DMR_SLOT_TYPE_LENGTH_SAMPLES / 2U - DMR_INFO_LENGTH_SAMPLES / 2U; + m_endPtr = m_dataPtr + DMR_SLOT_TYPE_LENGTH_SAMPLES / 2U + DMR_INFO_LENGTH_SAMPLES / 2U - 1U; } } else { // if (voice) uint8_t errs = 0U; @@ -309,10 +321,11 @@ void CDMRSlotRX::correlateSync(bool first) m_averagePtr = 0U; } - m_maxCorr = corr; - m_control = CONTROL_VOICE; - m_syncPtr = m_dataPtr; - m_endPtr = m_dataPtr + DMR_SLOT_TYPE_LENGTH_SAMPLES / 2U + DMR_INFO_LENGTH_SAMPLES / 2U - 1U; + m_maxCorr = corr; + m_control = CONTROL_VOICE; + m_syncPtr = m_dataPtr; + m_startPtr = m_dataPtr - DMR_SLOT_TYPE_LENGTH_SAMPLES / 2U - DMR_INFO_LENGTH_SAMPLES / 2U; + m_endPtr = m_dataPtr + DMR_SLOT_TYPE_LENGTH_SAMPLES / 2U + DMR_INFO_LENGTH_SAMPLES / 2U - 1U; } } } diff --git a/DMRSlotRX.h b/DMRSlotRX.h index 6c3c446..994839f 100644 --- a/DMRSlotRX.h +++ b/DMRSlotRX.h @@ -48,6 +48,7 @@ private: uint16_t m_bitPtr; uint16_t m_dataPtr; uint16_t m_syncPtr; + uint16_t m_startPtr; uint16_t m_endPtr; uint16_t m_delayPtr; q31_t m_maxCorr; diff --git a/DStarRX.cpp b/DStarRX.cpp index d0cb104..e2ebc60 100644 --- a/DStarRX.cpp +++ b/DStarRX.cpp @@ -333,7 +333,9 @@ void CDStarRX::processNone(bool bit) // Exact matching of the data sync bit sequence if (countBits32((m_patternBuffer & DATA_SYNC_MASK) ^ DATA_SYNC_DATA) == 0U) { DEBUG1("DStarRX: found data sync in None"); + io.setDecode(true); + io.setADCDetection(true); #if defined(WANT_DEBUG) q15_t min = 16000; @@ -374,6 +376,7 @@ void CDStarRX::processHeader(bool bit) bool ok = rxHeader(m_rxBuffer, header); if (ok) { io.setDecode(true); + io.setADCDetection(true); serial.writeDStarHeader(header, DSTAR_HEADER_LENGTH_BYTES); @@ -401,7 +404,9 @@ void CDStarRX::processData(bool bit) // Fuzzy matching of the end frame sequences if (countBits32((m_patternBuffer & END_SYNC_MASK) ^ END_SYNC_DATA) <= END_SYNC_ERRS) { DEBUG1("DStarRX: Found end sync in Data"); + io.setDecode(false); + io.setADCDetection(false); serial.writeDStarEOT(); @@ -440,7 +445,9 @@ void CDStarRX::processData(bool bit) m_dataBits--; if (m_dataBits == 0U) { DEBUG1("DStarRX: data sync timed out, lost lock"); + io.setDecode(false); + io.setADCDetection(false); serial.writeDStarLost(); diff --git a/IO.cpp b/IO.cpp index 17aa528..c0343c6 100644 --- a/IO.cpp +++ b/IO.cpp @@ -120,6 +120,7 @@ m_txLevel(128 * 128), m_ledCount(0U), m_ledValue(true), m_dcd(false), +m_detect(false), m_overflow(0U), m_overcount(0U), m_count(0U), @@ -299,7 +300,7 @@ void CIO::process() m_rxBuffer.get(sample, control[i]); // Detect ADC overflow - if (m_dcd && (sample == 0U || sample == 4095U)) + if (m_detect && (sample == 0U || sample == 4095U)) m_overflow++; m_overcount++; @@ -449,6 +450,11 @@ void CIO::setDecode(bool dcd) m_dcd = dcd; } +void CIO::setADCDetection(bool detect) +{ + m_detect = detect; +} + void CIO::setMode() { #if !defined(__MBED__) diff --git a/IO.h b/IO.h index bd8d985..43f0a2d 100644 --- a/IO.h +++ b/IO.h @@ -36,6 +36,7 @@ public: uint16_t getSpace() const; void setDecode(bool dcd); + void setADCDetection(bool detect); void setMode(); void interrupt(); @@ -82,6 +83,7 @@ private: bool m_ledValue; bool m_dcd; + bool m_detect; uint16_t m_overflow; uint16_t m_overcount; diff --git a/YSFRX.cpp b/YSFRX.cpp index 4a6849d..4c1b0a1 100644 --- a/YSFRX.cpp +++ b/YSFRX.cpp @@ -167,7 +167,9 @@ void CYSFRX::processNone(q15_t sample) m_lostCount = MAX_SYNC_FRAMES; m_bufferPtr = YSF_SYNC_LENGTH_BITS; m_state = YSFRXS_DATA; + io.setDecode(true); + io.setADCDetection(true); } } @@ -226,7 +228,9 @@ void CYSFRX::processData(q15_t sample) m_lostCount--; if (m_lostCount == 0U) { DEBUG1("YSFRX: sync timed out, lost lock"); + io.setDecode(false); + io.setADCDetection(false); serial.writeYSFLost();