kopia lustrzana https://github.com/OpenRTX/OpenRTX
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.replace/c8317c674eee51ca2d0bd7785e75c6f1b2d83b29
rodzic
92ef5fe896
commit
5949a481fa
|
@ -22,18 +22,9 @@
|
|||
#define CPS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <rtx.h>
|
||||
#include <datatypes.h>
|
||||
|
||||
/**
|
||||
* \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.
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <ui.h>
|
||||
#include <rtx.h>
|
||||
#include <delays.h>
|
||||
#include <graphics.h>
|
||||
#include <keyboard.h>
|
||||
|
@ -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
|
||||
|
|
Ładowanie…
Reference in New Issue