How to determine if code is generated for PIL in PostCodeGenCommand or hook?

1 view (last 30 days)
Hello,
we have a custom code generation target that also includes PIL functionality.
We use the PostCodeGenCommand to add some additional includes to the buildInfo object.
Is there a way to determine in the PostCodeGenCommand or in the STF_make_rtw_hook if a code generation was triggered for a PIL simulation? I would like to use this information to add different include files for PIL vs a "normal" production code generation.
Thank you for your help.

Answers (1)

Malay Agarwal
Malay Agarwal on 24 Dec 2024
Edited: Malay Agarwal on 24 Dec 2024
You can access the SimulationMode parameter of the model to determine if the code generation was triggered with PIL.
You can use either of PostCodeGenCommand or STF_make_rtw_hook to achieve this.
Refer to the example below, which uses STF_make_rtw_hook (due to simplicity):
% Note: Please change the function name according to your target
% For example, if you are using grt.tlc, the name should be grt_make_rtw_hook
% This will work for custom TLC files as well
function ert_make_rtw_hook(hookMethod, modelName, rtwRoot, templateMakefile, buildOpts, buildArgs, buildInfo)
switch hookMethod
case "entry"
simulationMode = get_param(modelName, 'SimulationMode');
if strcmpi(simulationMode, 'Processor-in-the-Loop (PIL)')
disp('PIL simulation detected. Modifying build options for PIL.');
% Modify build options here
else
disp("Normal code generation. Using default build options.");
end
end
end
Note that using SFT_make_rtw_hook will affect all models which use, for example, ert.tlc to generate code.
The benefit of using PostCodeGenCommand would be that the customization would affect only the model the command has been set for instead of all models.
Please refer to the following resources for more information on using PostCodeGenCommand and STF_make_rtw_hook:
Hope this helps!
  1 Comment
Alexander Sinn
Alexander Sinn on 7 Jan 2025
Hi Malay,
thank you for your help.
This solution works when a whole model is simulated in PIL mode (e.g. the SimulationMode parameter of the model is set to PIL).
However, this will fail in case only a referenced model is set to be simulated in PIL mode (e.g. the SimulationMode parameter of a model block is set to PIL). In this case the modelName argument is the name of the referenced model and the simulation mode is set to the default mode.
Do you know any way I can cover this case as well?

Sign in to comment.

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!