From 5949a481fa19044b4871ebb4646b5bfa61209d88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Izzo?= Date: Fri, 18 Dec 2020 21:44:59 +0100 Subject: [PATCH] Add synchronization between radio state and RTX Now the FSM update function takes an additional parameter, which determines if the radio state has to be synchronized with the RTX state. If so, the ui_task does the job. --- openrtx/include/cps.h | 21 +-------------------- openrtx/include/interfaces/rtx.h | 31 +++++++++++++++++++------------ openrtx/include/state.h | 8 -------- openrtx/include/ui.h | 3 ++- openrtx/src/threads.c | 23 ++++++++++++++++++++++- openrtx/src/ui.c | 14 +++++++------- 6 files changed, 51 insertions(+), 49 deletions(-) diff --git a/openrtx/include/cps.h b/openrtx/include/cps.h index e833257e..441b857d 100644 --- a/openrtx/include/cps.h +++ b/openrtx/include/cps.h @@ -22,18 +22,9 @@ #define CPS_H #include +#include #include -/** - * \enum mode_t Enumeration type defining the operating mode associated to each - * channel. - */ -enum mode_t -{ - FM = 0, /**< Analog FM mode */ - DMR = 1 /**< DMR mode */ -}; - /** * \enum admit_t Enumeration type defining the admission criteria to a the * channel. @@ -46,16 +37,6 @@ enum admit_t COLOR = 3 /**< Transmit only if color code is not used yet */ }; -/** - * \enum bw_t Enumeration type defining the bandwidth of a the channel. - */ -enum bw_t -{ - BW_12_5 = 0, /**< Bandwidth is 12.5kHz */ - BW_20 = 1, /**< Bandwidth is 20kHz */ - BW_25 = 2 /**< Bandwidth is 25kHz */ -}; - /** * Data structure containing all and only the information for analog FM channels, * like CTC/DCS tones. diff --git a/openrtx/include/interfaces/rtx.h b/openrtx/include/interfaces/rtx.h index 0e3d6ba1..9e6224ba 100644 --- a/openrtx/include/interfaces/rtx.h +++ b/openrtx/include/interfaces/rtx.h @@ -45,18 +45,25 @@ typedef struct } rtxStatus_t; -// enum bandwidth -// { -// BW_12_5 = 0, /**< 12.5kHz bandwidth */ -// BW_20 = 1, /**< 20kHz bandwidth */ -// BW_25 = 2 /**< 25kHz bandwidth */ -// }; -// -// enum opmode -// { -// FM = 0, /**< Analog FM */ -// DMR = 1 /**< DMR */ -// }; +/** + * \enum bandwidth Enumeration type defining the bandwidth of the channel. + */ +enum bandwidth +{ + BW_12_5 = 0, /**< 12.5kHz bandwidth */ + BW_20 = 1, /**< 20kHz bandwidth */ + BW_25 = 2 /**< 25kHz bandwidth */ +}; + +/** + * \enum opmode Enumeration type defining the operating mode associated to each + * channel. + */ +enum opmode +{ + FM = 0, /**< Analog FM */ + DMR = 1 /**< DMR */ +}; enum opstatus { diff --git a/openrtx/include/state.h b/openrtx/include/state.h index fdfe7d96..e1dec5f3 100644 --- a/openrtx/include/state.h +++ b/openrtx/include/state.h @@ -39,7 +39,6 @@ typedef struct uint8_t ui_screen; uint8_t tuner_mode; - uint8_t radio_mode; //time_t rx_status_tv; //bool rx_status; @@ -65,13 +64,6 @@ enum TunerMode CHSCAN }; -enum RadioMode -{ - MODE_FM = 0, - MODE_NFM, - MODE_DMR, -}; - enum RtxStatus { RTX_OFF = 0, diff --git a/openrtx/include/ui.h b/openrtx/include/ui.h index 8d36e4ba..650726f0 100644 --- a/openrtx/include/ui.h +++ b/openrtx/include/ui.h @@ -59,8 +59,9 @@ void ui_drawSplashScreen(); * current radio state and the keys pressed. * @param last_state: A local copy of the previous radio state * @param event: An event from other threads + * @param sync_rtx: If true RTX needs to be synchronized */ -void ui_updateFSM(event_t event); +void ui_updateFSM(event_t event, bool *sync_rtx); /** * This function redraws the GUI based on the last radio state. diff --git a/openrtx/src/threads.c b/openrtx/src/threads.c index 9e7c43d5..7796090e 100644 --- a/openrtx/src/threads.c +++ b/openrtx/src/threads.c @@ -78,6 +78,9 @@ static void ui_task(void *arg) (void) arg; OS_ERR os_err; OS_MSG_SIZE msg_size = 0; + rtxStatus_t rtx_cfg; + // RTX needs synchronization + bool sync_rtx = true; // Get initial state local copy OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err); @@ -99,12 +102,30 @@ static void ui_task(void *arg) // Lock mutex, read and write state OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err); // React to keypresses and update FSM inside state - ui_updateFSM(event); + ui_updateFSM(event, &sync_rtx); // Update state local copy last_state = state; // Unlock mutex OSMutexPost(&state_mutex, OS_OPT_POST_NONE, &os_err); + // If synchronization needed take mutex and update RTX configuration + if(sync_rtx) + { + OSMutexPend(&rtx_mutex, 0, OS_OPT_PEND_BLOCKING, NULL, &os_err); + rtx_cfg.opMode = state.channel.mode; + rtx_cfg.bandwidth = state.channel.bandwidth; + rtx_cfg.rxFrequency = state.channel.rx_frequency; + rtx_cfg.txFrequency = state.channel.tx_frequency; + rtx_cfg.txPower = state.channel.power; + rtx_cfg.sqlLevel = state.channel.squelch; + rtx_cfg.rxTone = state.channel.fm.ctcDcs_rx; + rtx_cfg.txTone = state.channel.fm.ctcDcs_tx; + OSMutexPost(&rtx_mutex, OS_OPT_POST_NONE, &os_err); + + rtx_configure(&rtx_cfg); + sync_rtx = false; + } + // Redraw GUI based on last state copy bool renderNeeded = ui_updateGUI(last_state); diff --git a/openrtx/src/ui.c b/openrtx/src/ui.c index 3f08d6d8..8357449d 100644 --- a/openrtx/src/ui.c +++ b/openrtx/src/ui.c @@ -66,6 +66,7 @@ #include #include #include +#include #include #include #include @@ -239,15 +240,12 @@ void _ui_drawTopBar(state_t* last_state) // Print radio mode on top bar char mode[4] = ""; - switch(last_state->radio_mode) + switch(last_state->channel.mode) { - case MODE_FM: + case FM: strcpy(mode, "FM"); break; - case MODE_NFM: - strcpy(mode, "NFM"); - break; - case MODE_DMR: + case DMR: strcpy(mode, "DMR"); break; } @@ -378,7 +376,7 @@ bool _ui_drawLowBatteryScreen() return true; } -void ui_updateFSM(event_t event) +void ui_updateFSM(event_t event, bool *sync_rtx) { // Check if battery has enough charge to operate float charge = battery_getCharge(state.v_bat); @@ -407,12 +405,14 @@ void ui_updateFSM(event_t event) // Advance TX and RX frequency of 12.5KHz state.channel.rx_frequency += 12500; state.channel.tx_frequency += 12500; + *sync_rtx = true; } else if(msg.keys & KEY_DOWN) { // Advance TX and RX frequency of 12.5KHz state.channel.rx_frequency -= 12500; state.channel.tx_frequency -= 12500; + *sync_rtx = true; } else if(msg.keys & KEY_ENTER) // Open Menu