📄 os_cpu_c.c
字号:
*/
OS_STK *OSTaskStkInit (void (*task)(void *pd), void *p_arg, OS_STK *ptos, INT16U opt)
{
OS_STK *stk;
(void)opt; /* 'opt' is not used, prevent warning */
stk = ptos;
*stk-- = (INT32U) 0x08080808; /* R8 */
*stk-- = (INT32U) 0x09090909; /* R9 */
*stk-- = (INT32U) 0x10101010; /* R10 */
*stk-- = (INT32U) 0x11111111; /* R11 */
*stk-- = (INT32U) p_arg; /* R12 */
*stk-- = (INT32U) 0x14141414; /* R14/LR */
*stk-- = (INT32U) task; /* R15/PC */
*stk-- = (INT32U) OS_CPU_SR_M0_MASK; /* SR: Supervisor mode */
*stk-- = (INT32U) 0xFF0000FF; /* R0 */
*stk-- = (INT32U) 0x01010101; /* R1 */
*stk-- = (INT32U) 0x02020202; /* R2 */
*stk-- = (INT32U) 0x03030303; /* R3 */
*stk-- = (INT32U) 0x04040404; /* R4 */
*stk-- = (INT32U) 0x05050505; /* R5 */
*stk-- = (INT32U) 0x06060606; /* R6 */
*stk = (INT32U) 0x07070707; /* R7 */
return (stk);
}
/*
*********************************************************************************************************
* TASK SWITCH HOOK
*
* Description: This function is called when a task switch is performed. This allows you to perform other
* operations during a context switch.
*
* Arguments : none
*
* Note(s) : 1) Interrupts are disabled during this call.
* 2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
* will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
* task being switched out (i.e. the preempted task).
*********************************************************************************************************
*/
#if (OS_CPU_HOOKS_EN > 0) && (OS_TASK_SW_HOOK_EN > 0)
void OSTaskSwHook (void)
{
#if OS_APP_HOOKS_EN > 0
App_TaskSwHook();
#endif
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* OS_TCBInit() HOOK
*
* Description: This function is called by OS_TCBInit() after setting up most of the TCB.
*
* Arguments : ptcb is a pointer to the TCB of the task being created.
*
* Note(s) : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if (OS_CPU_HOOKS_EN > 0) && (OS_VERSION > 203)
void OSTCBInitHook (OS_TCB *ptcb)
{
#if OS_APP_HOOKS_EN > 0
App_TCBInitHook(ptcb);
#else
(void)ptcb; /* Prevent compiler warning */
#endif
}
#endif
/*
*********************************************************************************************************
* TICK HOOK
*
* Description: This function is called every tick.
*
* Arguments : none
*
* Note(s) : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if (OS_CPU_HOOKS_EN > 0) && (OS_TIME_TICK_HOOK_EN > 0)
void OSTimeTickHook (void)
{
#if OS_APP_HOOKS_EN > 0
App_TimeTickHook();
#endif
#if (OS_VERSION >= 281) && (OS_TMR_EN > 0)
OSTmrCtr++;
if (OSTmrCtr >= (OS_TICKS_PER_SEC / OS_TMR_CFG_TICKS_PER_SEC)) {
OSTmrCtr = 0;
OSTmrSignal();
}
#endif
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* INTERRUPT LEVEL CONTEXT SWITCH
*
* Description: This function is called by OSIntExit() to perform a context switch from an ISR.
*
* Arguments : none
*
* Note(s) : 1) The stack frame is assumed to look as follows:
*
* OSTCBHighRdy->OSTCBStkPtr --> SP -->
* R7 ----/ (Low memory)
* .
* .
* R0
* SR
* PC
* LR
* R12
* .
* .
* R8 ----\ (High memory)
*
* where the stack pointer points to the task start address.
*
* 2) OSIntCtxSw() MUST:
* a) Call OSTaskSwHook() then,
* b) Set OSTCBCur = OSTCBHighRdy,
* c) Set OSPrioCur = OSPrioHighRdy,
* d) Switch to the highest priority task.
*********************************************************************************************************
*/
void OSIntCtxSw (void)
{
OSTaskSwHook();
OSTCBCur = OSTCBHighRdy;
OSPrioCur = OSPrioHighRdy;
OSIntCtxRestore(OSTCBHighRdy->OSTCBStkPtr);
}
/*
*********************************************************************************************************
* START HIGHEST PRIORITY TASK READY-TO-RUN
*
* Description: This function is called by OSStart() to start the highest priority task that was created
* by your application before calling OSStart().
*
* Arguments : none
*
* Note(s) : 1) The stack frame is assumed to look as follows:
*
* OSTCBHighRdy->OSTCBStkPtr --> SP -->
* R7 ----/ (Low memory)
* .
* .
* R0
* SR
* PC
* LR
* R12
* .
* .
* R8 ----\ (High memory)
*
* where the stack pointer points to the task start address.
*
* 2) OSStartHighRdy() MUST:
* a) Call OSTaskSwHook() then,
* b) Set OSRunning to TRUE,
* c) Switch to the highest priority task.
*********************************************************************************************************
*/
void OSStartHighRdy (void)
{
OSTaskSwHook();
OSRunning = 1;
OSCtxRestore(OSTCBHighRdy->OSTCBStkPtr);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -