Small reorganization of threads and tasks

pull/114/head
Silvano Seva 2022-08-27 09:50:07 +02:00
rodzic b861beb0e6
commit 91d608cc6b
8 zmienionych plików z 37 dodań i 30 usunięć

Wyświetl plik

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

Wyświetl plik

@ -115,7 +115,7 @@ void state_terminate();
/**
* 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.

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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