File tree Expand file tree Collapse file tree 4 files changed +22
-9
lines changed
Expand file tree Collapse file tree 4 files changed +22
-9
lines changed Original file line number Diff line number Diff line change 3535#include "rt_TypeDef.h"
3636#include "RTX_Config.h"
3737#include "rt_HAL_CM.h"
38-
38+ #include "cmsis_os.h"
3939
4040/*----------------------------------------------------------------------------
4141 * Global Variables
@@ -93,12 +93,12 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
9393
9494#ifdef __MBED_CMSIS_RTOS_CM
9595 /* Set a magic word for checking of stack overflow.
96- For the main thread (ID: 0x02 ) the stack is in a memory area shared with the
96+ For the main thread (ID: MAIN_THREAD_ID ) the stack is in a memory area shared with the
9797 heap, therefore the last word of the stack is a moving target.
9898 We want to do stack/heap collision detection instead.
9999 Similar applies to stack filling for the magic pattern.
100100 */
101- if (p_TCB -> task_id != 0x02 ) {
101+ if (p_TCB -> task_id != MAIN_THREAD_ID ) {
102102 p_TCB -> stack [0 ] = MAGIC_WORD ;
103103
104104 /* Initialize stack with magic pattern. */
Original file line number Diff line number Diff line change 3939 * RTX User configuration part BEGIN
4040 *---------------------------------------------------------------------------*/
4141
42- #if defined(MBED_RTOS_SINGLE_THREAD )
43- #define OS_TASKCNT 1
44- #define OS_TIMERS 0
45- #endif
46-
4742//-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
4843//
4944// <h>Thread Configuration
Original file line number Diff line number Diff line change 7272# define WORDS_STACK_SIZE 128
7373#endif
7474
75+ #ifdef __MBED_CMSIS_RTOS_CM
76+
77+ /* Single thread - disable timers and set task count to one */
78+ #if defined(MBED_RTOS_SINGLE_THREAD )
79+ #define OS_TASKCNT 1
80+ #define OS_TIMERS 0
81+ #endif
82+
83+ /* If os timers macro is set to 0, there's no timer thread created, therefore
84+ * main thread has tid 0x01
85+ */
86+ #if (OS_TIMERS != 0 )
87+ #define MAIN_THREAD_ID 0x02
88+ #else
89+ #define MAIN_THREAD_ID 0x01
90+ #endif
91+ #endif
92+
7593#define DEFAULT_STACK_SIZE (WORDS_STACK_SIZE*4)
7694
7795#define osCMSIS 0x10002U ///< CMSIS-RTOS API version (main [31:16] .sub [15:0])
Original file line number Diff line number Diff line change @@ -315,7 +315,7 @@ void rt_systick (void) {
315315__weak void rt_stk_check (void ) {
316316#ifdef __MBED_CMSIS_RTOS_CM
317317 /* Check for stack overflow. */
318- if (os_tsk .run -> task_id == 0x02 ) {
318+ if (os_tsk .run -> task_id == MAIN_THREAD_ID ) {
319319 // TODO: For the main thread the check should be done against the main heap pointer
320320 } else {
321321 if ((os_tsk .run -> tsk_stack < (U32 )os_tsk .run -> stack ) ||
You can’t perform that action at this time.
0 commit comments