From 4feca3c5b7d320200e6d35be6c7f4428990f304b Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 3 May 2020 13:08:33 +0100 Subject: [PATCH 01/10] Clock the timers seperately. --- FM.cpp | 29 +++++++++++++++++------------ FM.h | 4 +++- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/FM.cpp b/FM.cpp index e843996..5a1ca00 100644 --- a/FM.cpp +++ b/FM.cpp @@ -53,6 +53,8 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length) if (!m_useCOS) cos = true; + clock(length); + uint8_t i = 0U; for (; i < length; i++) { q15_t currentSample = samples[i];//save to a local variable to avoid indirection on every access @@ -65,20 +67,20 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length) } else if (CTCSS_READY(ctcssState) && m_modemState != STATE_FM) { //we had enough samples for CTCSS and we are in some other mode than FM bool validCTCSS = CTCSS_VALID(ctcssState); - stateMachine(validCTCSS && cos, i + 1U); + stateMachine(validCTCSS && cos); if (m_modemState != STATE_FM) continue; } else if (CTCSS_READY(ctcssState) && m_modemState == STATE_FM) { //We had enough samples for CTCSS and we are in FM mode, trigger the state machine bool validCTCSS = CTCSS_VALID(ctcssState); - stateMachine(validCTCSS && cos, i + 1U); + stateMachine(validCTCSS && cos); if (m_modemState != STATE_FM) break; } else if (CTCSS_NOT_READY(ctcssState) && m_modemState == STATE_FM && i == length - 1) { //Not enough samples for CTCSS but we already are in FM, trigger the state machine //but do not trigger the state machine on every single sample, save CPU! bool validCTCSS = CTCSS_VALID(ctcssState); - stateMachine(validCTCSS && cos, i + 1U); + stateMachine(validCTCSS && cos); } // Only let audio through when relaying audio @@ -182,16 +184,8 @@ uint8_t CFM::setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFreque return m_ctcssTX.setParams(ctcssFrequency, ctcssLevel); } -void CFM::stateMachine(bool validSignal, uint8_t length) +void CFM::stateMachine(bool validSignal) { - m_callsignTimer.clock(length); - m_timeoutTimer.clock(length); - m_holdoffTimer.clock(length); - m_kerchunkTimer.clock(length); - m_ackMinTimer.clock(length); - m_ackDelayTimer.clock(length); - m_hangTimer.clock(length); - switch (m_state) { case FS_LISTENING: listeningState(validSignal); @@ -232,6 +226,17 @@ void CFM::stateMachine(bool validSignal, uint8_t length) } } +void CFM::clock(uint8_t length) +{ + m_callsignTimer.clock(length); + m_timeoutTimer.clock(length); + m_holdoffTimer.clock(length); + m_kerchunkTimer.clock(length); + m_ackMinTimer.clock(length); + m_ackDelayTimer.clock(length); + m_hangTimer.clock(length); +} + void CFM::listeningState(bool validSignal) { if (validSignal) { diff --git a/FM.h b/FM.h index a852a80..9bf821c 100644 --- a/FM.h +++ b/FM.h @@ -83,7 +83,7 @@ private: q15_t m_rfAudioBoost; CFMDownsampler m_downsampler; - void stateMachine(bool validSignal, uint8_t length); + void stateMachine(bool validSignal); void listeningState(bool validSignal); void kerchunkState(bool validSignal); void relayingState(bool validSignal); @@ -92,6 +92,8 @@ private: void timeoutWaitState(bool validSignal); void hangState(bool validSignal); + void clock(uint8_t length); + void sendCallsign(); void beginRelaying(); }; From 2d876b8d8e29b45b42ca7d30dad12584f3744742 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Sun, 3 May 2020 15:36:10 +0200 Subject: [PATCH 02/10] Fix Fancy LED effect accessing unused ports --- IOSTM_CMSIS.cpp | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/IOSTM_CMSIS.cpp b/IOSTM_CMSIS.cpp index e3763b4..17e6518 100644 --- a/IOSTM_CMSIS.cpp +++ b/IOSTM_CMSIS.cpp @@ -158,16 +158,29 @@ void GPIOConfigPin(GPIO_TypeDef *port_ptr, uint32_t pin, uint32_t mode_cnf_value #if defined(STM32F1_POG) void FancyLEDEffect() { - bitband_t foo[] = {&BB_LED, &BB_COSLED, &BB_PTT, &BB_DMR, &BB_DSTAR, &BB_YSF, &BB_P25, &BB_NXDN, &BB_POCSAG, &BB_FM}; - - for(int i=0; i<10; i++){ - *foo[i] = 0x01; + int ledCount = 10; + + bitband_t foo[] = {&BB_LED, &BB_COSLED, &BB_PTT, &BB_DMR, &BB_DSTAR, &BB_YSF, &BB_P25, NULL, NULL, NULL}; +#if !defined(USE_ALTERNATE_NXDN_LEDS) + foo_[7] = &BB_NXDN; +#endif +#if !defined(USE_ALTERNATE_POCSAG_LEDS) + foo__[8] = &BB_POCSAG; +#endif +#if !defined(USE_ALTERNATE_FM_LEDS) + foo__[9] = &BB_FM; +#endif + + for(int i=0; iODR, PIN_USART1_TXD)) = 0x00; delay(SystemCoreClock/1000*100); - for(int i=0; i<7; i++){ - *foo[i] = 0x00; + for(int i=0; iODR, PIN_USART1_TXD)) = 0x01; delay(SystemCoreClock/1000*20); @@ -176,18 +189,22 @@ void FancyLEDEffect() *((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x01; *foo[0] = 0x01; - for(int i=1; i<10; i++){ + for(int i=1; i=0; i--){ + for(int i=ledCount - 2; i>=0; i--) { delay(SystemCoreClock/1000*10); - *foo[i+1] = 0x00; - *foo[i] = 0x01; + if (foo[i+1] != NULL) + *foo[i+1] = 0x00; + if (foo[i] != NULL) + *foo[i] = 0x01; } delay(SystemCoreClock/1000*10); - *foo[5+1-6] = 0x00; + *foo[0] = 0x00; *((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x00; delay(SystemCoreClock/1000*10); *((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x01; From 5e8556520818d339e8175d35ef16e12f24798906 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 4 May 2020 15:26:17 +0200 Subject: [PATCH 03/10] Fix compile isue --- IOSTM_CMSIS.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/IOSTM_CMSIS.cpp b/IOSTM_CMSIS.cpp index 17e6518..4d36e9f 100644 --- a/IOSTM_CMSIS.cpp +++ b/IOSTM_CMSIS.cpp @@ -162,13 +162,13 @@ void FancyLEDEffect() bitband_t foo[] = {&BB_LED, &BB_COSLED, &BB_PTT, &BB_DMR, &BB_DSTAR, &BB_YSF, &BB_P25, NULL, NULL, NULL}; #if !defined(USE_ALTERNATE_NXDN_LEDS) - foo_[7] = &BB_NXDN; + foo[7] = &BB_NXDN; #endif #if !defined(USE_ALTERNATE_POCSAG_LEDS) - foo__[8] = &BB_POCSAG; + foo[8] = &BB_POCSAG; #endif #if !defined(USE_ALTERNATE_FM_LEDS) - foo__[9] = &BB_FM; + foo[9] = &BB_FM; #endif for(int i=0; i Date: Mon, 4 May 2020 16:43:08 +0200 Subject: [PATCH 04/10] Change FM LED Pin --- IOSTM_CMSIS.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IOSTM_CMSIS.cpp b/IOSTM_CMSIS.cpp index 17e6518..4418d1a 100644 --- a/IOSTM_CMSIS.cpp +++ b/IOSTM_CMSIS.cpp @@ -85,7 +85,7 @@ USART1_RXD PA10 input (AF) #define PIN_POCSAG 11 #define PORT_POCSAG GPIOB #define BB_POCSAG *((bitband_t)BITBAND_PERIPH(&PORT_POCSAG->ODR, PIN_POCSAG)) -#define PIN_FM 12 +#define PIN_FM 14 #define PORT_FM GPIOB #define BB_FM *((bitband_t)BITBAND_PERIPH(&PORT_FM->ODR, PIN_FM)) From 87feadd4514548c3d6c27621ba522a084ce12a85 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 4 May 2020 19:12:45 +0200 Subject: [PATCH 05/10] Better LED management --- IOSTM_CMSIS.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/IOSTM_CMSIS.cpp b/IOSTM_CMSIS.cpp index 938a6db..6cd92a2 100644 --- a/IOSTM_CMSIS.cpp +++ b/IOSTM_CMSIS.cpp @@ -160,15 +160,21 @@ void FancyLEDEffect() { int ledCount = 10; - bitband_t foo[] = {&BB_LED, &BB_COSLED, &BB_PTT, &BB_DMR, &BB_DSTAR, &BB_YSF, &BB_P25, NULL, NULL, NULL}; -#if !defined(USE_ALTERNATE_NXDN_LEDS) - foo[7] = &BB_NXDN; + bitband_t foo[] = {&BB_LED, &BB_COSLED, &BB_PTT, &BB_DMR, &BB_DSTAR, &BB_YSF, &BB_P25, +#if defined(USE_ALTERNATE_NXDN_LEDS) + NULL, +#else + &BB_NXDN, #endif -#if !defined(USE_ALTERNATE_POCSAG_LEDS) - foo[8] = &BB_POCSAG; +#if defined(USE_ALTERNATE_POCSAG_LEDS) + NULL, +#else + &BB_POCSAG, #endif -#if !defined(USE_ALTERNATE_FM_LEDS) - foo[9] = &BB_FM; +#if defined(USE_ALTERNATE_FM_LEDS) + NULL}; +#else + &BB_FM}; #endif for(int i=0; i Date: Mon, 4 May 2020 22:06:57 +0100 Subject: [PATCH 06/10] Calculate the AckMinTime accurately. --- FM.cpp | 4 +++- SerialPort.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/FM.cpp b/FM.cpp index 5a1ca00..d3fa0ab 100644 --- a/FM.cpp +++ b/FM.cpp @@ -160,7 +160,9 @@ uint8_t CFM::setCallsign(const char* callsign, uint8_t speed, uint16_t frequency uint8_t CFM::setAck(const char* rfAck, uint8_t speed, uint16_t frequency, uint8_t minTime, uint16_t delay, uint8_t level) { m_ackDelayTimer.setTimeout(0U, delay); - m_ackMinTimer.setTimeout(minTime, 0U); + + if (minTime > 0U) + m_ackMinTimer.setTimeout(minTime, delay); return m_rfAck.setParams(rfAck, speed, frequency, level, level); } diff --git a/SerialPort.cpp b/SerialPort.cpp index 8d6a6f9..2922b57 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -101,7 +101,7 @@ const uint8_t MMDVM_DEBUG5 = 0xF5U; #define HW_TYPE "MMDVM" #endif -#define DESCRIPTION "20200502 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)" +#define DESCRIPTION "20200504 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)" #if defined(GITVERSION) #define concat(h, a, b, c) h " " a " " b " GitID #" c "" From aa7a484c7a5bc38da9c10592798083510dcfaeb7 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 4 May 2020 22:18:51 +0100 Subject: [PATCH 07/10] Allow the start callsign to occur when the kerchunk timer has latched. --- FM.cpp | 10 +++++++++- FM.h | 3 ++- SerialPort.cpp | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/FM.cpp b/FM.cpp index d3fa0ab..8d31e37 100644 --- a/FM.cpp +++ b/FM.cpp @@ -29,6 +29,7 @@ m_timeoutTone(), m_state(FS_LISTENING), m_callsignAtStart(false), m_callsignAtEnd(false), +m_callsignAtLatch(false), m_callsignTimer(), m_timeoutTimer(), m_holdoffTimer(), @@ -140,10 +141,11 @@ void CFM::reset() m_timeoutTone.stop(); } -uint8_t CFM::setCallsign(const char* callsign, uint8_t speed, uint16_t frequency, uint8_t time, uint8_t holdoff, uint8_t highLevel, uint8_t lowLevel, bool callsignAtStart, bool callsignAtEnd) +uint8_t CFM::setCallsign(const char* callsign, uint8_t speed, uint16_t frequency, uint8_t time, uint8_t holdoff, uint8_t highLevel, uint8_t lowLevel, bool callsignAtStart, bool callsignAtEnd, bool callsignAtLatch) { m_callsignAtStart = callsignAtStart; m_callsignAtEnd = callsignAtEnd; + m_callsignAtLatch = callsignAtLatch; uint16_t holdoffTime = holdoff * 60U; uint16_t callsignTime = time * 60U; @@ -246,6 +248,8 @@ void CFM::listeningState(bool validSignal) DEBUG1("State to KERCHUNK"); m_state = FS_KERCHUNK; m_kerchunkTimer.start(); + if (m_callsignAtStart && !m_callsignAtLatch) + sendCallsign(); } else { DEBUG1("State to RELAYING"); m_state = FS_RELAYING; @@ -269,6 +273,10 @@ void CFM::kerchunkState(bool validSignal) DEBUG1("State to RELAYING"); m_state = FS_RELAYING; m_kerchunkTimer.stop(); + if (m_callsignAtStart && m_callsignAtLatch) { + sendCallsign(); + m_callsignTimer.start(); + } } } else { DEBUG1("State to LISTENING"); diff --git a/FM.h b/FM.h index 9bf821c..7e2e79f 100644 --- a/FM.h +++ b/FM.h @@ -53,7 +53,7 @@ public: void reset(); - uint8_t setCallsign(const char* callsign, uint8_t speed, uint16_t frequency, uint8_t time, uint8_t holdoff, uint8_t highLevel, uint8_t lowLevel, bool callsignAtStart, bool callsignAtEnd); + uint8_t setCallsign(const char* callsign, uint8_t speed, uint16_t frequency, uint8_t time, uint8_t holdoff, uint8_t highLevel, uint8_t lowLevel, bool callsignAtStart, bool callsignAtEnd, bool callsignAtLatch); uint8_t setAck(const char* rfAck, uint8_t speed, uint16_t frequency, uint8_t minTime, uint16_t delay, uint8_t level); uint8_t setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency, uint8_t ctcssThreshold, uint8_t ctcssLevel, uint8_t kerchunkTime, uint8_t hangTime, bool useCOS, uint8_t rfAudioBoost, uint8_t maxDev, uint8_t rxLevel); @@ -66,6 +66,7 @@ private: FM_STATE m_state; bool m_callsignAtStart; bool m_callsignAtEnd; + bool m_callsignAtLatch; CFMTimer m_callsignTimer; CFMTimer m_timeoutTimer; CFMTimer m_holdoffTimer; diff --git a/SerialPort.cpp b/SerialPort.cpp index 2922b57..190e105 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -376,6 +376,7 @@ uint8_t CSerialPort::setFMParams1(const uint8_t* data, uint8_t length) bool callAtStart = (data[6U] & 0x01U) == 0x01U; bool callAtEnd = (data[6U] & 0x02U) == 0x02U; + bool callAtLatch = (data[6U] & 0x04U) == 0x04U; char callsign[50U]; uint8_t n = 0U; @@ -383,7 +384,7 @@ uint8_t CSerialPort::setFMParams1(const uint8_t* data, uint8_t length) callsign[n] = data[i]; callsign[n] = '\0'; - return fm.setCallsign(callsign, speed, frequency, time, holdoff, highLevel, lowLevel, callAtStart, callAtEnd); + return fm.setCallsign(callsign, speed, frequency, time, holdoff, highLevel, lowLevel, callAtStart, callAtEnd, callAtLatch); } uint8_t CSerialPort::setFMParams2(const uint8_t* data, uint8_t length) From a938c8b70871f848e8e8f752645a0baf7504a1df Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 5 May 2020 10:48:44 +0200 Subject: [PATCH 08/10] Reduce buffer size --- FM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FM.cpp b/FM.cpp index e843996..9f238da 100644 --- a/FM.cpp +++ b/FM.cpp @@ -44,7 +44,7 @@ m_deemphasis (32768, -18801, 0, 32768, 13967, 0),//75µS 24kHz sampling rate m_blanking(), m_useCOS(true), m_rfAudioBoost(1U), -m_downsampler(1024)//Size might need adjustement +m_downsampler(128)//Size might need adjustement { } From bd16d13531f04ca7a56500135b80681569e989d5 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 5 May 2020 21:00:36 +0100 Subject: [PATCH 09/10] Add the dot to the CW Id. --- CWIdTX.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CWIdTX.cpp b/CWIdTX.cpp index 189e774..641b374 100644 --- a/CWIdTX.cpp +++ b/CWIdTX.cpp @@ -77,6 +77,7 @@ const struct { {',', 0xEEAEE000U, 22U}, {'-', 0xEAAE0000U, 18U}, {'=', 0xEAB80000U, 16U}, + {'.', 0xBAEB8000U, 20U}, {' ', 0x00000000U, 4U}, {0U, 0x00000000U, 0U} }; @@ -170,4 +171,3 @@ void CCWIdTX::reset() m_poPtr = 0U; m_n = 0U; } - From 79a09e61fa596b2da0fa3f1a92396481e632884c Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 5 May 2020 21:02:56 +0100 Subject: [PATCH 10/10] Add the dot to the FM keyer. --- FMKeyer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/FMKeyer.cpp b/FMKeyer.cpp index 36a2815..8109fb0 100644 --- a/FMKeyer.cpp +++ b/FMKeyer.cpp @@ -66,6 +66,7 @@ const struct { {',', 0xEEAEE000U, 22U}, {'-', 0xEAAE0000U, 18U}, {'=', 0xEAB80000U, 16U}, + {'.', 0xBAEB8000U, 20U}, {' ', 0x00000000U, 4U}, {0U, 0x00000000U, 0U} };