mirror of https://github.com/ARMmbed/mbed-os.git
RTOS - fix for main thread id might not be 0x02
Fixes #2059. As reported, if timer thread is not created, the main thread id is 0x01. We introduce MAIN_THREAD_ID macro to define the id. We shall consider, if we keep this in a variable. I placed MAIN_THREAD_ID in cmsis_os.h as that header is safe to include within RTX, not like RTX_Config.h or RTX_CM_Lib.h).pull/2075/head
parent
467c8d5b15
commit
757d340b0a
|
@ -35,7 +35,7 @@
|
|||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_HAL_CM.h"
|
||||
|
||||
#include "cmsis_os.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Global Variables
|
||||
|
@ -93,12 +93,12 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
|
|||
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
/* Set a magic word for checking of stack overflow.
|
||||
For the main thread (ID: 0x02) the stack is in a memory area shared with the
|
||||
For the main thread (ID: MAIN_THREAD_ID) the stack is in a memory area shared with the
|
||||
heap, therefore the last word of the stack is a moving target.
|
||||
We want to do stack/heap collision detection instead.
|
||||
Similar applies to stack filling for the magic pattern.
|
||||
*/
|
||||
if (p_TCB->task_id != 0x02) {
|
||||
if (p_TCB->task_id != MAIN_THREAD_ID) {
|
||||
p_TCB->stack[0] = MAGIC_WORD;
|
||||
|
||||
/* Initialize stack with magic pattern. */
|
||||
|
|
|
@ -39,11 +39,6 @@
|
|||
* RTX User configuration part BEGIN
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#if defined(MBED_RTOS_SINGLE_THREAD)
|
||||
#define OS_TASKCNT 1
|
||||
#define OS_TIMERS 0
|
||||
#endif
|
||||
|
||||
//-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
|
||||
//
|
||||
// <h>Thread Configuration
|
||||
|
|
|
@ -72,6 +72,24 @@
|
|||
# define WORDS_STACK_SIZE 128
|
||||
#endif
|
||||
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
|
||||
/* Single thread - disable timers and set task count to one */
|
||||
#if defined(MBED_RTOS_SINGLE_THREAD)
|
||||
#define OS_TASKCNT 1
|
||||
#define OS_TIMERS 0
|
||||
#endif
|
||||
|
||||
/* If os timers macro is set to 0, there's no timer thread created, therefore
|
||||
* main thread has tid 0x01
|
||||
*/
|
||||
#if (OS_TIMERS != 0)
|
||||
#define MAIN_THREAD_ID 0x02
|
||||
#else
|
||||
#define MAIN_THREAD_ID 0x01
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define DEFAULT_STACK_SIZE (WORDS_STACK_SIZE*4)
|
||||
|
||||
#define osCMSIS 0x10002U ///< CMSIS-RTOS API version (main [31:16] .sub [15:0])
|
||||
|
|
|
@ -315,7 +315,7 @@ void rt_systick (void) {
|
|||
__weak void rt_stk_check (void) {
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
/* Check for stack overflow. */
|
||||
if (os_tsk.run->task_id == 0x02) {
|
||||
if (os_tsk.run->task_id == MAIN_THREAD_ID) {
|
||||
// TODO: For the main thread the check should be done against the main heap pointer
|
||||
} else {
|
||||
if ((os_tsk.run->tsk_stack < (U32)os_tsk.run->stack) ||
|
||||
|
|
Loading…
Reference in New Issue