Target Language Compiler    

Getting Started

In the example directory, the "external function" is found in the file my_alg.c. You are also provided with a C S-function called wrapsfcn.c that glues my_alg.c into Simulink. Set up the exercise as follows:

  1. Copy the folder tlctutorial/wrapper to your working directory.
  2. In MATLAB, run the model externalcode.mdl from your working directory. The block diagram looks like the following.

  1. Run the model (from the Simulation menu, or type Ctrl+T). You will get an error telling you that wrapsfcn does not exist. Can you figure out why?
  1. Answer: wrapsfcn isn't available because there is no mex file for it.

  1. To rectify this, in the MATLAB command window type
  2. Run the simulation again. With the S-function present, no error occurs.

The S-function block simply multiplies its input by two. If you activate the Scope block, you see a sine wave that oscillates between -2.0 and 2.0. The variable yout that is created in your MATLAB workspace steps through these values.

In the remainder of the exercise, you build and run a stand-alone version of the model, then write some TLC code that allows Real-Time Workshop to build a stand-alone executable that calls the S-function my_alg.c directly.


  Why Wrap? Generate Code Without a Wrapper