/*
*********************************************************************************************************
* 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;
#endif
if (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 进行上下文切换 */
#endif
OSCtxSwCtr++; /* Keep track of the number of ctx switches上下文切换的次数(统计任务计数器) */
OSIntCtxSw(); /* Perform interrupt level ctx switch 做中断任务切换 */
}
}
}
OS_EXIT_CRITICAL(); /*打开中断*/
}
}