Real-Time Workshop Embedded Coder    

Model Entry Points

This section discusses the entry points to the generated code.

Note carefully that the calling interface generated for each of these functions will differ significantly depending on how you set the Generate reusable code option (See Generate Reusable Code).

By default, Generate reusable code is off, and the model entry point functions access model data via statically allocated global data structures. When Generate reusable code is on, model data structures are passed in (by reference) as arguments to the model entry point functions. For efficiency, only those data structures that are actually used in the model are passed in. Therefore when Generate reusable code is on, the argument lists generated for the entry point functions vary according to the requirements of the model.

The descriptions below document the default (Generate reusable code off) calling interface generated for these functions.

The entry points are exported via model.h. To call the entry-point functions from your hand-written code, add an #include model.h directive to your code. If Generate reusable code is on, you must examine the generated code to determine the calling interface required for these functions.

model_step

Default Calling Interface.   In a single-rate model, the model_step function prototype is

In a multi-rate model, the model_step function prototype is

where tid is a task identifier. The tid is determined by logic within rt_OneStep (See rt_OneStep).

Operation.   model_step combines the model output and update functions into a single routine. model_step is designed to be called at interrupt level from rt_OneStep, which is assumed to be invoked as a timer ISR.

Single-Rate Operation.   In a single-rate model, model_step computes the current value of all blocks. If logging is enabled, model_step updates logging variables. If the model's stop time is finite, model_step signals the end of execution when the current time equals the stop time.

Multi-Rate Operation.   In a multi-rate model, model_step execution is almost identical to single-rate execution, except for the use of the task identifier (tid) argument.

The caller (rt_OneStep) assigns each block a tid (See rt_OneStep). model_step uses the tid argument to determine which blocks have a sample hit (and therefore should execute).

Under any of the following conditions, model_step does not check the current time against the stop time:

Therefore, if any of these conditions are true, the program runs indefinitely.

model_initialize

Default Calling Interface.   The model_initialize function prototype is

Operation.   If firstTime equals 1 (TRUE), model_initialize initializes rtM and other data structures private to the model. If firstTime equals 0 (FALSE), model_initialize resets the model's states, but does not initialize other data structures.

The generated code calls model_initialize once, passing in firstTime as 1(TRUE).

model_terminate

Default Calling Interface.   The model_terminate function prototype is

Operation.   When model_terminate is called, blocks that have a terminate function execute their terminate code. If logging is enabled, model_terminate ends data logging. model_terminate should only be called once. If your application runs indefinitely, you do not need the model_terminate function.

If you do not require a terminate function, see Basic Code Generation Options for information on using the Terminate function required option. Note that if Terminate function required is off, the program runs indefinitely

model_SetEventsForThisBaseStep

Calling Interface.   By default, the model_SetEventsForThisBaseStep function prototype is

where eventFlags is a pointer to the model's event flags array.

If Generate reusable code is on, an additional argument is included:

where model_M is a pointer to the real-time model object.

Operation.   The model_SetEventsForThisBaseStep function is a utility function that is generated and called only for multi-rate, multitasking programs.

model_SetEventsForThisBaseStep maintains the event flags, which determine which sub-rate tasks need to run on a given base rate time step. model_SetEventsForThisBaseStep must be called prior to calling the model_step function. See Multi-Rate Multitasking Operation for further information.


  Task Management The Static Main Program Module