Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
egzumer committed Jan 29, 2024
1 parent dc1808b commit aa92e93
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 82 deletions.
87 changes: 32 additions & 55 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,30 +241,26 @@ 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;

Mode = END_OF_RX_MODE_END;
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;
Expand All @@ -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;
Expand All @@ -284,61 +279,48 @@ 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;
}
}
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;
}
break;

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;

Expand All @@ -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;

Expand All @@ -399,12 +377,11 @@ static void HandleReceive(void)
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;
}
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions app/dtmf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions driver/bk4819.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions driver/bk4819.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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);
}

Expand All @@ -1035,6 +1035,6 @@ void RADIO_PrepareCssTX(void)

SYSTEM_DelayMs(200);

RADIO_EnableCxCSS();
RADIO_SendCssTail();
RADIO_SetupRegisters(true);
}
2 changes: 1 addition & 1 deletion radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit aa92e93

Please sign in to comment.