Motorola DSP Developer's Kit | ![]() ![]() |
Simulink S-Function MEX-Files
Before continuing, we recommend you read "Getting Started" (Chapter 1), "Creating a Model" (Chapter 3) and the "Writing S-Functions as C MEX-Files" section of "S-Functions" (Chapter 8), in Using Simulink. For more detailed information, refer to Writing S-Functions.
Note The supplied Simulink files use macros defined in <matlab>/toolbox/motdsp/motdspmex/include/headers/56k/motdsp_api.h in place of the C++ style function calls. The purpose of these macros is to use the correct simulator object for each iteration (sample) of the simulation when in INTERACTIVE mode. If a sample hit occurs, as specified from the dialog box parameter, the simulator object will launch the simulator GUI. At other times, it will run in NON_INTERACTIVE mode. For a list of these macros see Macros. |
Required Definitions
Define only the following macros in your MEX-file:
S_MEX_FUNC_NAME
S_FUNCTION_NAME
For the Simulink environment, these names must exactly match the name of the MEX-file source (including case sensitivity), omitting the .cpp
extension. The functions supplied in the Motorola DSP Blockset (<matlab>/toolbox/motdsp/motdspmex/56300 and <matlab>/toolbox/motdsp/motdspmex/56600) are all prefixed with mot563_
or mot566_
. Also, the S_MEX_FUNC_NAME
macro is always defined as a string.
S_FUNCTION_LEVEL
These macros are required for any MEX S-function. The S_FUNCTION_LEVEL
macro is always defined to equal 2.
//fn name as a string. #define S_MEX_FUNC_NAME "motdsp_stemplate" //fn name for compile purposes. #define S_FUNCTION_NAME motdsp_stemplate #define S_FUNCTION_LEVEL 2
The MAX*/MIN* macros described for MATLAB MEX-files are specifically not required for Simulink S-functions.
Also, the template provides an example of optional dialog box parameter checking within the mdlCheckParameters function.
/* Get the first dialog box parameter and check to see if it is a string.*/ if (!mxIsChar(ssGetSFcnParam(S,0)) ) { ssSetErrorStatus(S,"1st parameter to S-function must be a " "string which represents the filename " "of the command file."); return; }
![]() | Terminating and Allocated Memory Cleanup | Input Objects | ![]() |