Architecture of Generated C Code : Tasks View of the Code : Using Simulated Time Model

Using Simulated Time Model

Generated code uses the real-time model by default. In this model, timeouts and scheduled actions are treated very similarly to other inputs. The system clock keeps time and generates interrupts that are processed along with the other inputs.

When using this time model, it is possible for the code to miss a timeout or scheduled action due to heavy loading of the processor or an extremely small request for a timeout. In such a situation, the generated code may actually behave slightly different than a simulation of the same model.

An additional time model is provided called the simulated-time model. The purpose of this model is to force the generated code to behave in the same manner as the simulated model. It does this at the cost of the real-time nature of the generated code.

The simulated-time model may be either asynchronous or synchronous. In the asynchronous time model, time is consumed only for timeout statements and scheduled actions; otherwise, it runs in real-time. In the synchronous time model, transitions are made on a clock. Every transition consumes one clock period and every step consumes one clock cycle.

In order to meet all timeouts regardless of duration and CPU loading, the code would be required to run at an arbitrarily fast speed. Since this is not possible, code which is compiled using the simulated-time model, does not adhere to the system clock. Rather, it keeps its own artificial time, much the same as a simulator. The code executes model steps until it reaches a stable status. It then advances the internal clock to the necessary value to execute the next timeout or scheduled action.

-- The main loop, loops forever
int main(argc, argv)
int argc;
char **argv;
{
while (TRUE) {
-- Execute a step --
-- Advance internal time keeper to next
relevant time --
-- Apply timeouts and scheduled actions. --