Simulink custom target system file configuration (5) - srmain.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_srmain.tlc controls the generation of the main function file

This file is used to control what and how the generated main file needs to be generated .

This file is called by file_process , so if you want to customize srmain.tlc, you must modify the corresponding tlc in the file_process file.
modify operation
bareboard_srmain.tlc template:

%% ==============================================================================
%%
%% 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

By running this TLC file, we can generate our custom main function and interrupt function, and at the same time, the model running function can also be placed where you want to run.

Supongo que te gusta

Origin blog.csdn.net/dbqwcl/article/details/126958905
Recomendado
Clasificación