前言
自定义目标系统文件由五大文件组成:
- xx.tlc 系统目标文件
- xx_callback_handler.m RTW工具箱回调函数
- xx_make_rtw_hook.m tlc文件调用
- xx_file_process.tlc 文件处理TLC文件
- xx_srmain.tlc 控制主函数文件的生成
该文件的目的是用来控制自动代码生成的过程中,针对不同的情况,在各阶段生成什么样的代码。该文件可以在callback_handle里面配置,也可以在Configuration Parameter中查看。 我这边是沿用了ert.tlc的file_process文件,因为对生成代码没有具体的要求。
在callback_handle里面可以设置这个配置项:
% 配置用户自定义的模板文件
slConfigUISetVal(hDlg,hSrc,'ERTCustomFileTemplate','example_file_process.tlc');
slConfigUISetEnabled(hDlg,hSrc,'ERTCustomFileTemplate',0);
可以参考下面的模板自定义:
%selectfile NULL_FILE
%% Uncomment this TLC line to execute the example
%% || ||
%% || ||
%% \/ \/
%% %assign ERTCustomFileTest = TLC_TRUE
%if EXISTS("ERTCustomFileTest") && ERTCustomFileTest == TLC_TRUE
%% Add a new C file timestwo.c and put a simple function in it
%assign cFile = LibCreateSourceFile("Source", "Custom", "timestwo")
%openfile typesBuf
#include "rtwtypes.h"
%closefile typesBuf
%
%openfile tmpBuf
/* Times two function */
real_T timestwofcn(real_T input) {
return (input * 2.0);
}
%closefile tmpBuf
%
%% Add a corresponding H file timestwo.h
%assign hFile = LibCreateSourceFile("Header", "Custom", "timestwo")
%openfile tmpBuf
/* Times two function */
extern real_T timestwofcn(real_T input);
%closefile tmpBuf
%
%
%% Add a #define to the model's public header file model.h
%assign pubName = LibGetMdlPubHdrBaseName()
%assign modelH = LibCreateSourceFile("Header", "Simulink", pubName)
%openfile tmpBuf
#define ACCELERATION 9.81
%closefile tmpBuf
%
%% Add a #define to the model's private header file model_private.h
%assign prvName = LibGetMdlPrvHdrBaseName()
%assign privateH = LibCreateSourceFile("Header", "Simulink", prvName)
%openfile tmpBuf
#define STARTING_POINT 100.0
%closefile tmpBuf
%
%% Add a #include to the model's C file model.c
%assign srcName = LibGetMdlSrcBaseName()
%assign modelC = LibCreateSourceFile("Source", "Simulink", srcName)
%openfile tmpBuf
/* #include "mytables.h" */
%closefile tmpBuf
%
%% Create a simple main. Files are located in MATLAB/rtw/c/tlc/mw.
%if LibIsSingleRateModel() || LibIsSingleTasking()
%include "bareboard_srmain.tlc"
%
%else
%include "bareboard_mrmain.tlc"
%
%endif
%endif
当然,这里也是不建议新手去修改或者自己写,对代码没有特殊要求的话完全可以依靠这个建立工程。