User`s guide

10 Targeting Custom Hardware
10-10
Figure 10-1: Format of a Device Driver S-Function
#define S_FUNCTION_NAME filename
Define a name for the entry point function:
Include the definition of the Simulink
data structure (SimStruct):
#include "simstruc.h"
Initialize the size information in the
mdlInitializeSizes(S)
Readfromorwritetohardware(depending
SimStruct:
mdlOutputs(y,x,u,S)
Obtain dialog box parameters and
mdlInitializeConditions(x0,S)
Include code generator header file:
#include "cg_sfun.h"
Set the block’s sample time to the sample
time specified in the dialog box:
mdlInitializeSampleTimes(S)
Device Driver
Clean up after completion of program:
mdlTerminate(S)
on whether the block is for input or output):
S-Function
initialize the board:
Include MEX header file:
#include "simulink.c"
Define the S-function as level 2:
#define S_FUNCTION_LEVEL 2
Include the MEX header file:
#ifdef MATLAB_MEX_FILE
#include "mex.h"
#endif