Small reorganization of threads and tasks

This commit is contained in:
Silvano Seva 2022-08-27 09:50:07 +02:00
parent b861beb0e6
commit 91d608cc6b
8 changed files with 37 additions and 30 deletions

View File

@ -61,6 +61,6 @@ gps_t;
* if available, enabled and ready, decode NMEA sentences and update * if available, enabled and ready, decode NMEA sentences and update
* the radio state with the retrieved data. * the radio state with the retrieved data.
*/ */
void gps_taskFunc(); void gps_task();
#endif /* GPS_H */ #endif /* GPS_H */

View File

@ -115,7 +115,7 @@ void state_terminate();
/** /**
* Update radio state fetching data from device drivers. * Update radio state fetching data from device drivers.
*/ */
void state_update(); void state_task();
/** /**
* Reset the fields of radio state containing user settings and VFO channel. * Reset the fields of radio state containing user settings and VFO channel.

View File

@ -124,7 +124,7 @@ rtxStatus_t rtx_getCurrentStatus();
* High-level code is in charge of calling this function periodically, since it * High-level code is in charge of calling this function periodically, since it
* contains all the RTX management functionalities. * contains all the RTX management functionalities.
*/ */
void rtx_taskFunc(); void rtx_task();
/** /**
* Get current RSSI in dBm. * Get current RSSI in dBm.

View File

@ -32,8 +32,12 @@ static bool isRtcSyncronised = false;
static bool gpsEnabled = false; static bool gpsEnabled = false;
static bool readNewSentence = true; static bool readNewSentence = true;
void gps_taskFunc() void gps_task()
{ {
// No GPS, return
if(state.gpsDetected == false)
return;
// Handle GPS turn on/off // Handle GPS turn on/off
if(state.settings.gps_enabled != gpsEnabled) if(state.settings.gps_enabled != gpsEnabled)
{ {

View File

@ -31,7 +31,7 @@
#include <stdlib.h> #include <stdlib.h>
#endif #endif
extern void *dev_task(void *arg); extern void *main_thread(void *arg);
void openrtx_init() void openrtx_init()
{ {
@ -87,10 +87,10 @@ void *openrtx_run()
// Start the OpenRTX threads // Start the OpenRTX threads
create_threads(); create_threads();
// Jump to the device management task // Jump to the device management thread
dev_task(NULL); main_thread(NULL);
// Device task terminated, complete shutdown sequence // Device thread terminated, complete shutdown sequence
state_terminate(); state_terminate();
platform_terminate(); platform_terminate();

View File

@ -18,6 +18,7 @@
* along with this program; if not, see <http://www.gnu.org/licenses/> * * along with this program; if not, see <http://www.gnu.org/licenses/> *
***************************************************************************/ ***************************************************************************/
#include <ui.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -26,9 +27,11 @@
#include <hwconfig.h> #include <hwconfig.h>
#include <interfaces/platform.h> #include <interfaces/platform.h>
#include <interfaces/nvmem.h> #include <interfaces/nvmem.h>
#include <interfaces/delays.h>
state_t state; state_t state;
pthread_mutex_t state_mutex; pthread_mutex_t state_mutex;
long long int lastUpdate = 0;
void state_init() void state_init()
{ {
@ -86,8 +89,14 @@ void state_terminate()
pthread_mutex_destroy(&state_mutex); pthread_mutex_destroy(&state_mutex);
} }
void state_update() void state_task()
{ {
// Update radio state once every 100ms
if((getTick() - lastUpdate) < 100)
return;
lastUpdate = getTick();
pthread_mutex_lock(&state_mutex); pthread_mutex_lock(&state_mutex);
/* /*
@ -107,6 +116,8 @@ void state_update()
#endif #endif
pthread_mutex_unlock(&state_mutex); pthread_mutex_unlock(&state_mutex);
ui_pushEvent(EVENT_STATUS, 0);
} }
void state_resetSettingsAndVfo() void state_resetSettingsAndVfo()

View File

@ -43,9 +43,9 @@
pthread_mutex_t rtx_mutex; pthread_mutex_t rtx_mutex;
/** /**
* \internal Task function managing user input and UI * \internal Thread managing user input and UI
*/ */
void *ui_task(void *arg) void *ui_threadFunc(void *arg)
{ {
(void) arg; (void) arg;
@ -118,20 +118,17 @@ void *ui_task(void *arg)
} }
/** /**
* \internal Task function in charge of managing the device and update the * \internal Thread managing the device and update the global state variable.
* global state variable.
*/ */
void *dev_task(void *arg) void *main_thread(void *arg)
{ {
(void) arg; (void) arg;
long long time = 0; long long time = 0;
uint8_t tick_5ms = 0;
while(state.devStatus != SHUTDOWN) while(state.devStatus != SHUTDOWN)
{ {
time = getTick(); time = getTick();
tick_5ms++;
// Check if power off is requested // Check if power off is requested
pthread_mutex_lock(&state_mutex); pthread_mutex_lock(&state_mutex);
@ -164,16 +161,11 @@ void *dev_task(void *arg)
// Run GPS task // Run GPS task
#if defined(GPS_PRESENT) && !defined(MD3x0_ENABLE_DBG) #if defined(GPS_PRESENT) && !defined(MD3x0_ENABLE_DBG)
if(state.gpsDetected) gps_task();
gps_taskFunc();
#endif #endif
// Update radio state every 100ms // Run state update task
if((tick_5ms % 20) == 0) state_task();
{
state_update();
ui_pushEvent(EVENT_STATUS, 0);
}
// Run this loop once every 5ms // Run this loop once every 5ms
time += 5; time += 5;
@ -188,9 +180,9 @@ void *dev_task(void *arg)
} }
/** /**
* \internal Task function for RTX management. * \internal Thread for RTX management.
*/ */
void *rtx_task(void *arg) void *rtx_threadFunc(void *arg)
{ {
(void) arg; (void) arg;
@ -198,7 +190,7 @@ void *rtx_task(void *arg)
while(state.devStatus == RUNNING) while(state.devStatus == RUNNING)
{ {
rtx_taskFunc(); rtx_task();
} }
rtx_terminate(); rtx_terminate();
@ -228,7 +220,7 @@ void create_threads()
pthread_attr_setschedparam(&rtx_attr, &param); pthread_attr_setschedparam(&rtx_attr, &param);
#endif #endif
pthread_create(&rtx_thread, &rtx_attr, rtx_task, NULL); pthread_create(&rtx_thread, &rtx_attr, rtx_threadFunc, NULL);
// Create UI thread // Create UI thread
pthread_t ui_thread; pthread_t ui_thread;
@ -236,5 +228,5 @@ void create_threads()
pthread_attr_init(&ui_attr); pthread_attr_init(&ui_attr);
pthread_attr_setstacksize(&ui_attr, UI_TASK_STKSIZE); pthread_attr_setstacksize(&ui_attr, UI_TASK_STKSIZE);
pthread_create(&ui_thread, &ui_attr, ui_task, NULL); pthread_create(&ui_thread, &ui_attr, ui_threadFunc, NULL);
} }

View File

@ -100,7 +100,7 @@ rtxStatus_t rtx_getCurrentStatus()
return rtxStatus; return rtxStatus;
} }
void rtx_taskFunc() void rtx_task()
{ {
// Check if there is a pending new configuration and, in case, read it. // Check if there is a pending new configuration and, in case, read it.
bool reconfigure = false; bool reconfigure = false;