Target Language Compiler    

A Basic Example

This section presents a basic example of creating a target language file that generates specific text from a Real-Time Workshop model. This example shows the sequence of steps that you should follow in creating and using your own target language files.

Process

To begin, create the Simulink model shown below and save it as basic.mdl.

Figure 4-1: Simulink Model

Selecting Simulation Parameters from Simulink's Simulation menu displays the Simulation Parameters dialog box.

Figure 4-2: Simulation Parameters Dialog Box

Select Fixed-step from the Solver pane of the Simulation Parameters dialog box and then click the Real-Time Workshop tab. Then, click the Generate Code only button. From the Category drop down list select the TLC Debugging option. The dialog changes, allowing you to select the Retain .rtw file option. After doing so, click the Generate Code button.

The build process then generates the code into the basic_grt_rtw directory and you can see the progress in the MATLAB window.

The output eventually displays:

Viewing basic.rtw.   

Open the file ./basic_grt_rtw/basic.rtw in a text editor to see what it looks like. The hierarchy of records it contains includes among others, the following elements (where elided lines are denoted by "..."; comments are delimited by < > and do not appear in the file).

Creating the Target File.   Next, create a basic.tlc file to act as a target file for this model. However, instead of generating code, simply print out some information about the model using this file. The concept is the same as used in code generation.

Create a file called basic.tlc in ./ (the directory containing basic.mdl). This file should contain the following lines:

For the build process, you need to include some further information in the TLC file for the build process to successfully proceed. Instead, in this example, you will generate the .rtw file directly and then run the Target Language Compiler on this file to generate the desired output. To do this, enter at the MATLAB prompt

The first line generates the .rtw file in the build directory 'basic_grt_rtw', (this step is actually unnecessary since the file has already been generated in the previous step; however, it will be useful if the model is changed and the operation has to be repeated).

The second line runs the Target Language Compiler on the file basic.tlc. The -r option tells the Target Language Compiler that it should use the file basic.rtw as the .rtw file. Note that a space must separate -r and the input filename. The -v option tells TLC to be verbose in reporting its activity.

The output of this pair of commands is (date will differ):

You may also try changing the model (such as using rand(2,2) as the value for the constant block) and then repeating the process to see how the output of TLC changes.

As you continue through this chapter, you will learn more about creating target files.


  Build Process Invoking Code Generation