diff --git a/meson.build b/meson.build index 9441ddce..5ccea935 100644 --- a/meson.build +++ b/meson.build @@ -14,10 +14,12 @@ project('OpenRTX', 'c', openrtx_src = ['openrtx/src/main.c', 'openrtx/src/bootstrap.c', 'openrtx/src/state.c', - 'openrtx/src/ui.c'] + 'openrtx/src/ui.c', + 'openrtx/src/threads.c'] openrtx_inc = ['openrtx/include/interfaces', 'openrtx/include/fonts', + 'openrtx/include', 'platform/drivers/ADC', 'platform/drivers/tones'] diff --git a/openrtx/include/interfaces/datatypes.h b/openrtx/include/datatypes.h similarity index 100% rename from openrtx/include/interfaces/datatypes.h rename to openrtx/include/datatypes.h diff --git a/openrtx/include/interfaces/state.h b/openrtx/include/state.h similarity index 96% rename from openrtx/include/interfaces/state.h rename to openrtx/include/state.h index 6df13fd5..aa7c8d0e 100644 --- a/openrtx/include/interfaces/state.h +++ b/openrtx/include/state.h @@ -64,17 +64,18 @@ typedef struct state_t { */ void state_init(); -/** - * This function is the entry point of the state thread - */ -void state_main(); - /** * This function updates the state information by sourcing the * updated values of the various fields of the state_t struct * from corresponding device drivers. */ -state_t state_update(); +void state_update(); + +/** + * Fetch current state. + * @return current state. + */ +state_t state_getCurrentState(); /** * This function terminates the Radio state. diff --git a/openrtx/include/threads.h b/openrtx/include/threads.h new file mode 100644 index 00000000..694ef52e --- /dev/null +++ b/openrtx/include/threads.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, * + * Niccolò Izzo IU2KIN * + * Frederik Saraci IU2NRO * + * Silvano Seva IU2KWO * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see * + ***************************************************************************/ + +#ifndef THREADS_H +#define THREADS_H + +#include + +/** + * Spawn all the threads for the various functionalities. + */ +void create_threads(); + +/** + * Stack size for UI task, in bytes. + */ +#define UI_TASK_STKSIZE 128 + +/** + * Stack size for state update task, in bytes. + */ +#define STATE_TASK_STKSIZE 128 + +/** + * Stack size for baseband control task, in bytes. + */ +#define RTX_TASK_STKSIZE 128 + +/** + * Stack size for DMR task, in bytes. + */ +#define DMR_TASK_STKSIZE 128 + +#endif /* THREADS_H */ diff --git a/openrtx/include/interfaces/ui.h b/openrtx/include/ui.h similarity index 96% rename from openrtx/include/interfaces/ui.h rename to openrtx/include/ui.h index 45a3ad57..29508b5a 100644 --- a/openrtx/include/interfaces/ui.h +++ b/openrtx/include/ui.h @@ -30,11 +30,6 @@ */ void ui_init(); -/** - * This function is the entry point of the UI thread - */ -void ui_main(); - /** * This function advances the User Interface FSM, basing on the * current radio state and the keys pressed. diff --git a/openrtx/src/main.c b/openrtx/src/main.c index 1a57c776..c0eb4b4b 100644 --- a/openrtx/src/main.c +++ b/openrtx/src/main.c @@ -19,156 +19,17 @@ ***************************************************************************/ #include -#include -#include -#include "delays.h" -#include "state.h" -#include "ui.h" - -// Allocate UI thread task control block and stack -static OS_TCB ui_tcb; -static CPU_STK_SIZE ui_stk[128]; -static void ui_task(void *arg); - -// Allocate state thread task control block and stack -static OS_TCB state_tcb; -static CPU_STK_SIZE state_stk[128]; -static void state_task(void *arg); - -// Allocate rtx radio thread task control block and stack -static OS_TCB rtx_tcb; -static CPU_STK_SIZE rtx_stk[128]; -static void rtx_task(void *arg); - -// Allocate dmr radio thread task control block and stack -static OS_TCB dmr_tcb; -static CPU_STK_SIZE dmr_stk[128]; -static void dmr_task(void *arg); - - -void create_threads() -{ - OS_ERR os_err; - - // Create UI thread - OSTaskCreate((OS_TCB *)&ui_tcb, - (CPU_CHAR *)" ", - (OS_TASK_PTR ) ui_task, - (void *) 0, - (OS_PRIO ) 10, - (CPU_STK *)&ui_stk[0], - (CPU_STK ) 0, - (CPU_STK_SIZE) 128, - (OS_MSG_QTY ) 0, - (OS_TICK ) 0, - (void *) 0, - (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), - (OS_ERR *)&os_err); - - // Create state thread - OSTaskCreate((OS_TCB *)&state_tcb, - (CPU_CHAR *)" ", - (OS_TASK_PTR ) state_task, - (void *) 0, - (OS_PRIO ) 30, - (CPU_STK *)&state_stk[0], - (CPU_STK ) 0, - (CPU_STK_SIZE) 128, - (OS_MSG_QTY ) 0, - (OS_TICK ) 0, - (void *) 0, - (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), - (OS_ERR *)&os_err); - - // Create rtx radio thread - OSTaskCreate((OS_TCB *)&rtx_tcb, - (CPU_CHAR *)" ", - (OS_TASK_PTR ) rtx_task, - (void *) 0, - (OS_PRIO ) 5, - (CPU_STK *)&rtx_stk[0], - (CPU_STK ) 0, - (CPU_STK_SIZE) 128, - (OS_MSG_QTY ) 0, - (OS_TICK ) 0, - (void *) 0, - (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), - (OS_ERR *)&os_err); - - // Create dmr radio thread - OSTaskCreate((OS_TCB *)&dmr_tcb, - (CPU_CHAR *)" ", - (OS_TASK_PTR ) dmr_task, - (void *) 0, - (OS_PRIO ) 3, - (CPU_STK *)&dmr_stk[0], - (CPU_STK ) 0, - (CPU_STK_SIZE) 128, - (OS_MSG_QTY ) 0, - (OS_TICK ) 0, - (void *) 0, - (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), - (OS_ERR *)&os_err); -} +#include "threads.h" +#include "platform.h" int main(void) { - // Initialize the radio state - state_init(); - + // Initialize platform drivers + platform_init(); + // Create OpenRTX threads create_threads(); - + while(1) ; return 0; } - -static void ui_task(void *arg) -{ - (void) arg; - OS_ERR os_err; - while(1) - { - // Execute UI thread every 30ms to get ~33FPS - ui_main(); - OSTimeDlyHMSM(0u, 0u, 0u, 30u, OS_OPT_TIME_HMSM_STRICT, &os_err); - } -} - -static void state_task(void *arg) -{ - (void) arg; - OS_ERR os_err; - while(1) - { - // Execute state thread every 1s - state_main(); - OSTimeDlyHMSM(0u, 0u, 1u, 0u, OS_OPT_TIME_HMSM_STRICT, &os_err); - } -} - -static void rtx_task(void *arg) -{ - (void) arg; - OS_ERR os_err; - while(1) - { - // Execute rtx radio thread every 30ms to match DMR task - //TODO: uncomment after rtx.h merge - //rtx_main(); - OSTimeDlyHMSM(0u, 0u, 0u, 30u, OS_OPT_TIME_HMSM_STRICT, &os_err); - } -} - -static void dmr_task(void *arg) -{ - (void) arg; - OS_ERR os_err; - while(1) - { - // Execute dmr radio thread every 30ms to match DMR timeslot - //TODO: uncomment after dmr.h merge - //dmr_main(); - OSTimeDlyHMSM(0u, 0u, 0u, 30u, OS_OPT_TIME_HMSM_STRICT, &os_err); - } -} diff --git a/openrtx/src/state.c b/openrtx/src/state.c index 30578ebf..5bfbc8ac 100644 --- a/openrtx/src/state.c +++ b/openrtx/src/state.c @@ -30,11 +30,12 @@ void state_init() current_state.tx_freq = 0.0; } -void state_main() +void state_update() { + } -state_t state_update() +state_t state_getCurrentState() { return current_state; } diff --git a/openrtx/src/ui.c b/openrtx/src/ui.c index 107b8053..a46fd81a 100644 --- a/openrtx/src/ui.c +++ b/openrtx/src/ui.c @@ -236,43 +236,6 @@ void ui_init() layout_ready = true; } -void ui_main() -{ - OS_ERR os_err; - - if(first_run) - { - first_run = false; - // Init the graphic stack - gfx_init(); - platform_setBacklightLevel(255); - - // Print splash screen - point_t splash_origin = {0, SCREEN_HEIGHT / 2}; - color_t color_yellow_fab413 = {250, 180, 19}; - char *splash_buf = "OpenRTX"; - gfx_clearScreen(); - gfx_print(splash_origin, splash_buf, FONT_SIZE_4, TEXT_ALIGN_CENTER, color_yellow_fab413); - gfx_render(); - while(gfx_renderingInProgress()); - OSTimeDlyHMSM(0u, 0u, 1u, 0u, OS_OPT_TIME_HMSM_STRICT, &os_err); - - // Clear screen - gfx_clearScreen(); - gfx_render(); - while(gfx_renderingInProgress()); - } - - state_t state = state_update(); - uint32_t keys = kbd_getKeys(); - bool renderNeeded = ui_update(state, keys); - if(renderNeeded) - { - gfx_render(); - while(gfx_renderingInProgress()); - } -} - bool ui_update(state_t state, uint32_t keys) { if(!layout_ready)