mirror of https://github.com/ARMmbed/mbed-os.git
RTX - expose rt_tid2ptcb() function to get TCB
This enables the stack info methods to be supported for Cortex-M targets. The rt_TypeDef required one small change - rename new structure member as this is a reserved keyword in C++. We need to ask for tid everytime we need to use tcb, do not expose internal RTX details, we keep it within Thread.cpp file.pull/1702/head
parent
9d06547135
commit
bc270f1fe2
|
@ -24,6 +24,12 @@
|
|||
#include "mbed_error.h"
|
||||
#include "rtos_idle.h"
|
||||
|
||||
// rt_tid2ptcb is an internal function which we exposed to get TCB for thread id
|
||||
#undef NULL //Workaround for conflicting macros in rt_TypeDef.h and stdio.h
|
||||
#include "rt_TypeDef.h"
|
||||
|
||||
extern "C" P_TCB rt_tid2ptcb(osThreadId thread_id);
|
||||
|
||||
namespace rtos {
|
||||
|
||||
Thread::Thread(void (*task)(void const *argument), void *argument,
|
||||
|
@ -87,7 +93,8 @@ uint32_t Thread::stack_size() {
|
|||
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
|
||||
return _thread_def.tcb.priv_stack;
|
||||
#else
|
||||
return 0;
|
||||
P_TCB tcb = rt_tid2ptcb(_tid);
|
||||
return tcb->priv_stack;
|
||||
#endif
|
||||
#else
|
||||
return 0;
|
||||
|
@ -100,7 +107,9 @@ uint32_t Thread::free_stack() {
|
|||
uint32_t bottom = (uint32_t)_thread_def.tcb.stack;
|
||||
return _thread_def.tcb.tsk_stack - bottom;
|
||||
#else
|
||||
return 0;
|
||||
P_TCB tcb = rt_tid2ptcb(_tid);
|
||||
uint32_t bottom = (uint32_t)tcb->stack;
|
||||
return tcb->tsk_stack - bottom;
|
||||
#endif
|
||||
#else
|
||||
return 0;
|
||||
|
@ -113,7 +122,9 @@ uint32_t Thread::used_stack() {
|
|||
uint32_t top = (uint32_t)_thread_def.tcb.stack + _thread_def.tcb.priv_stack;
|
||||
return top - _thread_def.tcb.tsk_stack;
|
||||
#else
|
||||
return 0;
|
||||
P_TCB tcb = rt_tid2ptcb(_tid);
|
||||
uint32_t top = (uint32_t)tcb->stack + tcb->priv_stack;
|
||||
return top - tcb->tsk_stack;
|
||||
#endif
|
||||
#else
|
||||
return 0;
|
||||
|
@ -128,7 +139,11 @@ uint32_t Thread::max_stack() {
|
|||
high_mark++;
|
||||
return _thread_def.tcb.priv_stack - (high_mark * 4);
|
||||
#else
|
||||
return 0;
|
||||
P_TCB tcb = rt_tid2ptcb(_tid);
|
||||
uint32_t high_mark = 0;
|
||||
while (tcb->stack[high_mark] == 0xE25A2EA5)
|
||||
high_mark++;
|
||||
return tcb->priv_stack - (high_mark * 4);
|
||||
#endif
|
||||
#else
|
||||
return 0;
|
||||
|
|
|
@ -407,7 +407,7 @@ static uint16_t rt_ms2tick (uint32_t millisec) {
|
|||
}
|
||||
|
||||
/// Convert Thread ID to TCB pointer
|
||||
static P_TCB rt_tid2ptcb (osThreadId thread_id) {
|
||||
P_TCB rt_tid2ptcb (osThreadId thread_id) {
|
||||
P_TCB ptcb;
|
||||
|
||||
if (thread_id == NULL) { return NULL; }
|
||||
|
@ -506,8 +506,8 @@ osStatus svcKernelStart (void) {
|
|||
if (os_tsk.run->task_id == 0xFFU) { // Idle Thread
|
||||
__set_PSP(os_tsk.run->tsk_stack + (8U*4U)); // Setup PSP
|
||||
}
|
||||
if (os_tsk.new == NULL) { // Force context switch
|
||||
os_tsk.new = os_tsk.run;
|
||||
if (os_tsk.new_tsk == NULL) { // Force context switch
|
||||
os_tsk.new_tsk = os_tsk.run;
|
||||
os_tsk.run = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -276,7 +276,7 @@ extern void dbg_task_switch (U32 task_id);
|
|||
#ifdef DBG_MSG
|
||||
#define DBG_INIT() dbg_init()
|
||||
#define DBG_TASK_NOTIFY(p_tcb,create) if (dbg_msg) dbg_task_notify(p_tcb,create)
|
||||
#define DBG_TASK_SWITCH(task_id) if (dbg_msg && (os_tsk.new!=os_tsk.run)) \
|
||||
#define DBG_TASK_SWITCH(task_id) if (dbg_msg && (os_tsk.new_tsk!=os_tsk.run)) \
|
||||
dbg_task_switch(task_id)
|
||||
#else
|
||||
#define DBG_INIT()
|
||||
|
|
|
@ -99,7 +99,7 @@ static void rt_init_context (P_TCB p_TCB, U8 priority, FUNCP task_body) {
|
|||
|
||||
void rt_switch_req (P_TCB p_new) {
|
||||
/* Switch to next task (identified by "p_new"). */
|
||||
os_tsk.new = p_new;
|
||||
os_tsk.new_tsk = p_new;
|
||||
p_new->state = RUNNING;
|
||||
DBG_TASK_SWITCH(p_new->task_id);
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ typedef struct OS_PSQ { /* Post Service Queue */
|
|||
|
||||
typedef struct OS_TSK {
|
||||
P_TCB run; /* Current running task */
|
||||
P_TCB new; /* Scheduled task to run */
|
||||
P_TCB new_tsk; /* Scheduled task to run */
|
||||
} *P_TSK;
|
||||
|
||||
typedef struct OS_ROBIN { /* Round Robin Control */
|
||||
|
|
Loading…
Reference in New Issue