User`s guide
3 Writing S-Functions As C-MEX files
3-24
Typically, it is safe to have an mdlCheckParameters in your S-function when it
is used with the Real-Time Workshop, providing that when parameter tuning
is performed, it is done using Simulink external mode. If you have an
mdlProcessParameters routine in yourS-function code,you may need to inline
the S-function for it to work correctly in external mode. This is necessary
because only changes to the tunable parameters are p assed to the generated
code. For more information on inlining S-functions, see the Target Language
Compiler Reference Guide.
The flowchart on page 3-16 shows that Simulink only calls
mdlCheckParameters when parameters are changed during simulation. Once
mdlCheckParameters verifies that parameter changes are correct, Simulink
calls
mdlProcessParameters to translate the parameters into a more
convenient and efficient form, such as caching the values i n the work vectors.
In general, your S-function doesn’t need to have an
mdlProcessParameters;it
is provided to help you speed up the execution of S-functions. This is achieved
by only evaluating the parameters when they change.
mdlCheckParameters
Use mdlCheckParameters to verify that param eter s ettings are correct:
#define MDL_CHECK_PARAMETERS /* define is required for use*/
#if defined (MDL_CHECK_PARAMETERS)
static void mdlCheckParameters(SimStruct *S)
{
}
#endif
mdlCheckParameters
verifies new parameter settings whenever parameters
change or are re-evaluated during a simulation.
When a simulation is running, changes t o S-function parameters can occur at
any time during the simulation loop; that is, either at the start of a simulation
step or during a simulation step. When the change o ccurs during a simulation
step, Simulink calls this routine twice to handle the parameter change. The
first call during the simula tion step is used to verify that the para meters are
correct.A fterverifying thenewparameters,thesimulation continuesu sing the
original parameter valuesuntil the next simulationstep at which time the new
parameter values will be used. Redundant calls are needed to maintain
simulation consistency.