Writing S-Functions | ![]() ![]() |
Fully Inlined S-Functions
Continuing the example of the previous section, you could eliminate the call to my_alg
entirely by specifying the explicit code (i.e., 2.0 * u
) in wrapsfcn.tlc
. This is referred to as a fully inlined S-function. While this can improve performance, if your C code is large this can be a lengthy task. In addition, you now have to maintain your algorithm in two places, the C S-function itself and the corresponding TLC file. However, the performance gains might outweigh the disadvantages. To inline the algorithm used in this example, in the Outputs
section of your wrapsfcn.tlc
file, instead of writing
This is the code produced in mdlOutputs
:
void mdlOutputs(int_T tid) { /* Sin Block: <Root>/Sin */ rtB.Sin = rtP.Sin.Amplitude * sin(rtP.Sin.Frequency * ssGetT(rtS) + rtP.Sin.Phase); /* S-Function Block: <Root>/S-Function */![]()
rtB.S_Function = 2.0 * rtB.Sin;
/* Outport Block: <Root>/Out */ rtY.Out = rtB.S_Function; }
The Target Language Compiler has replaced the call to my_alg
with the algorithm itself.
![]() | The Inlined Code | Multiport S-Function Example | ![]() |