Target Language Compiler    

Creating an Inlined S-Function

Now, create an inlined S-function to replace the timestwo.c code. Do this by creating a TLC file named timestwo.tlc in your working directory. When the Target Language Compiler detects a TLC file with the same name as the S-function, it uses the TLC version instead of a function call to the external C coded S-function. This process enables TLC to inline the code within the generated C code:

  1. Copy the file tlctutorial/timestwo/timestwo.tlc into your working directory.
  2. Select Inline parameters from the Advanced page before you build your executable code. Confirm that your timestwo.tlc file works correctly by generating C code, viewing the generated code, running the stand-alone simulation with data logging, and plotting the resulting data.
  3. Copy the model tlctutorial/timestwo/sfun_x2v.mdl into your working directory. Try using the timestwo.tlc file with this model, which is essentially just a vectored version of sfun_x2.mdl, and look at the generated C code.
  4. Close both models (sfun_x2 and sfun_x2v) before continuing with the tutorial.

A key difference when using TLC to inline an S-function is that S-functions often contain empty function calls. Once inlined, the model code only has function calls for functions that actually do something. Empty function calls can be eliminated. Function calls are expensive on DSPs, therefore, eliminating unnecessary function calls can provide better performance, especially when the S-function is used in multiple instances in the same model.

Keep in mind, TLC is not a substitute for writing C code S-functions. In order to simulate within Simulink, it is still necessary to have a C code S-function since Simulink does not make use of TLC files. TLC can inline an S-function to make the S-function much more efficient in your RTW target code.


 Basic Inlined S-Function Written in TLC Introduction to TLC Token Expansion