Real-Time Workshop User's Guide    

Model Entry Points

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

In a multirate model, the macro expands to a function call with the prototype

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).

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

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

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.


 rt_OneStep Automatic S-Function Wrapper Generation