Real-Time Workshop Embedded Coder    

Task Management

In a VxWorks example program, the main program and the base rate and sub-rate tasks (if any) run as proritized tasks under VxWorks. The logic of a VxWorks example program parallels that of a stand-alone program; the main difference lies in the fact that base rate and sub-rate tasks are activated by clock semaphores managed by the operating system, rather than directly by timer interrupts.

Your application code must spawn model_main() as an independent VxWorks task. The task priority you specify is passed in to model_main().

As with a stand-alone program, the VxWorks example program architecture is tailored to the number of rates in the model and to the solver mode (see Table 2-3). The following sections discuss each possible case.

Single-Rate Singletasking Operation

In a single-rate, singletasking model, model_main() spawns a base rate task, tBaseRate. In this case tBaseRate is the functional equivalent to rtOneStep. The base rate task is activated by a clock semaphore provided by VxWorks, rather than by a timer interrupt. On each activation, tBaseRate calls model_step.

Note that the clock rate granted by VxWorks may not be the same as the rate requested by model_main.

Multi-Rate Multitasking Operation

In a multi-rate, multitasking model, model_main() spawns a base rate task and sub-rate tasks. Task priorities are assigned by rate. The base rate task calls model_step with tid 0, while the sub-rate tasks call model_step with their associated tids. The base rate task and model_step are responsible for maintaining event flags and scheduling counter, using the same rate monotonic scheduler algorithm as a stand-alone program,

Multi-Rate Singletasking Operation

In a multi-rate, singletasking model, model_main() spawns only a base rate task, tBaseRate. All rates run under this task. The base rate task is activated by a clock semaphore provided by VxWorks, rather than by a timer interrupt. On each activation, tBaseRate calls model_step.

model_step in turn calls the rate_monotonic_scheduler utility, which maintains the scheduling counters that determine which rates should execute. model_step is responsible for checking the counters, using macros provided for the purpose (rtmIsSampleHit and rtmIsSpecialSampleHit).


  VxWorks Example Main Program Execution Model Entry Points