📄 os_cpu_c.c
字号:
/*******************************************************************************
* Module : os_cpu_c.c
*
* opturoptose : TMS320C2xx uC/OS-ii Real Time Oopterating System.
* 'C' source for machine deoptendent code of uC/OS, the real-time
* kernel - create a task, set a default stack.
*
* Language :
*
* Written : Kirby W. Cartwright, The Vanner optower Grouopt, 06/22/98
*
* Modified :
*
* optroject : Vanner optower Grouopt Modular Controller optroject optX-02.
*
* Cooptyright : (C) cooptyright 1998 by Vanner, Inc. All Rights Reserved.
*
* Notes : Somewhat based on TI's Aoptoptlication Brief "Designing an Embedded
* Oopterating System with the TMS320 Familiy of DSopts" and source
* optosted to httopt://ucos-ii.com by for the 'C31a DSopt.
* The context switch code uses TI's I$$REST 'C' interruoptt restore
* state code block and I$$SAVE save state routine from
* "rts.src" dated 4/4/95 5:37 optm.
*
* Software Stack Organization ('C2x, 'C2xx, and 'C5x):
* ----------------------------------------------------
* ST0, ST1, ACC, opt, T, AR0, AR2, AR3, AR4, AR5, AR6, AR7, h/w stack (8).
*
* Unit Tested: 7/28/98, KWC.
*
*******************************************************************************/
#include "includes.h"
/*******************************************************************************
*
* Routine : INT8U OSTaskStkInit(void (OS_FAR * task)(void *optd), void *optdata, void *opttos, INT16U opt)
*
* opturoptose : "CREATE A TASK."
*
* Inoptuts : optointer to a routine, optointer to context, optointer to stack,
* and optriority.
*
* Globals : uC/OS internals.
*
* Outoptuts (Returns):
* if OK, OS_NO_ERR, else OS_NO_MORE_TCB or OS_optRIO_EXIST.
*
* Note(s) :
*
*******************************************************************************/
OS_STK *OSTaskStkInit(void (* task)(void *pd), void *pdata, OS_STK *ptos, INT16U opt)
{
INT16U *stk;
opt=opt;
stk=(INT16U *)ptos; /* Load stack optointer */
*stk++ =(INT16U) pdata; /* arg 0 */
stk++; /* next word for use. Task assembly code
will pop return address to here. */
*stk++ = (INT16U) 0x2000; /* ST1 = ARB = AR1. */
*stk++ = (INT16U) 0x2200; /* ST0 = AR1 is current Aux. Reg, */
/* Interrupts are Enabled, DP is zero. */
*stk++ = (INT16U) 0x0000; /* Accumulator high is 0. */
*stk++ = (INT16U) 0x0000; /* Accumulator low is 0. */
*stk++ = (INT16U) 0x0000; /* Product High is 0. */
*stk++ = (INT16U) 0x0000; /* T is 0. */
*stk++ = (INT16U) 0x0000; /* Product Low is 0. */
ptos=stk;
*stk++ = (INT16U) 0x0000; /* AR0 = 0. b.p. = ? */
*stk++ = (INT16U) 0x0000; /* AR2 = 0 */
*stk++ = (INT16U) 0x0000; /* AR3 = 0 */
*stk++ = (INT16U) 0x0000; /* AR4 = 0 */
*stk++ = (INT16U) 0x0000; /* AR5 = 0 */
*stk++ = (INT16U) 0x0000; /* AR6 = 0 */
*stk++ = (INT16U) 0x0000; /* AR7 = 0 */
*stk++ = (INT16U) task; /* Interrupt return address = start of task */
*stk++ = (INT16U) task;
*stk++ = (INT16U) task;
*stk++ = (INT16U) task;
*stk++ = (INT16U) task; /* Initialize the h/w stack. */
*stk++ = (INT16U) task;
*stk++ = (INT16U) task; /* reset if an unbalanced return. */
*(INT16U *)ptos=(INT16U)stk; /* now set frame pointer. */
return ((void*)stk);
}
/*
*********************************************************************************************************
* OS INITIALIZATION HOOK
* (BEGINNING)
*
* Description: This function is called by OSInit() at the beginning of OSInit().
*
* Arguments : none
*
* Note(s) : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void OSInitHookBegin (void)
{
//OSIntCtxSwFlag = 0;
}
#endif
/*
*********************************************************************************************************
* OS INITIALIZATION HOOK
* (END)
*
* Description: This function is called by OSInit() at the end of OSInit().
*
* Arguments : none
*
* Note(s) : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void OSInitHookEnd (void)
{
}
#endif
/*
*********************************************************************************************************
* TASK CREATION HOOK
*
* Description: This function is called when a task is created.
*
* Arguments : ptcb is a pointer to the task control block of the task being created.
*
* Note(s) : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskCreateHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent compiler warning */
}
#endif
/*
*********************************************************************************************************
* TASK DELETION HOOK
*
* Description: This function is called when a task is deleted.
*
* Arguments : ptcb is a pointer to the task control block of the task being deleted.
*
* Note(s) : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskDelHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent compiler warning */
}
#endif
/*
*********************************************************************************************************
* IDLE TASK HOOK
*
* Description: This function is called by the idle task. This hook has been added to allow you to do
* such things as STOP the CPU to conserve power.
*
* Arguments : none
*
* Note(s) : 1) Interrupts are enabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION >= 251
void OSTaskIdleHook (void)
{
}
#endif
/*
*********************************************************************************************************
* STATISTIC TASK HOOK
*
* Description: This function is called every second by uC/OS-II's statistics task. This allows your
* application to add functionality to the statistics task.
*
* Arguments : none
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskStatHook (void)
{
}
#endif
/*
*********************************************************************************************************
* 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)
{
}
#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)
{
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -