📄 os_cpu_c.c
字号:
opt = opt; /* 'opt' is not used, prevent compiler warning */
switch ((INT32U)ptos & 0x00000003) { /* Align the stack on a longword boundary */
case 0:
pstk32 = (OS_STK *)((INT32U)ptos + 0);
break;
case 1:
pstk32 = (OS_STK *)((INT32U)ptos - 1);
break;
case 2:
pstk32 = (OS_STK *)((INT32U)ptos - 2);
break;
case 3:
pstk32 = (OS_STK *)((INT32U)ptos - 3);
break;
}
*pstk32 = 0; /* -- SIMULATE CALL TO FUNCTION WITH ARGUMENT -- */
*--pstk32 = (INT32U)p_arg; /* p_arg */
*--pstk32 = (INT32U)task; /* Task return address */
/* ------ SIMULATE INTERRUPT STACK FRAME ------- */
*--pstk32 = (INT32U)task; /* Task return address */
*--pstk32 = (INT32U)(0x40000000 | OS_INITIAL_SR); /* format and status register */
/* ------- SAVE ALL PROCESSOR REGISTERS -------- */
*--pstk32 = (INT32U)0x00A600A6L; /* Register A6 */
*--pstk32 = (INT32U)0x00A500A5L; /* Register A5 */
*--pstk32 = (INT32U)0x00A400A4L; /* Register A4 */
*--pstk32 = (INT32U)0x00A300A3L; /* Register A3 */
*--pstk32 = (INT32U)0x00A200A2L; /* Register A2 */
*--pstk32 = (INT32U)0x00A100A1L; /* Register A1 */
*--pstk32 = (INT32U)p_arg; /* Register A0 */
*--pstk32 = (INT32U)0x00D700D7L; /* Register D7 */
*--pstk32 = (INT32U)0x00D600D6L; /* Register D6 */
*--pstk32 = (INT32U)0x00D500D5L; /* Register D5 */
*--pstk32 = (INT32U)0x00D400D4L; /* Register D4 */
*--pstk32 = (INT32U)0x00D300D3L; /* Register D3 */
*--pstk32 = (INT32U)0x00D200D2L; /* Register D2 */
*--pstk32 = (INT32U)0x00D100D1L; /* Register D1 */
*--pstk32 = (INT32U)p_arg; /* Register D0 */
/* ------- SAVE ALL EMAC REGISTERS ------------- */
*--pstk32 = (INT32U)0x00000000L; /* Register MACSR */
*--pstk32 = (INT32U)0x00000000L; /* Register MASK */
*--pstk32 = (INT32U)0x000ACE23L; /* Register ACCEXT23 */
*--pstk32 = (INT32U)0x000ACE01L; /* Register ACCEXT01 */
*--pstk32 = (INT32U)0x0000ACC3L; /* Register ACC3 */
*--pstk32 = (INT32U)0x0000ACC2L; /* Register ACC2 */
*--pstk32 = (INT32U)0x0000ACC1L; /* Register ACC1 */
*--pstk32 = (INT32U)0x0000ACC0L; /* Register ACC0 */
return ((OS_STK *)pstk32); /* Return pointer to new top-of-stack */
}
/*$PAGE*/
/*
*********************************************************************************************************
* 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_VIEW_MODULE > 0
OSView_TaskSwHook();
#endif
}
#endif
/*
*********************************************************************************************************
* 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)
{
ptcb = ptcb; /* Prevent Compiler warning */
}
#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_VIEW_MODULE > 0
OSView_TickHook();
#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*/
/*
*********************************************************************************************************
* GET ISR VECTOR
*
* Description: This function is called to get the address of the exception handler specified by 'vect'.
* It is assumed that the VBR (Vector Base Register) is set to 0x00000000.
*
* Arguments : vect is the vector number
*
* Note(s) : 1) Interrupts are disabled during this call
* 2) It is assumed that the VBR (Vector Base Register) is set to 0x00000000.
*********************************************************************************************************
*/
INT32U OSVectGet (INT8U vect)
{
INT32U addr;
OS_CPU_SR cpu_sr = 0;
OS_ENTER_CRITICAL();
addr = *(INT32U *)((INT16U)vect * 4);
OS_EXIT_CRITICAL();
return ((INT32U)addr);
}
/*
*********************************************************************************************************
* SET ISR VECTOR
*
* Description: This function is called to set the contents of an exception vector. The function assumes
* that the VBR (Vector Base Register) is set to 0x00000000.
*
* Arguments : vect is the vector number
* addr is the address of the ISR handler
*
* Note(s) : 1) Interrupts are disabled during this call
*********************************************************************************************************
*/
void OSVectSet (INT8U vect, void (*addr)(void))
{
INT32U *pvect;
OS_CPU_SR cpu_sr = 0;
pvect = (INT32U *)((INT16U)vect * 4);
OS_ENTER_CRITICAL();
*pvect = (INT32U)addr;
OS_EXIT_CRITICAL();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -