diff --git a/app/app.c b/app/app.c index f4ed832..26d4390 100644 --- a/app/app.c +++ b/app/app.c @@ -586,16 +586,34 @@ static void CheckRadioInterrupts(void) if (SCANNER_IsScanning()) return; - while (BK4819_ReadRegister(BK4819_REG_0C) & 1u) - { // BK chip interrupt request - - uint16_t interrupt_status_bits; - - // reset the interrupt ? + while (BK4819_ReadRegister(BK4819_REG_0C) & 1u) { // BK chip interrupt request + // clear interrupts BK4819_WriteRegister(BK4819_REG_02, 0); + // fetch interrupt status bits - // fetch the interrupt status bits - interrupt_status_bits = BK4819_ReadRegister(BK4819_REG_02); + union { + struct { + uint16_t __UNUSED : 1; + uint16_t fskRxSync : 1; + uint16_t sqlLost : 1; + uint16_t sqlFound : 1; + uint16_t voxLost : 1; + uint16_t voxFound : 1; + uint16_t ctcssLost : 1; + uint16_t ctcssFound : 1; + uint16_t cdcssLost : 1; + uint16_t cdcssFound : 1; + uint16_t cssTailFound : 1; + uint16_t dtmf5ToneFound : 1; + uint16_t fskFifoAlmostFull : 1; + uint16_t fskRxFinied : 1; + uint16_t fskFifoAlmostEmpty : 1; + uint16_t fskTxFinied : 1; + }; + uint16_t __raw; + } interrupts; + + interrupts.__raw = BK4819_ReadRegister(BK4819_REG_02); // 0 = no phase shift // 1 = 120deg phase shift @@ -605,18 +623,13 @@ static void CheckRadioInterrupts(void) // if (ctcss_shift > 0) // g_CTCSS_Lost = true; - if (interrupt_status_bits & BK4819_REG_02_DTMF_5TONE_FOUND) - { // save the RX'ed DTMF character - const char c = DTMF_GetCharacter(BK4819_GetDTMF_5TONE_Code()); - if (c != 0xff) - { - if (gCurrentFunction != FUNCTION_TRANSMIT) - { - if (gSetting_live_DTMF_decoder) - { + if (interrupts.dtmf5ToneFound) { + const char c = DTMF_GetCharacter(BK4819_GetDTMF_5TONE_Code()); // save the RX'ed DTMF character + if (c != 0xff) { + if (gCurrentFunction != FUNCTION_TRANSMIT) { + if (gSetting_live_DTMF_decoder) { size_t len = strlen(gDTMF_RX_live); - if (len >= (sizeof(gDTMF_RX_live) - 1)) - { // make room + if (len >= sizeof(gDTMF_RX_live) - 1) { // make room memmove(&gDTMF_RX_live[0], &gDTMF_RX_live[1], sizeof(gDTMF_RX_live) - 1); len--; } @@ -627,10 +640,8 @@ static void CheckRadioInterrupts(void) } #ifdef ENABLE_DTMF_CALLING - if (gRxVfo->DTMF_DECODING_ENABLE || gSetting_KILLED) - { - if (gDTMF_RX_index >= (sizeof(gDTMF_RX) - 1)) - { // make room + if (gRxVfo->DTMF_DECODING_ENABLE || gSetting_KILLED) { + if (gDTMF_RX_index >= sizeof(gDTMF_RX) - 1) { // make room memmove(&gDTMF_RX[0], &gDTMF_RX[1], sizeof(gDTMF_RX) - 1); gDTMF_RX_index--; } @@ -647,40 +658,35 @@ static void CheckRadioInterrupts(void) } } - if (interrupt_status_bits & BK4819_REG_02_CxCSS_TAIL) + if (interrupts.cssTailFound) g_CxCSS_TAIL_Found = true; - if (interrupt_status_bits & BK4819_REG_02_CDCSS_LOST) - { + if (interrupts.cdcssLost) { g_CDCSS_Lost = true; gCDCSSCodeType = BK4819_GetCDCSSCodeType(); } - if (interrupt_status_bits & BK4819_REG_02_CDCSS_FOUND) + if (interrupts.cdcssFound) g_CDCSS_Lost = false; - if (interrupt_status_bits & BK4819_REG_02_CTCSS_LOST) + if (interrupts.ctcssLost) g_CTCSS_Lost = true; - if (interrupt_status_bits & BK4819_REG_02_CTCSS_FOUND) + if (interrupts.ctcssFound) g_CTCSS_Lost = false; - #ifdef ENABLE_VOX - if (interrupt_status_bits & BK4819_REG_02_VOX_LOST) - { +#ifdef ENABLE_VOX + if (interrupts.voxLost) { g_VOX_Lost = true; gVoxPauseCountdown = 10; - if (gEeprom.VOX_SWITCH) - { - if (gCurrentFunction == FUNCTION_POWER_SAVE && !gRxIdleMode) - { + if (gEeprom.VOX_SWITCH) { + if (gCurrentFunction == FUNCTION_POWER_SAVE && !gRxIdleMode) { gPowerSave_10ms = power_save2_10ms; gPowerSaveCountdownExpired = 0; } - if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF && (gScheduleDualWatch || gDualWatchCountdown_10ms < dual_watch_count_after_vox_10ms)) - { + if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF && (gScheduleDualWatch || gDualWatchCountdown_10ms < dual_watch_count_after_vox_10ms)) { gDualWatchCountdown_10ms = dual_watch_count_after_vox_10ms; gScheduleDualWatch = false; @@ -691,27 +697,24 @@ static void CheckRadioInterrupts(void) } } - if (interrupt_status_bits & BK4819_REG_02_VOX_FOUND) - { + if (interrupts.voxFound) { g_VOX_Lost = false; gVoxPauseCountdown = 0; } - #endif +#endif - if (interrupt_status_bits & BK4819_REG_02_SQUELCH_LOST) - { + if (interrupts.sqlLost) { g_SquelchLost = true; BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2_GREEN, true); } - if (interrupt_status_bits & BK4819_REG_02_SQUELCH_FOUND) - { + if (interrupts.sqlFound) { g_SquelchLost = false; BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2_GREEN, false); } #ifdef ENABLE_AIRCOPY - if (interrupt_status_bits & BK4819_REG_02_FSK_FIFO_ALMOST_FULL && + if (interrupts.fskFifoAlmostFull && gScreenToDisplay == DISPLAY_AIRCOPY && gAircopyState == AIRCOPY_TRANSFER && gAirCopyIsSendMode == 0)