4. Interrupts and clocks of μC/OS-Ⅱ

4. Interrupts and clocks of μC/OS-Ⅱ 

1. The process of μ C/OS-II system responding to interrupts

The process of the μ C/OS-II system responding to interrupts is: after the system receives an interrupt request, if the CPU is in the interrupt enable state (that is, the interrupt is open), the system will suspend the current task that is running, and according to the interrupt vector Point to run the interrupt service subroutine; when the interrupt service subroutine is finished, the system will return to the suspended task to continue running or turn to run another ready task with a higher priority according to the situation.

Notice! After the interrupt service subroutine finishes running, the system will perform a task scheduling according to the situation to run the ready task with the highest priority, instead of continuing to run the interrupted task . 

 2. Interrupt-level task switching function

 The function OSIntCtxSw( ) responsible for task switching called in the interrupt service routine is called the interrupt-level task switching function

OSIntCtxSw( )
{
    OSTCBCur = OSTCBHighRdy;	  //任务控制块的切换	
    OSPrioCur=OSPrioHighRdy;
    SP = OSTCBHighRdy->OSTCBStkPtr;	//SP指向待运行任务堆栈
    用出栈指令把R1,R2,……弹入CPU的通用寄存器;
    RETI;			//中断返回,使PC指向待运行任务
}

3. The system clock of μC /OS-II

μ C/OS-II , like most computer systems, uses a hardware timer to generate a periodic interrupt with a period of ms to realize the system clock. The smallest clock unit is the interval between two interrupts. This minimum clock The unit is called a clock beat ( Time Tick ).

The hardware timer generates an interrupt periodically with the clock tick, and the interrupt service routine of this interrupt is called OSTickISR( ) . The interrupt service routine calls the function OSTimeTick ( ) to complete the work that the system needs to do in each clock tick .

The schematic code of the function OSTickISR() function:    

void OSTickISR(void)
{
	保存CPU寄存器;
	调用OSIntEnter( );			//记录中断嵌套层数
	if (OSIntNesting = = 1;				
	{
		OSTCBCur->OSTCBStkPtr = SP; //保存堆栈指针
	}
	调用OSTimeTick( );			//节拍处理
	清除中断;
	开中断;
	调用OSIntExit( );			//中断嵌套层数减一 
	恢复CPU寄存器;
	中断返回;
}

Guess you like

Origin blog.csdn.net/weixin_51659166/article/details/131113679