![Keil RTX51 Скачать руководство пользователя страница 9](http://html1.mh-extra.com/html/keil/rtx51/rtx51_manual_3913946009.webp)
RTX Tiny
9
1
RTX51 uses a timing routine which is interrupt driven by one of the 8051 hardware tim-
ers. The periodic interrupt that is generated is used to drive the RTX51 clock.
RTX51 does not require you to have a main function in your program. It will automati-
cally begin executing task 0. If you do have a main function, you must manually start
RTX51 using the
os_create_task
function in RTX51 Tiny and the
os_start_system
function in RTX51.
The following example shows a simple RTX51 application that uses only round
-
robin
task scheduling. The two tasks in this program are simple counter loops. RTX51 starts
executing task 0 which is the function names
job0
. This function adds another task
called
job1
. After
job0
executes for a while, RTX51 switches to
job1
. After
job1
executes for a while, RTX51 switches back to
job0
. This process is repeated in-
definitely.
#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 */
}
}
void job1 (void) _task_ 1 {
while (1) {
/* loop forever */
c+;
/* update the counter */
}
}
RTX51 Events
Rather than waiting for a task’s time slice to be up, you can use the
os_wait
function to
signal RTX51 that it can let another task begin execution. This function suspends execu-
tion of the current task and waits for a specified event to occur. During this time, any
number of other tasks may be executing.
Using Time
-
outs with RTX51
The simplest event you can wait for with the
os_wait
function is a time
-
out period in
RTX51 clock ticks. This type of event can be used in a task where a delay is required.
This could be used in code that polled a switch. In such a situation, the switch need only
be checked every 50ms or so.
The next example shows how you can use the
os_wait
function to delay execution while
allowing other tasks to execute.
Содержание 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...