User`s guide
4 Guidelines for Writing C MEX S-Functions
4-14
/* Level2 S-Function Block: <Root>/S-Function (wrapsfcn) */
{
SimStruct *rts = ssGetSFunction(rtS, 0);
sfcnOutputs(rts, tid);
}
/* Outport Block: <Root>/Out */
rtY.Out = rtB.S_Function;
}
/* Perform model update */
void MdlUpdate(int_T tid)
{
/* (no update code required) */
}
/* Terminate function */
void MdlTerminate(void)
{
/* Level2 S-Function Block: <Root>/S-Function (wrapsfcn) */
{
SimStruct *rts = ssGetSFunction(rtS, 0);
sfcnTerminate(rts);
}
}
#include “wrapper.reg”
/* [EOF] wrapper.c */
In addition to the overhead outlined above, the wrapper.reg generated file
contains the initialization of the
SimStruct for the wrapper S-function block.
There is one child
SimStruct for each S-function block in your model. This
overhead ca n be significantly reduced by creating a T LC wrapper for the
S-function.
How to Inline
The generated code makes the call to your S-function, wrapsfcn.c,in
MdlOutputs by using this code:
SimStruct *rts = ssGetSFunction(rtS, 0);
sfcnOutputs(rts, tid);
This call has a significant amount of computational overhead associated with
it. First, Simulink creates a
SimStruct data structure for the S-function block.
Second, the Real -Time Workshop constructs a call through a function pointer
to execute
MdlOutputs,andthenMdlOutputs calls my_alg. By inlining the call
Noninlined S-functions
create a SimStruct
object and generate a
call to the S-function
routine mdlOutputs.
Noninlined S-functions
require a SimStruct
object and the call to the
S-function routine
mdlTerminate.