Simulink custom target system file configuration (2) - callback_handler.m file

foreword

The custom target system file consists of five major files:

  • xx.tlc system target file
  • xx_callback_handler.m RTW toolbox callback function
  • xx_make_rtw_hook.m tlc file call
  • xx_file_process.tlc file processes TLC files
  • xx_srmain.tlc controls the generation of the main function file

xx_callback_handler.m callback function

This function file is used to configure the basic settings of the model , such as Code Generation , Hardware Implementation , etc. can be configured in this callback function, because after selecting tlc, Simulink will automatically execute the callback function xx_callback_handler of tlc for configuration .

Here is part of my configuration:

function jxert_callback_handler(hDlg,hSrc)

slConfigUISetVal(hDlg,hSrc,'ModelReferenceCompliant','on');
slConfigUISetEnabled(hDlg,hSrc,'ModelReferenceCompliant',false);

slConfigUISetVal(hDlg,hSrc,'CompOptLevelCompliant','on');
slConfigUISetEnabled(hDlg,hSrc,'CompOptLevelCompliant',false);

% 设置硬件类型 F407ARM Cortex-M架构
slConfigUISetVal(hDlg,hSrc,'ProdHWDeviceType','ARM Compatible->ARM Cortex-M');
% slConfigUISetVal(hDlg,hSrc,'ProdHWDeviceType','ARM Cortex-M');
slConfigUISetEnabled(hDlg,hSrc,'ProdHWDeviceType',0);

% 指定用于测试从该模型生成的代码的硬件与代码最终在其上运行的硬件相同
slConfigUISetVal(hDlg,hSrc,'ProdEqTarget','on');
slConfigUISetEnabled(hDlg,hSrc,'ProdEqTarget',0);

slConfigUISetVal(hDlg,hSrc,'ZeroExternalMemoryAtStartup','off');%~ZeroExternalMemoryAtStartup off表示勾选
slConfigUISetVal(hDlg,hSrc,'ZeroInternalMemoryAtStartup','off');%~ZeroInternalMemoryAtStartup off表示勾选

% 删除超出范围的浮点数到整数转换的代码
slConfigUISetVal(hDlg,hSrc,'EfficientFloat2IntCast','on');

% 设置需要生成ERT主函数
slConfigUISetVal(hDlg,hSrc,'GenerateSampleERTMain','on');
slConfigUISetEnabled(hDlg,hSrc,'GenerateSampleERTMain',0);

% 不使用Makefile进行代码生成
slConfigUISetVal(hDlg,hSrc,'GenerateMakefile','off');
slConfigUISetEnabled(hDlg,hSrc,'GenerateMakefile',0);

% 创建一个SIL块来验证生成的代码
% slConfigUISetVal(hDlg,hSrc,'CreateSILPILBlock','SIL');
% 取消创建一个SIL/PIL块来验证生成的代码
slConfigUISetVal(hDlg,hSrc,'CreateSILPILBlock','None');

% 指定代码接口打包,设置Nonreusable function表示生成的代码不可用
slConfigUISetVal(hDlg,hSrc,'CodeInterfacePackaging','Nonreusable function');
slConfigUISetEnabled(hDlg,hSrc,'CodeInterfacePackaging',0);

% 不生成mat文件
slConfigUISetVal(hDlg,hSrc,'MatFileLogging','off');
slConfigUISetEnabled(hDlg,hSrc,'MatFileLogging',0);

% 配置用户自定义的模板文件
slConfigUISetVal(hDlg,hSrc,'ERTCustomFileTemplate','example_file_process.tlc');
slConfigUISetEnabled(hDlg,hSrc,'ERTCustomFileTemplate',0);

% 配置取消支持未与TLC文件内联的s函数
slConfigUISetVal(hDlg,hSrc,'SupportNonInlinedSFcns','off');

% 指定在何处生成实用函数、导出数据类型定义和导出数据的声明以及自定义存储类。
slConfigUISetVal(hDlg,hSrc,'UtilityFuncGeneration','Auto');

% 设置取消生成一个模型终止函数
slConfigUISetEnabled(hDlg,hSrc,'IncludeMdlTerminateFcn',0);

% 设置生成将浮点数据显示初始化为0.0
slConfigUISetVal(hDlg,hSrc,'InitFltsAndDblsToZero','off');
slConfigUISetVal(hDlg,hSrc,'PurelyIntegerCode','off');

% 取消在生成的代码中支持非有限值(inf, nan,-inf)
slConfigUISetVal(hDlg,hSrc,'SupportNonFinite','off');

% 只生成代码
slConfigUISetVal(hDlg,hSrc,'GenCodeOnly','on');

% 设置解析器为类型Fixed-step
slConfigUISetVal(hDlg,hSrc,'SolverType','Fixed-step');
slConfigUISetEnabled(hDlg,hSrc,'SolverType',0);
% 默认设置步长为0.02(20ms)
slConfigUISetVal(hDlg,hSrc,'FixedStep','0.02');% 后期可以修改,但不是修改代码,而是在选项中自行修改

% 设置模型编译优先目标,暂定效率优先
slConfigUISetVal(hDlg,hSrc,'ObjectivePriorities','Execution efficiency');
% 遇到警告继续编译,输出报告后找到问题fix就好
slConfigUISetVal(hDlg,hSrc,'CheckMdlBeforeBuild','Warning');
end

The hDlg and hSrc in jxert_callback_handler (hDlg, hSrc) can be ignored, and matlab will automatically allocate them .

How to customize and modify the required parameters?

Right-click the target you want to modify, select what's this:
Custom modification parameters
Then the command code of the script/function file will be displayed:
Operation Figure 2
Then you can click Show more information to see the specific usage of the parameters.

Guess you like

Origin blog.csdn.net/dbqwcl/article/details/126958798