User`s guide
Writing Wrapper S-Functions
4-13
The TLC S-Function Wrapper
This section describes how to inline the call to my_alg in the MdlOutputs
section of the generated code. In the above example, the call to my_alg is
embedded in the
mdlOutputs section as:
*y = my_alg(*uPtrs[0]);
When creating a TLC S-function wrapper, the g oal is to have the Real-Time
Workshop embed t he same type of call in the generated code.
It is instructive to look at how the Real-Time Workshop executes S-functions
that are not inlined. A noninlined S-function is identified by the absence of the
file
sfunction.tlc and the existence of sfunction.mex.When generatingcode
for a noninlined S-function, the Real-Time Workshop generates a call to
mdlOutputs through afunction pointerthat, inthisexample,then callsmy_alg.
The wrapper example contains one S-function (
wrapsfcn.mex). You must
compile and link an additional module,
my_alg, with the generated code. To do
this, specify
set_param('wrapper/S-Function','SFunctionModules','my_alg').
The code generated when using
grt.tlc as the system target file without
wrapsfcn.tlc is:
<Generated code comments for wrapper model with noninlined wrapsfcn S-function>
#include <math.h>
#include <string.h>
#include “wrapper.h”
#include “wrapper.prm”
/* Start the model */
void MdlStart(void)
{
/* (no start code required) */
}
/* Compute block outputs */
void MdlOutputs(int_T tid)
{
/* Sin Block: <Root>/Sin */
rtB.Sin = rtP.Sin.Amplitude *
sin(rtP.Sin.Frequency * ssGetT(rtS) + rtP.Sin.Phase);