Real-Time Workshop User's Guide | ![]() ![]() |
Where to Find Information in This Manual
The list below will guide you to information relevant to your development tasks and interests.
Single- and Multitasking Code Generation
The Real-Time Workshop fully supports single- and multitasking code generation. See Chapter 6, Program Architecture and Chapter 7, Models with Multiple Sample Rates for a complete description.
Customizing Generated Code
The Real-Time Workshop Custom Code library supports customization of the generated code. See Chapter 14, Custom Code Blocks for a description of this library.
An alternative approach to customizing generated code is to modify Target Language Compiler (TLC) files. The Target Language Compiler is an interpreted language that translates Simulink models into C code. Using the Target Language Compiler, you can direct the code generation process.
There are two TLC files, hookslib.tlc
and cachelib.tlc
, that contain functions you can use to customize Real-Time Workshop generated code. See the Target Language Compiler Reference Guide for more information about these TLC files. See also the source code, located in matlabroot
/rtw/c/tlc
.
Optimizing Generated Code
The default code generation settings are generic for flexible rapid prototyping systems. The penalty for this flexibility is code that is less than optimal. There are several optimization techniques that you can use to minimize the source code size and memory usage once you have a model that meets your requirements.
See Chapter 3, Code Generation and the Build Process and Chapter 8, Optimizing the Model for Code Generation for details on code optimization techniques available for all target configurations.
Chapter 9, Real-Time Workshop Embedded Coder contains information about optimization specifically for embedded code.
Validating Generated Code
Using the Real-Time Workshop data logging features, you can create an executable that runs on your workstation and creates a data file. You can then compare the results of your program with the results of running an equivalent Simulink simulation.
For more information on how to validate Real-Time Workshop generated code, see Workspace I/O Options and Data Logging. See also Tutorial 2: Data Logging and Tutorial 3: Code Validation in this chapter.
Incorporating Generated Code into Larger Systems
If your Real-Time Workshop generated code is intended to function within an existing code base (for example, if you want to use the generated code as a plug-in function), you should use the Real-Time Workshop Embedded Coder. Chapter 9, Real-Time Workshop Embedded Coder documents the entry points and header files you will need to interface your code to Real-Time Workshop Embedded Coder generated code.
Incorporating Your Code into Generated Code
To interface your hand-written code with Real-Time Workshop generated code, you can use an S-function wrapper. See the Writing S-Functions manual for more information.
Creating and Communicating with Device Drivers
S-functions provide a flexible method for communicating with device drivers. See Chapter 17, Targeting Real-Time Systems for a description of how to build device drivers. Also, for a complete discussion of S-functions, see the Writing S-Functions manual.
Code Tracing
The Real-Time Workshop includes special tags throughout the generated code that make it easy to trace generated code back to your Simulink model. See Tracing Generated Code Back to Your Simulink Model for more information about this feature.
Automatic Build Procedure
Using the Real-Time Workshop, you can generate code with the push of a button. The automatic build procedure, initiated by a single mouse click, generates code, a makefile, and optionally compiles (or cross-compiles) and downloads a program. See Automatic Program Building for an overview, and Chapter 3, Code Generation and the Build Process for complete details.
Parameter Tuning
Parameter tuning enables you to change block parameters while a generated program runs, thus avoiding recompiling the generated code. The Real-Time Workshop supports parameter tuning in four different environments:
rsim
) in batch mode to provide fast simulations for performing parametric studies. Although this is not an on-the-fly application of parameter tuning, it is nevertheless a useful way to evaluate a model. This mode is also useful for Monte Carlo simulation. See Chapter 11, Real-Time Workshop Rapid Simulation Target for further information.See also Interfacing Signals and Parameters.
Monitoring Signals and Logging Data
There are several ways to monitor signals and data in the Real-Time Workshop:
Interfacing Signals and Parameters
You can interface signals and parameters in your model to hand-written code by specifying the storage declarations of signals and parameters. For more information, see:
Sample Implementations
The Real-Time Workshop provides sample implementations that illustrate the development of real-time programs under DOS and Tornado, as well as generic real-time programs under Windows and UNIX.
These sample implementations are located in the following directories:
matlabroot
/rtw/c/grt
:
Generic real-time examplesmatlabroot
/rtw/c/dos
: DOS examplesmatlabroot
/rtw/c/tornado
: Tornado examples![]() | Tutorial 4: A First Look at Generated Code | Technical Overview | ![]() |