Real-Time Workshop User's Guide | ![]() ![]() |
model_step
Calling Interface.. The MODEL_STEP
macro is the standard way to call your model's generated step function.
In a single-rate model, the macro expands to a function call with the prototype
voidmodel
_
step(void);
In a multirate model, the macro expands to a function call with the prototype
voidmodel
_
step(int_Ttid
);
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.
Multirate Operation. In a multirate 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).
Note
If the model's stop time is set to inf , or if logging is disabled, model _ step does not check the current time against the stop time. Therefore, the program runs indefinitely.
|
model_initialize
Calling Interface. The MODEL_INITIALIZE
macro is the standard way to call your model's generated initialization code. The macro expands to a function call with the prototype
voidmodel
_
initialize(boolean_T firstTime);
Operation. If firstTime
equals 1 (TRUE
), model
_initialize
initializes the real-time object and other data structures private to the model. If firstTime
equals 0 (FALSE
), model
_initialize
resets the model's states.
The generated code calls model
_initialize
once, passing in firstTime
as 1
(TRUE
).
model_terminate
Calling Interface. The MODEL_TERMINATE
macro is a standard way to call your model's generated termination code. The macro expands to a function call with the prototype
voidmodel
_
terminate(void);
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.
How to Call the Entry Points Directly
You can replace the generated macro calls with direct calls to the entry points. This is necessary when interfacing your code with code generated from more than one model. In such cases, the macro calls are ambiguous. Include model_
export
.h to make the entry points visible to your code, as in the following code fragment.
#include "modelA
_Export.h" /* Make model A entry points visible */ #include "modelB
_Export.h" /* Make model B entry points visible */ void myHandWrittenFunction(void) { const char_T *errStatus; modelA_initialize(1); /* Call model A initializer */ modelB_initialize(1); /* Call model B initializer */ /* Refer to model A's real-time Object */ errStatus = ssGetErrorStatus(modelA_rtO); /* Refer to model B's real-time Object */ errStatus = ssGetErrorStatus(modelB_rtO); }
![]() | rt_OneStep | Automatic S-Function Wrapper Generation | ![]() |