User`s guide
Fully Inlined S-Function with the mdlRTW Routine
4-25
When creating this model, you need to specify the following for each S-function
block:
set_param(‘sfun_directlook_ex/S-Function’,’SFunctionModules’,’lookup_index’)
set_param(‘sfun_directlook_ex/S-Function1’,’SFunctionModules’,’lookup_index’)
This informs the Real-Time Workshop build process that the m odule
lookup_index.c is needed when creating the executable.
The generated code for the lookup table example model is
<Generated header for sfun_directlook_ex model>
#include <math.h>
#include <string.h>
#include “sfun_directlook_ex.h”
#include “sfun_directlook_ex.prm”
/* Start the model */
void MdlStart(void)
{
/* (no start code required) */
}
/* Compute block outputs */
void MdlOutputs(int_T tid)
{
/* local block i/o variables */
real_T rtb_Sine_Wave;
real_T rtb_buffer2;
/* Sin Block: <Root>/Sine Wave */
rtb_Sine_Wave = rtP.Sine_Wave.Amplitude *
sin(rtP.Sine_Wave.Frequency * ssGetT(rtS) + rtP.Sine_Wave.Phase);
/* S-Function Block: <Root>/S-Function */
{
real_T *xData = &rtP.S_Function.XData[0];
real_T *yData = &rtP.S_Function.YData[0];
real_T spacing = xData[1] - xData[0];
if ( rtb_Sine_Wave <= xData[0] ) {
rtb_buffer2 = yData[0];
} else if ( rtb_Sine_Wave >= yData[20] ) {
rtb_buffer2 = yData[20];
} else {
int_T idx = (int_T)( ( rtb_Sine_Wave - xData[0] ) / spacing );
rtb_buffer2 = yData[idx];
}
}
/* Outport Block: <Root>/Out1 */
Thisisthecodethatis
inlined for the top
S-function block in the
sfun_directlook_ex
model.