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

前言

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

  • xx.tlc 系统目标文件
  • xx_callback_handler.m RTW工具箱回调函数
  • xx_make_rtw_hook.m tlc文件调用
  • xx_file_process.tlc 文件处理TLC文件
  • xx_srmain.tlc 控制主函数文件的生成

xx_file_process.tlc文件处理

该文件的目的是用来控制自动代码生成的过程中,针对不同的情况,在各阶段生成什么样的代码。该文件可以在callback_handle里面配置,也可以在Configuration Parameter中查看。
操作图1
我这边是沿用了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
  
  %<LibSetSourceFileSection(cFile,"Includes",typesBuf)>

  %openfile tmpBuf

  /* Times two function */
  real_T timestwofcn(real_T input) {
    return (input * 2.0);
  }

  %closefile tmpBuf
  
  %<LibSetSourceFileSection(cFile,"Functions",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
  
  %<LibSetSourceFileSection(hFile,"Includes",typesBuf)>
  %<LibSetSourceFileSection(hFile,"Declarations",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
  
  %<LibSetSourceFileSection(modelH,"Defines",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
  
  %<LibSetSourceFileSection(privateH,"Defines",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
  
  %<LibSetSourceFileSection(modelC,"Includes",tmpBuf)>
  
  %% Create a simple main.  Files are located in MATLAB/rtw/c/tlc/mw.
  
  %if LibIsSingleRateModel() || LibIsSingleTasking()
    %include "bareboard_srmain.tlc"
    %<FcnSingleTaskingMain()>
  %else
    %include "bareboard_mrmain.tlc"
    %<FcnMultiTaskingMain()>
  %endif
  
%endif

当然,这里也是不建议新手去修改或者自己写,对代码没有特殊要求的话完全可以依靠这个建立工程。

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值