您当前的位置: 首页 > 

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

发布时间:2022-09-22 08:00:00 ,浏览量:9

前言

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

  • 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 "%.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函数以及中断函数,同时模型运行函数也可以放到自己想要运行的地方运行。

关注
打赏
1688896170
查看更多评论

暂无认证

  • 9浏览

    0关注

    115984博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0402s