Real-Time Workshop | ![]() ![]() |
Basic Real-Time Workshop Concepts
Even if you have experience in building real-time systems, you may find it helpful to review the following descriptions to be sure of understanding the nomenclature that Real Time Workshop documentation uses. A more extensive list of terms may be found in Appendix A, "Glossary.
The process of generating source code from Simulink models is shown in the following diagram. The terms and concepts involved are described below.
Figure 3-1: Real-Time Workshop Code Generation Process
Target and Host
A target is an environment--hardware or operating system--on which your generated code will run. The process of specifying this environment is called targeting.
The process of generating target-specific code is controlled by a system target file, a template makefile, and a make command. To select a desired target, you can specify these items individually, or you can choose from a wide variety of ready-to-run configurations.
The host is the system you use to run MATLAB, Simulink, and Real-Time Workshop. Using the build tools on the host, you create code and an executable that runs on your target system.
Available Target Configurations
Real-Time Workshop supports many target environments. These include ready-to-run configurations and third-party targets. You can also develop your own custom target.
For a complete list of bundled targets, with their associated system target files and template makefiles, see The System Target File Browser of the Real-Time Workshop documentation.
Code Formats
A code format specifies a framework for code generation suited for specific applications.
When you choose a target configuration, you implicitly choose a code format. If you use Real-Time Workshop Embedded Coder, for example, the code generated will be in embedded C format. The embedded C code format is a compact format designed for production code generation. Its small code size, use of static memory, and simple call structure make it optimal for embedded applications.
Many other targets, such as the generic real-time (GRT) target, use the real-time code format. This format, less compact but more flexible, is optimal for rapid prototyping applications.
For a complete discussion of available code formats, see Generated Code Formats of the Real-Time Workshop documentation.
The Generic Real-Time Target
Real-Time Workshop provides a generic real-time development target. The GRT target provides an environment for simulating fixed-step models in single or multitasking mode. A program generated with the GRT target runs your model, in simulated time, as a stand-alone program on your workstation.
The GRT target allows you to perform code validation by logging system outputs, states, and simulation time to a data file. The data file can then be loaded into the MATLAB workspace for analysis or comparison with the output of the original model.
The GRT target also provides a starting point for targeting custom hardware. You can modify the GRT harness program, grt_main.c
, to execute code generated from your model at interrupt level under control of a real-time clock.
Target Language Compiler Files
Real-Time Workshop generates source code for models and blocks through the Target Language Compiler, which reads script files (or TLC files) that specify the format and content of output source files. Two types of TLC files are used:
System and block target files have the extension .tlc
. By convention, a system target file has a name corresponding to your target. For example, grt.tlc
is the system target file for the GRT target.
If you need to incorporate legacy code or maximize the efficiency of code for models containing S-functions, you will need to prepare your own TLC files to augment code generation for such models. These and other advanced uses of TLC scripts are explained in the Target Language Compiler Reference Guide, which provides a set of tutorials to help you get started.
Template Makefiles
Real-Time Workshop uses template makefiles to build an executable from the generated code.
The Real-Time Workshop build process creates a makefile from the template makefile. Each line from the template makefile is copied into the makefile; tokens encountered during this process are expanded into the makefile.
The name of the makefile created by the build process is
model
.mk
(where model
is the name of the Simulink model). The model
.mk
file is passed to a make utility, which compiles and links an executable from a set of files.
By convention, a template makefile has an extension of .tmf
and a name corresponding to your target and compiler. For example, grt_vc.tmf
is the template makefile for building a generic real-time program under Visual C/C++.
You specify system target files and template makefiles using the Real-Time Workshop pane of the Simulation Parameters dialog box, either by typing their filenames or choosing them with the Target File Browser. Tutorial 1: Building a Generic Real-Time Program below introduces these interfaces. See Target Configuration Options for additional documentation.
The Build Process
A high-level M-file command controls the Real-Time Workshop build process. The default command, used with most targets, is make_rtw
. When you initiate a build, Real-Time Workshop invokes make_rtw
. The make_rtw
command, in turn, invokes the Target Language Compiler and utilities such as make
. The build process consists of the following stages:
make_rtw
compiles the block diagram and generates a model description file, model
.rtw.
make_rtw
invokes the Target Language Compiler to generate target-specific code, processing model
.rtw
as specified by the selected system target file.
make_rtw
creates a makefile, model
.mk
, from the selected template makefile.
make
is invoked. make
compiles and links a program from the generated code, as instructed in the generated makefile.
Automatic Program Building gives an overview of the build process. Simulation Parameters and Code Generation of the Real-Time Workshop documentation expands on how model data affects code generation.
Model Parameters and Code Generation
The simulation parameters of your model directly affect code generation and program building. For example, if your model is configured to stop execution after 60 seconds, the program generated from your model will also run for 60 seconds.
Before you generate code and build an executable, you must verify that you have set the model parameters correctly in the Simulation Parameters dialog box. See Simulation Parameters and Code Generation of the Real-Time Workshop documentation for more information. Real-Time workshop will refuse to generate code and issue diagnostics when certain parameters (such as solver type) are set inappropriately. However, when other parameters (such as Production Hardware Characteristics) have inappropriate values, code generated by Real-Time Workshop can yield incorrect results.
Real-Time Workshop imposes certain requirements and restrictions on the model from which code is generated. Many of these, for example, the use of variable-step solvers, are target specific. The following sections in the Real-Time Workshop documentation may help you understand restrictions on code generation that may apply:
![]() | Working with Real-Time Workshop | Quick Start Tutorials | ![]() |