%selectfile NULL_FILE
%if EXISTS("_COMMONHDRLIB_") == 0
%assign _COMMONHDRLIB_ = 1
%function SLibGetOldStrNames() void
%return !((CodeFormat == "RealTime") || (SLibIsERTCodeFormat()))
%endfunction
%function SLibGetPrmsName(oldStrNames) void
%return oldStrNames ? ::tDefaultParameters : "%<LibGetParametersStruct()>"
%endfunction
%function LibCacheModelStructureDefinitions() void
%<LibCacheExportedGlobalSignalsDefinition()>
%<LibCacheCustomReusableSignalsDefinition()>
%<LibCacheImportedExternSignalsDefinition()>
%<LibCacheImportedExternPointerSignalsDefinition()>
%if CodeFormat != "S-Function" || Accelerator
%<LibCacheNonAutoStorageClassDWorkDefinition()>
%endif
%if !SLibAutosarActive()
%<LibCacheExternalInputsStructDefinitionByVarGroup()>
%<LibCacheExternalOutputsStructDefinitionByVarGroup()>
%<LibCacheExternalInputSizesStructDefinition()>
%<LibCacheExternalOutputSizesStructDefinition()>
%endif
%endfunction
%function FcnOmitParameter(prm) void
%if prm.SuppressInRTW
%return TLC_TRUE
%else
%return InlineParameters == 1 && SLibIsERTTarget() && ...
!GenerateErtSFunction && !IsModelReferenceSimTarget() && ...
(!prm.UseAccessFunctions && !prm.WasAccessedAsVariable)
%endif
%endfunction
%function SLibOmitRecord(aRecord) void
%if ISEMPTY(aRecord)
%return TLC_FALSE
%endif
%if ISFIELD(aRecord, "IsRemovedInIR") && aRecord.IsRemovedInIR
%return TLC_TRUE
%endif
%if ISFIELD(aRecord, "RecordType") && (aRecord.RecordType == "DWork")
%if aRecord.OptimizedAwayInTLC
%return TLC_TRUE
%endif
%endif
%if ISFIELD(aRecord, "RecordType") && (aRecord.RecordType == "ModelParameter")
%if FcnOmitParameter(aRecord)
%return TLC_TRUE
%endif
%endif
%return TLC_FALSE
%endfunction
%function SLibSkipAlloc(recType, recIdx) void
%assign dataRec = SLibGetDataRecForVarGroupMember(recType, recIdx)
%if SLibOmitRecord(dataRec)
%return TLC_TRUE
%endif
%if (recType == "U" && PassExtInpByRef(dataRec)) || (recType == "Y" && PassExtOutpByRef(dataRec))
%return TLC_TRUE
%endif
%return TLC_FALSE
%endfunction
%function LibGetChildSystemStructCommentName(sysIdx, childSSBlock)
%assign dataGrSrcBlk = ISFIELD(childSSBlock, "GrSrc") ? SLibGrBlock(childSSBlock.GrSrc) : []
%if (LibSystemIsReusedLibraryFcn(System[sysIdx]) && !ISEMPTY(dataGrSrcBlk) && ...
ISFIELD(dataGrSrcBlk, "RLSCommentName"))
%assign commentName = dataGrSrcBlk.RLSCommentName
%else
%if BlockCommentType == "BlockSIDComment"
%assign commentName = ::CompiledModel.System[childSSBlock.BlockIdx[1]].SIDCommentName
%else
%assign commentName = "'" + childSSBlock.Name + "'"
%if ::CompiledModel.System[childSSBlock.BlockIdx[1]].Synthesized
%assign origBlkSet = ISFIELD(::CompiledModel.System[childSSBlock.BlockIdx[1]],"OriginatorBlock")
%if origBlkSet
%assign origBlockName = ::CompiledModel.System[childSSBlock.BlockIdx[1]].OriginatorBlock
%assign commentName = "'" + origBlockName + "'"
%else
%assign commentName = ""
%endif
%endif
%endif
%endif
%return commentName
%endfunction
%function FcnGetChildSystemTypedefs(sysIdx, struct, typetag) void
%assign childsysTypedefs = ""
%assign numElements = 0
%assign res = ["", 0]
%assign inlineFcn = "SLibGetSystem%<struct>"
%with ::CompiledModel.System[sysIdx]
%if NumChildSystems > 0
%if struct == "Parameters"
%assign childSystems = ChildPrmStructs
%else
%assign childSystems = ChildSystems
%endif
%openfile childsysTypedefs
%foreach childIdx = NumChildSystems
%assign chIdx = childSystems[childIdx]
%if chIdx[1] == 0 && chIdx[3] > -1
%assign blk = System[chIdx[2]].Block[chIdx[3]]
%if (struct == "CStates" || ...
struct == "CStateDeriv" || ...
struct == "ContStatesDisabled") && ...
SLibIsPartitionGrouping() && ...
EXISTS(::GlobalCurrentPID) && ...
!ISEMPTY(::GlobalCurrentPID) && ...
::GlobalCurrentPID >= 0 && ...
::GlobalCurrentPID != SLibGetPIDFromBlock(blk, 0)
%continue
%endif
%with blk
%assign childSys = System[CallSiteInfo.SystemIdx]
%if childSys.StandaloneSubsystem
%continue
%endif
%if !SLibSystemHasOwnDataScope(childSys)
%assign inlRes = %<inlineFcn>(childSys.SystemIdx)
%assign numElements = numElements + inlRes[1]
%/
%elseif childSys.Has%<struct>Arg
%assign csIdx = blk.CallSiteIdx
%assign varGroupIdx = FcnSysVarGroupIndex(childSys, typetag, csIdx)
%if varGroupIdx < 0
%continue
%endif
%assign structType = SLibVarGroupType(varGroupIdx, typetag)
%assign structName = SLibVarGroupName(varGroupIdx)
%assign comment = "/* '%<childSys.Name>' */"
%if SLibSysVarGroupUsedAsMatrix(System[childSys.SystemIdx],typetag, csIdx)
%assign structWidth = SLibSysVarGroupWidth(System[childSys.SystemIdx],typetag, csIdx)
%<structType> %<structName>[%<structWidth>]; %<comment>
%else
%<structType> %<structName>; %<comment>
%endif
%assign numElements = numElements + 1
%endif
%endwith
%endif
%endforeach
%closefile childsysTypedefs
%endif
%endwith
%if numElements > 0
%assign res[0] = "%<childsysTypedefs>"
%assign res[1] = %<numElements>
%endif
%return res
%endfunction
%function SLibAddPreprocessingFunctionsToCommonIncludes(sysIdx) void
%assign system = ::CompiledModel.System[sysIdx]
%assign module = ::CompiledModel.RTWCGModules.RTWCGModule[system.CGIRModuleIdx]
%foreach fcnIdx = module.NumSubFunctions
%assign fcn = module.Function[fcnIdx]
%if ISFIELD(fcn, "LoggingWrapperType")
%<SLibAddToCommonIncludes(fcn.Name + ".h")>
%endif
%endforeach
%endfunction
%function SLibContainsToWorkspaceBlocks()
%assign containsToWorkspace = TLC_FALSE
%foreach sysIdx = ::CompiledModel.NumSystems
%assign system = ::CompiledModel.System[sysIdx]
%foreach blkIdx = system.NumBlocks
%assign block = system.Block[blkIdx]
%if block.Type == "ToWorkspace" || block.Type == "SignalToWorkspace"
%assign containsToWorkspace = TLC_TRUE
%break
%endif
%endforeach
%if containsToWorkspace
%break
%endif
%endforeach
%return containsToWorkspace
%endfunction
%function LibRegCommonIncludes(sysIdx) void
%<SLibAddToCommonIncludes(SLibCoderTypesFilename())>
%if ::needZeroCrossingTypes
%<SLibAddToCommonIncludes(SLibCoderZerocrossingTypesFilename())>
%endif
%if SLibDeclareHalfPrecisionUsage()
%<SLibAddToCommonIncludes(SLibCoderHalfTypeHdrFilename())>
%endif
%if ::CompiledModel.OpaqueFBT
%<SLibAddToNonSharedIncludes("OpaqueTypeFbt.hpp")>
%endif
%if !GenRTModel || SLibModelHierarchyContainsNoninlinedSfcn() || ...
IsModelReferenceForASimstructBasedTarget() || ...
GenerateGRTWrapper
%if (::CompiledModel.NumChildSFunctions > 0) && ...
!Accelerator && CodeFormat != "S-Function"
%assign fpath = FEVAL("matlabroot") + "//rtw//c//src"
%assign tf = FEVAL("coder.internal.callBuildInfo", ::CompiledModel.Name, 1, "addSourceFiles", "rt_matrx.c", fpath, "TLC")
%assign tf = FEVAL("coder.internal.callBuildInfo", ::CompiledModel.Name, 1, "addSourceFiles", "rt_printf.c", fpath, "TLC")
%endif
%<SLibAddToNonSharedIncludes("simstruc.h")>
%<SLibAddToNonSharedIncludes("fixedpoint.h")>
%elseif SLibIsERTCodeFormat()
%if ::ExtMode == 1
%<SLibAddToNonSharedIncludes("rtw_extmode.h")>
%<SLibAddToNonSharedIncludes("sysran_types.h")>
%endif
%if ::CompiledModel.ConfigSet.SupportContinuousTime == 1
%<SLibAddToNonSharedIncludes("rtw_continuous.h")>
%if !PurelyIntegerCode
%<SLibAddToNonSharedIncludes("rtw_solver.h")>
%endif
%endif
%endif
%if isRSim
%if isRAccel
%<SLibAddToNonSharedIncludes("raccel.h")>
%<SLibAddToNonSharedIncludes("slsv_diagnostic_codegen_c_api.h")>
%if ISFIELD(::CompiledModel,"ModelHasParallelForEachSS") && ...
::CompiledModel.ModelHasParallelForEachSS
%<SLibAddToNonSharedIncludes("slexec_parallel.h")>
%endif
%else
%<SLibAddToNonSharedIncludes("rsim.h")>
%endif
%endif
%if IsModelReferenceSimTarget() && (::CompiledModel.NumChildSFunctions > 0)
%assign sfcnLoaderHeader = "sfcn_loader_c_api.h"
%openfile sfcnLoaderInclTempBuf
#include "%<sfcnLoaderHeader>"
%closefile sfcnLoaderInclTempBuf
%<SLibCacheCodeToFile("mdl_src_incl", sfcnLoaderInclTempBuf)>
%endif
%if MatFileLogging != 0
%assign mroot = FEVAL("matlabroot")
%assign fpath = FEVAL("fullfile", mroot, "rtw", "c", "src")
%assign tf = FEVAL("coder.internal.callBuildInfo", ::CompiledModel.Name, 1, "addSourceFiles", "rt_logging.c", fpath, "TLC")
%<SLibAddGeneratedFileToList("rt_logging.c", "other", "source", fpath)>
%<SLibAddToNonSharedIncludes("rt_logging.h")>
%if SLibContainsToWorkspaceBlocks() && CGMODEL_ACCESS("CGModel.RowMajorDimensionSupport") == 1
%<SLibAddToCommonIncludes("")>
%endif
%endif
%if ::CompiledModel.GenUtilsSrcInSharedLocation == 1
%<SLibAddPreprocessingFunctionsToCommonIncludes(sysIdx)>
%endif
%if CreateTransitionTable == 1
%<SLibAddToNonSharedIncludes("dt_info.h")>
%endif
%if (ExtMode == 1)
%if !ExtModeXCP || ExtModeXCPClassicInterface
%<SLibAddToNonSharedIncludes("ext_work.h")>
%else
%if (NumSynchronousSampleTimes != 1) && CombineOutputUpdateFcns && ((::CompiledModel.FixedStepOpts.SolverMode == "SingleTasking") || (NumContStates > 0))
%<SLibAddToNonSharedIncludes("ext_mode.h")>
%endif
%endif
%endif
%if UsingMalloc || FcnIsERTMalloc() || isRSim || isRSimWithSolverModule
%<SLibAddToNonSharedIncludes("")>
%endif
%if SLibAutosarGenSubMdlMacro()
%openfile memBuf
#ifdef INCLUDE_RTE_HEADER
#include RTE_COMPONENT_HEADER
#endif
%closefile memBuf
%<SLibCacheCodeToFile("mdl_hdr_incl", memBuf)>
%endif
%if SLibAutosarActive()
%if MultiInstanceERTCode
%if !ISFIELD(RTWAutosar, "Rte_SWC_Header_Included")
%addtorecord RTWAutosar Rte_SWC_Header_Included TLC_TRUE
%assert !SLibIsCompactFileFormat()
%openfile tmpBuf
#include "%<MainAutosarInterfaceName()>.h"
%closefile tmpBuf
%<SLibCacheCodeToFile("mdl_priv_hdr_incl", tmpBuf)>
%endif
%else
%<SLibAddToNonSharedIncludes("%<MainAutosarInterfaceName()>.h")>
%endif
%elseif SLibAdaptiveAutosarActive()
%openfile memBuf
#include
%closefile memBuf
%<SLibCacheCodeToFile("mdl_hdr_incl", memBuf)>
%endif
%<SLibGenProfHeaders()>
%endfunction
%function LibDumpCommonDefines(sysIdx) void
%openfile tmpDefineBuf
%if UsingMalloc || isRSim
%<LibDeclareMemoryAllocationMacros()>/
%endif
%closefile tmpDefineBuf
%return tmpDefineBuf
%endfunction
%function LibDeclareERTDefines(sysIdx) void
%openfile tmpDefineBuf
%if MatFileLogging == 1 || GenerateGRTWrapper
%if GenerateGRTWrapper
#define QUOTE1(name) #name
#define QUOTE(name) QUOTE1(name) /* need to expand name */
%endif
%if MatFileLogging == 1
#ifndef SAVEFILE
# define MATFILE2(file) #file ".mat"
# define MATFILE1(file) MATFILE2(file)
# define MATFILE MATFILE1(MODEL)
#else
%if !GenerateGRTWrapper
#define QUOTE1(name) #name
#define QUOTE(name) QUOTE1(name) /* need to expand name */
%endif
# define MATFILE QUOTE(SAVEFILE)
#endif
%endif
%endif
%closefile tmpDefineBuf
%return tmpDefineBuf
%endfunction
%function LibSFcnPreSimstrucDefines(system) void
%assign tmpDefineBuf = ""
%openfile tmpDefineBuf
%assign tmpName = Accelerator ? "simulink_only_sfcn" : Name
%if system.Type == "root"
#define S_FUNCTION_NAME %<tmpName>
%endif
#define S_FUNCTION_LEVEL 2
#define RTW_GENERATED_S_FUNCTION
%closefile tmpDefineBuf
%return tmpDefineBuf
%endfunction
%function LibSFcnPostSimstrucDefines() void
%assign tmpDefineBuf = ""
%if !Accelerator
%openfile tmpDefineBuf
#if !defined(MATLAB_MEX_FILE)
#include "rt_matrx.h"
#endif
#if !defined(RTW_SFUNCTION_DEFINES)
#define RTW_SFUNCTION_DEFINES
typedef struct {
void *blockIO;
void *defaultParam;
void *nonContDerivSig;
} LocalS;
#define %<RTMSet("LocalBlockIO","io")> ...
((LocalS *)%<RTMGet("UserData")>)->blockIO = ((void *)(io))
#define %<RTMGet("LocalBlockIO")> ...
((LocalS *)%<RTMGet("UserData")>)->blockIO
#define %<RTMSet("LocalDefaultParam", "paramVector")> ...
((LocalS *)%<RTMGet("UserData")>)->defaultParam = (paramVector)
#define %<RTMGet("LocalDefaultParam")> ...
((LocalS *)%<RTMGet("UserData")>)->defaultParam
#define %<RTMSet("LocalNonContDerivSig", "pSig")> ...
((LocalS *)%<RTMGet("UserData")>)->nonContDerivSig = (pSig)
#define %<RTMGet("LocalNonContDerivSig")> ...
((LocalS *)%<RTMGet("UserData")>)->nonContDerivSig
#endif
%closefile tmpDefineBuf
%endif
%return tmpDefineBuf
%endfunction
%function LibDeclareTrueFalse() void
%warning This function will be obsoleted in next release. True/False definitions is inside rtwtypes.h.
%openfile tmpFcnBuf
#ifndef TRUE
# define TRUE (1)
#endif
#ifndef FALSE
# define FALSE (0)
#endif
%closefile tmpFcnBuf
%return tmpFcnBuf
%endfunction
%function SLibGenerateProprocessorDefnForVariantObjectsWithCSC() void
%if ISFIELD(GlobalMemoryMap,"CustomData")
%openfile tmpFcnBuf
%assign nDataRecs = GlobalMemoryMap.NumCustomData
%foreach dataRecIdx = nDataRecs
%assign customDataRec = GlobalMemoryMap.CustomData[dataRecIdx]
%assign nData = customDataRec.NumData
%assign cscDefn = SLibGetCSCDefForCSC(customDataRec)
%foreach dataIdx = nData
%if nData == 1
%assign data = customDataRec.Data
%else
%assign data = customDataRec.Data[dataIdx]
%endif
%with data
%if (SLibGetDataInitForData(cscDefn, data) == "Macro" && cscDefn.DataScope == "Imported")
%assign id = LibGetRecordIdentifier(data.RTWRecord)
%assign varName = LibGetRecordVarName(data.RTWRecord)
%assign ppIf = ""
%if EXISTS(data.PPIf)
%assign ppIf = data.PPIf
%endif
%assign ppEndif = ""
%if EXISTS(data.PPEndIf)
%assign ppEndif = data.PPEndIf
%endif
%if varName == id
%assign idDescr = "variable for the parameter /"%<varName>/""
%else
%assign idDescr = "variable /"%<id>/" for the parameter /"%<varName>/""
%endif
%if !ISEMPTY(ppIf)
%<ppIf>
#ifndef %<id>
#error The %<idDescr> is not defined
#endif
%<ppEndif>
%endif
%endif
%endwith
%endforeach
%endforeach
%closefile tmpFcnBuf
%return tmpFcnBuf
%endif
%endfunction
%function SLibGenerateVariantStuff() void
%assign nsparams = ISFIELD(::CompiledModel, "CodeVariants") ? ::CompiledModel.CodeVariants.NumNormalVariantControlVars : 0
%if nsparams > 0
%openfile nmvDefinitions
%<SLibDeclareNormalMATLABVariables()>/
%closefile nmvDefinitions
%<SLibCacheCodeToFile("data_simulink_variant_include", nmvDefinitions)>
%endif
%assign needsComment = nsparams > 0 ? TLC_FALSE : TLC_TRUE
%openfile simVarObj
%if CGMODEL_ACCESS("CGModel.InlineSimulinkVariantObjectsInCompile") == 0
%<SLibDeclareSimulinkVariantObjects(TLC_FALSE, needsComment)>
%endif
%closefile simVarObj
%<SLibCacheCodeToFile("data_simulink_variant_include", simVarObj)>
%undef nmvDefinitions
%undef simVarObj
%openfile simulinkVariantObjects
%if CGMODEL_ACCESS("CGModel.InlineSimulinkVariantObjectsInCompile") == 1
%<SLibDeclareSimulinkVariantObjects(TLC_FALSE, needsComment)>/
%endif
%closefile simulinkVariantObjects
%<SLibCacheCodeToFile("data_simulink_variant_define", simulinkVariantObjects)>
%undef simulinkVariantObjects
%assign hasVariant = ::CompiledModel.HasVariants
%if !(hasVariant)
%return
%endif
%openfile paramWithGuards
%<SLibGenerateProprocessorDefnForVariantObjectsWithCSC()>
%closefile paramWithGuards
%<SLibCacheCodeToFile("param_variant_errorChecks", paramWithGuards)>
%undef paramWithGuards
%openfile preprocessorConstraints
%<SLibDeclarePreprocessorConstraints()>/
%closefile preprocessorConstraints
%<SLibCacheCodeToFile("data_simulink_variant_define", ...
preprocessorConstraints)>
%undef preprocessorConstraints
%endfunction
%function SLibDeclarePrimitiveTypedefs() void
%openfile tmpFcnBuf
%if 0
/* Primitive typedefs */
#ifndef TMW_PRIMITIVE_TYPEDEFS
#define TMW_PRIMITIVE_TYPEDEFS
#endif
%endif
%closefile tmpFcnBuf
%return tmpFcnBuf
%endfunction
%function LibDeclareGenericModelDefines() void
%openfile tmpFcnBuf
#define MODEL_NAME %<Name>
#define NSAMPLE_TIMES (%<NumSampleTimes>) /* Number of sample times */
#define NINPUTS (%<NumModelInputs>) /* Number of model inputs */
#define NOUTPUTS (%<NumModelOutputs>) /* Number of model outputs */
#define NBLOCKIO (%<BlockOutputs.NumSignalsInBlockIO>) ...
/* Number of data output port signals */
#define NUM_ZC_EVENTS (%<NumZCEvents>) /* Number of zero-crossing events */
%closefile tmpFcnBuf
%return tmpFcnBuf
%endfunction
%function LibDeclareNCSTATES() void
%openfile tmpFcnBuf
#ifndef NCSTATES
# define NCSTATES (%<NumContStates>) /* Number of continuous states */
#elif NCSTATES != %<NumContStates>
# error Invalid specification of NCSTATES defined in compiler command
#endif
%closefile tmpFcnBuf
%return tmpFcnBuf
%endfunction
%function SLibDeclareNormalMATLABVariables() void
%openfile nmvar
%assign nsparams = ::CompiledModel.CodeVariants.NumNormalVariantControlVars
%if nsparams > 0
%with ::CompiledModel.CodeVariants
/**
* You can use either of the following to alter the value of "normal" variant
* control variables:
*
* 1. -DVC_VARIABLE1=VALUE1 -DVC_VARIABLE2=VALUE2, etc.
* 2. -DUSE_VARIANT_DEFINES_HEADER="header.h" and within header.h you
* specify "#define VC_VARIABLE VALUE1", etc.
*
* Variant control variables are the independent variables of variant control
* expressions specified in a variant block. For example, a Variant Source block
* may contain "V==1" and V is the variant control variable of this
* expression. A normal variant control variable is a plain MATLAB variable,
* i.e. not a Simulink.Parameter. The default define for a normal variant
* control variable is the value specified in MATLAB at time of code generation.
*
* Alternatively, you can use Simulink.Parameter's as variant control variables to
* explicitly specify code generation behavior.
*/
#ifdef USE_VARIANT_DEFINES_HEADER
#define VARIANT_DEFINES_HEADER_STR(h) #h
#define VARIANT_DEFINES_HEADER(h) VARIANT_DEFINES_HEADER_STR(h)
#include VARIANT_DEFINES_HEADER(USE_VARIANT_DEFINES_HEADER)
#endif /* USE_VARIANT_DEFINES_HEADER */
/*
* Validate the variant control variables are consistent with the model requirements
*/
%foreach paramIdx = nsparams
%assign paramName = NormalVariantControlVars[paramIdx].Name
%assign paramValue = NormalVariantControlVars[paramIdx].Value
#ifndef %<paramName>
#define %<paramName> %<paramValue>
#endif
%endforeach
%endwith
%endif
%closefile nmvar
%if !ISEMPTY(nmvar)
%openfile retBuf
/* Model Code Variants */
%<nmvar>
%closefile retBuf
%return retBuf
%else
%return
%endif
%endfunction
%function SLibDeclareSimulinkVariantObjects(IsStub, NeedsComment) void
%openfile tmpSVBuf
%if ISFIELD(::CompiledModel, "CodeVariants")
%if ::CompiledModel.CodeVariants.NumSimulinkVariantObjects > 0
%with ::CompiledModel.CodeVariants
%assign numSVIdxs = NumVariantObjectOrderedIndexs
%foreach svIdxIdx = numSVIdxs
%assign svIdx = VariantObjectOrderedIndexs[svIdxIdx]
%with SimulinkVariantObject[svIdx]
%if Name != Condition
%if IsStub && IsImported
#ifndef Rte_SysCon_%<Name>
#define Rte_SysCon_%<Name> (%<Condition>)
#endif
%elseif !IsStub && !IsImported
#ifndef %<Name>
#define %<Name> (%<Condition>)
#endif
%endif
%endif
%endwith
%endforeach
%endwith
%endif
%endif
%assign mdlRefBlks = ISFIELD(::CompiledModel,"ModelReferenceBlocks") ? ...
::CompiledModel.ModelReferenceBlocks : []
%if !ISEMPTY(mdlRefBlks)
%foreach rowIdx = SIZE(mdlRefBlks,0)
%assign mdlRefInfo = mdlRefBlks[rowIdx]
%assign mSysIdx = mdlRefInfo[0]
%assign bIdx = mdlRefInfo[1]
%assign blkInterface = GetModelrefInterface(System[mSysIdx].Block[bIdx])
%if ISFIELD(blkInterface, "CodeVariants")
%assign variantControl = blkInterface.CodeVariants.VariantControl
%if ISFIELD(variantControl, "Variant")
%assign numVariants = SIZE(variantControl.Variant, 1)
%foreach idx = numVariants
%assign variant = variantControl.Variant[idx]
%if variant.Name != variant.Condition
%if IsStub && variant.IsImported
#ifndef Rte_SysCon_%<variant.Name>
#define Rte_SysCon_%<variant.Name> (%<variant.Condition>)
#endif
%elseif !IsStub && !variant.IsImported
#ifndef %<variant.Name>
#define %<variant.Name> (%<variant.Condition>)
#endif
%endif
%endif
%endforeach
%endif
%endif
%endforeach
%endif
%closefile tmpSVBuf
%if !ISEMPTY(tmpSVBuf)
%assign comment = NeedsComment ? "/* Model Code Variants */" : ""
%openfile retBuf
%<comment>
%<tmpSVBuf>
%closefile retBuf
%return retBuf
%else
%return
%endif
%endfunction
%function SLibEnumeralPreprocessorSymbol(enumDataTypeId, enumIdx) void
%assign enumTypeName = DataTypes.DataType[enumDataTypeId].Name
%assign enumeralName = SLibGetEnumTypeCodeGenStringFromIndexForVariantPreprocessor(enumDataTypeId, enumIdx)
%return "%<enumTypeName>_%<enumeralName>"
%endfunction
%function SLibDeclarePreprocessorEnums() void
%assign hasVariant = ::CompiledModel.HasVariants
%if hasVariant && ...
::CompiledModel.CodeVariants.NumEnumeratedTypeIds > 0
%with ::CompiledModel.CodeVariants
%openfile tmpEnumsBuf
/* Simulink enumerals used in Code Variant condition expressions */
%assign numEnumTypes = NumEnumeratedTypeIds
%foreach enumTypeIdx = numEnumTypes
%assign enumDataTypeId = EnumeratedTypeIds[enumTypeIdx]
%assert LibIsEnumDataType(enumDataTypeId)
%assert enumDataTypeId == DataTypes.DataType[enumDataTypeId].Id
%assign enumTypeName = DataTypes.DataType[enumDataTypeId].Name
#ifndef _RTW_ENUMS_%<enumTypeName>_
#define _RTW_ENUMS_%<enumTypeName>_
%foreach enumIdx = FcnGetEnumTypeNumEnums(enumDataTypeId)
%assign enumeralPreprocessorSymbol = ...
SLibEnumeralPreprocessorSymbol(enumDataTypeId, enumIdx)
%assign enumeralValue = SLibGetEnumTypeValueFromIndex(enumDataTypeId, enumIdx)
#define %<enumeralPreprocessorSymbol> %<enumeralValue>
%endforeach
#endif
%endforeach
%closefile tmpEnumsBuf
%endwith
%return tmpEnumsBuf
%else
%return
%endif
%endfunction
%function SLibDeclarePreprocessorConstraints() void
%assign hasVariant = ::CompiledModel.HasVariants
%if (!hasVariant) || ...
(!EXISTS(::CompiledModel.CodeVariants.ErrorCheckVariantGroup))
%return
%endif
%openfile tmpBuf
%assign errChkVarGrps = ::CompiledModel.CodeVariants.ErrorCheckVariantGroup
%assign errChkVarGrpLength = SIZE(errChkVarGrps,1)
%assign cntGrp = 0
%assign errChkBeginCmt = TLC_FALSE
%foreach idx = errChkVarGrpLength
%if errChkVarGrpLength == 1
%assign blockRec = errChkVarGrps
%else
%assign blockRec = errChkVarGrps[idx]
%endif
%assign varCtrlList = blockRec.VariantControlList
%assign numControls = SIZE(varCtrlList,1)
%assign BlkNameList = blockRec.BlockNameList
%assign numBlks = SIZE(BlkNameList,1)
%assign isDefaultList = blockRec.isDefaultList
%assign isAZVCList = blockRec.isAZVCList
%assign cmntBlkNameList = ""
%assign cmntNonAZVCBlkNameList = ""
%assign numNonAZVCs = 0
%assign firstNonAZVCBlkName = ""
%foreach idx = numBlks
%if idx > 0
%assign cmntBlkNameList = cmntBlkNameList + ", "
%endif
%assign cmntBlkNameList = cmntBlkNameList + "'%'"
%if ((!isDefaultList[idx])) && (!isAZVCList[idx])
%if numNonAZVCs == 0
%assign firstNonAZVCBlkName = "'%'"
%endif
%if numNonAZVCs > 0
%assign cmntNonAZVCBlkNameList = cmntNonAZVCBlkNameList + ", "
%endif
%assign cmntNonAZVCBlkNameList = cmntNonAZVCBlkNameList + "'%'"
%assign numNonAZVCs = numNonAZVCs + 1
%endif
%endforeach
%if(errChkBeginCmt == TLC_FALSE)
/* MW_VALIDATE_PREPROCESSOR_VARIANT_CHOICES */
%assign errChkBeginCmt = TLC_TRUE
%endif
#undef MW_HAVE_ACTIVE_VARIANT_CHOICE
%if(numControls > 1)
#undef MW_HAVE_MORE_THAN_ONE_ACTIVE_CHOICE
%endif
%foreach idx = numControls
%assign ctrl = varCtrlList[idx]
#if %<ctrl>
%if(numControls > 1)
#ifdef MW_HAVE_ACTIVE_VARIANT_CHOICE
#define MW_HAVE_MORE_THAN_ONE_ACTIVE_CHOICE
#else
#define MW_HAVE_ACTIVE_VARIANT_CHOICE
#endif
%else
#define MW_HAVE_ACTIVE_VARIANT_CHOICE
%endif
#endif
%endforeach
%if(numControls > 1 && numBlks > 0 )
%assign firstBlkName = BlkNameList[0]
/* At most one variant choice can be active for block %<cmntBlkNameList> */
#ifdef MW_HAVE_MORE_THAN_ONE_ACTIVE_CHOICE
%if(numBlks > 1)
#error "At most one variant choice can be active for block '%<firstBlkName>' and others"
%else
#error "At most one variant choice can be active for block '%<firstBlkName>'"
%endif
#endif
%endif
%if(numNonAZVCs)
/*At least one variant choice must be active for block %<cmntNonAZVCBlkNameList> */
#ifndef MW_HAVE_ACTIVE_VARIANT_CHOICE
%if(numNonAZVCs > 1)
#error "At least one variant choice must be active for block %<firstNonAZVCBlkName> and others"
%else
#error "At least one variant choice must be active for block %<firstNonAZVCBlkName>"
%endif
#endif
%endif
%endforeach
%if(errChkBeginCmt == TLC_TRUE)
/* MW_END_VALIDATE_PREPROCESSOR_VARIANT_CHOICES */
%endif
%closefile tmpBuf
%return tmpBuf
%endfunction
%function SLibParamIsVariantControlParamInVariantCondition(dataRec) void
%return (SLibIsParameterType(dataRec) && dataRec.IsVariantControlPrmInCondExpr)
%endfunction
%function SLibParamIsVariantControlParamInDimensionsExpression(dataRec) void
%return (SLibIsParameterType(dataRec) && dataRec.IsVariantControlPrmInDimsExpr)
%endfunction
%function SLibParamIsVariantControlParam(dataRec) void
%return ((dataRec.RecordType == "ModelParameter") && ...
(SLibParamIsVariantControlParamInVariantCondition(dataRec) || ...
SLibParamIsVariantControlParamInDimensionsExpression(dataRec)))
%endfunction
%function LibCacheSystemIncludes(sysIdx) void
%assign system = System[sysIdx]
%if (system.FileNameOwnerIdx == sysIdx)
%openfile sysheader
%foreach idx = SIZE(system.IncludedChildSystemIdx,1)
%assign inChildSysIdx = system.IncludedChildSystemIdx[idx]
%assign inChildSys = ::CompiledModel.System[inChildSysIdx]
%assign inChildSysFileName = inChildSys.SystemHeaderFileName
%assign childSysFileNeeded = LibSystemIsReusedLibraryFcn(System[sysIdx]) || ...
SLibModelHasServicePortDWork()
%if !childSysFileNeeded
%<GetHideChildDefineSymbol("ifndef")>/
%endif
%if LibIsGlobalServer(inChildSys)
%assign isRapidAccelOnly = (isRSim && !isRAccel)
%if !::GenerateClassInterface && (!SLibIsHostBasedSimulationTarget() || isRapidAccelOnly)
%if inChildSysFileName == inChildSys.Identifier
#include "%<inChildSys.Identifier>_private.h"
%endif
%if !SLibAutosarActive() && ...
inChildSys.IsConstUncalledFunction == "no"
#include "%<inChildSys.Identifier>.h"
%endif
%endif
%elseif(inChildSysFileName != system.SystemHeaderFileName)
#include "%<inChildSysFileName>.h"
%endif
%if !childSysFileNeeded
%<GetHideChildDefineSymbol("endif")>/
%endif
%endforeach
%assign numMdlRefBlks = system.NumIncludedModelReference
%foreach rowIdx = numMdlRefBlks
%assign mdlRefInfo = system.IncludedModelReference[rowIdx]
%assign mSysIdx = mdlRefInfo.SysIdx
%assign bIdx = mdlRefInfo.BlockIdx
%assign blk = ::CompiledModel.System[mSysIdx].Block[bIdx]
%assert 0 == blk.DeletedInIR
%assign blockInterface = GetModelrefInterface(blk)
%assign name = blockInterface.FileName
%assign condition = CGMODEL_ACCESS("FileRepository.getFileVariantCondition",name)
%if !ISEMPTY(condition)
#if %<condition>
%endif
%if !SLibModelHasServicePortDWork()
%<GetHideChildDefineSymbol("ifndef")>/
%endif
%if ( blockInterface.IsScalableBuild && ...
!blockInterface.AncestorAllocatesCoderDataGroups && ...
!blk.MdlRefIsCPPClassGenMode)
#define %<blockInterface.HideChildDefineSymbol>
%endif
%if blockInterface.AncestorAllocatesCoderDataGroups || ...
!( blk.MdlRefIsCPPClassGenMode && ...
(blockInterface.IsScalableBuild || CGMODEL_ACCESS("CGModel.getUseOperatorNewForModelRefRegistration") ))
#include "%<name>.h"
%endif
%if !SLibModelHasServicePortDWork()
%<GetHideChildDefineSymbol("endif")>/
%endif
%if !ISEMPTY(condition)
#endif
%endif
%endforeach
%closefile sysheader
%<LibAddToSystemField(system, "SystemIncludes", sysheader)>
%endif
%endfunction
%function LibCacheUtilityIncludes(sysIdx) void
%assign system = System[sysIdx]
%if (system.FileNameOwnerIdx == sysIdx)
%openfile utilheader
%assign rtwModule = RTWCGModules.RTWCGModule[system.CGIRModuleIdx]
%assign headers = rtwModule.FcnHeaders
%assign numHeaders = SIZE(headers, 0)
%foreach idx = numHeaders
%assign headerIdx = headers[idx][0]
%assign incFileName = ::CompiledModel.RTWCGStrings[headerIdx]
%assign modelHeaderFileName = LibGetMdlPubHdrBaseName() + ".h"
%assign moduleFileTypeIdx = headers[idx][1]
%if incFileName != modelHeaderFileName
%<FcnAppendSystemFcnHeaders(system, incFileName, moduleFileTypeIdx)>
%endif
%endforeach
%closefile utilheader
%endif
%endfunction
%function LibCacheSharedTypeIncludes(sysIdx) void
%assign system = System[sysIdx]
%openfile sysheader
%if LibSystemIsReusedLibraryFcn(system)
#include "%<SLibCoderTypesFilename()>"
%if system.DumpZCInclude
#include "%<SLibCoderZerocrossingTypesFilename()>"
%endif
%endif
%if SLibUsedMultiwordTypes()
%assign multiwordFileName = SLibCoderMultiwordTypesFilename()
%if LibSystemIsReusedLibraryFcn(system)
%assign rtwCtx = ::CompiledModel.RTWContext
%assign isMultiword = SLibIsHostBasedSimulationTarget() ? ...
TLC_TRUE : ...
FEVAL("rtwprivate", "retrieveMultiWordUtilitiesAndFunctions", "%<MasterSharedCodeManagerFile>", rtwCtx, system.SystemHeaderFileName)
%if isMultiword
#include "%<multiwordFileName>"
%endif
%else
#include "%<multiwordFileName>"
%endif
%endif
%if SLibUsedModelReferenceTypes() && ...
::tMdlRefTimingBridgeAccessed && ...
(LibSystemIsRoot(system) || ...
IsModelReferenceBaseSys(system))
#include "%<SLibCoderModelReferenceTypesFilename()>"
%endif
%if LibSystemIsReusedLibraryFcn(system) || LibIsGlobalServer(system)
%if ISFIELD(system, "IncludedSharedDataTypes")
%foreach idx = SIZE(system.IncludedSharedDataTypes,1)
#include %
%endforeach
%endif
%endif
%if SLibUsedHalfPrecisionTypes()
%if LibSystemIsReusedLibraryFcn(system)
#include "%<SLibCoderHalfTypeHdrFilename()>"
%endif
%endif
%closefile sysheader
%<LibAddToSystemField(system, "SharedTypeIncludes", sysheader)>
%endfunction
%function LibDumpSystemIncludes(system) void
%assign systemIncludes = LibGetSystemField(system, "SystemIncludes")
%if !WHITE_SPACE(systemIncludes)
%openfile sysIncludeBuffer
/* Child system includes */
%<systemIncludes>
%closefile sysIncludeBuffer
%return sysIncludeBuffer
%else
%return ""
%endif
%endfunction
%function LibCacheSharedDataIncludes(sysIdx) void
%assign system = System[sysIdx]
%if LibSystemIsReusedLibraryFcn(system)
%openfile sysheader
%if ISFIELD(system, "SystemSharedDataIncludes")
%foreach idx = SIZE(system.SystemSharedDataIncludes,1)
%assign sharedDataHeader = system.SystemSharedDataIncludes[idx]
#include %<sharedDataHeader>
%endforeach
%endif
%closefile sysheader
%<LibAddToSystemField(system, "SystemSharedDataIncludes", sysheader)>
%endif
%endfunction
%function LibDumpSharedDataIncludes(system) void
%assign sharedDataIncludes = LibGetSystemField(system, "SystemSharedDataIncludes")
%if !WHITE_SPACE(sharedDataIncludes)
%openfile sharedDataIncludeBuffer
/* Shared Data Includes */
%<sharedDataIncludes>
%closefile sharedDataIncludeBuffer
%return sharedDataIncludeBuffer
%else
%return ""
%endif
%endfunction
%function LibDumpSharedTypeIncludes(system) void
%assign sharedTypeIncludes = LibGetSystemField(system, "SharedTypeIncludes")
%if !WHITE_SPACE(sharedTypeIncludes)
%openfile sharedTypeIncludeBuffer
/* Shared type includes */
%<sharedTypeIncludes>
%closefile sharedTypeIncludeBuffer
%return sharedTypeIncludeBuffer
%else
%return ""
%endif
%endfunction
%function LibDumpSystemTypeDefs(system) void
%assign systemTypeDefs = LibGetSystemField(system, "SystemTypeDefs")
%if !WHITE_SPACE(systemTypeDefs)
%openfile sysTypeDefBuffer
/* Type definitions */
%<systemTypeDefs>
%closefile sysTypeDefBuffer
%return sysTypeDefBuffer
%else
%return ""
%endif
%endfunction
%function LibDumpSystemFcnPrototype(system) void
%assign tmpFcnBuffer = ""
%if !WHITE_SPACE(LibGetSystemField(system, "SystemFcnPrototype"))
%openfile tmpFcnBuffer
%if IsModelReferenceBaseSys(system)
%<GetHideChildDefineSymbol("ifndef")>/
%endif
%<LibDumpSystemPrototype(system)>/
%if IsModelReferenceBaseSys(system)
%<GetHideChildDefineSymbol("endif")>/
%endif
%closefile tmpFcnBuffer
%endif
%return tmpFcnBuffer
%endfunction
%function LibDumpSystemBanner(system) void
%assign bannerBuf = ""
%assign sysInfo = GetSystemNameForComments(system)
%openfile bannerBuf
/*
* Code generation for system %<sysInfo>
* For more details, see corresponding source file %<system.SystemSourceFileName>.c
*
*/
%closefile bannerBuf
%return bannerBuf
%endfunction
%function SLibFcnPrototypeToRec(fcnDecl)
%assign fcnRec = FEVAL("rtwprivate", "rtw_getFcnRecFromDecl", fcnDecl)
%return fcnRec
%endfunction
%function SLibDumpFunctionBanner(fcnRec) void
%assign cs = ::CompiledModel.ConfigSet
%if !cs.GenerateComments
%return SLibGetNamespace(fcnRec.Name)
%endif
%assign ModelName = LibGetModelName()
%assign IsSharedUtility = GenUtilsSrcInSharedLocation && ...
ISEQUAL(fcnRec.Category, "utility")
%assign BlockDescription = ""
%assign BlockDescriptionContent = ""
%if ISFIELD(fcnRec, "BlockDescription")
%assign BlockDescription = fcnRec.BlockDescription
%if !ISEMPTY(BlockDescription)
%assign BlockDescriptionContent = FEVAL("rtwprivate", ...
"rtw_format_banner", "getBlockDescriptionContent", BlockDescription)
%endif
%endif
%if IsSharedUtility
%if GenerateDefaultFcnBannerSharedUtil == 0
%if !SLibIsERTTarget() || !FILE_EXISTS("function_banner_template_sharedutility.tlc")
%assign ::GenerateDefaultFcnBannerSharedUtil = 1
%else
%assign ::GenerateDefaultFcnBannerSharedUtil = 2
%endif
%endif
%else
%if GenerateDefaultFcnBanner == 0
%if !SLibIsERTTarget() || !FILE_EXISTS("function_banner_template.tlc")
%assign ::GenerateDefaultFcnBanner = 1
%else
%assign ::GenerateDefaultFcnBanner = 2
%endif
%endif
%endif
%if (!IsSharedUtility && GenerateDefaultFcnBanner == 1) || ...
(IsSharedUtility && GenerateDefaultFcnBannerSharedUtil == 1)
%assign FunctionDescription = FEVAL("rtwprivate", "rtw_format_banner", "formatFcnDescription",...
fcnRec.Abstract, 0, 0)
%assign bannerBuf = FunctionDescription + "/n" + BlockDescription
%assign bannerBuf = FEVAL("rtwprivate", "rtw_format_banner", "formatBanner", ...
bannerBuf, "classic", 0)
%assign nameSpaceDecl = SLibGetNamespace(fcnRec.Name)
%assign bannerBuf = nameSpaceDecl + bannerBuf
%return bannerBuf
%endif
%if ISFIELD(fcnRec, "GeneratedFor")
%assign GeneratedFor = "%<fcnRec.GeneratedFor>"
%else
%assign GeneratedFor = ""
%if ISEQUAL(fcnRec.Category, "model")
%if BlockCommentType == "BlockPathComment"
%assign GeneratedFor = "''"
%else
%assign GeneratedFor = "'%<LibGetModelName()>'"
%endif
%endif
%endif
%if TYPE(fcnRec.Params) == "Vector" && SIZE(fcnRec.Params, 1) > 1
%assign fcnParams = ""
%foreach idx = SIZE(fcnRec.Params, 1)
%assign fcnParams = "%<fcnParams>%"
%endforeach
%assign fcnRec.Params = "%<fcnParams>"
%endif
%assign rawArguments = fcnRec.Params
%assign rawFcnDescription = fcnRec.Abstract
%assign rawReturnType = fcnRec.Returns
%assign FunctionName = fcnRec.Name
%if ISEQUAL(fcnRec.Category, "cpp") && ISFIELD(fcnRec, "Type") && ...
(ISEQUAL(fcnRec.Type, "C++ constructor") || ISEQUAL(fcnRec.Type, "C++ destructor"))
%assign isCppStructor = TLC_TRUE
%else
%assign isCppStructor = TLC_FALSE
%endif
%assign GeneratedBy = fcnRec.GeneratedBy
%if IsSharedUtility
%include "function_banner_template_sharedutility.tlc"
%else
%include "function_banner_template.tlc"
%endif
%assign nameSpaceDecl = SLibGetNamespace(fcnRec.Name)
%assign bannerBuf = nameSpaceDecl + bannerBuf
%return bannerBuf
%endfunction
%function SLibGetNamespace(fName) void
%assign nameSpaceDecl = ""
%assign className = ""
%if GenerateClassInterface
%assign classConfObj = FcnGetRTWCPPStepPrototypeRecord()
%assign className = classConfObj.ModelClassName
%endif
%if className != ""
%if !ISEMPTY(FEVAL("strfind", fName, "%<className>::")) && ...
(System[NumSystems-1].SystemNamespaceFlag == 0) && ...
EXISTS(::NamespaceName) && (::NamespaceName != "")
%assign nameSpaceDecl = "namespace %<::NamespaceName>" + "/n"+ "{" + "/n"
%assign System[NumSystems-1].SystemNamespaceFlag = 1
%endif
%endif
%return nameSpaceDecl
%endfunction
%function LibDumpSystemHeader(system) void
%if system.FileNameOwnerIdx == system.SystemIdx
%assign fileName = SLibGetSystemHeaderFileName(system)
%openfile fcnBuff
%<LibDumpSystemFcnPrototype(system)>
%closefile fcnBuff
%assign rootSysFileName = GetRootSystemHeaderFileName()
%assert(system.SystemHeaderFileName != rootSysFileName)
%assign duplicate = LibAddToModelHeaders(fileName)
%assign bannerBuf = LibDumpSystemBanner(system)
%<LibRegCommonIncludes(system.SystemIdx)>
%assign includeBuf = SLibDumpCommonIncludes(system)
%<SLibCacheSystemCodeToFile("sys_hdr_ban", system, bannerBuf)>
%if IsModelReferenceBaseSys(system) && IsModelRefScalableBuild()
%if LibIsSystemField(system, "MRSystemFcnPrototype")
%assign mrFcnBuff = LibGetSystemField(system, "MRSystemFcnPrototype")
%if !WHITE_SPACE(mrFcnBuff) && !GenerateClassInterface
%<SLibCacheSystemCodeToFile("sys_fcn_prototype", ...
system, mrFcnBuff)>
%endif
%endif
%endif
%if !(IsModelReferenceBaseSys(system) && GenerateClassInterface)
%<SLibCacheSystemCodeToFile("sys_fcn_decl", system, fcnBuff)>
%endif
%<SLibCacheSystemCodeToFile("sys_hdr_incl", system, includeBuf)>
%if !LibSystemIsReusedLibraryFcn(system) && !LibIsGlobalServer(system)
%assign mdlTypesHdrFileName = SLibGetFileNameForCode("mdl_types_hdr")
%if !WHITE_SPACE(mdlTypesHdrFileName)
%openfile typesIncludeBuf
#include "%<mdlTypesHdrFileName>.h"
%closefile typesIncludeBuf
%<SLibCacheSystemCodeToFile("sys_hdr_incl", system, typesIncludeBuf)>
%endif
%endif
%<SLibCacheSystemCodeToFile("sys_hdr_incl", system, LibDumpSharedTypeIncludes(system))>
%<SLibCacheSystemCodeToFile("sys_hdr_incl_guarded", system, LibDumpSystemIncludes(system))>
%<SLibCacheSystemCodeToFile("sys_primitive_typedef", system, ...
SLibDeclarePrimitiveTypedefs())>
%endif
%endfunction
%function LibDeclareCompoundDataTypes() void
%return ""
%endfunction
%function LibDeclareMemoryAllocationMacros() void
%assign nulldef = SLibGetNullDefinitionFromTfl()
%openfile tmpFcnBuf
%if CodeFormat != "S-Function"
#if !defined(rt_VALIDATE_MEMORY)
#define rt_VALIDATE_MEMORY(S, ptr) /
%else
#if !defined(ss_VALIDATE_MEMORY)
#define ss_VALIDATE_MEMORY(S, ptr) /
%endif
if(!(ptr)) {%<"//">
%<RTMSetErrStat("RT_MEMORY_ALLOCATION_ERROR")>;%<"//">
%<"}">
#endif
#if !defined(rt_FREE)
#if !defined(_WIN32)
#define rt_FREE(ptr) /
if((ptr) != %<nulldef>) {%<"//">
free((ptr));%<"//">
(ptr) = %<nulldef>;%<"//">
%<"}">
#else
/* Visual and other windows compilers declare free without const */
#define rt_FREE(ptr) /
if((ptr) != %<nulldef>) {%<"//">
free((void *)(ptr));%<"//">
(ptr) = %<nulldef>;%<"//">
%<"}">
#endif
#endif
%closefile tmpFcnBuf
%return tmpFcnBuf
%endfunction
%function LibCheckForValidMTaskDefine() void
%openfile tmpFcnBuf
%if ::CompiledModel.SolverType == "FixedStep"
%if ::CompiledModel.FixedStepOpts.SolverMode == "MultiTasking"
%assign str = "Model (%<::CompiledModel.Name>) was built ///n" ...
"in MultiTasking solver mode, however the MULTITASKING define ///n" ...
"is not present. Please verify that your template makefile is ///n" ...
"configured correctly."
#if !defined(MULTITASKING) && !defined(NRT)
# error %<str>
#endif
%else
%assign str = "Model (%<::CompiledModel.Name>) was built in ///n" ...
"SingleTasking solver mode, however the MULTITASKING define is " ...
"///npresent. If you have multitasking (e.g. -DMT or " ...
"-DMULTITASKING) ///ndefined on the Code Generation page of Simulation " ...
"parameter dialog, please ///nremove it and on the Solver page, " ...
"select solver mode ///nMultiTasking. If the Simulation parameter " ...
"dialog is configured ///ncorrectly, please verify that your " ...
"template makefile is ///nconfigured correctly."
#if defined(MULTITASKING)
# error %<str>
#endif
%endif
%else
%assign str = "Models using the variable step solvers cannot define " ...
"MULTITASKING"
#if defined(MULTITASKING)
# error %<str>
#endif
%endif
%closefile tmpFcnBuf
%return tmpFcnBuf
%endfunction
%function LibDeclareSystemRequirements() void
%openfile tmpFcnBuf
%if ISFIELD(::CompiledModel, "Requirements")
/*-
%if BlockCommentType == "BlockPathComment"
* Requirements for '': %<Name>
%else
* Requirements for model: %<Name>
%endif
%if ISFIELD(::CompiledModel.Requirements, "Requirements")
%<::CompiledModel.Requirements.Requirements>
%endif
%if ISFIELD(::CompiledModel.Requirements, "InheritedRequirements")
%<::CompiledModel.Requirements.InheritedRequirements>
%endif
*/
%endif
%closefile tmpFcnBuf
%return tmpFcnBuf
%endfunction
%function LibDeclareSystemHierarchy() void
%openfile tmpFcnBuf
%assign parentName = ""
%assign srcSubsysName = ""
%if ISFIELD(::CompiledModel, "SubsystemPathForRightClickBuild")
%assign parentName = ::CompiledModel.SubsystemPathForRightClickBuild
%assign srcSubsysName = ::CompiledModel.SubsystemNameForRightClickBuild
%endif
/*-
* The generated code includes comments that allow you to trace directly
* back to the appropriate location in the model. The basic format
%if BlockCommentType == "BlockPathComment"
* is /block_name, where system is the system number (uniquely
* assigned by Simulink) and block_name is the name of the block.
*
%else
* is 'block_name' ('SID'), where block_name is the name of the block
* and SID is the Simulink identifier of the block without the model name.
*
%endif
%if ISEMPTY(parentName)
* Use the MATLAB hilite_system command to trace the generated code back
* to the model. For example,
*
%if BlockCommentType == "BlockPathComment"
* hilite_system('') - opens system 3
* hilite_system('/Kp') - opens and selects block Kp which resides in S3
%else
* hilite_system(':3') - opens block with Simulink identifier 'model:3'
%endif
%else
%assign srcSubsys = parentName + "/" + srcSubsysName
* Note that this particular code originates from a subsystem build,
* and has its own system numbers different from the parent model.
* Refer to the system hierarchy for this subsystem below, and use the
* MATLAB hilite_system command to trace the generated code back
* to the parent model. For example,
*
* hilite_system('%<srcSubsys>') - opens subsystem %<srcSubsys>
* hilite_system('%<srcSubsys>/Kp') - opens and selects block Kp
%endif
%if BlockCommentType == "BlockPathComment"
*
* Here is the system hierarchy for this model
*
%if ISEMPTY(parentName)
* '' : '%<Name>'
%else
* '' : '%<parentName>'
%endif
%foreach sysIdx = NumSubsystems
%assign id = sysIdx+1
%if ISEMPTY(parentName)
%assign path = LibMangledPathName(Subsystem[sysIdx].Name)
%else
%assign sysName = SYSNAME(Subsystem[sysIdx].Name)
%if ISEQUAL(sysName[0], "Root") && !ISEQUAL(sysName[1], srcSubsysName)
%continue
%endif
%assign path = SLibMangledSubsystemPathName(parentName,...
Subsystem[sysIdx].Name)
%endif
%if id < 10
* 'id>>' : '%<path>'
%elseif id < 100
* 'id>>' : '%<path>'
%else
* 'id>>' : '%<path>'
%endif
%endforeach
%endif
*/
%closefile tmpFcnBuf
%return tmpFcnBuf
%endfunction
%function LibDeclareReducedBlocks() void
%if (!ShowEliminatedStatements)
%return
%endif
%openfile tmpFcnBuf
%with ReducedBlocks
%if NumReducedBlocks > 0
/*-
* These blocks were eliminated from the model due to optimizations:
*
%foreach bIdx = NumReducedBlocks
%assign b = Block[bIdx]
%if BlockCommentType == "BlockPathComment"
* Block '%<b.Name>' : %<b.OptimizationInfo>
%else
%assign blkName = SLibGrBlockSIDCommentByIdx(b.GrSrc)
* Block %<blkName> : %<b.OptimizationInfo>
%endif
%endforeach
*/
%endif
%endwith
%closefile tmpFcnBuf
%return tmpFcnBuf
%endfunction
%function LibDumpGroundExterns() void
%openfile tmpFcnBuf
%createrecord externedGroundNames {}
%with DataTypes
%foreach dtIdx = NumDataTypes
%assign dt = DataType[dtIdx]
%if !ISEMPTY(SLibDataTypeConstructFcnName(dtIdx))
%assign qualifiers = ""
%else
%assign qualifiers = SLibGetGroundQualifiers()
%endif
%if dt.GroundReqInMemory
%assign groundName = SLibGetDtGroundName(dtIdx, TLC_FALSE, "")
%if ISFIELD(externedGroundNames,groundName)
%continue
%endif
%openfile declaration
%if SLibAutosarCompilerAbstractionRequired()
%<SLibAutosarCompilerAbstractionForDataDecl(TLC_TRUE, dt.Name, TLC_FALSE, TLC_FALSE, dt.GroundName, "DataGlobal")>;/
%else
%<qualifiers> %<dt.Name> %<groundName>;/
%endif
/* %<dt.Name> ground */
%closefile declaration
%<SLibApplyMemSecToDataDecl(declaration, ...
"MemSecDataConstants", groundName)>/
%addtorecord externedGroundNames %<groundName> 1
%endif
%if dt.ComplexGroundReqInMemory
%assign groundName = dt.ComplexGroundName
%assign complexName = SLibGetContainerSLTypeComplexName(dt)
%if ISFIELD(externedGroundNames,groundName)
%continue
%endif
%openfile declaration
%<qualifiers> %<complexName> %<groundName>;/
/* %<dt.Name> complex ground */
%closefile declaration
%<SLibApplyMemSecToDataDecl(declaration, ...
"MemSecDataConstants", groundName)>/
%addtorecord externedGroundNames %<groundName> 1
%endif
%endforeach
%endwith
%closefile tmpFcnBuf
%return tmpFcnBuf
%endfunction
%function LibDumpGroundDeclarations(declareAsStatic) void
%assign keyword = declareAsStatic ? "static" : ""
%if !EXISTS(::definedGroundNames)
%createrecord ::definedGroundNames {}
%endif
%openfile tmpFcnBuffer
%with DataTypes
%foreach dtIdx = NumDataTypes
%assign dt = DataType[dtIdx]
%if dt.GroundReqInMemory
%if !ISFIELD(dt, "GroundAlreadyDefined")
%assign name = dt.GroundName
%if ISFIELD(definedGroundNames,name)
%continue
%endif
%if !ISEMPTY(SLibDataTypeConstructFcnName(dtIdx))
%assign qualifiers = ""
%assign init = ""
%elseif LibIsDataTypeCGClassType(dtIdx)
%assign qualifiers = SLibGetGroundQualifiers()
%assign init = ""
%else
%assign qualifiers = SLibGetGroundQualifiers()
%assign init = " = %<LibGetGroundInitFromId(dtIdx)>"
%endif
%openfile definition
%if SLibAutosarCompilerAbstractionRequired()
%<keyword> %<SLibAutosarCompilerAbstractionForDataDecl(TLC_TRUE, dt.Name, TLC_FALSE, TLC_FALSE, name, "DataGlobal")>%<init>;/
%else
%<keyword> %<qualifiers> %<dt.Name> %<name>%<init>;/
%endif
/* %<dt.Name> ground *//
%closefile definition
%<SLibApplyMemSecToDataDefn(definition, ...
"MemSecDataConstants", name)>/
%addtorecord dt GroundAlreadyDefined TLC_TRUE
%addtorecord ::definedGroundNames %<name> 1
%endif
%endif
%if dt.ComplexGroundReqInMemory
%if !ISFIELD(dt, "CmplxGroundAlreadyDefined")
%assign groundName = dt.ComplexGroundName
%if ISFIELD(definedGroundNames,groundName)
%continue
%endif
%if ISFIELD(dt, "ContainerSLTypeIdx")
%assign containerTypeIdx = dt.ContainerSLTypeIdx
%assign complexName = LibGetDataTypeComplexNameFromId(containerTypeIdx)
%else
%assign complexName = dt.ComplexName
%endif
%if !ISEMPTY(SLibDataTypeConstructFcnName(dtIdx))
%assign qualifiers = ""
%else
%assign qualifiers = SLibGetGroundQualifiers()
%endif
%openfile definition
%if SLibAutosarCompilerAbstractionRequired()
%<keyword> %<SLibAutosarCompilerAbstractionForDataDecl(TLC_TRUE, complexName, TLC_FALSE, TLC_FALSE, groundName, "DataGlobal")> = ...
{%<dt.GroundValue>, %<dt.GroundValue>};/
%else
%<keyword> %<qualifiers> %<complexName> %<groundName> = ...
{%<dt.GroundValue>, %<dt.GroundValue>};/
%endif
/* %<dt.Name> complex ground *//
%closefile definition
%<SLibApplyMemSecToDataDefn(definition, ...
"MemSecDataConstants", groundName)>/
%addtorecord dt CmplxGroundAlreadyDefined TLC_TRUE
%addtorecord ::definedGroundNames %<groundName> 1
%endif
%endif
%endforeach
%endwith
%closefile tmpFcnBuffer
%if !WHITE_SPACE(tmpFcnBuffer)
%return ("/n" + tmpFcnBuffer)
%else
%return ""
%endif
%endfunction
%function FcnCommonHeaderInfo() void
%openfile tmpFcnBuf
%if FEVAL("eval","~isempty(emit(coder.internal.watermark))")
%<FEVAL("eval","emit(coder.internal.watermark,'* ')")>
*
%endif
* Code generation for model "%<::CompiledModel.Name>".
*
* Model version : %<ModelVersion>
* Simulink Coder version : %<Version>
%if GenerateFullHeader
* %<CorCPPForBuildLogsandComments()> source code generated on : %<TLC_TIME>
%endif
%if ISFIELD(::CompiledModel, "CompiledWarningMsg")
* Warning Messages : %<CompiledWarningMsg>
%endif
%closefile tmpFcnBuf
%return tmpFcnBuf
%endfunction
%function SLibCodeGenSettings() void
%if !GenerateFullHeader || !IncludeCodeGenSettings
%return ""
%endif
%openfile tmpFcnBuf
Target selection: %<ConfigSet.SystemTargetFile>
%if !SLibIsERTTarget()
Note: GRT includes extra infrastructure and instrumentation for prototyping
%endif
Embedded hardware selection: %<ConfigSet.ProdHWDeviceType>
%if !%<ConfigSet.ProdEqTarget>
%assign emulationHWComment = SLibEmulationHWComment()
%if !ISEMPTY(emulationHWComment)
Emulation hardware selection: %<emulationHWComment>
%endif
%endif
%if ISEMPTY(ConfigCheckComments)
%assign ::ConfigCheckComments = FEVAL(...
"coder.internal.genConfigCheckReportComments", LibGetModelName())
%endif
%<ConfigCheckComments>
%closefile tmpFcnBuf
%return tmpFcnBuf
%endfunction
%function SLibCommonHeaderInfo() void
%assign tmpbuf = FEVAL("rtwprivate", "rtw_format_banner", "insert_comment_prefix", SLibCodeGenSettings())
%return FcnCommonHeaderInfo() + tmpbuf
%endfunction
%function LibCommonHeaderInfo() void
%return SLibCommonHeaderInfo()
%endfunction
%function SLibCommonUtilHeaderInfo() void
%assign str = FcnCommonHeaderInfo()
%if !GenUtilsSrcInSharedLocation
%assign tmpbuf = FEVAL("rtwprivate", "rtw_format_banner", "insert_comment_prefix", SLibCodeGenSettings())
%assign str = str + tmpbuf
%endif
%return str
%endfunction
%function SLibSystemBanner(system) void
%assign sysInfo = GetSystemNameForComments(system)
%openfile tmpFcnBuf
* Code generation for system %<sysInfo>
*
* Model : %<::CompiledModel.Name>
* Model version : %<ModelVersion>
* Simulink Coder version : %<Version>
%if GenerateFullHeader
* %<CorCPPForBuildLogsandComments()> source code generated on : %<TLC_TIME>
%endif
%closefile tmpFcnBuf
%return tmpFcnBuf
%endfunction
%function SLibGetSystemOutputSrcFileBaseName(system) void
%if (system.Type == "root")
%return LibGetMdlSrcBaseName()
%else
%if (system.SystemSourceFileName == LibGetModelName())
%return LibGetMdlSrcBaseName()
%else
%return system.SystemSourceFileName
%endif
%endif
%endfunction
%function SLibGetSystemOutputHdrFileBaseName(system) void
%if (system.Type == "root")
%return LibGetMdlPubHdrBaseName()
%else
%if (system.SystemHeaderFileName == LibGetModelName())
%return LibGetMdlPubHdrBaseName()
%else
%return system.SystemHeaderFileName
%endif
%endif
%endfunction
%function SLibGetSystemOutputFileName(system) void
%assign baseFileName = SLibGetSystemOutputSrcFileBaseName(system)
%assign baseFile = baseFileName + "." + ::LangFileExt
%return(baseFile)
%endfunction
%function SLibGetSystemHeaderFileName(system) void
%assign baseFileName = SLibGetSystemOutputHdrFileBaseName(system)
%return("%<baseFileName>.h")
%endfunction
%function LibAddToModelHeaders(newFile) void
%assign duplicate = 0
%if ::CompiledModel.NumHeaders > 0
%foreach idx = ::CompiledModel.NumHeaders
%if (::CompiledModel.Headers[idx] == "%<newFile>")
%assign duplicate = 1
%break
%endif
%endforeach
%if (!duplicate)
%assign ::CompiledModel.Headers = ::CompiledModel.Headers + "%<newFile>"
%assign ::CompiledModel.NumHeaders = ::CompiledModel.NumHeaders + 1
%endif
%else
%assign ::CompiledModel.Headers = ::CompiledModel.Headers + "%<newFile>"
%assign ::CompiledModel.NumHeaders = 1
%endif
%return (duplicate)
%endfunction
%function SLibIncludeRTWGeneratedChildSysExportFile() void
%if ISFIELD(::CompiledModel, "RTWGeneratedChildSfcnExportFiles")
%openfile includesBuf
%assign expFiles = ::CompiledModel.RTWGeneratedChildSfcnExportFiles
%<expFiles>
%if CodeFormat == "S-Function"
%assign tmpName = Accelerator ? "simulink_only_sfcn" : Name
#undef S_FUNCTION_NAME
#define S_FUNCTION_NAME %<tmpName>
%endif
%closefile includesBuf
%<SLibCacheCodeToFile("mdl_src_incl", includesBuf)>
%endif
%endfunction
%function SLibDumpStructDefWithAlignment(idTag, id, align, memBuf) void
%if ISEMPTY(id)
%assert !(ISEMPTY(idTag) || WHITE_SPACE(idTag))
%assign typedef = ""
%else
%assign typedef = "typedef"
%endif
%openfile structdef
%assign aSyntax = ""
%if structDAFlag.supported && align > 0
%assign aSyntax = SLibGetAlignmentSyntax(::CompiledModel.Name, id, "", ...
align, "DATA_ALIGNMENT_WHOLE_STRUCT")
%endif
%if !ISEMPTY(aSyntax)
%if structDAFlag.position == "DATA_ALIGNMENT_PREDIRECTIVE"
%<typedef> %<aSyntax> struct %<idTag>/
%elseif structDAFlag.position == "DATA_ALIGNMENT_PRECEDING_STATEMENT"
%<aSyntax>
%<typedef> struct %<idTag>/
%else
%<typedef> struct %<idTag>/
%endif
%else
%<typedef> struct %<idTag>/
%endif
%if !WHITE_SPACE(memBuf)
{
%<memBuf>
}/
%endif
%if !ISEMPTY(aSyntax)
%if structDAFlag.position == "DATA_ALIGNMENT_POSTDIRECTIVE"
%<id> %<aSyntax>;
%elseif structDAFlag.position == "DATA_ALIGNMENT_FOLLOWING_STATEMENT"
%<id>;
%<aSyntax>
%else
%<id>;
%endif
%else
%<id>;
%endif
%closefile structdef
%return structdef
%endfunction
%assign ::UseParamIdentifierForSymbolicDim = TLC_FALSE
%function SLibScalarCSCP(aParamIdx) void
%if ::UseParamIdentifierForSymbolicDim
%assign mdlParam = ::CompiledModel.ModelParameters.Parameter[aParamIdx]
%return LibGetRecordIdentifier(mdlParam)
%else
%assign preventCastForMacroAccess = TLC_TRUE
%return SLibCGIR_CSCP(aParamIdx, preventCastForMacroAccess, 1, "", -1, "", 0)
%endif
%endfunction
%function SLibGenerateConstraint(aConstraint, aOp, aInvOp, aNatOp) Output
%assign lhs = %<"/"" + aConstraint.lhs + "/"">
%assign rhs = %<"/"" + aConstraint.rhs + "/"">
%if aConstraint.NumGraphicalRefs > 0
/* Constraint '%<lhs> %<aOp> %<rhs>' registered by:
%foreach blkIdx = aConstraint.NumGraphicalRefs
* %<SLibGrBlockCommentName(aConstraint.GraphicalRef[blkIdx])>
%endforeach
*/
%endif
#if %<lhs> %<aInvOp> %<rhs>
# error "The preprocessor definition '%<lhs>' must be %<aNatOp> '%<rhs>'"
#endif
%endfunction
%function SLibGenerateDivisionConstraint(aConstraint) Output
%assign lhs = %<"/"" + aConstraint.lhs + "/"">
%assign rhs = %<"/"" + aConstraint.rhs + "/"">
#if (%<rhs> == 0) || ((%<lhs> % %<rhs>) != 0)
# error "The preprocessor definition '%<rhs>' must not be equal to zero and /
the division of '%<lhs>' by '%<rhs>' must not have a remainder."
#endif
%endfunction
%function SLibGenerateModuloConstraint(aConstraint) Output
%assign rhs = %<"/"" + aConstraint.rhs + "/"">
#if (%<rhs> == 0)
# error "The preprocessor definition '%<rhs>' must not be equal to zero, /
since it is used as the right hand side of a modulo operation."
#endif
%endfunction
%function SLibCachSymbolicDimensionConstraints() void
%with ::CompiledModel.SymbolicDimsConstraints
%assign symbolicDimsConstraintsBuff = ""
%openfile symbolicDimsConstraintsBuff
%if 0 < NumModuloSymbolicDims
/*
* Constraints for modulo operations in dimension variants
*/
%foreach cstrIdx = NumModuloSymbolicDims
%assign divC = ModuloSymbolicDims[cstrIdx]
%<SLibGenerateModuloConstraint(divC)>
%endforeach
%endif
%if 0 < NumDivisionSymbolicDims
/*
* Constraints for division operations in dimension variants
*/
%foreach cstrIdx = NumDivisionSymbolicDims
%assign divC = DivisionSymbolicDims[cstrIdx]
%<SLibGenerateDivisionConstraint(divC)>
%endforeach
%endif
%if 0 < NumEquivalentSymbolicDims || 0 < NumGreaterThanSymbolicDims
/*
* Registered constraints for dimension variants
*/
%foreach cstrIdx = NumEquivalentSymbolicDims
%assign eqC = EquivalentSymbolicDims[cstrIdx]
%<SLibGenerateConstraint(eqC,"==","!=","equal to")>
%endforeach
%foreach cstrIdx = NumGreaterThanSymbolicDims
%assign gtC = GreaterThanSymbolicDims[cstrIdx]
%<SLibGenerateConstraint(gtC,">","<=","greater than")>
%endforeach
%endif
%if 0 < NumLessThanSymbolicDims
%foreach cstrIdx = NumLessThanSymbolicDims
%assign gtC = LessThanSymbolicDims[cstrIdx]
%<SLibGenerateConstraint(gtC,"<",">=","less than")>
%endforeach
%endif
%closefile symbolicDimsConstraintsBuff
%if !WHITE_SPACE(symbolicDimsConstraintsBuff)
%<SLibCacheCodeToFile("data_simulink_variant_define", symbolicDimsConstraintsBuff)>
%endif
%endwith
%endfunction
%endif