Real-Time Workshop User's Guide | ![]() ![]() |
Analysis of the Model
The build process begins with the analysis of your Simulink block diagram. The analysis process consists of these tasks:
During this phase, the Real-Time Workshop reads your model file (model
.mdl
) and compiles an intermediate representation of the model. This intermediate description is stored, in a language-independent format, in an ASCII file named model
.rtw
. The model
.rtw file is the input to the next stage of the build process.
model
.rtw
files are similar in format to Simulink model (.mdl
) files. Overview of a model.rtw File explains the basic features of a .rtw
file. For a detailed description of the contents of model
.rtw
files, see the Target Language Compiler Reference Guide.
Generation of Code by the Target Language Compiler
In the second stage of the build procedure, the Target Language Compiler transforms the intermediate model description stored in model
.rtw
into target-specific code.
The Target Language Compiler is an interpreted programming language designed for the sole purpose of converting a model description into code. The Target Language Compiler executes a TLC program comprising several target files (.tlc
files). The TLC program specifies how to generate code from the model, using the model
.rtw
file as input.
The system target file is the entry point or main file.
For each block in a Simulink model, there is a block target file that specifies how to translate that block into target-specific code.
The Target Language Compiler function library contains functions that support the code generation process.
The Target Language Compiler begins by reading in the model
.rtw
file. It then compiles and executes the commands in the target files -- first the system target file, then the individual block target files. The output of the Target Language Compiler is a source code version of the Simulink block diagram.
Generation of the Customized Makefile
The third step in the build procedure is to generate a customized makefile, model
.mk
. The generated makefile instructs the make
utility to compile and link source code generated from the model, as well as any required harness program, libraries, or user-provided modules.
The Real-Time Workshop creates model
.mk
from a system template makefile, system
.tmf
. The system template makefile is designed for your target environment. The template makefile allows you to specify compilers, compiler options, and additional information used during the creation of the executable.
The model
.mk
file is created by copying the contents of system
.tmf
and expanding tokens that describe your model's configuration.
The Real-Time Workshop provides many system template makefiles, configured for specific target environments and development systems. The System Target File Browser lists all template makefiles that are bundled with the Real-Time Workshop.
You can fully customize your build process by modifying an existing template makefile or providing your own template makefile.
Creation of the Executable
Creation of an executable program is the final stage of the build process. This stage is optional, as illustrated in Figure 2-5.
If you are targeting a system such as an embedded microcontroller or a DSP board, you can choose to generate only source code. You can then cross compile your code and download it to your target hardware. Making an Executable in Chapter 3 discusses the options that control whether or not the build creates an executable.
The creation of the executable, if enabled, takes place after the model
.mk
file has been created. At this point, the build process invokes the make
utility, which in turn runs the compiler. To avoid unnecessary recompilation of C files, the make
utility performs date checking on the dependencies between the object and C files; only out-of-date source files are compiled.
Optionally, make
can also download the executable to your target hardware.
Figure 2-5: Automatic Program Building: Control Flow
Summary of Files Created by the Build Procedure
The following is a list of the main of the model
.*
files created during the code generation and build process. Each performs a specific function in the Real-Time Workshop. Depending on code generation options, other files may also be created by the build process.
model
.mdl
, created by Simulink, is analogous to a high-level programming language source file.model
.rtw
, generated by the Real-Time Workshop build process, is analogous to the object file created from a high-level language source program.model
.c
, generated by the Target Language Compiler, is the C source code corresponding to the model
.mdl
file.model
.h
, generated by the Target Language Compiler, is a header file that maps the links between blocks in the model.model
_export.h
, generated by the Target Language Compiler, is a header file that contains exported signal, parameter, and function symbols.model
.mk
, generated by the Real-Time Workshop build process, is the customized makefile used to build an executable.model
.exe
(on PC) or
model
(on UNIX), is an executable program, created under control of the make
utility by your development system.Overview of a model.rtw File
This section examines the basic features of a model
.rtw
file. The .rtw
file shown is generated from the source model shown below.
This model is saved in a file called example.mdl
. The Real-Time Workshop generates example.rtw
., an ASCII file. The example.rtw
file consists of parameter name/parameter value pairs, stored in a hierarchical structure consisting of records.
Below is an excerpt from example.rtw
.
For more information on .rtw
files, see the Target Language Compiler Reference Guide, which contains detailed descriptions of the contents of model
.rtw
files.
![]() | Automatic Program Building | Code Generation and the Build Process | ![]() |