MATLAB Digest - September 2003
Creating Custom Code with Real-Time Workshop Embedded Coder 3.1by Tom Erkkinen and Pete Szpak |
|
Featuring a collection of tips and best practices for Simulink, Stateflow, and Real-Time Workshop Embedded Coder users, this article describes how to generate custom code files, create a custom user interface for code generation, and improve code efficiency. The examples are based on MathWorks R13 Service Pack 1.
Tips and Models- Tip 1: Generating Efficient Code via Optimized ERT Targets
- Tip 2: Customizing Code File Banners Using ERT Target
- Tip 3: Developing a Custom User Interface via a New System Target
- Tip 4: Creating Code Files Statically with TLC APIs
- Tip 5: Creating Code Files Dynamically via a Custom Interface
- Tip 6: Generating a Custom Main File via TLC APIs
- Model: BIT_Sensor_Fault
- Conclusion
Unless specified, the tips are independent of each other and do not have to be read in a particular order. The tips follow a consistent format that includes a references section with related tips.
For more Real-Time Workshop Embedded Coder tips and techniques, see the 2003: July, May, March, January, and 2002: November issues of MATLAB Digest.
Tip 1: Generating Efficient Code via Optimized ERT Targets
R13 SP1 includes new Embedded Real-Time (ERT) targets that make generating efficient code easier through automation. These new targets are based on the auto-configuration tools and techniques described in the May issue of MATLAB Digest. They enable developers to get optimized code for initial benchmarks studies or analyses even if they have not reviewed the individual code generation option and studied the various efficiency tradeoffs, and are a great starting point for fined-tuned optimization.Description
The three ERT targets are:- Real-Time Workshop Embedded Coder (no auto configuration) This is the default ERT target. Its code-generation configuration options are set to the same values used in R13. The auto-configuration capability is not employed and the configuration values that are set within the model are used for code generation.
- Real-Time Workshop Embedded Coder (auto configures for optimized fixed-point code)
This is a new ERT target. Its code-generation configuration options are set to values that maximize fixed-point code efficiency. The model’s settings are overwritten during the auto-configuration process and a warning is displayed within MATLAB informing the user of this. - Real-Time Workshop Embedded Coder (auto configures for optimized floating-point code)
This is a new ERT target. Its code-generation configuration options are set to values that maximize floating-point code efficiency. The model’s settings are overwritten during the auto-configuration process and a warning is displayed within MATLAB informing the user of this.
Procedure
To use an optimized ERT target:- Browse System Target Files (see Figure 1)
- Select the appropriate target
- Optimized for fixed-point code
- Optimized for floating-point code
- Set Target Word Sizes if required
- Generate code

Figure 1: Browsing system target files. Click on image to see enlarged view.

Figure 2: The selected optimized fixed-point target. Click on image to see enlarged view.
The make command includes an optimized_fixed_point=1 argument. This argument is automatically passed into the ert_make_rtw_hook.m hook file, described in Tip 1 in “Configuring the Code Generator and Tailoring the Build Process for Embedded Targeting," which appears in the May issue of MATLAB Digest, to configure the model with optimized fixed-point settings.
The optimized targets verify that you are using ert_rtw_info_hook.m to specify target word sizes as described in Tip 2 in “Configuring the Code Generator and Tailoring the Build Process for Embedded Targeting," which appears in the May issue of MATLAB Digest. If not, an editor will appear with a default file for you to edit and save.
References
- Related tips: Tip 1 and Tip 2 in "Configuring the Code Generator and Tailoring the Build Process for Embedded Targeting," which appeared in the May 2003 MATLAB Digest
- Additional software: R13 SP1 includes an optimized ert target file. Visit MATLAB Central for R13.0.1 Optimized ert target file support files.
- User documentation: Real-Time Workshop: Release Notes R13 SP1
Store