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
.
Selecting Simulation Parameters from Simulink's Simulation menu displays the Simulation Parameters dialog box.
Figure 3-2: Simulation Parameters Dialog Box
Select Fixed Step Solver from the Simulation Parameters dialog box and then move to the Real-Time Workshop tab. Then, click the Generate Code only button. Next, move to the Category drop down list and select the TLC Debugging option. The tab changes and you should check the Retain .rtw file option. Next, 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.
### Successful completion of Real-Time Workshop build procedure for model: basic
Open the file ./basic_grt_rtw/basic.rtw
in a text editor to see what it looks like. The file should look similar to this
CompiledModel { Name "basic" ... <General model information such as
> Solver FixedStepDiscrete ... BlockOutputs { -- Information blocks output signals: characteristics and connectivity BlockOutputDefaults { TestPoint no ... } ... BlockOutput { Identifier Constant SigIdx [0, 1] StorageClass DefinedInTLC SigSrc [0, 0, 0] } } ... System { <Subsystem description
> Type root Name "<Root>" ... <Blocks in subsystem, listed by block execution order
> Block { Type Constant Name "<Root>/Constant" ... Parameters [1, 1] Parameter { Name "Value" ... } } ... } ... }
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
%with CompiledModel My model is called %<Name>. It was generated on %<GeneratedOn>. It has %<NumModelOutputs> output(s) and %<NumContStates> continuous states. %endwith
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
rtwgen('
basic'
,'
OutputDirectory'
,'
basic_grt_rtw'
) tlc -r basic_grt_rtw/basic.rtw basic.tlc -v
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, and -v
tells TLC to be verbose.
The output of this pair of commands is
My model is called basic. It was generated on Tue May 09 11:41:40 2000. It has 1 output(s) and 0 continuous states.
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.
![]() | Code Generation Architecture | Invoking TLC to Generate Code | ![]() |