How do I customize the "main" function generated by Real-Time Workshop Embedded Coder 5.2 (R2008b)?

21 views (last 30 days)
I want to customize the "main" function generated by Real-Time Workshop Embedded Coder when I select the "Generate example main program" option in 'Configuration Parameters -> Real-Time Workshop -> Templates'.
For example, I do not want the following lines of code to appear in the generated file:
printf("Warning: The simulation will run forever. "
"Generated ERT main won't simulate model step behavior. "
"To change this behavior select the 'MAT-file logging' option.\n");

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 23 Jan 2017
Among other ways, Real-Time Workshop Embedded Coder 5.2 (R2008b) provides two types of customization files to change the appearance of the generated code:
1. Code Generation Template or CGT files which control the overall structure of the generated code. These customizations are applied to most of the code and data files generated by Real-Time Workshop Embedded Coder. These template files are specified in the “Code Template” and “Data Template” panels under 'Configuration Parameters -> Real-Time Workshop -> Templates'.
2. Custom File Processing or CFP Templates which control the control the content of individual files in the generated code. This file is specified in the “Custom Template” panel of 'Configuration Parameters -> Real-Time Workshop -> Templates'.
In order to customize the auto-generated "main" function, a custom CFP Template file needs to be specified.
Refer to the steps below in order to customize the "main" function:
1. For any model, by default, "example_file_process.tlc" CFP Template file is specified to generate the "main" function. However, in this file, line 23 declaring the flag "ERTCustomFileTest" is commented out. Hence the contents of this file are not being used. Uncommenting this line will cause Real-Time Workshop Embedded Coder to use the contents of this CFP template file.
2. Lines 104-112 of this file call the template for a "main" function stored in the files "bareboard_srmain.tlc" OR "bareboard_mrmain.tlc". The structure of the main program depends on the content of these TLC files.
Now if you try to generate code for a model by using this file (after uncommenting line 23), the following lines of code will be executed and the warning message will no longer appear in the generated "main" function since it is not defined in the TLC files that are being called in the code below.
 
%%Create a simple main. Files are located in $MATLABROOT/rtw/c/tlc/mw.
%if LibIsSingleRateModel() || LibIsSingleTasking()
%include "bareboard_srmain.tlc"
%<FcnSingleTaskingMain()>
%else
%include "bareboard_mrmain.tlc"
%<FcnMultiTaskingMain()>
%endif
In fact, these are the only lines of TLC code required in a custom "File customization template" file to create a custom "main" function and for picking up the template for the "main" function from "bareboard_srmain.tlc" or "bareboard_mrmain.tlc" file. Hence, the rest of the lines in the TLC file can be deleted while testing.
To create a custom look for the "main" function, modify the contents of the following files to suit the requirements:
a. $MATLABROOT\rtw\c\tlc\mw\bareboard_mrmain.tlc
b. $MATLABROOT\rtw\c\tlc\mw\bareboard_srmain.tlc
c. $MATLABROOT\toolbox\rtw\targets\ecoder\example_file_process.tlc
For details on how to use these advanced customization techniques please refer to the link below:
or
In MATLAB 8.0 (R2012b) from MATLAB commad line:
>> web([docroot '/ecoder/ug/configure-templates-for-customizing-code-organization-and-format.html'])

More Answers (0)

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Products


Release

R2008b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!