User`s guide
10 Targeting Custom Hardware
10-12
Conditional Compilations
In general, you can use an S-function in these environments:
• Simulink
• Real-Time
When you use your S-function in Simulink, you do so by creating a MEX-file
from it. In this case, the macro
MATLAB_MEX_FILE is defined.
When you use your S-function in real-time (for example, with a fixed-step
solver and the Real-Time Workshop), the macro
RT is defined.
Initialization
Initialization is performed in three separate steps. The S-function API requires
you to implement three functions for initialization:
•
mdlInitializeSizes — specifies the sizes of various parameters in the
SimStruct.
•
mdlInitializeSampleTimes — obtains the board’s sample time from the
dialog box and sets this value in the
SimStruct.
•
mdlInitializeConditions — reads values from the dialog box, initializes
the board, and saves parameter values in the
SimStruct.
Obtaining Values from Dialog Boxes
Obtaining the values of parameters from the block’s dialog box requires you to:
1 Get the S-function input parameter (in this case the dialog box entry) using
the
ssGetSFcnParam macro.
2 Get the particular value from the input mxArray (since all input arguments
to MEX-files are of type
Mxarray *)usingthemxGetPr function.
For example, suppose you want the value of the third item in the block’s dialog
box, which happens to be an integer. For convenience, you can define a macro
that obtains the desired argument:
#define THIRD_ARGUMENT ssGetSFcnParam(S, 2)