将操作写入到死循环中,不可预知地重复执行两个程序。
首先,系统函数 os_dly_wait()任务暂停几个系统时间间隔。RTX核通过对ARM处理器片上定时器的编程来实现系统定时器,默认情况下,系统间隔10ms,使用0号定时器,不过这可以调整。
系统函数 os_evt_wait_or的作用是用于让task1等待task2完成,而 os_evt_set作用是传送信号给task2。
这个例子中使用的是3号事件标志。task2必须在task1完成20ms之后才能启动。同样的函数可以在task2等待task1以及传送信号给task1时使用。以下列举了运行RTX例程所有的要求:
/* Include type and function declarations for RTX */
#include "rtl.h"/* id1, id2 will contain task identifications at run-time */
OS_TID id1, id2;/* Forward declaration of tasks. */
void task1 (void) __task;
void task2 (void) __task;void task1 (void) __task
{/* Obtain own system task identification number */id1 = os_tsk_self(); /* Create task2 and obtain its task identification number */id2 = os_tsk_create (task2, 0); for (;;){/* ... place code for task1 activity here ... */ /* Signal to task2 that task1 has compelted *