有时候进行单片机程序开发的时候我们需要用到多任务,这时就必须涉及到操作系统了,因为没有操作系统的话很难达到多任务协调调度的目的...以前我阅读过uCOS-II的源码,也曾将其移植到51系列单片机上,但是由于其需要很大的内存,单片机需另扩展RAM才能跑起来,所以此次电梯模拟的程序我决定使用KEIL的RTX51 Tiny.这可是为51系列单片机量身定做的超小操作系统.能实现基本的任务调度,任务通信等基本功能.
RTX51 Tiny使用了定时器0为它提供时钟.所以应用程序中应避免使用定时器0.
RTX51 Tiny中任务有以下五种状态(摘自keil的帮助文档):
State | Description |
RUNNING | The task that is currently running is in the RUNNING State. Only one task at a time may be in this state. The os_running_task_id returns the task number of the currently executing task. |
READY | Tasks which are ready to run are in the READY State. Once the Running task has completed processing, RTX51 Tiny selects and starts the next Ready task. A task may be made ready immediately (even if the task is waiting for a timeout or signal) by setting its ready flag using the os_set_ready or isr_set_ready functions. |
WAITING | Tasks which are waiting for an event are in the WAITING State. Once the event occurs, the task is switched to the READY State. The os_wait function is used to place a task in the WAITING State. |
DELETED | Tasks which have not been started or tasks which have been deleted are in the DELETED State. The os_delete_task routine places a task that has been started (with os_create_task) into the DELETED State |
TIME-OUT | Tasks which were interrupted by a Round-Robin Time-Out are in the TIME-OUT State. This state is equivalent to the READY State for Round-Robin programs. |
RTX51 Tiny也可以配置成分时的操作系统,可以在配置文件中配置.
RTX51 Tiny有一个IDLE task 在应用程序所有的任务不运行时,系统运行这个任务.这个任务很简单:SJMP $
RTX51 Tiny的配置文件是/KEIL/C51/RTXTINY2/ 下的CONF_TNY.A51, 可以参考帮助文档修改.
使用RTX51 Tiny:
1.包含头文件 RTX51TNY.H
2.创建任务(至少一个,不需要main,因为操作系统有自己的main)
3.任务0是第一个运行的
4.至少使用一个操作系统的函数,使它连接库文件
5.在Target里的Operation System中选择RTX-51 Tiny
任务的定义方法:void func (void) _task_ task_id
一共可以使用16个任务._task_是KEIL扩展关键字.
调试时可以使用Peripherals菜单中的RTX51 Tiny Tasklist 查看任务列表与状态.
以上是我今晚上看KEIL帮助总结的,顺便记录一下,为以后复习使用时方便.呵呵