diff --git a/openrtx/include/core/gps.h b/openrtx/include/core/gps.h index 0577fc23..2b27a123 100644 --- a/openrtx/include/core/gps.h +++ b/openrtx/include/core/gps.h @@ -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 */ diff --git a/openrtx/include/core/state.h b/openrtx/include/core/state.h index d166f4e8..e56e4bff 100644 --- a/openrtx/include/core/state.h +++ b/openrtx/include/core/state.h @@ -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. diff --git a/openrtx/include/rtx/rtx.h b/openrtx/include/rtx/rtx.h index a7bd9b25..b5a3b064 100644 --- a/openrtx/include/rtx/rtx.h +++ b/openrtx/include/rtx/rtx.h @@ -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. diff --git a/openrtx/src/core/gps.c b/openrtx/src/core/gps.c index 830b8722..3e8cb857 100644 --- a/openrtx/src/core/gps.c +++ b/openrtx/src/core/gps.c @@ -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) { diff --git a/openrtx/src/core/openrtx.c b/openrtx/src/core/openrtx.c index b842eccb..52ec2926 100644 --- a/openrtx/src/core/openrtx.c +++ b/openrtx/src/core/openrtx.c @@ -31,7 +31,7 @@ #include #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(); diff --git a/openrtx/src/core/state.c b/openrtx/src/core/state.c index 16866bc0..e65296e7 100644 --- a/openrtx/src/core/state.c +++ b/openrtx/src/core/state.c @@ -18,6 +18,7 @@ * along with this program; if not, see * ***************************************************************************/ +#include #include #include #include @@ -26,9 +27,11 @@ #include #include #include +#include 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() diff --git a/openrtx/src/core/threads.c b/openrtx/src/core/threads.c index eb722b94..b4f06f4e 100644 --- a/openrtx/src/core/threads.c +++ b/openrtx/src/core/threads.c @@ -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, ¶m); #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); } diff --git a/openrtx/src/rtx/rtx.cpp b/openrtx/src/rtx/rtx.cpp index 7e30a135..6b0f66eb 100644 --- a/openrtx/src/rtx/rtx.cpp +++ b/openrtx/src/rtx/rtx.cpp @@ -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;