M68K Ada offers a limited form of tasking that supports the Ravenscar Profile and the Ada 83 rendezvous. When using the Ravenscar profile, application programs are guaranteed to be deterministic and may be analyzed using static analysis tools.
This chapter describes how to use Ada tasks, and the associated language features, in an example real-time program.
The relevant Ada language features are as follows:
The pragma Priority
Task specs and bodies
Protected objects
Interrupt handlers
The delay until statement
The package Ada.Real_Time
The main subprogram, which contains the program entry point runs as task number 1. The TCB[1] for this task is created in the run-time system, and the stack is the main stack declared in the linker script file.
For other than a trivial program, the main task should probably be regarded as the idle task or background task. You can make sure that it runs at the lowest priority using the pragma Priority in the declarative part of the main subprogram.
Example 3-1. Main Subprogram with Idle Loop
with My_Packages...
procedure T1 is
pragma Priority (0);
begin
loop
null;
end loop;
end T1;
You might want the background task to continuously run some built-in tests, or you may wish to switch the CPU into low power mode until the next interrupt is raised.
Here is an example main subprogram that goes into low-power mode when there is nothing else to do. Note that the function __xgc_set_pwdn is included in the standard library libc.
Example 3-2. Idle Loop with Power-Down
with My_Packages...
procedure T1 is
pragma Priority (0);
procedure Power_Down;
pragma Import (C, Power_Down, "__xgc_set_pwdn");
begin
-- Confirm successful entry to the main program (say)
...
-- Enter idle loop
loop
Power_Down;
end loop;
end T1;
The rest of the program comprises periodic and aperiodic tasks that are declared in packages, that are with-ed from the main subprogram. Tasks are numbered from 2 in the order in which they are elaborated.
Important: In M68K Ada, there is no default idle task. If all of your application tasks become blocked, then the program will fail with Program_Error.
| [1] | Task Control Block |