Target Language Compiler    

Noninlined Code Generation

  1. Copy the tutorial directory tlctutorial/timestwo into your working directory. It contains a Simulink S-function, timestwo.c.

  1. In the MATLAB command window, create a MEX-file for the S-function:
  1. This is needed to avoid picking up the version shipped with Simulink.

  1. Open the model sfun_x2.mdl, which uses the timestwo S-function. The block diagram looks like this.

  1. Set up simulation parameters to use a fixed-step discrete solver with a step size of 0.01 and stop time of 10.0.
  2. Go to the Advanced tab of the Simulation Parameters... dialog, and make sure that the Inline parameters box is not selected.
  3. Select Generate code only from the Real-Time Workshop tab in the Simulation Parameters... dialog box. The text of the Build button will change to Generate code. Click on Generate code to generate C source for the model. In your editor, view the MdlOutputs and MdlTerminate portions of the resulting file, sfun_x2.c, shown below.

  1. Notice the overhead of calling the function that the S-function API necessitates (highlighted lines).


  Inlining S-Functions with TLC Why Use TLC to Implement S-functions?