Code: Select all
chSysGetIdleThreadX()
The reason I looking for a pointer to the idle thread in the hook is because I need to do something different in the case of switching to/from the idle thread. Specifically, I was writing a hook for Segger's SystemView. I used a workaround where I looked at the incoming and outgoing threads' priority levels. The hack requires that the only thread to have idle priority is the idle thread. And here is the code for anyone who's interested:
Code: Select all
/**
* @brief Context switch hook.
* @details This hook is invoked just before switching between threads.
*/
#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) \
{ \
/* Context switch code here.*/ \
if (otp->prio != IDLEPRIO) { \
SEGGER_SYSVIEW_OnTaskStopReady(otp, otp->state); \
} \
if (ntp->prio == IDLEPRIO) { \
SEGGER_SYSVIEW_OnIdle(); \
} else { \
SEGGER_SYSVIEW_OnTaskStartExec((unsigned)ntp); \
} \
\
}