User`s guide
Overview of the C MEX S-Function Routines
3-23
and NUM_OF_CHANNELS_PRM. The code uses #define statements to associate
particular input arguments with the parameter names.
/* Input Parameters */
#define BASE_ADDRESS_PRM(S) ssGetSFcnParam(S, 0)
#define GAIN_RANGE_PRM(S) ssGetSFcnParam(S, 1)
#define PROG_GAIN_PRM(S) ssGetSFcnParam(S, 2)
#define NUM_OF_CHANNELS_PRM(S) ssGetSFcnParam(S, 3)
When running the simulation, enter four variable names or values in the
S-Function parameters field of the block’s dialogbox. The first corresponds to
the first expected parameter,
BASE_ADDRESS_PRM(S). The second corresponds
to the next expected parameter, and so on.
The
mdlInitializeSizes function contains this statement:
ssSetNumSFcnParams(S, 4);
Parameter Changes
To notify your S-function of parameter changes during a Simulink simulation,
the S-function must register an
mdlCheckParameters routine. This S-function
routine is called any time after
mdlInitializeSizes has been called. If you
want to process the changed parameters, register the
mdlProcessParameters
routine. Typically this routine caches the parameters in work vectors.
The optional S-function routines,
mdlCheckParameters and
mdlProcessParameters are generally used together when writing an
S-function that contains parameters that can change during simulation. These
routines can only be used in a C MEX S-function.
S-functions that include these routines should verify that their code robustly
handles parameter changes when working with the Real-Time Workshop.
When S-functions are used with the Real-Time Workshop, that is, linked with
the generated code to form an executable, there is a global parameter vector
that you can modify by a number of external means. One such means is
external mode. When running in external mode, Simulink calls
mdlCheckParameters and mdlProcessParameters in your MEX-file. After
Simulink completes thesecalls,theexternalmode linkchanges theparameters
in the generated code executable directly in memory. For more information on
external mode, see The Real-Time Workshop User’s Guide.