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:
inf
.
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.
Note
The macro MODEL_SETEVENTS, defined in the static ert_main.c module, provides a way to call model _SetEventsForThisBaseStep from a static main program.
|
![]() | Task Management | The Static Main Program Module | ![]() |