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;
#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();									/*打开中断*/
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

allein_STR

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值