Clean termination of all the threads on device shutdown

This commit is contained in:
Silvano Seva 2022-06-17 07:57:16 +02:00
parent bc0c80edf6
commit 6d10f52b5b
7 changed files with 25 additions and 19 deletions

View File

@ -59,8 +59,8 @@ typedef struct
bool bank_enabled; bool bank_enabled;
uint16_t bank; uint16_t bank;
uint8_t rtxStatus; uint8_t rtxStatus;
bool rtxShutdown;
bool shutdown;
bool emergency; bool emergency;
settings_t settings; settings_t settings;
gps_t gps_data; gps_t gps_data;

View File

@ -84,7 +84,7 @@ void state_init()
state.channel_index = 1; // Set default channel index (it is 1-based) state.channel_index = 1; // Set default channel index (it is 1-based)
state.bank_enabled = false; state.bank_enabled = false;
state.rtxStatus = RTX_OFF; state.rtxStatus = RTX_OFF;
state.rtxShutdown = false; state.shutdown = false;
state.emergency = false; state.emergency = false;
// Force brightness field to be in range 0 - 100 // Force brightness field to be in range 0 - 100

View File

@ -144,7 +144,7 @@ void *kbd_task(void *arg)
// Initialize keyboard driver // Initialize keyboard driver
kbd_init(); kbd_init();
while(1) while(state.shutdown == false)
{ {
kbd_msg_t msg; kbd_msg_t msg;
@ -165,6 +165,8 @@ void *kbd_task(void *arg)
// Read keyboard state at 40Hz // Read keyboard state at 40Hz
sleepFor(0u, 25u); sleepFor(0u, 25u);
} }
return NULL;
} }
/** /**
@ -174,7 +176,7 @@ void *dev_task(void *arg)
{ {
(void) arg; (void) arg;
while(1) while(state.shutdown == false)
{ {
// Lock mutex and update internal state // Lock mutex and update internal state
pthread_mutex_lock(&state_mutex); pthread_mutex_lock(&state_mutex);
@ -190,6 +192,8 @@ void *dev_task(void *arg)
// Execute state update thread every 1s // Execute state update thread every 1s
sleepFor(1u, 0u); sleepFor(1u, 0u);
} }
return NULL;
} }
/** /**
@ -201,20 +205,13 @@ void *rtx_task(void *arg)
rtx_init(&rtx_mutex); rtx_init(&rtx_mutex);
while(1) while(state.shutdown == false)
{ {
rtx_taskFunc(); rtx_taskFunc();
// TODO: implement a cleaner shutdown procedure
if(state.rtxShutdown == true)
{
radio_disableRtx();
platform_ledOff(RED);
platform_ledOff(GREEN);
break;
}
} }
rtx_terminate();
return NULL; return NULL;
} }
@ -230,7 +227,7 @@ void *gps_task(void *arg)
gps_init(9600); gps_init(9600);
while(1) while(state.shutdown == false)
{ {
pthread_mutex_lock(&state_mutex); pthread_mutex_lock(&state_mutex);
gps_taskFunc(); gps_taskFunc();
@ -238,6 +235,10 @@ void *gps_task(void *arg)
sleepFor(0u, 100u); sleepFor(0u, 100u);
} }
gps_terminate();
return NULL;
} }
#endif #endif

View File

@ -78,6 +78,8 @@ void OpMode_FM::enable()
void OpMode_FM::disable() void OpMode_FM::disable()
{ {
// Clean shutdown. // Clean shutdown.
platform_ledOff(GREEN);
platform_ledOff(RED);
audio_disableAmp(); audio_disableAmp();
audio_disableMic(); audio_disableMic();
radio_disableRtx(); radio_disableRtx();

View File

@ -54,6 +54,8 @@ void OpMode_M17::disable()
{ {
startRx = false; startRx = false;
startTx = false; startTx = false;
platform_ledOff(GREEN);
platform_ledOff(RED);
codec_terminate(); codec_terminate();
audio_disableAmp(); audio_disableAmp();
audio_disableMic(); audio_disableMic();

View File

@ -935,6 +935,7 @@ void ui_updateFSM(event_t event, bool *sync_rtx)
// User wants to power off the radio, so shutdown. // User wants to power off the radio, so shutdown.
if(!platform_pwrButtonStatus()) if(!platform_pwrButtonStatus())
{ {
state.shutdown = true;
state_terminate(); state_terminate();
platform_terminate(); platform_terminate();
return; return;

View File

@ -467,8 +467,8 @@ void _ui_drawMenuBackup(ui_state_t* ui_state)
gfx_print(line, FONT_SIZE_8PT, TEXT_ALIGN_CENTER, gfx_print(line, FONT_SIZE_8PT, TEXT_ALIGN_CENTER,
color_white, "press PTT to start."); color_white, "press PTT to start.");
// Shutdown RF stage // Shutdown all the other parts
state.rtxShutdown = true; state.shutdown = true;
if(platform_getPttStatus() == 1) if(platform_getPttStatus() == 1)
{ {
@ -500,8 +500,8 @@ void _ui_drawMenuRestore(ui_state_t* ui_state)
gfx_print(line, FONT_SIZE_8PT, TEXT_ALIGN_CENTER, gfx_print(line, FONT_SIZE_8PT, TEXT_ALIGN_CENTER,
color_white, "press PTT to start."); color_white, "press PTT to start.");
// Shutdown RF stage // Shutdown all the other parts
state.rtxShutdown = true; state.shutdown = true;
if(platform_getPttStatus() == 1) if(platform_getPttStatus() == 1)
{ {