OS_CORE.C(5)
生活随笔
收集整理的這篇文章主要介紹了
OS_CORE.C(5)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*$PAGE*/
/*
*********************************************************************************************************
* ENTER ISR
* 進入中斷(執行中斷)
* Description: This function is used to notify uC/OS-II that you are about to service an interrupt
* service routine (ISR). This allows uC/OS-II to keep track of interrupt nesting and thus
* only perform rescheduling at the last nested ISR.該功能用來通知uc/os-II,正在進行一個中斷服務。該功能可以使uc/os-II追蹤中斷嵌套信息并且只能在最后嵌套中斷
*
* Arguments : none
*
* Returns : none
*
* Notes : 1) This function should be called ith interrupts already disabled在任務級不能調用該函數
* 2) Your ISR can directly increment OSIntNesting without calling this function because
* OSIntNesting has been declared 'global'.如果系統使用的處理器能夠執行自動的獨立執行讀取-修改-寫入的操作,那么就可以直接遞增265 * 中斷嵌套層數(OSIntNesting),這樣可以避免調用函數所帶來的額外開銷。在中斷服務子程序中266 * 給OSIntNesting加1是不會有問題的,因為給OSIntNesting加1時,中斷是關閉的
* 3) You MUST still call OSIntExit() even though you increment OSIntNesting directly.必須要有OSIntNesting()函數
* 4) You MUST invoke OSIntEnter() and OSIntExit() in pair. In other words, for every call
* to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
* end of the ISR. -- OSIntEnter()和OSIntExit()成對出現
* 5) You are allowed to nest interrupts up to 255 levels deep.中斷深度可達255
* 6) I removed the OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL() around the increment because
* OSIntEnter() is always called with interrupts disabled.
*********************************************************************************************************
*/void OSIntEnter(void)
{if (OSRunning == OS_TRUE) {if (OSIntNesting < 255u) { /*如果中斷層次<255*/OSIntNesting++; /* Increment ISR nesting level 增加中斷嵌套層次 */}}
}
/*$PAGE*/
/*
*********************************************************************************************************
* EXIT ISR
* 退出中斷(中斷完成)
* Description: This function is used to notify uC/OS-II that you have completed serviving an ISR. When
* the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
* a new, high-priority task, is ready to run.
* 該功能用來通知uc/os-II已完成中斷。當最后一個中斷嵌套完成時,uc/os-II將調用調度程序確定是否有個新的高優先級的任務準備運行
* Arguments : none
*
* Returns : none
*
* Notes : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair. In other words, for every call
* to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
* end of the ISR.OSIntEnter()和OSIntExit()配套使用
* 2) Rescheduling is prevented when the scheduler is locked (see OS_SchedLock()) 給調度器上鎖用于禁止任務調度 (查看 OSSchedLock()函數)
*********************************************************************************************************
*/void OSIntExit(void)
{
#if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register為CPU狀態寄存器分配存儲空間 */OS_CPU_SR cpu_sr = 0u;
#endifif (OSRunning == OS_TRUE) { /*如果操作系統還在運行,關閉中斷*/OS_ENTER_CRITICAL();if (OSIntNesting > 0u) { /* Prevent OSIntNesting from wrapping 如果嵌套>0層,嵌套層減1 */OSIntNesting--;}if (OSIntNesting == 0u) { /* Reschedule only if all ISRs complete ...所有的中斷都完成了 */if (OSLockNesting == 0u) { /* ... and not locked.并且嵌套鎖也沒有了 */OS_SchedNew(); /*進行新一輪的調用*/OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];/*在任務優先級表中找到最高優先級任務*/if (OSPrioHighRdy != OSPrioCur) { /* No Ctx Sw if current task is highest rdy檢查具有最高優先級別的就緒任務的優先級是否是正在運行的任務的優先級 */
#if OS_TASK_PROFILE_EN > 0u /*如果不是*/OSTCBHighRdy->OSTCBCtxSwCtr++; /* Inc. # of context switches to this task 進行上下文切換 */
#endifOSCtxSwCtr++; /* Keep track of the number of ctx switches上下文切換的次數(統計任務計數器) */OSIntCtxSw(); /* Perform interrupt level ctx switch 做中斷任務切換 */}}}OS_EXIT_CRITICAL(); /*打開中斷*/}
}
總結
以上是生活随笔為你收集整理的OS_CORE.C(5)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OS_CORE.C(4)
- 下一篇: OS_CORE.C(6)