四、μC/OS-Ⅱ的中断和时钟

文章详细介绍了μC/OS-II操作系统响应中断的流程,包括中断服务子程序执行后可能的任务调度。OSIntCtxSw函数用于中断级的任务切换,而系统时钟由硬件定时器产生的周期性中断(OSTickISR)驱动,通过OSTimeTick函数处理每个时钟节拍的任务。
摘要由CSDN通过智能技术生成

四、μC/OS-Ⅱ的中断和时钟 

1.μC/OS-II系统响应中断的过程

μC/OS-II系统响应中断的过程为:系统接收到中断请求后,这时如果CPU处于中断允许状态(即中断是开放的),系统就会中止正在运行的当前任务,而按照中断向量的指向转而去运行中断服务子程序;当中断服务子程序的运行结束后,系统将会根据情况返回到被中止的任务继续运行或者转向运行另一个具有更高优先级别的就绪任务。

注意!中断服务子程序运行结束之后,系统将会根据情况进行一次任务调度去运行优先级别最高的就绪任务,而并不是一定要接续运行被中断的任务的 

 2.中断级任务切换函数

 在中断服务程序中调用的负责任务切换工作的函数OSIntCtxSw( )叫做中断级任务切换函数

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

3.μC/OS-II系统时钟

μC/OS-II与大多数计算机系统一样,用硬件定时器产生一个周期为ms级的周期性中断来实现系统时钟,最小时钟单位就是两次中断之间相间隔的时间,这个最小时钟单位叫做时钟节拍Time Tick)。

硬件定时器以时钟节拍为周期定时地产生中断,该中断的中断服务程序叫做OSTickISR( )。中断服务程序通过调用函数OSTimeTick( )来完成系统在每个时钟节拍时需要做的工作

函数 OSTickISR()函数的示意性代码:    

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
This book describes the design and implementation of mC/OS-II (pronounced "Micro C O S 2") which stands for<br>Micro-Controller Operating System Version 2. μC/OS -II is based on μC/OS, The Real-Time Kernel which was first<br>published in 1992. Thousands of people around the world are using μC/OS in all kinds of applications such as<br>cameras, medical instruments, musical instruments, engine controls, network adapters, highway telephone call boxes,<br>ATM machines, industrial robots, and many more. Nu merous colleges and Universities have also used μC/OS to<br>teach students about real-time systems.<br>μC/OS-II is upward compatible with μC/OS (V1.11) but provides many improvements over μC/OS such as the<br>addition of a fixed-sized memory manager, user definable callouts on task creation, task deletion, task switch and<br>system tick, supports TCB extensions, stack checking and, much more. I also added comments to just about every<br>function and I made μC/OS -II much easier to port to different processors. The source code in μC/OS was found in two<br>source files. Because μC/OS-II contains many new features and functions, I decided to split μC/OS-II in a few source<br>files to make the code easier to maintain.<br>If you currently have an application (i.e. product) that runs with μC/OS, your application should be able to run,<br>virtually unchanged, with μC/OS-II. All of the services (i.e. function calls) provided by μC/OS have been preserved.<br>You may, however, have to change include files and product build files to ‘point’ to the new file names.<br>This book contains ALL the source code for μC/OS-II and a port for the Intel 80x86 processor running in Real-Mode<br>and for the Large Model. The code was developed on a PC running the Microsoft Windows 95 operating system.<br>Examples run in a DOS compatible box under the Windows 95 environment. Development was done using the<br>Borland International C/C++ compiler version 3.1. Although μC/OS-II was developed and tested on a PC, mC/OS-II<br>was actually targeted for embedded systems and can easily be ported to many different processor architectures.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值