Target Language Compiler    

Creating an Inlined S-Function

The Target Language Compiler creates an inlined S-function whenever it detects a .tlc file with the same name as an S-function. Assuming the .tlc file is properly formed, it directs construction of code that functionally duplicates the external S-function without incurring API overhead.

See how this process works by completing the following steps:

  1. Find the file in your working directory called rename_timestwo.tlc. Rename this file to be timestwo.tlc, so that it will be used when generating code. The executable portion of the file is
  1. The highlighted TLC code expands to implement the algorithm.

Now create the inline version of the S-function.

  1. Select Inline parameters from the Advanced tab of the Simulation Parameters dialog box.
  2. Change the diagram's label from model: sfun_x2 to model: sfun_x2_ilp.
  3. Save the model as sfun_x2_ilp.mdl.
  4. Click Generate code. Source files are created in a new subdirectory called sfun_x2_ilp_grt_rtw. Inspect the generated file sfun_x2_ilp.c, paying attention to the highlighted lines corresponding to those above:

Continue the exercise by creating a stand-alone simulation, as follows.

  1. Clear Generate code only from the Real-Time Workshop pane in the Simulation Parameters... dialog.
  2. Go to Workspace I/O tab and select the Output box under Save to workspace (this causes the model's output data to be logged in your MATLAB workspace).
  3. Click Build to generate source, compile, and link the model into an executable, named sfun_x2_ilp.exe (or, on UNIX systems, sfun_x2_ilp).
  4. Confirm that the timestwo.tlc file did the right thing by running the stand-alone executable. To run it, in the MATLAB command window, type:
  1. The following responses appear:

    View or plot the contents of the sfun_x2_ilp.mat file to verify that the stand-alone model generated sine output ranging from -2 to +2. In the MATLAB command window, type


  Why Use TLC to Implement S-functions? Scalar or Vector, It's the Same