How do I add non-UI elements in a custom System Target file (STF) and use the build hooks to pass the variables to the makefile in real-Time Workshop Embedded Coder 5.4 (R2010b)?

2 views (last 30 days)
I have a custom System Target file (STF). I want to define certain non-UI elements in it. The values of these non-UI elements are determined during the build process. I would like to use the STF hooks to modify these non-UI elements and consequently make these modified variables available to the makefile.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Nov 2010
This can be accomplished using the STF hooks. In the STF, you can create the elements of the custom target's UI using the 'rtwoptions' structure. This is used to create both invisible ('non UI') and visible UI components by specifying the type of the component, default value of the component, and etc. When you create a component using this structure, you can add additional fields such as 'tlcvariable' and 'makevariable'. The field 'tlcvariable' allows you to control the name of this variable as available to the Target Language Compiler whereas 'makevariable' allows you to control the name as available in the make file creation.
For example, following code creates a 'non-UI' component that can be accessed from TLC and make file with their names as specified below:
rtwoptions(oIdx).prompt = 'myNonUI';
rtwoptions(oIdx).type = 'NonUI';
rtwoptions(oIdx).default = 'off';
rtwoptions(oIdx).tlcvariable = 'myNonUI';
rtwoptions(oIdx).makevariable = 'MYNONUI';
These values can be modified using the STF hooks during the BUILD process.
For example, in the 'after_tlc' hook, you can use the following code to modify the variable after generating the code:
case 'after_tlc'
% Called just after to invoking TLC Compiler (actual code generation.)
% Valid arguments at this stage are hookMethod, modelName, and
% buildArgs
disp('############Executing After TLC Hook##########');
set_param(gcs,'myNonUI','on')
disp('###Done changing the non UI parameter myNonUI');
This variable can then be used in the TMF to create corresponding variable in the 'model.mk' file. There is ZIP file attached that illustrates this with an example.
1. Download and extract the files to a location that is in MATLAB path. Please make sure to add the sub-folders to the path as well.
2. Open the model and build it. You will see that the generated 'pk.mk' file in the code generation folder has the value of modified non-UI variable 'myNonUI'.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2010b

Community Treasure Hunt

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

Start Hunting!