前言
自定义目标系统文件由五大文件组成:
- xx.tlc 系统目标文件
- xx_callback_handler.m RTW工具箱回调函数
- xx_make_rtw_hook.m tlc文件调用
- xx_file_process.tlc 文件处理TLC文件
- xx_srmain.tlc 控制主函数文件的生成
这个文件就是用来控制生成的main文件需要生成什么和怎么生成。
这个文件是被file_process调用的,所以如果要自定义srmain.tlc的话,一定要在file_process文件里面修改对应的tlc。 bareboard_srmain.tlc模板:
%% ==============================================================================
%%
%% Abstract:
%% Example main for bare board target (single rate model)
%%
%% Copyright 1994-2013 The MathWorks, Inc.
%%
%selectfile NULL_FILE
%function FcnSingleTaskingMain() void
%
%if GenerateSampleERTMain
%assign ::CompiledModel.GenerateSampleERTMain = TLC_FALSE
%warning Overriding example ert_main.c!
%endif
%openfile tmpBuf
static boolean_T OverrunFlag = 0;\
%\
%% 这个应该是全局变量
%\
%% 返回模型的数据(仅对ERT有效)
%closefile tmpBuf
%
%openfile tmpBuf
#include "%.h"
%closefile tmpBuf
%
%openfile tmpBuf
%assign fcnReturns = "void"
%assign fcnName = "rt_OneStep"
%assign fcnParams = ""
%assign fcnCategory = "main"
%createrecord fcnRec {Name fcnName; Returns fcnReturns; Params fcnParams; ...
Abstract ""; Category fcnCategory; GeneratedBy "bareboard_srmain.tlc"; ...
Type "Utility"}
%
%undef fcnRec
% %(%)
{
/* Disable interrupts here */
/* Check for overun */
if (OverrunFlag++) {
%;
return;
}
/* Save FPU context here (if necessary) */
/* Re-enable timer or interrupt here */
%assign varsbuf = LibWriteModelInputs()
%if varsbuf != ""
/* Remove conditional, and set model inputs here */
%\
%endif
%\
%assign varsbuf = LibWriteModelOutputs()
%if varsbuf != ""
/* Remove conditional, and get model outputs here */
%\
%endif
OverrunFlag--;
/* Disable interrupts here */
/* Restore FPU context here (if necessary) */
/* Enable interrupts here */
}
%assign fcnReturns = "int_T"
%assign fcnName = "main"
%assign fcnParams = "int_T argc, const char *argv[]"
%assign fcnCategory = "main"
%createrecord fcnRec {Name fcnName; Returns fcnReturns; Params fcnParams; ...
Abstract ""; Category fcnCategory; GeneratedBy "bareboard_srmain.tlc"; ...
Type "Main"}
%
%undef fcnRec
% %(%)
{
/* Unused arguments */
(void)(argc);
(void)(argv);
/* Initialize model */
%\
/* Associate rt_OneStep() with a timer that executes at the base rate of the model */
%\
return 0;
}
%closefile tmpBuf
%
%
%endfunction
通过运行这个TLC文件,可以生成我们自定义的main函数以及中断函数,同时模型运行函数也可以放到自己想要运行的地方运行。