From 5f669d1c18761bc423f3854dac8465cf4c68576c Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Sat, 28 Nov 2020 21:19:37 +0100 Subject: [PATCH] Made task stack size platform dependent, since values for ARM target were too small for a correct execution on x64 --- openrtx/include/threads.h | 31 ++++++++++++++++++++++++---- openrtx/src/bootstrap.c | 2 +- openrtx/src/threads.c | 40 ++++++++++++++++++------------------ rtos/uC-OS3/Cfg/os_cfg_x64.h | 14 ++++++------- 4 files changed, 55 insertions(+), 32 deletions(-) diff --git a/openrtx/include/threads.h b/openrtx/include/threads.h index cd0b01aa..a61d8497 100644 --- a/openrtx/include/threads.h +++ b/openrtx/include/threads.h @@ -28,24 +28,47 @@ */ void create_threads(); +#ifdef __arm__ + /** * Stack size for UI task, in bytes. */ -#define UI_TASK_STKSIZE 1024 +#define UI_TASK_STKSIZE 1024*4 /** * Stack size for state update task, in bytes. */ -#define STATE_TASK_STKSIZE 128 +#define STATE_TASK_STKSIZE 128*4 /** * Stack size for baseband control task, in bytes. */ -#define RTX_TASK_STKSIZE 128 +#define RTX_TASK_STKSIZE 128*4 /** * Stack size for DMR task, in bytes. */ -#define DMR_TASK_STKSIZE 128 +#define DMR_TASK_STKSIZE 128*4 + +#else /* __arm__ */ + +#define UI_TASK_STKSIZE 4096 + +/** + * Stack size for state update task, in bytes. + */ +#define STATE_TASK_STKSIZE 1024 + +/** + * Stack size for baseband control task, in bytes. + */ +#define RTX_TASK_STKSIZE 1024 + +/** + * Stack size for DMR task, in bytes. + */ +#define DMR_TASK_STKSIZE 1024 + +#endif /* __arm__ */ #endif /* THREADS_H */ diff --git a/openrtx/src/bootstrap.c b/openrtx/src/bootstrap.c index 0a6610de..2cc9c6fe 100644 --- a/openrtx/src/bootstrap.c +++ b/openrtx/src/bootstrap.c @@ -29,7 +29,7 @@ int main(int argc, char *argv[]); /* * OS startup task, will call main() when all initialisations are done. */ -#define START_TSK_STKSIZE 512/4 +#define START_TSK_STKSIZE 512/sizeof(CPU_STK) static OS_TCB startTCB; static CPU_STK startStk[START_TSK_STKSIZE]; static void startTask(void *arg); diff --git a/openrtx/src/threads.c b/openrtx/src/threads.c index e3e5a92f..72f457c9 100644 --- a/openrtx/src/threads.c +++ b/openrtx/src/threads.c @@ -33,34 +33,34 @@ static OS_MUTEX state_mutex; - /**************************** IMPORTANT NOTE ********************************** - * * - * Rationale for "xx_TASK_STKSIZE/4": uC/OS-III manages task stack in terms * - * of CPU_STK elements which, on a 32-bit target, are something like uint32_t,* - * that is, one CPU_STK elements takes four bytes. * - * * - * Now, the majority of the world manages stack in terms of *bytes* and this * - * leads to an excessive RAM usage if not properly managed. For example, if * - * we have, say, xx_TASK_SIZE = 128 with these odd CPU_STK elements we end * - * up eating 128*4 = 512 bytes. * - * The simple workaround for this is dividing the stack size by four. * - ******************************************************************************/ + /**************************** IMPORTANT NOTE *********************************** + * * + * Rationale for "xx_TASK_STKSIZE/sizeof(CPU_STK)": uC/OS-III manages task * + * stack in terms of CPU_STK elements which, on a 32-bit target, are something * + * like uint32_t, that is, one CPU_STK elements takes four bytes. * + * * + * Now, the majority of the world manages stack in terms of *bytes* and this * + * leads to an excessive RAM usage if not properly managed. For example, if * + * we have, say, xx_TASK_SIZE = 128 with these odd CPU_STK elements we end * + * up eating 128*4 = 512 bytes. * + * The simple workaround for this is dividing the stack size by sizeof(CPU_STK)* + *******************************************************************************/ /* UI task control block and stack */ static OS_TCB ui_tcb; -static CPU_STK ui_stk[UI_TASK_STKSIZE/4]; +static CPU_STK ui_stk[UI_TASK_STKSIZE/sizeof(CPU_STK)]; /* State task control block and stack */ static OS_TCB state_tcb; -static CPU_STK state_stk[STATE_TASK_STKSIZE/4]; +static CPU_STK state_stk[STATE_TASK_STKSIZE/sizeof(CPU_STK)]; /* Baseband task control block and stack */ static OS_TCB rtx_tcb; -static CPU_STK rtx_stk[RTX_TASK_STKSIZE/4]; +static CPU_STK rtx_stk[RTX_TASK_STKSIZE/sizeof(CPU_STK)]; /* DMR task control block and stack */ static OS_TCB dmr_tcb; -static CPU_STK dmr_stk[DMR_TASK_STKSIZE/4]; +static CPU_STK dmr_stk[DMR_TASK_STKSIZE/sizeof(CPU_STK)]; /** @@ -207,7 +207,7 @@ void create_threads() (OS_PRIO ) 10, (CPU_STK *) &ui_stk[0], (CPU_STK ) 0, - (CPU_STK_SIZE) UI_TASK_STKSIZE/4, + (CPU_STK_SIZE) UI_TASK_STKSIZE/sizeof(CPU_STK), (OS_MSG_QTY ) 0, (OS_TICK ) 0, (void *) 0, @@ -222,7 +222,7 @@ void create_threads() (OS_PRIO ) 30, (CPU_STK *) &state_stk[0], (CPU_STK ) 0, - (CPU_STK_SIZE) STATE_TASK_STKSIZE/4, + (CPU_STK_SIZE) STATE_TASK_STKSIZE/sizeof(CPU_STK), (OS_MSG_QTY ) 0, (OS_TICK ) 0, (void *) 0, @@ -237,7 +237,7 @@ void create_threads() (OS_PRIO ) 5, (CPU_STK *) &rtx_stk[0], (CPU_STK ) 0, - (CPU_STK_SIZE) RTX_TASK_STKSIZE/4, + (CPU_STK_SIZE) RTX_TASK_STKSIZE/sizeof(CPU_STK), (OS_MSG_QTY ) 0, (OS_TICK ) 0, (void *) 0, @@ -252,7 +252,7 @@ void create_threads() (OS_PRIO ) 3, (CPU_STK *) &dmr_stk[0], (CPU_STK ) 0, - (CPU_STK_SIZE) DMR_TASK_STKSIZE/4, + (CPU_STK_SIZE) DMR_TASK_STKSIZE/sizeof(CPU_STK), (OS_MSG_QTY ) 0, (OS_TICK ) 0, (void *) 0, diff --git a/rtos/uC-OS3/Cfg/os_cfg_x64.h b/rtos/uC-OS3/Cfg/os_cfg_x64.h index c372ae35..28e7557d 100644 --- a/rtos/uC-OS3/Cfg/os_cfg_x64.h +++ b/rtos/uC-OS3/Cfg/os_cfg_x64.h @@ -28,7 +28,7 @@ #define OS_CFG_x64_H /* --------------------------- MISCELLANEOUS --------------------------- */ -#define OS_CFG_APP_HOOKS_EN 0u /* Enable (1) or Disable (0) application specific hooks */ +#define OS_CFG_APP_HOOKS_EN 1u /* Enable (1) or Disable (0) application specific hooks */ #define OS_CFG_ARG_CHK_EN 1u /* Enable (1) or Disable (0) argument checking */ #define OS_CFG_CALLED_FROM_ISR_CHK_EN 1u /* Enable (1) or Disable (0) check for called from ISR */ #define OS_CFG_DBG_EN 1u /* Enable (1) or Disable (0) debug code/variables */ @@ -54,7 +54,7 @@ /* ------------------------ MEMORY MANAGEMENT ------------------------- */ -#define OS_CFG_MEM_EN 0u /* Enable (1) or Disable (0) code generation for the MEMORY MANAGER */ +#define OS_CFG_MEM_EN 1u /* Enable (1) or Disable (0) code generation for the MEMORY MANAGER */ /* ------------------- MUTUAL EXCLUSION SEMAPHORES -------------------- */ @@ -78,13 +78,13 @@ /* -------------------------- TASK MANAGEMENT -------------------------- */ -#define OS_CFG_STAT_TASK_EN 0u /* Enable (1) or Disable (0) the statistics task */ -#define OS_CFG_STAT_TASK_STK_CHK_EN 0u /* Check task stacks from the statistic task */ +#define OS_CFG_STAT_TASK_EN 1u /* Enable (1) or Disable (0) the statistics task */ +#define OS_CFG_STAT_TASK_STK_CHK_EN 1u /* Check task stacks from the statistic task */ #define OS_CFG_TASK_CHANGE_PRIO_EN 1u /* Include code for OSTaskChangePrio() */ #define OS_CFG_TASK_DEL_EN 1u /* Include code for OSTaskDel() */ #define OS_CFG_TASK_IDLE_EN 1u /* Include the idle task */ -#define OS_CFG_TASK_PROFILE_EN 0u /* Include variables in OS_TCB for profiling */ +#define OS_CFG_TASK_PROFILE_EN 1u /* Include variables in OS_TCB for profiling */ #define OS_CFG_TASK_Q_EN 1u /* Include code for OSTaskQXXXX() */ #define OS_CFG_TASK_Q_PEND_ABORT_EN 1u /* Include code for OSTaskQPendAbort() */ #define OS_CFG_TASK_REG_TBL_SIZE 1u /* Number of task specific registers */ @@ -106,8 +106,8 @@ /* ------------------------- TIMER MANAGEMENT -------------------------- */ -#define OS_CFG_TMR_EN 0u /* Enable (1) or Disable (0) code generation for TIMERS */ -#define OS_CFG_TMR_DEL_EN 0u /* Enable (1) or Disable (0) code generation for OSTmrDel() */ +#define OS_CFG_TMR_EN 1u /* Enable (1) or Disable (0) code generation for TIMERS */ +#define OS_CFG_TMR_DEL_EN 1u /* Enable (1) or Disable (0) code generation for OSTmrDel() */ /* ------------------------- TRACE RECORDER ---------------------------- */