From aa92e93c5638b32229e0f47846bd30a6c77c2d23 Mon Sep 17 00:00:00 2001 From: Krzysiek Egzmont Date: Mon, 29 Jan 2024 22:42:38 +0100 Subject: [PATCH] Refactor --- app/app.c | 87 ++++++++++++++++++------------------------------- app/dtmf.c | 6 ++-- driver/bk4819.c | 10 +++--- driver/bk4819.h | 4 +-- functions.c | 4 +-- misc.c | 4 +-- misc.h | 4 +-- radio.c | 14 ++++---- radio.h | 2 +- scheduler.c | 2 +- 10 files changed, 55 insertions(+), 82 deletions(-) diff --git a/app/app.c b/app/app.c index 9d57f6f..f24860d 100644 --- a/app/app.c +++ b/app/app.c @@ -241,14 +241,12 @@ static void HandleReceive(void) uint8_t Mode = END_OF_RX_MODE_SKIP; - if (gFlagTailNoteEliminationComplete) - { + if (gFlagTailToneEliminationComplete) { Mode = END_OF_RX_MODE_END; goto Skip; } - if (gScanStateDir != SCAN_OFF && IS_FREQ_CHANNEL(gNextMrChannel)) - { // we are scanning in the frequency mode + if (gScanStateDir != SCAN_OFF && IS_FREQ_CHANNEL(gNextMrChannel)) { // we are scanning in the frequency mode if (g_SquelchLost) return; @@ -256,15 +254,13 @@ static void HandleReceive(void) goto Skip; } - switch (gCurrentCodeType) - { + switch (gCurrentCodeType) { default: case CODE_TYPE_OFF: break; case CODE_TYPE_CONTINUOUS_TONE: - if (gFoundCTCSS && gFoundCTCSSCountdown_10ms == 0) - { + if (gFoundCTCSS && gFoundCTCSSCountdown_10ms == 0) { gFoundCTCSS = false; gFoundCDCSS = false; Mode = END_OF_RX_MODE_END; @@ -274,8 +270,7 @@ static void HandleReceive(void) case CODE_TYPE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL: - if (gFoundCDCSS && gFoundCDCSSCountdown_10ms == 0) - { + if (gFoundCDCSS && gFoundCDCSSCountdown_10ms == 0) { gFoundCTCSS = false; gFoundCDCSS = false; Mode = END_OF_RX_MODE_END; @@ -284,21 +279,16 @@ static void HandleReceive(void) break; } - if (g_SquelchLost) - { - #ifdef ENABLE_NOAA - if (!gEndOfRxDetectedMaybe && !IS_NOAA_CHANNEL(gRxVfo->CHANNEL_SAVE)) - #else - if (!gEndOfRxDetectedMaybe) - #endif - { - switch (gCurrentCodeType) - { + if (g_SquelchLost) { + if (!gEndOfRxDetectedMaybe +#ifdef ENABLE_NOAA + && !IS_NOAA_CHANNEL(gRxVfo->CHANNEL_SAVE) +#endif + ) { + switch (gCurrentCodeType) { case CODE_TYPE_OFF: - if (gEeprom.SQUELCH_LEVEL) - { - if (g_CxCSS_TAIL_Found) - { + if (gEeprom.SQUELCH_LEVEL) { + if (g_CxCSS_TAIL_Found) { Mode = END_OF_RX_MODE_TTE; g_CxCSS_TAIL_Found = false; } @@ -306,19 +296,15 @@ static void HandleReceive(void) break; case CODE_TYPE_CONTINUOUS_TONE: - if (g_CTCSS_Lost) - { + if (g_CTCSS_Lost) { gFoundCTCSS = false; } - else - if (!gFoundCTCSS) - { + else if (!gFoundCTCSS) { gFoundCTCSS = true; gFoundCTCSSCountdown_10ms = 100; // 1 sec } - if (g_CxCSS_TAIL_Found) - { + if (g_CxCSS_TAIL_Found) { Mode = END_OF_RX_MODE_TTE; g_CxCSS_TAIL_Found = false; } @@ -326,19 +312,15 @@ static void HandleReceive(void) case CODE_TYPE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL: - if (g_CDCSS_Lost && gCDCSSCodeType == CDCSS_POSITIVE_CODE) - { + if (g_CDCSS_Lost && gCDCSSCodeType == CDCSS_POSITIVE_CODE) { gFoundCDCSS = false; } - else - if (!gFoundCDCSS) - { + else if (!gFoundCDCSS) { gFoundCDCSS = true; gFoundCDCSSCountdown_10ms = 100; // 1 sec } - if (g_CxCSS_TAIL_Found) - { + if (g_CxCSS_TAIL_Found) { if (BK4819_GetCTCType() == 1) Mode = END_OF_RX_MODE_TTE; @@ -356,32 +338,28 @@ static void HandleReceive(void) Mode == END_OF_RX_MODE_SKIP && gNextTimeslice40ms && gEeprom.TAIL_TONE_ELIMINATION && - (gCurrentCodeType == CODE_TYPE_DIGITAL || gCurrentCodeType == CODE_TYPE_REVERSE_DIGITAL) && + (gCurrentCodeType == CODE_TYPE_DIGITAL || gCurrentCodeType == CODE_TYPE_REVERSE_DIGITAL) && BK4819_GetCTCType() == 1) Mode = END_OF_RX_MODE_TTE; else gNextTimeslice40ms = false; Skip: - switch (Mode) - { + switch (Mode) { case END_OF_RX_MODE_SKIP: break; case END_OF_RX_MODE_END: RADIO_SetupRegisters(true); - #ifdef ENABLE_NOAA - if (IS_NOAA_CHANNEL(gRxVfo->CHANNEL_SAVE)) - gNOAACountdown_10ms = 300; // 3 sec - #endif - +#ifdef ENABLE_NOAA + if (IS_NOAA_CHANNEL(gRxVfo->CHANNEL_SAVE)) + gNOAACountdown_10ms = 300; // 3 sec +#endif gUpdateDisplay = true; - if (gScanStateDir != SCAN_OFF) - { - switch (gEeprom.SCAN_RESUME_MODE) - { + if (gScanStateDir != SCAN_OFF) { + switch (gEeprom.SCAN_RESUME_MODE) { case SCAN_RESUME_TO: break; @@ -399,12 +377,11 @@ Skip: break; case END_OF_RX_MODE_TTE: - if (gEeprom.TAIL_TONE_ELIMINATION) - { + if (gEeprom.TAIL_TONE_ELIMINATION) { AUDIO_AudioPathOff(); - gTailNoteEliminationCountdown_10ms = 20; - gFlagTailNoteEliminationComplete = false; + gTailToneEliminationCountdown_10ms = 20; + gFlagTailToneEliminationComplete = false; gEndOfRxDetectedMaybe = true; gEnableSpeaker = false; } @@ -1196,7 +1173,7 @@ void APP_TimeSlice10ms(void) if (gAlarmState == ALARM_STATE_TXALARM) { gAlarmState = ALARM_STATE_SITE_ALARM; - RADIO_EnableCxCSS(); + RADIO_SendCssTail(); BK4819_SetupPowerAmplifier(0, 0); BK4819_ToggleGpioOut(BK4819_GPIO1_PIN29_PA_ENABLE, false); BK4819_Enable_AfDac_DiscMode_TxDsp(); diff --git a/app/dtmf.c b/app/dtmf.c index c7635c0..252721a 100644 --- a/app/dtmf.c +++ b/app/dtmf.c @@ -80,11 +80,9 @@ void DTMF_clear_RX(void) void DTMF_SendEndOfTransmission(void) { - if (gCurrentVfo->DTMF_PTT_ID_TX_MODE == PTT_ID_APOLLO) { + if (gCurrentVfo->DTMF_PTT_ID_TX_MODE == PTT_ID_APOLLO) BK4819_PlaySingleTone(2475, 250, 28, gEeprom.DTMF_SIDE_TONE); - } - - if ((gCurrentVfo->DTMF_PTT_ID_TX_MODE == PTT_ID_TX_DOWN || gCurrentVfo->DTMF_PTT_ID_TX_MODE == PTT_ID_BOTH) + else if ((gCurrentVfo->DTMF_PTT_ID_TX_MODE == PTT_ID_TX_DOWN || gCurrentVfo->DTMF_PTT_ID_TX_MODE == PTT_ID_BOTH) #ifdef ENABLE_DTMF_CALLING && gDTMF_CallState == DTMF_CALL_STATE_NONE #endif diff --git a/driver/bk4819.c b/driver/bk4819.c index 860911d..d6390a1 100644 --- a/driver/bk4819.c +++ b/driver/bk4819.c @@ -1395,18 +1395,16 @@ void BK4819_GenTail(uint8_t Tail) } } -void BK4819_EnableCDCSS(void) +void BK4819_PlayCDCSSTail(void) { BK4819_GenTail(0); // CTC134 - BK4819_WriteRegister(BK4819_REG_51, 0x804A); + BK4819_WriteRegister(BK4819_REG_51, 0x804A); // 1 0 0 0 0 0 0 0 0 1001010 } -void BK4819_EnableCTCSS(void) +void BK4819_PlayCTCSSTail(void) { #ifdef ENABLE_CTCSS_TAIL_PHASE_SHIFT - //BK4819_GenTail(1); // 120° phase shift BK4819_GenTail(2); // 180° phase shift - //BK4819_GenTail(3); // 240° phase shift #else BK4819_GenTail(4); // 55Hz tone freq #endif @@ -1448,7 +1446,7 @@ void BK4819_EnableCTCSS(void) // 0 = min // 127 = max - BK4819_WriteRegister(BK4819_REG_51, 0x904A); // 1 0 0 1 0 0 0 0 0 1001010 + BK4819_WriteRegister(BK4819_REG_51, 0x904A); // 1 0 0 1 0 0 0 0 0 1001010 } uint16_t BK4819_GetRSSI(void) diff --git a/driver/bk4819.h b/driver/bk4819.h index c5d3a47..1a6d06e 100644 --- a/driver/bk4819.h +++ b/driver/bk4819.h @@ -132,8 +132,8 @@ void BK4819_PlayDTMFString(const char *pString, bool bDelayFirst, uint16_t F void BK4819_TransmitTone(bool bLocalLoopback, uint32_t Frequency); void BK4819_GenTail(uint8_t Tail); -void BK4819_EnableCDCSS(void); -void BK4819_EnableCTCSS(void); +void BK4819_PlayCDCSSTail(void); +void BK4819_PlayCTCSSTail(void); uint16_t BK4819_GetRSSI(void); int8_t BK4819_GetRxGain_dB(void); diff --git a/functions.c b/functions.c index e4f631b..5e68a4a 100644 --- a/functions.c +++ b/functions.c @@ -57,8 +57,8 @@ void FUNCTION_Init(void) g_SquelchLost = false; - gFlagTailNoteEliminationComplete = false; - gTailNoteEliminationCountdown_10ms = 0; + gFlagTailToneEliminationComplete = false; + gTailToneEliminationCountdown_10ms = 0; gFoundCTCSS = false; gFoundCDCSS = false; gFoundCTCSSCountdown_10ms = 0; diff --git a/misc.c b/misc.c index e322e3f..2a23c4b 100644 --- a/misc.c +++ b/misc.c @@ -132,7 +132,7 @@ volatile bool gNextTimeslice_500ms; volatile uint16_t gTxTimerCountdown_500ms; volatile bool gTxTimeoutReached; -volatile uint16_t gTailNoteEliminationCountdown_10ms; +volatile uint16_t gTailToneEliminationCountdown_10ms; volatile uint8_t gVFOStateResumeCountdown_500ms; @@ -237,7 +237,7 @@ volatile bool gNextTimeslice40ms; volatile uint16_t gNOAACountdown_10ms = 0; volatile bool gScheduleNOAA = true; #endif -volatile bool gFlagTailNoteEliminationComplete; +volatile bool gFlagTailToneEliminationComplete; #ifdef ENABLE_FMRADIO volatile bool gScheduleFM; #endif diff --git a/misc.h b/misc.h index ed81573..2ea627d 100644 --- a/misc.h +++ b/misc.h @@ -205,7 +205,7 @@ extern volatile bool gNextTimeslice_500ms; extern volatile uint16_t gTxTimerCountdown_500ms; extern volatile bool gTxTimeoutReached; -extern volatile uint16_t gTailNoteEliminationCountdown_10ms; +extern volatile uint16_t gTailToneEliminationCountdown_10ms; #ifdef ENABLE_NOAA extern volatile uint16_t gNOAA_Countdown_10ms; @@ -315,7 +315,7 @@ extern volatile bool gNextTimeslice40ms; extern volatile uint16_t gNOAACountdown_10ms; extern volatile bool gScheduleNOAA; #endif -extern volatile bool gFlagTailNoteEliminationComplete; +extern volatile bool gFlagTailToneEliminationComplete; extern volatile uint8_t gVFOStateResumeCountdown_500ms; #ifdef ENABLE_FMRADIO extern volatile bool gScheduleFM; diff --git a/radio.c b/radio.c index 93a6e50..914bddd 100644 --- a/radio.c +++ b/radio.c @@ -983,9 +983,9 @@ void RADIO_PrepareTX(void) gTxTimerCountdown_500ms = 0; // no timeout - #if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) +#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) if (gAlarmState == ALARM_STATE_OFF) - #endif +#endif { if (gEeprom.TX_TIMEOUT_TIMER == 0) gTxTimerCountdown_500ms = 60; // 30 sec @@ -1004,15 +1004,15 @@ void RADIO_PrepareTX(void) #endif } -void RADIO_EnableCxCSS(void) +void RADIO_SendCssTail(void) { switch (gCurrentVfo->pTX->CodeType) { case CODE_TYPE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL: - BK4819_EnableCDCSS(); + BK4819_PlayCDCSSTail(); break; default: - BK4819_EnableCTCSS(); + BK4819_PlayCTCSSTail(); break; } @@ -1025,7 +1025,7 @@ void RADIO_SendEndOfTransmission(void) DTMF_SendEndOfTransmission(); // send the CTCSS/DCS tail tone - allows the receivers to mute the usual FM squelch tail/crash - RADIO_EnableCxCSS(); + RADIO_SendCssTail(); RADIO_SetupRegisters(false); } @@ -1035,6 +1035,6 @@ void RADIO_PrepareCssTX(void) SYSTEM_DelayMs(200); - RADIO_EnableCxCSS(); + RADIO_SendCssTail(); RADIO_SetupRegisters(true); } diff --git a/radio.h b/radio.h index c20098d..1e1d94e 100644 --- a/radio.h +++ b/radio.h @@ -164,7 +164,7 @@ void RADIO_SetupAGC(bool listeningAM, bool disable); void RADIO_SetModulation(ModulationMode_t modulation); void RADIO_SetVfoState(VfoState_t State); void RADIO_PrepareTX(void); -void RADIO_EnableCxCSS(void); +void RADIO_SendCssTail(void); void RADIO_PrepareCssTX(void); void RADIO_SendEndOfTransmission(void); diff --git a/scheduler.c b/scheduler.c index f76b4a6..1aa253d 100644 --- a/scheduler.c +++ b/scheduler.c @@ -92,7 +92,7 @@ void SystickHandler(void) if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) DECREMENT_AND_TRIGGER(gScanPauseDelayIn_10ms, gScheduleScanListen); - DECREMENT_AND_TRIGGER(gTailNoteEliminationCountdown_10ms, gFlagTailNoteEliminationComplete); + DECREMENT_AND_TRIGGER(gTailToneEliminationCountdown_10ms, gFlagTailToneEliminationComplete); #ifdef ENABLE_VOICE DECREMENT_AND_TRIGGER(gCountdownToPlayNextVoice_10ms, gFlagPlayQueuedVoice);