?? os_core.c
字號:
描述:阻止再次調度發生,它讓你準備執行任務切換的時候才進行任務切換
//參數:無
返回:無
備注:1、必須調用OSSchedLock() and OSSchedUnlock()成對
*********************************************************************************************************
*/
#if OS_SCHED_LOCK_EN > 0
void OSSchedLock (void)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
if (OSRunning == TRUE) { /* Make sure multitasking is running */
//保證多任務在運行
OS_ENTER_CRITICAL();
if (OSLockNesting < 255) { /* Prevent OSLockNesting from wrapping back to 0 */
//防止嵌套數返回到0
OSLockNesting++; /* Increment lock nesting level */
}
OS_EXIT_CRITICAL();
}
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* ENABLE SCHEDULING
*
* Description: This function is used to re-allow rescheduling.
*
* Arguments : none
*
* Returns : none
*
* Notes : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair. In other words, for every
* call to OSSchedLock() you MUST have a call to OSSchedUnlock().
能使任務調度
描述:用于再次允許任務調度
參數:無
返回:無
備注:1、必須將OSSchedLock() and OSSchedUnlock()成對調用
*********************************************************************************************************
*/
#if OS_SCHED_LOCK_EN > 0//能使包含代碼OSSchedLock() and OSSchedUnlock()
void OSSchedUnlock (void)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
if (OSRunning == TRUE) { /* Make sure multitasking is running */
//保證多任務運行
OS_ENTER_CRITICAL();
if (OSLockNesting > 0) { /* Do not decrement if already 0 */
//如果是零的話就不要再減了
OSLockNesting--; /* Decrement lock nesting level */
if ((OSLockNesting == 0) && (OSIntNesting == 0)) { /* See if sched. enabled and not an ISR */
//如果解鎖,且中斷嵌套數為零,由需要任務調度,看高優先
//級任務是否就緒
OS_EXIT_CRITICAL();
OS_Sched(); /* See if a HPT is ready */
} else {
OS_EXIT_CRITICAL();//否則就不要任務調度了
}
} else {
OS_EXIT_CRITICAL();//如果鎖定的話,就開中斷了。
}
}
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* START MULTITASKING
*
* Description: This function is used to start the multitasking process which lets uC/OS-II manages the
* task that you have created. Before you can call OSStart(), you MUST have called OSInit()
* and you MUST have created at least one task.
*
* Arguments : none
*
* Returns : none
*
* Note : OSStartHighRdy() MUST:
* a) Call OSTaskSwHook() then,
* b) Set OSRunning to TRUE.
* c) Load the context of the task pointed to by OSTCBHighRdy.
* d_ Execute the task.
開始多任務處理
描述:開始多任務處理,使ucos管理你建立的任務,在調用OSStart()前,你必須
先調用OSInit(),且至少建立了一個任務
參數:無
返回;無
備注:OSStartHighRdy()必須
1、先調用Call OSTaskSwHook()
2、再設置OSRunning為真
3、裝載指向OSTCBHighRdy的內容的指針
4、執行任務
*********************************************************************************************************
*/
void OSStart (void)
{
INT8U y;
INT8U x;
if (OSRunning == FALSE) {//如果沒有運行
y = OSUnMapTbl[OSRdyGrp]; /* Find highest priority's task priority number */
x = OSUnMapTbl[OSRdyTbl[y]];//又遇到你們,真是FUCK。
OSPrioHighRdy = (INT8U)((y << 3) + x);
OSPrioCur = OSPrioHighRdy;//高優先級的任務作為當前任務
OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run */
//下一個任務作為即將運行的任務
OSTCBCur = OSTCBHighRdy;
OSStartHighRdy(); /* Execute target specific code to start task */
//執行特定代碼去開始任務
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* STATISTICS INITIALIZATION
*
* Description: This function is called by your application to establish CPU usage by first determining
* how high a 32-bit counter would count to in 1 second if no other tasks were to execute
* during that time. CPU usage is then determined by a low priority task which keeps track
* of this 32-bit counter every second but this time, with other tasks running. CPU usage is
* determined by:
*
* OSIdleCtr
* CPU Usage (%) = 100 * (1 - ————)
* OSIdleCtrMax
*
* Arguments : none
*
* Returns : none
統計任務初始化
描述:假如沒有其它任務在這個時候運行,以在一秒內一個32位計數器能
計到多少數來建立CPU使用率CPU使用率由一個每秒跟蹤32位計數器的低優先
級任務決定,但如果其它任務運行,CPU使用率由下面函數決定:
* OSIdleCtr
* CPU Usage (%) = 100 * (1 - ————)
* OSIdleCtrMax
參數:無
返回:無
*********************************************************************************************************
*/
#if OS_TASK_STAT_EN > 0
void OSStatInit (void)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
OSTimeDly(2); /* Synchronize with clock tick */
//與時鐘節拍同步
OS_ENTER_CRITICAL();
OSIdleCtr = 0L; /* Clear idle counter */
//清除空閑計算器
OS_EXIT_CRITICAL();
OSTimeDly(OS_TICKS_PER_SEC); /* Determine MAX. idle counter value for 1 second */
//計算一秒內空閑計數器能計多少
OS_ENTER_CRITICAL();
OSIdleCtrMax = OSIdleCtr; /* Store maximum idle counter count in 1 second */
//保存計數值
OSStatRdy = TRUE;//統計任務就緒
OS_EXIT_CRITICAL();
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* PROCESS SYSTEM TICK
*
* Description: This function is used to signal to uC/OS-II the occurrence of a 'system tick' (also known
* as a 'clock tick'). This function should be called by the ticker ISR but, can also be
* called by a high priority task.
*
* Arguments : none
*
* Returns : none
建立系統時鐘
描述:這個函數向ucos發信號產生時鐘節拍,它能被ISR節拍調用,也可以由
高優先級任務調用
參數:無
返回:無
*********************************************************************************************************
*/
void OSTimeTick (void)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
OS_TCB *ptcb;
OSTimeTickHook(); /* Call user definable hook */
//用戶定義的時鐘節拍外連函數,,可將時鐘節拍函數OSTimeTick擴展,調用此
//函數是打算在中斷一開始給用戶一個可以做點什么的機會,
#if OS_TIME_GET_SET_EN > 0 //能使包含代碼OSTimeGet() and OSTimeSet()
OS_ENTER_CRITICAL(); /* Update the 32-bit tick counter */
OSTime++;//系統節拍現階段值,計算自系統上電以來的時鐘節拍數
OS_EXIT_CRITICAL();
#endif
if (OSRunning == TRUE) {
ptcb = OSTCBList; /* Point at first TCB in TCB list */
//指向PCB雙向鏈表中的第一個
while (ptcb->OSTCBPrio != OS_IDLE_PRIO) { /* Go through all TCBs in TCB list */
//將PCB鏈表中的TCB遍歷一遍,一直做到空閑任務
OS_ENTER_CRITICAL();
if (ptcb->OSTCBDly != 0) { /* Delayed or waiting for event with TO */
if (--ptcb->OSTCBDly == 0) { /* Decrement nbr of ticks to end of delay */
if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == OS_STAT_RDY) { /* Is task suspended? */
//確實被掛起的任務不會進入就緒態
OSRdyGrp |= ptcb->OSTCBBitY; /* No, Make task R-to-R (timed out)*/
//如果某任務的TCB中的時間延時項OSTCBDly減為0時,這個任務就進入了就緒態
OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
} else { /* Yes, Leave 1 tick to prevent ... */
//保留一個節拍防止去除掛起的時候任務不穩定
ptcb->OSTCBDly = 1; /* ... loosing the task when the ... */
} /* ... suspension is removed. */
}
}
ptcb = ptcb->OSTCBNext; /* Point at next TCB in TCB list */
//指向TCB鏈表的下一塊
OS_EXIT_CRITICAL();
}
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* GET VERSION
*
* Description: This function is used to return the version number of uC/OS-II. The returned value
* corresponds to uC/OS-II's version number multiplied by 100. In other words, version 2.00
* would be returned as 200.
*
* Arguments : none
*
* Returns : the version number of uC/OS-II multiplied by 100.
版本號
描述:返回UCOS版本號號,返回值為UCOS版本*100,換句話說,2.00版本將
返回200
參數:無
返回:版本號*100
*********************************************************************************************************
*/
INT16U OSVersion (void)
{
return (OS_VERSION);
}
/*$PAGE*/
/*
*********************************************************************************************************
* DUMMY FUNCTION
*
* Description: This function doesn't do anything. It is called by OSTaskDel().
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -