From 657e71238db319e8341a7e1ef3d450e1447103ed Mon Sep 17 00:00:00 2001 From: Tim Stewart Date: Sat, 28 Nov 2020 22:29:34 -0500 Subject: [PATCH 1/3] Detect full 48 bits of last data frame in a transmission While testing new support for DV Fast Data, I ran across a particular image that reliably generated a bit sequence that the MDMVM firmware interpreted as an end-of-transmission. I dug a bit and discovered that MMDVM only matches on 32 bits of the last data frame instead of the full 48 bits. See http://www.arrl.org/files/file/D-STAR.pdf section 2.1.2, item (6) for details. --- DStarRX.cpp | 20 +++++++++++++++++--- DStarRX.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/DStarRX.cpp b/DStarRX.cpp index f14f3fd..72b143e 100644 --- a/DStarRX.cpp +++ b/DStarRX.cpp @@ -41,8 +41,8 @@ const uint32_t DATA_SYNC_MASK = 0x00FFFFFFU; const uint8_t DATA_SYNC_ERRS = 2U; // D-Star bit order version of 0x55 0x55 0xC8 0x7A -const uint32_t END_SYNC_DATA = 0xAAAA135EU; -const uint32_t END_SYNC_MASK = 0xFFFFFFFFU; +const uint64_t END_SYNC_DATA = 0x0000AAAAAAAA135EU; +const uint64_t END_SYNC_MASK = 0x0000FFFFFFFFFFFFU; const uint8_t END_SYNC_ERRS = 1U; const uint8_t BIT_MASK_TABLE0[] = {0x7FU, 0xBFU, 0xDFU, 0xEFU, 0xF7U, 0xFBU, 0xFDU, 0xFEU}; @@ -242,6 +242,7 @@ m_pll(0U), m_prev(false), m_rxState(DSRXS_NONE), m_patternBuffer(0x00U), +m_patternBuffer64(0x00U), m_rxBuffer(), m_rxBufferBits(0U), m_dataBits(0U), @@ -263,6 +264,7 @@ void CDStarRX::reset() m_prev = false; m_rxState = DSRXS_NONE; m_patternBuffer = 0x00U; + m_patternBuffer64 = 0x00U; m_rxBufferBits = 0U; m_dataBits = 0U; m_rssiAccum = 0U; @@ -314,6 +316,10 @@ void CDStarRX::processNone(bool bit) if (bit) m_patternBuffer |= 0x01U; + m_patternBuffer64 <<= 1; + if (bit) + m_patternBuffer64 |= 0x01U; + // Fuzzy matching of the frame sync sequence if (countBits32((m_patternBuffer & FRAME_SYNC_MASK) ^ FRAME_SYNC_DATA) <= FRAME_SYNC_ERRS) { DEBUG1("DStarRX: found frame sync in None"); @@ -357,6 +363,10 @@ void CDStarRX::processHeader(bool bit) if (bit) m_patternBuffer |= 0x01U; + m_patternBuffer64 <<= 1; + if (bit) + m_patternBuffer64 |= 0x01U; + WRITE_BIT2(m_rxBuffer, m_rxBufferBits, bit); m_rxBufferBits++; @@ -389,11 +399,15 @@ void CDStarRX::processData(bool bit) if (bit) m_patternBuffer |= 0x01U; + m_patternBuffer64 <<= 1; + if (bit) + m_patternBuffer64 |= 0x01U; + WRITE_BIT2(m_rxBuffer, m_rxBufferBits, bit); m_rxBufferBits++; // Fuzzy matching of the end frame sequences - if (countBits32((m_patternBuffer & END_SYNC_MASK) ^ END_SYNC_DATA) <= END_SYNC_ERRS) { + if (countBits64((m_patternBuffer64 & END_SYNC_MASK) ^ END_SYNC_DATA) <= END_SYNC_ERRS) { DEBUG1("DStarRX: Found end sync in Data"); io.setDecode(false); diff --git a/DStarRX.h b/DStarRX.h index d636cde..cc327ce 100644 --- a/DStarRX.h +++ b/DStarRX.h @@ -41,6 +41,7 @@ private: bool m_prev; DSRX_STATE m_rxState; uint32_t m_patternBuffer; + uint64_t m_patternBuffer64; uint8_t m_rxBuffer[100U]; unsigned int m_rxBufferBits; unsigned int m_dataBits; From 9440b4311468bc34d6c33195dccafdf325e5a347 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 14 Dec 2020 09:45:53 +0000 Subject: [PATCH 2/3] Simplify the D-Star fast data support. --- DStarRX.cpp | 38 ++++++++++++-------------------------- DStarRX.h | 5 ++--- SerialPort.cpp | 2 +- 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/DStarRX.cpp b/DStarRX.cpp index 72b143e..86f7f31 100644 --- a/DStarRX.cpp +++ b/DStarRX.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2017 by Jonathan Naylor G4KLX + * Copyright (C) 2009-2017,2020 by Jonathan Naylor G4KLX * Copyright (C) 2017 by Andy Uribe CA6JAU * * This program is free software; you can redistribute it and/or modify @@ -31,13 +31,13 @@ const uint32_t INC = PLLINC / 32U; const unsigned int MAX_SYNC_BITS = 100U * DSTAR_DATA_LENGTH_BITS; // D-Star bit order version of 0x55 0x55 0x6E 0x0A -const uint32_t FRAME_SYNC_DATA = 0x00557650U; -const uint32_t FRAME_SYNC_MASK = 0x00FFFFFFU; +const uint64_t FRAME_SYNC_DATA = 0x0000000000557650U; +const uint64_t FRAME_SYNC_MASK = 0x0000000000FFFFFFU; const uint8_t FRAME_SYNC_ERRS = 2U; // D-Star bit order version of 0x55 0x2D 0x16 -const uint32_t DATA_SYNC_DATA = 0x00AAB468U; -const uint32_t DATA_SYNC_MASK = 0x00FFFFFFU; +const uint64_t DATA_SYNC_DATA = 0x0000000000AAB468U; +const uint64_t DATA_SYNC_MASK = 0x0000000000FFFFFFU; const uint8_t DATA_SYNC_ERRS = 2U; // D-Star bit order version of 0x55 0x55 0xC8 0x7A @@ -242,7 +242,6 @@ m_pll(0U), m_prev(false), m_rxState(DSRXS_NONE), m_patternBuffer(0x00U), -m_patternBuffer64(0x00U), m_rxBuffer(), m_rxBufferBits(0U), m_dataBits(0U), @@ -264,7 +263,6 @@ void CDStarRX::reset() m_prev = false; m_rxState = DSRXS_NONE; m_patternBuffer = 0x00U; - m_patternBuffer64 = 0x00U; m_rxBufferBits = 0U; m_dataBits = 0U; m_rssiAccum = 0U; @@ -316,12 +314,8 @@ void CDStarRX::processNone(bool bit) if (bit) m_patternBuffer |= 0x01U; - m_patternBuffer64 <<= 1; - if (bit) - m_patternBuffer64 |= 0x01U; - // Fuzzy matching of the frame sync sequence - if (countBits32((m_patternBuffer & FRAME_SYNC_MASK) ^ FRAME_SYNC_DATA) <= FRAME_SYNC_ERRS) { + if (countBits64((m_patternBuffer & FRAME_SYNC_MASK) ^ FRAME_SYNC_DATA) <= FRAME_SYNC_ERRS) { DEBUG1("DStarRX: found frame sync in None"); ::memset(m_rxBuffer, 0x00U, DSTAR_FEC_SECTION_LENGTH_BYTES); @@ -335,7 +329,7 @@ void CDStarRX::processNone(bool bit) } // Exact matching of the data sync bit sequence - if (countBits32((m_patternBuffer & DATA_SYNC_MASK) ^ DATA_SYNC_DATA) == 0U) { + if (countBits64((m_patternBuffer & DATA_SYNC_MASK) ^ DATA_SYNC_DATA) == 0U) { DEBUG1("DStarRX: found data sync in None"); io.setDecode(true); @@ -363,10 +357,6 @@ void CDStarRX::processHeader(bool bit) if (bit) m_patternBuffer |= 0x01U; - m_patternBuffer64 <<= 1; - if (bit) - m_patternBuffer64 |= 0x01U; - WRITE_BIT2(m_rxBuffer, m_rxBufferBits, bit); m_rxBufferBits++; @@ -399,15 +389,11 @@ void CDStarRX::processData(bool bit) if (bit) m_patternBuffer |= 0x01U; - m_patternBuffer64 <<= 1; - if (bit) - m_patternBuffer64 |= 0x01U; - WRITE_BIT2(m_rxBuffer, m_rxBufferBits, bit); m_rxBufferBits++; // Fuzzy matching of the end frame sequences - if (countBits64((m_patternBuffer64 & END_SYNC_MASK) ^ END_SYNC_DATA) <= END_SYNC_ERRS) { + if (countBits64((m_patternBuffer & END_SYNC_MASK) ^ END_SYNC_DATA) <= END_SYNC_ERRS) { DEBUG1("DStarRX: Found end sync in Data"); io.setDecode(false); @@ -422,7 +408,7 @@ void CDStarRX::processData(bool bit) // Fuzzy matching of the data sync bit sequence bool syncSeen = false; if (m_rxBufferBits >= (DSTAR_DATA_LENGTH_BITS - 3U)) { - if (countBits32((m_patternBuffer & DATA_SYNC_MASK) ^ DATA_SYNC_DATA) <= DATA_SYNC_ERRS) { + if (countBits64((m_patternBuffer & DATA_SYNC_MASK) ^ DATA_SYNC_DATA) <= DATA_SYNC_ERRS) { m_rxBufferBits = DSTAR_DATA_LENGTH_BITS; m_dataBits = MAX_SYNC_BITS; syncSeen = true; @@ -432,9 +418,9 @@ void CDStarRX::processData(bool bit) // Check to see if the sync is arriving late if (m_rxBufferBits == DSTAR_DATA_LENGTH_BITS && !syncSeen) { for (uint8_t i = 1U; i <= 3U; i++) { - uint32_t syncMask = DATA_SYNC_MASK >> i; - uint32_t syncData = DATA_SYNC_DATA >> i; - if (countBits32((m_patternBuffer & syncMask) ^ syncData) <= DATA_SYNC_ERRS) { + uint64_t syncMask = DATA_SYNC_MASK >> i; + uint64_t syncData = DATA_SYNC_DATA >> i; + if (countBits64((m_patternBuffer & syncMask) ^ syncData) <= DATA_SYNC_ERRS) { m_rxBufferBits -= i; break; } diff --git a/DStarRX.h b/DStarRX.h index cc327ce..1e1c4e5 100644 --- a/DStarRX.h +++ b/DStarRX.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2017,2020 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,8 +40,7 @@ private: uint32_t m_pll; bool m_prev; DSRX_STATE m_rxState; - uint32_t m_patternBuffer; - uint64_t m_patternBuffer64; + uint64_t m_patternBuffer; uint8_t m_rxBuffer[100U]; unsigned int m_rxBufferBits; unsigned int m_dataBits; diff --git a/SerialPort.cpp b/SerialPort.cpp index 17cb476..f47e01c 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -103,7 +103,7 @@ const uint8_t MMDVM_DEBUG5 = 0xF5U; #define HW_TYPE "MMDVM" #endif -#define DESCRIPTION "20200901 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)" +#define DESCRIPTION "20201214 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)" #if defined(GITVERSION) #define concat(h, a, b, c) h " " a " " b " GitID #" c "" From 7148cf9f7d62b0aa1edbad5b5078d96e2da35e5c Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 14 Dec 2020 09:46:53 +0000 Subject: [PATCH 3/3] Add I2C support. --- STM32F4XX_Lib | 2 +- STM32F7XX_Lib | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/STM32F4XX_Lib b/STM32F4XX_Lib index bcd346f..18aeb6e 160000 --- a/STM32F4XX_Lib +++ b/STM32F4XX_Lib @@ -1 +1 @@ -Subproject commit bcd346f53036ed0eab6643d662a410861655afe2 +Subproject commit 18aeb6ea3a236088fc9f376077c651098e3a495e diff --git a/STM32F7XX_Lib b/STM32F7XX_Lib index 2d5f423..6241f7c 160000 --- a/STM32F7XX_Lib +++ b/STM32F7XX_Lib @@ -1 +1 @@ -Subproject commit 2d5f4236fa5e9828beadbc72473293f25b3ad65e +Subproject commit 6241f7c05eeb6cf1ecd16ca0274bf310efee853f