10
RTX51 Real-Time Operating System
1
#include <rtx51tny.h>
int counter0;
int counter1;
void job0 (void) _task_ 0 {
os_create (1);
/* mark task 1 as ready */
while (1) {
/* loop forever */
c+;
/* update the counter */
os_wait (K_TMO, 3);
/* pause for 3 clock ticks */
}
}
void job1 (void) _task_ 1 {
while (1) {
/* loop forever */
c+;
/* update the counter */
os_wait (K_TMO, 5);
/* pause for 5 clock ticks */
}
}
In the above example,
job0
enables
job1
as before. But now, after incrementing
counter0
,
job0
calls the
os_wait
function to pause for 3 clock ticks. At this time,
RTX51 switches to the next task, which is
job1
. After
job1
increments
counter1
,
it too calls
os_wait
to pause for 5 clock ticks. Now, RTX51 has no other tasks to exe-
cute, so it enters an idle loop waiting for 3 clock ticks to elapse before it can continue
executing
job0
.
The result of this example is that
counter0
gets incremented every 3 timer ticks and
counter1
gets incremented every 5 timer ticks.
Using Signals with RTX51
You can use the
os_wait
function to pause a task while waiting for a signal (or binary
semaphore) from another task. This can be used for coordinating two or more tasks.
Waiting for a signal works as follows: If a task goes to wait for a signal, and the signal
flag is 0, the task is suspended until the signal is sent. If the signal flag is already 1 when
the task queries the signal, the flag is cleared, and execution of the task continues. The
following example illustrates this:
#include <rtx51tny.h>
int counter0;
int counter1;
void job0 (void) _task_ 0 {
os_create (1);
/* mark task 1 as ready */
while (1) {
/* loop forever */
if (++counter0 == 0)
/* update the counter */
os_send_signal (1);
/* signal task 1 */
}
}
Содержание RTX51
Страница 4: ......
Страница 6: ......
Страница 20: ......
Страница 24: ......
Страница 39: ...RTX Tiny 39 4...
Страница 40: ......
Страница 44: ...44 RTX51 Tiny Specifications 5...
Страница 68: ...RTX51 TINY REAL TIME OPERATING SYSTEM User s Guide 2 95...