S-Function Examples Note The mdlUpdate and mdlTerminate functions both use the macro UNUSED_ARG. This macro is defined inmatlabroot/simulink/include/simstruc_types.h and is used to indicate that one of the input arguments to these callbacks is required even though it is not used in these callbacks. The macro UNUSED_ARG accepts only a single input argument so must be called once for each callback input argument that is not used in the callback. Example of a Variable-Step S-Function The example S-function matlabroot/simulink/src/vsfunc.c uses a variable-step sample time. This S-function is used in the Simulink model matlabroot/toolbox/simulink/simdemos/simfeatures/sfcndemo_vsfunc.mdl. Variable step-size functions require a call to mdlGetTimeOfNextVarHit, which is an S-function routine that calculates the time of the next sample hit. S-functions that use the variable-step sample time can only be used with variable-step solvers. vsfunc is a discrete S-function that delays its first input by an amount of time determined by the second input. The output of vsfunc is simply the input u delayed by a variable amount of time. mdlOutputs sets the output y equal to state x. mdlUpdate sets the state vector x equal to u, the input vector. This example calls mdlGetTimeOfNextVarHit, an S-function routine that calculates and sets the time of the next hit, that is, the time when vsfunc is next called. In mdlGetTimeOfNextVarHit, the macro ssGetInputPortRealSignalPtrs is used to get a pointer to the input u. Then this call is made. ssSetTNext(S, ssGetT(S)(*u[1])); The macro ssGetT gets the simulation time t. The second input to the block, (*u[1]), is added to t, and the macro ssSetTNext sets the time of the next hit equal to t+(*u[1]), delaying the output by the amount of time set in (*u[1]). matlabroot/simulink/src/vsfunc.c The beginning of each S-function must include #define statements for the S-functionâs name and level, along with a #include statement for the simstruc.h header. Following these statements, the S-function can include or define any other necessary headers, data, etc. . In the vsfunc.c example 7-77