Simulink custom target system file configuration (4) - file_process.tlc file

foreword

The custom target system file consists of five major files:

  • xx.tlc system target file
  • xx_callback_handler.m RTW toolbox callback function
  • xx_make_rtw_hook.m tlc file call
  • xx_file_process.tlc file processes TLC files
  • xx_srmain.tlc controls the generation of the main function file

xx_file_process.tlc file processing

The purpose of this file is to control what kind of code is generated at each stage for different situations in the process of automatic code generation. This file can be configured in callback_handle or viewed in Configuration Parameter .
Operation Figure 1
I am using the file_process file of ert.tlc here, because there is no specific requirement for generating code.

This configuration item can be set in callback_handle:

% 配置用户自定义的模板文件
slConfigUISetVal(hDlg,hSrc,'ERTCustomFileTemplate','example_file_process.tlc');
slConfigUISetEnabled(hDlg,hSrc,'ERTCustomFileTemplate',0);

You can refer to the following template customization:

%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

Of course, it is not recommended for novices to modify or write it by themselves. If there are no special requirements for the code, you can rely on this to build the project.

Guess you like

Origin blog.csdn.net/dbqwcl/article/details/126958897