%%============================================================================
%%file:formatcommon.tlc
%%
%%
%%
%%Copyright1994-2019TheMathWorks,Inc.
%%
 
%%Function:DumpUserCodeAndCustomDataInst===================================
%%Dumpuserprminthebasefile
%%
%function DumpUserCodeAndCustomDataInst() void
  %%
  %% Custom prm header code - This code used to go at the top of the _prm file,
  %% it now goes at the bottom of the includes section of the model.c file.
  %%
  %if !Accelerator && !IsModelReferenceSimTarget()
    %openfile tmpBuf
    %<LibDumpTopOfPrmFileUserCode()>/
    %closefile tmpBuf
    %<SLibCacheCodeToFile("baseMdl_src_incl", tmpBuf)>
 
    %%
    %% Custom prm trailer code - this used to go at the bottom of the _prm.h file,
    %% it now goes as the bottom of the "Defines" section of model.c
    %%
    %openfile tmpBuf
    %<LibDumpBottomOfPrmFileUserCode()>/
    %closefile tmpBuf
    %<SLibCacheCodeToFile("baseMdl_src_define", tmpBuf)>
   
    %% Custom user code for bottom of file. For the generated S-function,
    %% put this code at the top of the top-level subsystem file.
    %%
    %openfile tmpBuf
    %<LibDumpBottomOfSourceFileUserCode()>/
    %closefile tmpBuf
    %<SLibCacheCodeToFile("custom_code_userBottom", tmpBuf)>
  %endif
 
  %if !Accelerator
    %% Need this for modelref sim
    %% Custom user code for top of file
    %%
    %openfile tmpBuf
    %<LibDumpTopOfSourceFileUserCode()>/
    %closefile tmpBuf
    %<SLibCacheCodeToFile("custom_code_topOfSrc", tmpBuf)>
  %endif
 
  %openfile tmpBuf
  %% Global block instance data (Cached by blocks in BlockInstanceSetup)
  %%
  %assign reqInsts = LibGetSystemField(System[NumSystems-1], "ReqRootPrmHdrDataInsts")
  %if reqInsts.GlobalPrmDataCacheInst
    %<LibDumpGlobalPrmDataCache()>/
  %endif
  %closefile tmpBuf
  %<SLibCacheCodeToFile("mdl_data_defn", tmpBuf)>
   
%endfunction %% DumpUserCodeAndCustomDataInst
 
%%Function:DumpExportFileUserCode==========================================
%%
%function DumpExportFileUserCode() void
  %assign isSfcnForm = (CodeFormat == "S-Function")
   
  %if !isSfcnForm && !Accelerator && !IsModelReferenceSimTarget()
 
    %openfile tmpBuf
    %<SLibDumpTopOfExportFileUserCode()>/
    %closefile tmpBuf
    %<SLibCacheCodeToFile("baseMdl_hdr_userTop", tmpBuf)>
     
    %openfile tmpBuf
    %<SLibDumpBottomOfExportFileUserCode()>/
    %closefile tmpBuf
    %<SLibCacheCodeToFile("mdl_hdr_userBottom", tmpBuf)>
     
  %endif
%endfunction %% DumpExportFileUserCode
 
%%Function:LibDumpGlobalCoderGroupInstancesToModelDotC
%%CallsLibDumpCoderDataGroupInstance()andcachesthereturnedstringto
%%modeldatadefinitionfilesection(inmodel.c)
%function LibDumpGlobalCoderGroupInstancesToModelDotC() void
  %openfile instances
     %<LibDumpCoderDataGroupInstance()> /
  %closefile instances
   
  %if !ISEMPTY(instances)
    %<SLibCacheCodeToFile("mdl_data_defn", instances)>
  %endif
%endfunction
 
%%Function:DumpExportedDataInstance========================================
%%
%function DumpExportedDataInstance() void
   
  %assign reqInsts = LibGetSystemField(System[NumSystems-1], "ReqRootPrmHdrDataInsts")
   
  %openfile expInst
  %% Exported Global (User) Signals
  %%
  %if reqInsts.ExpGlobalSigsInst && !LibExportedGlobalSignalsInstanceIsEmpty()
     
    /* Exported block signals */
    %<LibDumpExportedGlobalSignalsInstance()>/
  %endif
   
  %% Custom Reusable (User) Signals
  %%
  %if reqInsts.ExpGlobalSigsInst && !LibCustomReusableSignalsInstanceIsEmpty()
     
    %<LibDumpCustomReusableSignalsInstance()>/
  %endif
   
  %% Exported Global (User) Parameters
  %%
  %if !SLibPrmBufferIsEmpty("ExportedGlobal", "Instance")
     
    /* Exported block parameters */
    %<SLibGetPrmBuffer("ExportedGlobal", "Instance")>
  %endif
   
  %% Exported Global (User) States
  %%
  %if reqInsts.ExpGlobalDworkInst && !LibExportedGlobalDWorkInstanceIsEmpty()
     
    /* Exported block states */
    %<LibDumpExportedGlobalDWorkInstance()>/
  %endif
  
  %closefile expInst
   
  %if !WHITE_SPACE(expInst)
    %<SLibCacheCodeToFile("mdl_data_defn", expInst)>
  %endif
%endfunction %%DumpExportedDataInstance
 
%%Function:DumpExportedDataDefinition======================================
%%
%function DumpExportedDataDefinition() void
  %if !Accelerator && !IsModelReferenceSimTarget()
    %assign isSfcnForm = (CodeFormat == "S-Function")
   
    %% Exported signals
    %%
    %openfile expDef
    %if !SLibExportedGlobalSignalsIsEmpty()
       
      /*
      * Exported Global Signals
      *
      * Note: Exported global signals are block signals with an exported global
      * storage class designation. Code generation will declare the memory for
      * these signals and export their symbols.
      *
      */
      %if ::GenCPP && !SLibAutosarCompilerAbstractionRequired()
        #ifdef __cplusplus
        extern "C" {
        #endif
      %endif
      %<SLibDumpExportedGlobalSignalsDefinition()>/
      %if ::GenCPP && !SLibAutosarCompilerAbstractionRequired()
        #ifdef __cplusplus
        }
        #endif
      %endif
    %endif
     
    %% Custom Reusable signals
    %%
    %if !SLibCustomReusableSignalsIsEmpty()
       
      /*
      * Reusable Custom Storage Class
      *
      * Note: Reusable CSC signals are used for in-place optimization.
      * Code generation will declare the memory for these signals and
      * export their symbols.
      *
      */
      %<SLibDumpCustomReusableSignalsDefinition()>/
    %endif
     
    %% Exported global parameters
    %%
    %if !SLibPrmBufferIsEmpty("ExportedGlobal", "Decl")
      /*
      * Exported Global Parameters
      *
      * Note: Exported global parameters are tunable parameters with an exported
      * global storage class designation. Code generation will declare the memory for
      * these parameters and exports their symbols.
      *
      */
      %<SLibGetPrmBuffer("ExportedGlobal", "Decl")>/
    %endif
  
    %if !isSfcnForm
      %% Exported dwork
      %%
      %if !SLibExportedGlobalDWorkIsEmpty()
    /*
    * Exported States
    *
    * Note: Exported states are block states with an exported global
    * storage class designation. Code generation will declare the memory for these
    * states and exports their symbols.
    *
    */
    %<SLibDumpExportedGlobalDWorkDefinition()>/
      %endif
    %endif
    %closefile expDef
    %<SLibCacheCodeToFile("data_exportGlobal_decl", expDef)>
  %endif
%endfunction
 
%%Function:DumpHdrFileUserCode=============================================
%%Abstract:Dumptheusercode
%%
%function DumpHdrFileUserCode() void
  %if !Accelerator && !IsModelReferenceSimTarget()
    %% User top
    %openfile tmpBuf
    %<LibDumpTopOfHdrFileUserCode()>/
    %closefile tmpBuf
    %<SLibCacheCodeToFile("baseMdl_hdr_userTop", tmpBuf)>
         
    %% User bottom
    %openfile tmpBuf
    %<LibDumpBottomOfHdrFileUserCode()>/
    %closefile tmpBuf
    %<SLibCacheCodeToFile("mdl_hdr_userBottom", tmpBuf)>
  %elseif IsModelReferenceSimTarget()
    %% User top
    %openfile tmpBuf
    %<LibDumpTopOfHdrFileUserCode()>/
    %closefile tmpBuf
    %<SLibCacheCodeToFile("mdl_priv_userTop", tmpBuf)>
  %endif
%endfunction %% DumpHdrFileUserCode
 
 
%%Function:DumpAllSystemHeadersExcludingRootSystem===========================
%%Abstract:
%%Dumpallsystemheadersinthesystemfile,andreturntheheaders
%%thatmustbedumpedinmodel.h
%%
%function DumpAllSystemHeadersExcludingRootSystem()
  %openfile nonVirtSubsbys
  %foreach sysIdx = NumSystems - 1 %% root not included
    %assign system = System[sysIdx]
    %<LibDumpSystemHeader(system)>/
  %endforeach
  %closefile nonVirtSubsbys
  %return nonVirtSubsbys
%endfunction %%DumpAllSystemHeadersExcludingRootSystem