User`s manual

70 digi.com Multitasking with Dynamic C
5.8 Overview of Preemptive Multitasking
In a preemptive multitasking environment, tasks do not voluntarily relinquish control. Tasks are scheduled
to run by priority level and/or by being given a certain amount of time.
There are two ways to accomplish preemptive multitasking using Dynamic C. The first way is via a
Dynamic C construct called the “slice” statement (described in Section 5.9). The second way is µC/OS-II,
a real-time, preemptive kernel that runs on the Rabbit microprocessor and is fully supported by Dynamic C
(described in Section 5.10).
5.9 Slice Statements
The slice statement, based on the costatement language construct, allows the programmer to run a block
of code for a specific amount of time.
5.9.1 Slice Syntax
slice ([context_buffer,] context_buffer_size, time_slice)
[name]{[statement|yield;|abort;|waitfor(expression);]}
context_buffer_size
This value must evaluate to a constant integer. The value specifies the number of bytes for the buffer
context_buffer. It needs to be large enough for worst-case stack usage by the user program and
interrupt routines.
time_slice
The amount of time in ticks for the slice to run. One tick = 1/1024 second.
name
When defining a named slice statement, you supply a context buffer as the first argument. When you
define an unnamed slice statement, this structure is allocated by the compiler.
[statement | yield; | abort; | waitfor(expression);]
The body of a slice statement may contain:
Regular C statements
yield statements to make an unconditional exit.
abort statements to make an execution jump to the very end of the statement.
waitfor statements to suspend progress of the slice statement pending some condition indicated by
the expression.
5.9.2 Usage
The slice statement can run both cooperatively and preemptively all in the same framework. A slice
statement, like costatements and cofunctions, can suspend its execution with an abort, yield, or
waitfor. It can also suspend execution with an implicit yield determined by the time_slice
parameter that was passed to it. A routine called from the periodic interrupt forms the basis for scheduling
slice statements. It counts down the ticks and changes the slice statement’s context.