注意:
tlc文件通常分为两个等价,系统级和模块级。系统目标文件(system target file),例如ert.tlc就是常用的系统目标文件
系统目标文件非常特殊,%%也不都是注释,像这里告诉了Simulink环境,目标文件支持哪些功能,例如生成
一、MC9S12XEP底层驱动封装库
MC9S12XEP100.tlc(系统目标文件)
系统目标文件是控制主体代码生成,对代码生成进行全局的控制
%% SYSTLC: my_MC9S12XEP100 TMF: none MAKE: make_rtw EXTMODE: ext_comm
-
SYSTLC :对于系统目标文件(.tlc)的描述
-
TMF :不生成tmf文件的模板
-
MAKE :支持MAKE命令
-
EXTMOD : ext_comm 支持外部模式
%selectfile NULL_FILE %assign CodeFormat = "Embedded-C" %assign TargetType = "RT" %assign Language = "C" %assign AutoBuildProcedure = !GenerateSampleERTMain %include "codegenentry.tlc"
-
%assign CodeFormat :函数级或者非脚本类型的tlc,需要包含NULL_FILE
-
%assign TargetType :“Embedded-C”嵌入式代码支持的生成代码类型
-
assign Language :“RT” 单片机都是实时的硬件,所以用RT(real time)
-
assign AutoBuildProcedure : 这里指的是不生成Main文件,在此处也可以不写,自己去configuration里面选,相当于下图的蓝线没有勾选。
-
%include "codegenentry.tlc" :" codegenentry.tlc" 继承codegenentry内容
tlc里面的include和c语言不同,C语言是告诉程序包含了哪些头文件,可以去头文件里面寻找函数等,tlc的include相当于inline, 内联的功能,相当于直接展开到文件中。
/% BEGIN_RTW_OPTIONS END_RTW_OPTIONS %/
BEGIN_RTW_OPTIONS和END_RTW_OPTIONS中间这部分也是有用的,是对关于GUI的一些配置。
rtwoption_index = 1; rtwoptions(rtwoption_index).prompt = 'MC9S12XEP100 Target Options'; rtwoptions(rtwoption_index).type = 'Category'; rtwoptions(rtwoption_index).enable = 'on'; rtwoptions(rtwoption_index).default = 1; //有几个子模块 rtwoptions(rtwoption_index).popupstrings = ''; rtwoptions(rtwoption_index).tlcvariable = ''; rtwoptions(rtwoption_index).tooltip = ''; rtwoptions(rtwoption_index).callback = ''; rtwoptions(rtwoption_index).makevariable = ''; rtwoption_index = rtwoption_index + 1; rtwoptions(rtwoption_index).prompt = 'Actions'; rtwoptions(rtwoption_index).type = 'Popup'; //下拉框 rtwoptions(rtwoption_index).popupstrings = 'Build|Run'; //这里设置的是Action的下拉框里面有两个值可以选择Build或者Run rtwoptions(rtwoption_index).enable = 'on'; rtwoptions(rtwoption_index).default = 'Build'; //Action选项的默认是Build rtwoptions(rtwoption_index).tlcvariable = 'BuildAction'; rtwoptions(rtwoption_index).tooltip = 'Select CodeWarrior BuildAction.'; rtwoptions(rtwoption_index).callback = ''; rtwoptions(rtwoption_index).makevariable = '';
显示如下
rtwgensettings.BuildDirSuffix = ‘_MC9S12XEP100_rtw’;
//这个是设置代码的生成文件名,比如说你起了个simulink模型的名字是test,那么他便一直后生成的代码的文件的名字就是test_MC9S12XEP100_rtw;
rtwgensettings.SelectCallback = [‘MC9S12XEP100_callback_handler(hDlg, hSrc)’];
//这个是选择回调函数 就是你点击下图中的APPLY或者OK的时候执行的脚本函数
完整代码如下:
%% SYSTLC: my_MC9S12XEP100 TMF: none MAKE: make_rtw EXTMODE: ext_comm %selectfile NULL_FILE %assign CodeFormat = "Embedded-C" %assign TargetType = "RT" %assign Language = "C" %assign AutoBuildProcedure = !GenerateSampleERTMain %include "codegenentry.tlc" /% BEGIN_RTW_OPTIONS rtwoption_index = 1; rtwoptions(rtwoption_index).prompt = 'MC9S12XEP100 Target Options'; rtwoptions(rtwoption_index).type = 'Category'; rtwoptions(rtwoption_index).enable = 'on'; rtwoptions(rtwoption_index).default = 1; rtwoptions(rtwoption_index).popupstrings = ''; rtwoptions(rtwoption_index).tlcvariable = ''; rtwoptions(rtwoption_index).tooltip = ''; rtwoptions(rtwoption_index).callback = ''; rtwoptions(rtwoption_index).makevariable = ''; rtwoption_index = rtwoption_index + 1; rtwoptions(rtwoption_index).prompt = 'Actions'; rtwoptions(rtwoption_index).type = 'Popup'; rtwoptions(rtwoption_index).popupstrings = 'Build|Run'; rtwoptions(rtwoption_index).enable = 'on'; rtwoptions(rtwoption_index).default = 'Build'; rtwoptions(rtwoption_index).tlcvariable = 'BuildAction'; rtwoptions(rtwoption_index).tooltip = 'Select CodeWarrior BuildAction.'; rtwoptions(rtwoption_index).callback = ''; rtwoptions(rtwoption_index).makevariable = ''; %----------------------------------------% % Configure RTW code generation settings % %----------------------------------------% rtwgensettings.BuildDirSuffix = '_MC9S12XEP100_rtw'; rtwgensettings.DerivedFrom = 'ert.tlc'; rtwgensettings.Version = '1'; rtwgensettings.SelectCallback = ['MC9S12XEP100_callback_handler(hDlg, hSrc)']; END_RTW_OPTIONS %/