User`s guide

Model Execution
6-13
EndMainLoop
}
main()
{
Initialization
Start/spawn task "tSingleRate".
Start clock that does a "semGive" on a clockSem semaphore.
Wait on "model-running" semaphore.
Shutdown
}
In this multitasking environment, the model is executed using real-time
operating system tasking primitives. In this environment, it is necessary to
create several model tasks (tBaseRate and several tSubRate tasks) to run the
model code. The base rate task (tBaseRate) has a higher priority than the
subrate tasks. The subrate task for tid=1 has a higher priority than the subrate
task for tid=2, and so on. The base rate task is invoked when a clock tick occurs.
The clock tick gives a clockSem to tBaseRate. The first thing tBaseRate does is
givesemaphorestothesubtasksthathaveahitatthecurrentpointintime.
Since the base rate task has a higher priority, it continues to execute. Next it
executes the fastest task (tid=0) consisting of blocks in your model that have
the fastest sample time. After this execution, it resumes waiting for the clock
semaphore. The clock ticks are configured to occur at executing at the
fundamental step size for your model.
Program Timing
Real-time programs require careful timing of the task invocations (either via
an interrupt or a real-time operating system tasking primitive) to ensure that
the model code executes to completion before another task invocation occurs.
This includes time to read and write data to and from external hardware.