?? os_cpu_c.c
字號:
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskDelHook (OS_TCB *ptcb)
{
if (ptcb->OSTCBOpt & OS_TASK_OPT_SAVE_FP) { /* See if task had FP support */
if (ptcb->OSTCBExtPtr != (void *)0) { /* Yes, OSTCBExtPtr must not be NULL */
OSMemPut(OSFPPartPtr, ptcb->OSTCBExtPtr); /* Return memory block to free pool */
//釋放內存塊到原來的內存分區
}
}
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* 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 && 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
*********************************************************************************************************
*/
/*
*********************************************************************************************************
統計任務接口函數
描述:這個任務由icosII統計任務每一秒鐘調用,它允許應用中
加入功能到統計任務
參數:無
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskStatHook (void)
{
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* INITIALIZE A TASK'S STACK
*
* Description: This function is called by either OSTaskCreate() or OSTaskCreateExt() to initialize the
* stack frame of the task being created. This function is highly processor specific.
*
* Arguments : task is a pointer to the task code
*
* pdata is a pointer to a user supplied data area that will be passed to the task
* when the task first executes.
*
* ptos is a pointer to the top of stack. It is assumed that 'ptos' points to
* a 'free' entry on the task stack. If OS_STK_GROWTH is set to 1 then
* 'ptos' will contain the HIGHEST valid address of the stack. Similarly, if
* OS_STK_GROWTH is set to 0, the 'ptos' will contains the LOWEST valid address
* of the stack.
*
* opt specifies options that can be used to alter the behavior of OSTaskStkInit().
* (see uCOS_II.H for OS_TASK_OPT_???).
*
* Returns : Always returns the location of the new top-of-stack' once the processor registers have
* been placed on the stack in the proper order.
*
* Note(s) : Interrupts are enabled when your task starts executing. You can change this by setting the
* PSW to 0x0002 instead. In this case, interrupts would be disabled upon task startup. The
* application code would be responsible for enabling interrupts at the beginning of the task
* code. You will need to modify OSTaskIdle() and OSTaskStat() so that they enable
* interrupts. Failure to do this will make your system crash!
*********************************************************************************************************
*/
/*
*********************************************************************************************************
任務堆棧初始化函數
描述:這個函數由OSTaskCreate() or OSTaskCreateExt()調用,初始化將要建立任務的堆棧結構。
這個函數是一些處理器特有的。
參數:task:指向任務代碼的指針
pdata:當任務第一次運行時,指用戶將傳遞給任務的由任務指定的數據區域指針
ptos:指向棧頂的指針。它假定 ptos 指向任務堆棧的空閑入口。如果OS_STK_GROWTH
為1,ptos將包含堆棧的最高有效埴,同理,如果為0,將包含堆棧最低地址。
opt:用于改變OSTaskStkInit()習慣的專有特征(見uCOS_II.H for OS_TASK_OPT_???)
返回:如果處理器寄存器放置在堆棧適當順序,將始終返回新棧頂位置。
注意:當任務開始執行的時候中斷打開。你可以通過將PSW改變成0x0002來改變它,這種情況下,任務
啟動的時候中斷將關閉。你還需要修改OSTaskIdle() and OSTaskStat()這樣它們會開中斷,
如果不這樣做系統會崩潰。
*********************************************************************************************************
*/
OS_STK *OSTaskStkInit (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT16U opt)
{
INT16U *stk;
opt = opt; /* 'opt' is not used, prevent warning */
//opt沒有用到,防止編譯器警告
stk = (INT16U *)ptos; /* Load stack pointer */
//建立并初始化一個變量,指向以字為單位的內存區,同時
//指針ptos指向空堆棧入口
*stk-- = (INT16U)FP_SEG(pdata); /* Simulate call to function with argument *///用堆棧來傳遞參數pdata。此
*stk-- = (INT16U)FP_OFF(pdata);//時參數pdata的段地址和偏移量都將按次序保存在堆棧中
*stk-- = (INT16U)FP_SEG(task);//堆棧緊接著是任務函數的起始地址,理論上應該為任務的返回
*stk-- = (INT16U)FP_OFF(task);//地址,但ucos任務為無限循環結構,無返回點,所以此內容是什么不重要。
*stk-- = (INT16U)0x0202; /* SW = Interrupts enabled */
//接著是狀態字,為0x2020時任務啟動時,中斷開著,也可以設置成關著,但函數要么中斷全
//開,要么全關,否則會造成系統崩潰。
*stk-- = (INT16U)FP_SEG(task); /* Put pointer to task on top of stack */
*stk-- = (INT16U)FP_OFF(task);
//堆棧中還須留出各個寄存器空間,寄存器在堆棧中的位置要和運行
//指令PUSHA,PUSH ES和PUSH DS后壓入堆棧的次序相同。上述指令在
//每次進入中斷服務子程序時都會被調用。下面幾個寄存器的
//次序是與指令PUSHA的壓棧次序相同的。如果使用沒有PUSHA指令的
//處理器,就要使用多個PUSH指令壓入上述寄存器,且順序要與PUSHA
//相同,程序中,每個寄存器值各不相同是為了調試方便。
*stk-- = (INT16U)0xAAAA; /* AX = 0xAAAA */
*stk-- = (INT16U)0xCCCC; /* CX = 0xCCCC */
*stk-- = (INT16U)0xDDDD; /* DX = 0xDDDD */
*stk-- = (INT16U)0xBBBB; /* BX = 0xBBBB */
*stk-- = (INT16U)0x0000; /* SP = 0x0000 */
*stk-- = (INT16U)0x1111; /* BP = 0x1111 */
*stk-- = (INT16U)0x2222; /* SI = 0x2222 */
*stk-- = (INT16U)0x3333; /* DI = 0x3333 */
*stk-- = (INT16U)0x4444; /* ES = 0x4444 */
*stk = _DS; /* DS = Current value of DS */
//Borland編譯器支持虛擬寄存器變量操作,程序清單用_OS關鍵字
//取得CPU中DS的值,直接復制到堆棧中
return ((OS_STK *)stk);
//返回新的堆棧棧頂指針,OSTaskCreate() or OSTaskCreateExt()將指針保存在
//任務的控制塊OS_TCB中。
}
/*$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).
*********************************************************************************************************
*/
/*
*********************************************************************************************************
任務切換函數
描述:要執行任務切換的時候調用此函數,當任務切換時,允許做
其它運行動作。
參數:無
備注:1、調用此函數時中斷要關閉
2、它假定全局變量OSTCBHighRdy指向任務的TCB時將切換進去,
而如果OSTCBCur指向任務則被切換出去
3、OSTCBCur指向被切換出去任務的TCB,而 OSTCBHighRdy 指向新任務的TCB
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskSwHook (void)
{
INT8U err;
void *pblk;
/* Save FPU context of preempted task */
if (OSRunning == TRUE) { /* Don't save on OSStart()! */
if (OSTCBCur->OSTCBOpt & OS_TASK_OPT_SAVE_FP) { /* See if task used FP */
pblk = OSTCBCur->OSTCBExtPtr; /* Yes, Get pointer to FP storage area */
if (pblk != (void *)0) { /* Make sure we have storage */
OSFPSave(pblk); /* Save the FPU registers in block */
}
}
}
/* Restore FPU context of new task */
//保存新任務FPU內容
if (OSTCBHighRdy->OSTCBOpt & OS_TASK_OPT_SAVE_FP) { /* See if new task uses FP */
//新任務用浮點嗎?
pblk = OSTCBHighRdy->OSTCBExtPtr; /* Yes, Get pointer to FP storage area */
//用的話,得到FP存儲空間的地址
if (pblk != (void *)0) { /* Make sure we have storage */
//保證得到的空間合法
OSFPRestore(pblk); /* Get contents of FPU registers */
//保存
}
}
}
#endif
/*
*********************************************************************************************************
* OSTCBInit() 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.
*********************************************************************************************************
*/
/*
********************************************************************
OSTCBInit() HOOK
描述:這個函數在設置大多數TCB后由OS_TCBInit() 調用
參數:ptcb,是一個被創建任務的TCB的指針
備注:當調用它的時候中斷可以或者不被能使
**********************************************************************
*/
#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
void OSTimeTickHook (void)
{
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -