Simulink自定义目标系统文件配置(5)——srmain.tlc文件

前言

自定义目标系统文件由五大文件组成:

  • xx.tlc 系统目标文件
  • xx_callback_handler.m RTW工具箱回调函数
  • xx_make_rtw_hook.m tlc文件调用
  • xx_file_process.tlc 文件处理TLC文件
  • xx_srmain.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
  
  %<SetCurrentUtilsIncludesIdx("main_util_incl")>
  
  %if GenerateSampleERTMain
    %assign ::CompiledModel.GenerateSampleERTMain = TLC_FALSE
    %warning Overriding example ert_main.c!
  %endif

  %openfile tmpBuf
  static boolean_T OverrunFlag = 0;\
  
  %<SLibDeclareFcnProtoCtlVariables()>\
%% 这个应该是全局变量  

  %<LibWriteModelData()>\
%% 返回模型的数据(仅对ERT有效)
  %closefile tmpBuf
  
  %<SLibCacheCodeToFile("mainSrc_data_defn", tmpBuf)>
  
  %openfile tmpBuf
  #include "%<LibGetMdlPubHdrBaseName()>.h"
  %closefile tmpBuf
 
  %<SLibCacheCodeToFile("mainSrc_incl", 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"}
  %<SLibDumpFunctionBanner(fcnRec)>
  %undef fcnRec
  %<fcnReturns> %<fcnName>(%<fcnParams>)
  {
    /* Disable interrupts here */
    
    /* Check for overun */
    if (OverrunFlag++) {
      %<LibSetRTModelErrorStatus("\"Overrun\"")>;
      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 */
      %<varsbuf>\
    %endif
    
    %<LibCallModelStep(0)>\
    
    %assign varsbuf = LibWriteModelOutputs()
    %if varsbuf != ""
      /* Remove conditional, and get model outputs here */
      %<varsbuf>\
    %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"}
  %<SLibDumpFunctionBanner(fcnRec)>
  %undef fcnRec
  %<fcnReturns> %<fcnName>(%<fcnParams>)
  {
    
    /* Unused arguments */
    (void)(argc);
    (void)(argv);
    
    /* Initialize model */
    %<LibCallModelInitialize()>\
    
    /* Associate rt_OneStep() with a timer that executes at the base rate of the model */

    %<LibCallModelTerminate()>\
    return 0;
  }
  %closefile tmpBuf
  
  %<SLibCacheCodeToFile("mainSrc_fcn_defn", tmpBuf)>

  %<SetCurrentUtilsIncludesIdx("")>
  
%endfunction

通过运行这个TLC文件,可以生成我们自定义的main函数以及中断函数,同时模型运行函数也可以放到自己想要运行的地方运行。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值