Increased UI task stack size to 1kB, fixed some compiler warnings, code cleanup pass

This commit is contained in:
Silvano Seva 2020-11-27 10:12:54 +01:00
parent 82be1afe17
commit bf24c31be7
3 changed files with 49 additions and 37 deletions

View File

@ -31,7 +31,7 @@ void create_threads();
/** /**
* Stack size for UI task, in bytes. * Stack size for UI task, in bytes.
*/ */
#define UI_TASK_STKSIZE 128 #define UI_TASK_STKSIZE 1024
/** /**
* Stack size for state update task, in bytes. * Stack size for state update task, in bytes.

View File

@ -27,27 +27,31 @@
#include <platform.h> #include <platform.h>
#include <hwconfig.h> #include <hwconfig.h>
// Allocate state mutex #include <stdio.h>
/* Mutex for concurrent access to state variable */
static OS_MUTEX state_mutex; static OS_MUTEX state_mutex;
// Allocate UI task control block and stack /* UI task control block and stack */
static OS_TCB ui_tcb; static OS_TCB ui_tcb;
static CPU_STK ui_stk[UI_TASK_STKSIZE]; static CPU_STK ui_stk[UI_TASK_STKSIZE];
// Allocate state task control block and stack /* State task control block and stack */
static OS_TCB state_tcb; static OS_TCB state_tcb;
static CPU_STK state_stk[STATE_TASK_STKSIZE]; static CPU_STK state_stk[STATE_TASK_STKSIZE];
// Allocate baseband task control block and stack /* Baseband task control block and stack */
static OS_TCB rtx_tcb; static OS_TCB rtx_tcb;
static CPU_STK rtx_stk[RTX_TASK_STKSIZE]; static CPU_STK rtx_stk[RTX_TASK_STKSIZE];
// Allocate DMR task control block and stack /* DMR task control block and stack */
static OS_TCB dmr_tcb; static OS_TCB dmr_tcb;
static CPU_STK dmr_stk[DMR_TASK_STKSIZE]; static CPU_STK dmr_stk[DMR_TASK_STKSIZE];
// UI update task /**
* \internal Task function in charge of updating the UI.
*/
static void ui_task(void *arg) static void ui_task(void *arg)
{ {
(void) arg; (void) arg;
@ -61,20 +65,20 @@ static void ui_task(void *arg)
ui_init(); ui_init();
// Display splash screen // Display splash screen
ui_drawSplashScreen2(); ui_drawSplashScreen();
gfx_render(); gfx_render();
while(gfx_renderingInProgress()); while(gfx_renderingInProgress());
// Wait 30ms to hide random pixels on screen
// Wait 30ms before turning on backlight to hide random pixels on screen
OSTimeDlyHMSM(0u, 0u, 0u, 30u, OS_OPT_TIME_HMSM_STRICT, &os_err); OSTimeDlyHMSM(0u, 0u, 0u, 30u, OS_OPT_TIME_HMSM_STRICT, &os_err);
platform_setBacklightLevel(255); platform_setBacklightLevel(255);
// Keep the splash screen for 1 second // Keep the splash screen for 1 second
OSTimeDlyHMSM(0u, 0u, 1u, 0u, OS_OPT_TIME_HMSM_STRICT, &os_err); OSTimeDlyHMSM(0u, 0u, 1u, 0u, OS_OPT_TIME_HMSM_STRICT, &os_err);
// Get initial state local copy // Get initial state local copy
// Wait for unlocked mutex and lock it
OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err); OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err);
state_t last_state = state; state_t last_state = state;
// Unlock the mutex
OSMutexPost(&state_mutex, OS_OPT_POST_NONE, &os_err); OSMutexPost(&state_mutex, OS_OPT_POST_NONE, &os_err);
uint32_t last_keys = 0; uint32_t last_keys = 0;
@ -84,17 +88,18 @@ static void ui_task(void *arg)
uint32_t keys = kbd_getKeys(); uint32_t keys = kbd_getKeys();
if(keys != last_keys) if(keys != last_keys)
{ {
printf("Keys changed!\n");
last_keys = keys; last_keys = keys;
} }
// Wait for unlocked mutex and lock it
OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err); OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err);
// React to keypresses and update FSM inside state // React to keypresses and update FSM inside state
ui_updateFSM(last_state, keys); ui_updateFSM(last_state, keys);
// Update state local copy // Update state local copy
last_state = state; last_state = state;
// Unlock the mutex
OSMutexPost(&state_mutex, OS_OPT_POST_NONE, &os_err); OSMutexPost(&state_mutex, OS_OPT_POST_NONE, &os_err);
// Redraw GUI // Redraw GUI
bool renderNeeded = ui_updateGUI(last_state); bool renderNeeded = ui_updateGUI(last_state);
@ -109,7 +114,9 @@ static void ui_task(void *arg)
} }
} }
// State update task /**
* \internal Task function in charge of updating the radio state.
*/
static void state_task(void *arg) static void state_task(void *arg)
{ {
(void) arg; (void) arg;
@ -117,13 +124,11 @@ static void state_task(void *arg)
while(1) while(1)
{ {
// Wait for unlocked mutex and lock it
OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err); OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err);
state.time = rtc_getTime(); state.time = rtc_getTime();
state.v_bat = platform_getVbat(); state.v_bat = platform_getVbat();
// Unlock the mutex
OSMutexPost(&state_mutex, OS_OPT_POST_NONE, &os_err); OSMutexPost(&state_mutex, OS_OPT_POST_NONE, &os_err);
// Execute state update thread every 1s // Execute state update thread every 1s
@ -131,7 +136,9 @@ static void state_task(void *arg)
} }
} }
// RTX task /**
* \internal Task function for RTX management.
*/
static void rtx_task(void *arg) static void rtx_task(void *arg)
{ {
(void) arg; (void) arg;
@ -146,8 +153,9 @@ static void rtx_task(void *arg)
} }
} }
/**
// DMR task * \internal Task function for DMR management.
*/
static void dmr_task(void *arg) static void dmr_task(void *arg)
{ {
(void) arg; (void) arg;
@ -162,6 +170,9 @@ static void dmr_task(void *arg)
} }
} }
/**
* \internal This function creates all the system tasks and mutexes.
*/
void create_threads() void create_threads()
{ {
OS_ERR os_err; OS_ERR os_err;

View File

@ -221,23 +221,24 @@ void _ui_drawVFO(state_t* state)
{ {
// Print VFO frequencies // Print VFO frequencies
char freq_buf[20] = ""; char freq_buf[20] = "";
snprintf(freq_buf, sizeof(freq_buf), "Rx: %03d.%05d", snprintf(freq_buf, sizeof(freq_buf), "Rx: %03ld.%05ld",
state->channel.rx_frequency/1000000, state->channel.rx_frequency/1000000,
state->channel.rx_frequency%1000000); state->channel.rx_frequency%1000000);
gfx_print(layout.line2_pos, freq_buf, layout.line1_font, TEXT_ALIGN_CENTER, gfx_print(layout.line2_pos, freq_buf, layout.line1_font, TEXT_ALIGN_CENTER,
color_white); color_white);
snprintf(freq_buf, sizeof(freq_buf), "Tx: %03d.%05d",
snprintf(freq_buf, sizeof(freq_buf), "Tx: %03ld.%05ld",
state->channel.tx_frequency/1000000, state->channel.tx_frequency/1000000,
state->channel.tx_frequency%1000000); state->channel.tx_frequency%1000000);
gfx_print(layout.line3_pos, freq_buf, layout.line2_font, TEXT_ALIGN_CENTER, gfx_print(layout.line3_pos, freq_buf, layout.line2_font, TEXT_ALIGN_CENTER,
color_white); color_white);
} }
void _ui_drawBottomBar() void _ui_drawBottomBar()
{ {
// Print OpenRTX on bottom bar gfx_print(layout.bottom_pos, "OpenRTX", layout.bottom_font,
char bottom_buf[8] = "OpenRTX";
gfx_print(layout.bottom_pos, bottom_buf, layout.bottom_font,
TEXT_ALIGN_CENTER, color_white); TEXT_ALIGN_CENTER, color_white);
} }
@ -277,33 +278,33 @@ void ui_init()
void ui_drawSplashScreen() void ui_drawSplashScreen()
{ {
point_t splash_origin = {0, SCREEN_HEIGHT / 2 + 6};
gfx_clearScreen(); gfx_clearScreen();
#ifdef OLD_SPLASH
point_t splash_origin = {0, SCREEN_HEIGHT / 2 + 6};
gfx_print(splash_origin, "OpenRTX", FONT_SIZE_12PT, TEXT_ALIGN_CENTER, gfx_print(splash_origin, "OpenRTX", FONT_SIZE_12PT, TEXT_ALIGN_CENTER,
yellow_fab413); yellow_fab413);
} #else
void ui_drawSplashScreen2()
{
point_t splash_origin = {0, SCREEN_HEIGHT / 2 - 6}; point_t splash_origin = {0, SCREEN_HEIGHT / 2 - 6};
gfx_clearScreen();
gfx_print(splash_origin, "O P N\nR T X", FONT_SIZE_12PT, TEXT_ALIGN_CENTER, gfx_print(splash_origin, "O P N\nR T X", FONT_SIZE_12PT, TEXT_ALIGN_CENTER,
yellow_fab413); yellow_fab413);
#endif
} }
void ui_updateFSM(state_t last_state, uint32_t keys) void ui_updateFSM(state_t last_state, uint32_t keys)
{ {
(void) last_state;
// Temporary VFO controls // Temporary VFO controls
if(keys && KEY_UP) if(keys & KEY_UP)
{ {
printf("Frequency UP\n");
// Advance TX and RX frequency of 12.5KHz // Advance TX and RX frequency of 12.5KHz
state.channel.rx_frequency += 12500; state.channel.rx_frequency += 12500;
state.channel.tx_frequency += 12500; state.channel.tx_frequency += 12500;
} }
if(keys && KEY_DOWN)
if(keys & KEY_DOWN)
{ {
printf("Frequency DOWN\n");
// Advance TX and RX frequency of 12.5KHz // Advance TX and RX frequency of 12.5KHz
state.channel.rx_frequency -= 12500; state.channel.rx_frequency -= 12500;
state.channel.tx_frequency -= 12500; state.channel.tx_frequency -= 12500;