diff --git a/app/app.c b/app/app.c index 2c704ac..4c0764b 100644 --- a/app/app.c +++ b/app/app.c @@ -209,19 +209,17 @@ void FUN_000051e8(void) return; } - bFlag = (gStepDirection == 0 || gCopyOfCodeType == CODE_TYPE_OFF); + bFlag = (gStepDirection == 0 && gCopyOfCodeType == CODE_TYPE_OFF); if (gRxInfo->CHANNEL_SAVE >= NOAA_CHANNEL_FIRST && gSystickCountdown2) { bFlag = true; gSystickCountdown2 = 0; } if (g_CTCSS_Lost && gCopyOfCodeType == CODE_TYPE_CONTINUOUS_TONE) { bFlag = true; - g_20000375 = 0; + gFoundCTCSS = false; } - if (g_CDCSS_Lost && gCDCSSCodeReceived == 0x01) { - if (gCopyOfCodeType == CODE_TYPE_DIGITAL || gCopyOfCodeType == CODE_TYPE_REVERSE_DIGITAL) { - g_20000376 = 0; - } + if (g_CDCSS_Lost && gCDCSSCodeType == CDCSS_POSITIVE_CODE && (gCopyOfCodeType == CODE_TYPE_DIGITAL || gCopyOfCodeType == CODE_TYPE_REVERSE_DIGITAL)) { + gFoundCDCSS = false; } else { if (!bFlag) { return; @@ -295,10 +293,10 @@ void FUN_000052f0(void) switch (gCopyOfCodeType) { case CODE_TYPE_CONTINUOUS_TONE: - if (g_20000375 == 1) { - if (gSystickCountdown4 == 0) { - g_20000375 = 0; - g_20000376 = 0; + if (gFoundCTCSS) { + if (gFoundCTCSSCountdown == 0) { + gFoundCTCSS = false; + gFoundCDCSS = false; Value = 1; goto LAB_0000544c; } @@ -306,10 +304,10 @@ void FUN_000052f0(void) break; case CODE_TYPE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL: - if (g_20000376 == 1) { - if (gSystickCountdown3 == 0) { - g_20000375 = 0; - g_20000376 = 0; + if (gFoundCDCSS) { + if (gFoundCDCSSCountdown == 0) { + gFoundCTCSS = false; + gFoundCDCSS = false; Value = 1; goto LAB_0000544c; } @@ -323,10 +321,10 @@ void FUN_000052f0(void) switch (gCopyOfCodeType) { case CODE_TYPE_CONTINUOUS_TONE: if (g_CTCSS_Lost) { - g_20000375 = 0; - } else if (g_20000375 == 0) { - g_20000375 = 1; - gSystickCountdown4 = 100; + gFoundCTCSS = false; + } else if (!gFoundCTCSS) { + gFoundCTCSS = true; + gFoundCTCSSCountdown = 100; } if (g_CxCSS_TAIL_Found) { Value = 2; @@ -334,7 +332,7 @@ void FUN_000052f0(void) } break; case CODE_TYPE_OFF: - if (gEeprom.SQUELCH_LEVEL != 0) { + if (gEeprom.SQUELCH_LEVEL) { if (g_CxCSS_TAIL_Found) { Value = 2; g_CxCSS_TAIL_Found = false; @@ -343,14 +341,14 @@ void FUN_000052f0(void) break; case CODE_TYPE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL: - if (g_CDCSS_Lost && gCDCSSCodeReceived == 1) { - g_20000376 = 0; - } else if (g_20000376 == 0) { - g_20000376 = 1; - gSystickCountdown3 = 100; + if (g_CDCSS_Lost && gCDCSSCodeType == CDCSS_POSITIVE_CODE) { + gFoundCDCSS = false; + } else if (!gFoundCDCSS) { + gFoundCDCSS = true; + gFoundCDCSSCountdown = 100; } if (g_CxCSS_TAIL_Found) { - if (BK4819_GetCTCSSPhaseShift() == 1) { + if (BK4819_GetCTCType() == 1) { Value = 2; } g_CxCSS_TAIL_Found = false; @@ -368,7 +366,7 @@ void FUN_000052f0(void) switch (gCopyOfCodeType) { case CODE_TYPE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL: - if (BK4819_GetCTCSSPhaseShift() == 1) { + if (BK4819_GetCTCType() == 1) { gNextTimeslice40ms = false; } break; @@ -377,9 +375,9 @@ void FUN_000052f0(void) } } +LAB_0000544c: gNextTimeslice40ms = false; -LAB_0000544c: switch (Value) { case 1: RADIO_SetupRegisters(true); @@ -400,15 +398,13 @@ LAB_0000544c: } break; case 2: - if (!gEeprom.TAIL_NOTE_ELIMINATION) { - gNextTimeslice40ms = false; - break; + if (gEeprom.TAIL_NOTE_ELIMINATION) { + GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); + g_20000342 = 20; + gSystickFlag10 = false; + g_2000036B = 0; + g_20000377 = 1; } - GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); - g_20000342 = 20; - gSystickFlag10 = false; - g_2000036B = 0; - g_20000377 = 1; break; default: break; @@ -693,7 +689,7 @@ void APP_CheckRadioInterrupts(void) } if (Mask & BK4819_REG_02_CDCSS_LOST) { g_CDCSS_Lost = true; - gCDCSSCodeReceived = BK4819_CheckCDCSSCodeReceived(); + gCDCSSCodeType = BK4819_GetCDCSSCodeType(); } if (Mask & BK4819_REG_02_CDCSS_FOUND) { g_CDCSS_Lost = false; @@ -1431,7 +1427,7 @@ void FUN_000075b0(void) g_200003AA = 0; g_CxCSS_TAIL_Found = false; g_CDCSS_Lost = false; - gCDCSSCodeReceived = 0; + gCDCSSCodeType = 0; g_CTCSS_Lost = false; g_VOX_Lost = false; g_SquelchLost = false; diff --git a/dcs.h b/dcs.h index 122b457..26702de 100644 --- a/dcs.h +++ b/dcs.h @@ -28,6 +28,11 @@ enum DCS_CodeType_t { typedef enum DCS_CodeType_t DCS_CodeType_t; +enum { + CDCSS_POSITIVE_CODE = 1U, + CDCSS_NEGATIVE_CODE = 2U, +}; + extern const uint16_t CTCSS_Options[50]; extern const uint16_t DCS_Options[104]; diff --git a/driver/bk4819.c b/driver/bk4819.c index fbb7503..ad78fe5 100644 --- a/driver/bk4819.c +++ b/driver/bk4819.c @@ -814,14 +814,14 @@ uint8_t BK4819_GetDTMF_5TONE_Code(void) return (BK4819_GetRegister(BK4819_REG_0B) >> 8) & 0x0F; } -uint8_t BK4819_CheckCDCSSCodeReceived(void) +uint8_t BK4819_GetCDCSSCodeType(void) { return (BK4819_GetRegister(BK4819_REG_0C) >> 14) & 3; } -uint8_t BK4819_GetCTCSSPhaseShift(void) +uint8_t BK4819_GetCTCType(void) { - return (BK4819_GetRegister(BK4819_REG_0C) >> 14) & 3; + return (BK4819_GetRegister(BK4819_REG_0C) >> 10) & 3; } void BK4819_SendFSKData(uint16_t *pData) diff --git a/driver/bk4819.h b/driver/bk4819.h index 69a0c31..28f201c 100644 --- a/driver/bk4819.h +++ b/driver/bk4819.h @@ -122,8 +122,8 @@ void BK4819_StopScan(void); uint8_t BK4819_GetDTMF_5TONE_Code(void); -uint8_t BK4819_CheckCDCSSCodeReceived(void); -uint8_t BK4819_GetCTCSSPhaseShift(void); +uint8_t BK4819_GetCDCSSCodeType(void); +uint8_t BK4819_GetCTCType(void); void BK4819_SendFSKData(uint16_t *pData); void BK4819_PrepareFSKReceive(void); diff --git a/functions.c b/functions.c index 774df1b..4e87535 100644 --- a/functions.c +++ b/functions.c @@ -58,10 +58,10 @@ void FUNCTION_Init(void) g_SquelchLost = false; g_20000342 = 0; gSystickFlag10 = false; - g_20000375 = 0; - g_20000376 = 0; - gSystickCountdown4 = 0; - gSystickCountdown3 = 0; + gFoundCTCSS = false; + gFoundCDCSS = false; + gFoundCTCSSCountdown = 0; + gFoundCDCSSCountdown = 0; g_20000377 = 0; gSystickCountdown2 = 0; } diff --git a/misc.c b/misc.c index 468fce1..053cb07 100644 --- a/misc.c +++ b/misc.c @@ -61,8 +61,8 @@ uint8_t gUpdateStatus; uint8_t g_20000370; uint8_t g_20000371[2]; uint8_t g_20000373; -uint8_t g_20000375; -uint8_t g_20000376; +uint8_t gFoundCTCSS; +uint8_t gFoundCDCSS; uint8_t g_20000377; uint8_t gVFO_RSSI_Level[2]; uint8_t g_2000037E; @@ -96,7 +96,7 @@ uint8_t gFlagSaveChannel; bool gFlagSaveFM; uint8_t g_200003AA; bool g_CDCSS_Lost; -uint8_t gCDCSSCodeReceived; +uint8_t gCDCSSCodeType; bool g_CTCSS_Lost; bool g_CxCSS_TAIL_Found; bool g_VOX_Lost; @@ -173,8 +173,8 @@ uint8_t gScanPauseMode; uint8_t gScanState; uint8_t gShowChPrefix; volatile uint16_t gSystickCountdown2; -volatile uint8_t gSystickCountdown3; -volatile uint8_t gSystickCountdown4; +volatile uint8_t gFoundCDCSSCountdown; +volatile uint8_t gFoundCTCSSCountdown; volatile uint16_t gSystickCountdown11; volatile bool gTxTimeoutReached; volatile bool gNextTimeslice40ms; diff --git a/misc.h b/misc.h index c3d95f1..cca5abf 100644 --- a/misc.h +++ b/misc.h @@ -85,8 +85,8 @@ extern uint8_t gUpdateStatus; extern uint8_t g_20000370; extern uint8_t g_20000371[2]; extern uint8_t g_20000373; -extern uint8_t g_20000375; -extern uint8_t g_20000376; +extern uint8_t gFoundCTCSS; +extern uint8_t gFoundCDCSS; extern uint8_t g_20000377; extern uint8_t gVFO_RSSI_Level[2]; extern uint8_t g_2000037E; @@ -120,7 +120,7 @@ extern uint8_t gFlagSaveChannel; extern bool gFlagSaveFM; extern uint8_t g_200003AA; extern bool g_CDCSS_Lost; -extern uint8_t gCDCSSCodeReceived; +extern uint8_t gCDCSSCodeType; extern bool g_CTCSS_Lost; extern bool g_CxCSS_TAIL_Found; extern bool g_VOX_Lost; @@ -197,8 +197,8 @@ extern uint8_t gScanPauseMode; extern uint8_t gScanState; extern uint8_t gShowChPrefix; extern volatile uint16_t gSystickCountdown2; -extern volatile uint8_t gSystickCountdown3; -extern volatile uint8_t gSystickCountdown4; +extern volatile uint8_t gFoundCDCSSCountdown; +extern volatile uint8_t gFoundCTCSSCountdown; extern volatile uint16_t gSystickCountdown11; extern volatile bool gTxTimeoutReached; extern volatile bool gNextTimeslice40ms; diff --git a/scheduler.c b/scheduler.c index 587700d..42e9eb6 100644 --- a/scheduler.c +++ b/scheduler.c @@ -43,11 +43,11 @@ void SystickHandler(void) if (gSystickCountdown2) { gSystickCountdown2--; } - if (gSystickCountdown3) { - gSystickCountdown3--; + if (gFoundCDCSSCountdown) { + gFoundCDCSSCountdown--; } - if (gSystickCountdown4) { - gSystickCountdown4--; + if (gFoundCTCSSCountdown) { + gFoundCTCSSCountdown--; } if (gCurrentFunction == FUNCTION_0 && gBatterySaveCountdown) { gBatterySaveCountdown--;