%if EXISTS("_MODELREFUTIL_") == 0
%assign _MODELREFUTIL_ = 1
%function IsModelReferenceTarget()
%if "NONE" != ::CompiledModel.ModelReferenceTargetType
%return TLC_TRUE
%else
%return TLC_FALSE
%endif
%endfunction
%function IsModelReferenceInlineOffTarget()
%if IsModelReferenceTarget()
%switch InlineParameters
%case 0
%assert(TLC_FALSE)
%return TLC_FALSE
%case 1
%return TLC_FALSE
%case 2
%return TLC_TRUE
%endswitch
%else
%return TLC_FALSE
%endif
%endfunction
%function IsModelReferenceSimTarget()
%if "SIM" == ::CompiledModel.ModelReferenceTargetType
%return TLC_TRUE
%else
%return TLC_FALSE
%endif
%endfunction
%function IsModelReferenceForASimstructBasedTarget()
%return ::ModelReferenceForASimstructBasedTarget
%endfunction
%function IsModelReferenceNonSimstructBasedRTWTarget()
%return IsModelReferenceRTWTarget() && !IsModelReferenceForASimstructBasedTarget()
%endfunction
%function IsSimstructBasedTarget()
%return ::SimstructBasedTarget
%endfunction
%function IsModelReferenceRTWTarget()
%if "RTW" == ::CompiledModel.ModelReferenceTargetType
%return TLC_TRUE
%else
%return TLC_FALSE
%endif
%endfunction
%function IsModelRefScalableBuild()
%return IsModelReferenceTarget() && ...
::CompiledModel.ModelReferenceGenScalableCode
%endfunction
%function IsVariableStepModelReferenceTarget()
%return IsModelReferenceForASimstructBasedTarget() && ...
::CompiledModel.SolverType == "VariableStep"
%endfunction
%function IsFPCIgnored(fpc)
%if ISEMPTY(fpc) || (ISFIELD(fpc, "IsAuto") && fpc.IsAuto)
%return TLC_TRUE
%else
%return TLC_FALSE
%endif
%endfunction
%function HasModelReferenceBlocksInModel() void
%return ::CompiledModel.NumModelReferenceBlocksInModel > 0
%endfunction
%function HasModelReferenceBlocks() void
%return ::CompiledModel.NumModelReferenceBlocks > 0
%endfunction
%function GetRootSystemSourceFileName()
%return (::CompiledModel.System[::CompiledModel.NumSystems - 1].SystemSourceFileName)
%endfunction
%function ()
%return (::CompiledModel.System[::CompiledModel.NumSystems - 1].SystemHeaderFileName)
%endfunction
%function FcnIsRootSystem(system)
%if system.Type == "root"
%return TLC_TRUE
%else
%return TLC_FALSE
%endif
%endfunction
%function GetModelrefSFunctionName(name)
%assign suffix = FEVAL("coder.internal.modelRefUtil", name, "getBinExt", ::ProtectedModelReferenceTarget)
%return name + suffix
%endfunction
%function GetBaseSystemIdx()
%assign baseSysIdx = IsModelReferenceTarget() ? ...
::CompiledModel.NumSystems - 2 : ::CompiledModel.NumSystems - 1
%return baseSysIdx
%endfunction
%function GetBaseModuleIdx()
%assign baseSysIdx = GetBaseSystemIdx()
%return System[baseSysIdx].CGIRModuleIdx
%endfunction
%function GetNumSystemsForCodeGen()
%assign numSys = IsModelReferenceTarget() ? ...
::CompiledModel.NumSystems - 1 : ::CompiledModel.NumSystems
%return numSys
%endfunction
%function GetBaseFileName()
%assign baseSystem = ::CompiledModel.System[GetBaseSystemIdx()]
%assign baseName = SLibGetSystemOutputHdrFileBaseName(baseSystem)
%return baseName
%endfunction
%function GetHideChildDefineSymbol(mode) void
%assign retStr = ""
%if IsModelRefScalableBuild() && ...
!GenerateClassInterface && ...
!::CompiledModel.AncestorAllocatesCoderDataGroups
%if mode == "ifndef"
%assign retStr = "#ifndef %<::CompiledModel.Name>_MDLREF_HIDE_CHILD_"
%assign retStr = retStr + "/n"
%elseif mode == "endif"
%assign retStr = "#endif /*%<::CompiledModel.Name>_MDLREF_HIDE_CHILD_*/"
%assign retStr = retStr + "/n"
%elseif mode == "define"
%assign retStr = "%<::CompiledModel.Name>_MDLREF_HIDE_CHILD_"
%else
%return ""
%endif
%endif
%return retStr
%endfunction
%function GetBaseFile(type)
%assert(type == "SystemHeader" || type == "SystemBody")
%assign baseName = GetBaseFileName()
%assign baseFile = SLibAddModelFile(type,"Simulink", baseName)
%return baseFile
%endfunction
%function IsModelReferenceBaseSys(ss)
%return IsModelReferenceTarget() && ss.SystemIdx == NumSystems-2
%endfunction
%function LoadModelReferenceBlocksInterface() void
%<LibAddToCompiledModel("ModelBlocksHaveNonInlinedSfcns", 0)>
%<LibAddToCompiledModel("ContainsMultiThreadBlocker", 0)>
%assign zeroVec = CreateVectorWithValue(NumSampleTimes, 0)
%<LibAddToCompiledModel("ModelBlocksReqClockTicks", zeroVec)>
%<LibAddToCompiledModel("ModelBlocksReqLongClockTicks", zeroVec)>
%<LibAddToCompiledModel("ModelBlocksUseStopReq", 0)>
%<LibAddToCompiledModel("ModelBlocksUseContTimeOutputInconsistentWithStateAtMajorStep", 0)>
%<LibAddToCompiledModel("ModelBlockNeedsTriggerTID", 0)>
%<LibAddToCompiledModel("ReferencedModelMayResetSolver", TLC_FALSE)>
%assign mdlsReqLongClockTicks = CreateVectorWithValue(NumRuntimeExportedRates, 0)
%assign mdlsActRateInteraction = FEVAL("zeros", ...
NumRuntimeExportedRates, NumRuntimeExportedRates)
%assign hasMdlBlks = (ISFIELD(::CompiledModel,"ModelReferenceBlocks") && ...
SIZE(::CompiledModel.ModelReferenceBlocks,0) > 0)
%if !hasMdlBlks
%return
%endif
%assign mdlRefBlks = ::CompiledModel.ModelReferenceBlocks
%assign numMdlRefs = SIZE(mdlRefBlks,0)
%with ::CompiledModel
%assign buildStartDir = FEVAL("rtwprivate","rtwattic","getStartDir")
%addtorecord ::CompiledModel ModelReferenceInterfaces {}
%foreach rowIdx = numMdlRefs
%assign mdlRefInfo = mdlRefBlks[rowIdx]
%assign mSysIdx = mdlRefInfo[0]
%assign bIdx = mdlRefInfo[1]
%assign mdlrefBlk = System[mSysIdx].Block[bIdx]
%with mdlrefBlk
%assign mdlName = ParamSettings.ReferencedModelName
%assign needToAddBlockInterface = !EXISTS(ModelReferenceInterfaces.%<mdlName>Interface)
%assign needToLoadBlockInterface = needToAddBlockInterface || ...
( EXISTS(ModelReferenceInterfaces.%<mdlName>Interface.IsModelBlockInXILMode) && ...
ModelReferenceInterfaces.%<mdlName>Interface.IsModelBlockInXILMode)
%if needToLoadBlockInterface
%assign loadMatchingTarget = !Accelerator || (ParamSettings.XILCodeInterface == "None")
%if loadMatchingTarget
%assign blkInterface = LoadModelrefInterfaceInMatInfoFile(...
mdlName, buildStartDir)
%else
%assign lIsModelRefTarget = (ParamSettings.XILCodeInterface == "Model reference")
%assign lFormattedBlockPath = LibGetFormattedBlockPath(mdlrefBlk)
%assign blkInterface = FEVAL("rtw.pil.ModelBlockPIL.getModelInterfaceForTLC", ...
lFormattedBlockPath, lIsModelRefTarget)
%addtorecord blkInterface IsModelBlockInXILMode TLC_TRUE
%endif
%if needToAddBlockInterface
%addtorecord ::CompiledModel.ModelReferenceInterfaces /
%<mdlName>Interface blkInterface
%else
%assign ::CompiledModel.ModelReferenceInterfaces.%<mdlName>Interface=blkInterface
%endif
%endif
%endwith
%endforeach
%endwith
%endfunction
%function PropModelReferenceBlocksInterface() void
%assign hasMdlBlks = (ISFIELD(::CompiledModel,"ModelReferenceBlocks") && ...
SIZE(::CompiledModel.ModelReferenceBlocks,0) > 0)
%if !hasMdlBlks
%return
%endif
%assign mdlRefBlks = ::CompiledModel.ModelReferenceBlocks
%assign numMdlRefs = SIZE(mdlRefBlks,0)
%with ::CompiledModel
%foreach rowIdx = numMdlRefs
%assign mdlRefInfo = mdlRefBlks[rowIdx]
%assign mSysIdx = mdlRefInfo[0]
%assign bIdx = mdlRefInfo[1]
%assign mdlrefBlk = System[mSysIdx].Block[bIdx]
%assign interface = GetModelrefInterface(mdlrefBlk)
%<PropModelBlocksInfoToCompiledModel(interface, mdlrefBlk)>
%endforeach
%endwith
%endfunction
%function PropModelBlocksInfoToCompiledModel(blkInterface, mdlrefBlock) void
%if blkInterface.HasNonInlinedSfcn
%assign ::CompiledModel.ModelBlocksHaveNonInlinedSfcns = 1
%endif
%if blkInterface.FirstInitConditionReq
%assign ::CompiledModel.IsFirstInitCondMacroUsed = 1
%endif
%if blkInterface.FcnCallMdlRefTriggerTIDIsReq && ...
RTMMdlRefTriggerTIDMayBeRequired()
%assign ::CompiledModel.ModelBlockNeedsTriggerTID = 1
%endif
%if SLibIsERTCodeFormat()
%if IsModelReferenceTarget()
%with InheritedFunctionCallSystems
%assign numSystemsInBlk = SIZE(blkInterface.InheritedFcnCallSystems,1)
%assign numSystemsInModel = NumInheritedFunctionCallSystems
%if numSystemsInModel < 10
%assign numSlotsLeft = 10 - numSystemsInModel
%assign numSystemsToAdd = (numSlotsLeft < numSystemsInBlk) ? ...
numSlotsLeft : numSystemsInBlk
%foreach idx = numSystemsToAdd
%addtorecord ::CompiledModel.InheritedFunctionCallSystems ...
InheritedFunctionCallSystem %
%endforeach
%assign ::CompiledModel.InheritedFunctionCallSystems.NumInheritedFunctionCallSystems = ...
numSystemsInModel + numSystemsToAdd
%endif
%endwith
%endif
%if blkInterface.RequireMultiRateSampleHits
%if SLibSingleTasking() && !IsModelReferenceForASimstructBasedTarget()
%assign modelName = ::CompiledModel.Name
%assign refName = blkInterface.Name
%assign msg = FEVAL("DAStudio.message", ...
"Simulink:modelReference:multiTaskingInSingleTasking", ...
"%<modelName>", "%<refName>")
%<LibReportError("%<msg>")>
%endif
%assign ::CompiledModel.RequireMultiRateSampleHits = 1
%endif
%if blkInterface.StopReqAccessed
%assign ::CompiledModel.ModelBlocksUseStopReq = 1
%endif
%if blkInterface.ContTimeOutputInconsistentWithStateAtMajorStepAccessed
%assign ::CompiledModel.ModelBlocksUseContTimeOutputInconsistentWithStateAtMajorStep = 1
%endif
%assign origBlockFcn = ::BlockFcn
%foreach i = NumSampleTimes
%assign iChildTid = MapParentTID2ChildTID(mdlrefBlock, i)
%if iChildTid >= 0
%if blkInterface.ClockTicksReq[iChildTid]
%assign ::CompiledModel.ModelBlocksReqClockTicks[i] = 1
%if LibAsynchronousTriggeredTID(i)
%assign ::BlockFcn = "OutputUpdate"
%endif
%<SLibSetNeedAbsoluteTime(i)>
%if LibAsynchronousTriggeredTID(i)
%assign ::BlockFcn = origBlockFcn
%endif
%endif
%if blkInterface.LongClockTicksReq[iChildTid]
%assign ::CompiledModel.ModelBlocksReqLongClockTicks[i] = 1
%assert SLibNeedAbsoluteTimeForTID(i)
%endif
%if blkInterface.NeedFloatTime[iChildTid]
%<SLibSetNeedFloatAbsoluteTime(i)>
%endif
%endif
%endforeach
%foreach i = NumRuntimeExportedRates
%assign iChildTid = MapParentTID2ChildTID(mdlrefBlock, i)
%if iChildTid >= 0
%if blkInterface.RequireMultiRateSampleHits
%foreach j = NumRuntimeExportedRates
%assign jChildTid = MapParentTID2ChildTID(mdlrefBlock, j)
%if jChildTid >= 0
%if blkInterface.ActualRateInteraction[iChildTid][jChildTid]
%assign ::CompiledModel.MatrixOfRequireRateInteraction[i][j] = 1
%assign ::CompiledModel.RequireRateInteraction = TLC_TRUE
%endif
%endif
%endforeach
%endif
%endif
%endforeach
%endif
%assign subModelDecls = blkInterface.GlobalDSMDeclarations
%if(! ISEMPTY(subModelDecls))
%if(! ISFIELD(::CompiledModel, "SubModelGlobalDSMDeclarations"))
%addtorecord ::CompiledModel SubModelGlobalDSMDeclarations {}
%endif
%assign numDecls = SIZE(subModelDecls.DSMDeclaration, 1)
%foreach idx = numDecls
%assign decl = subModelDecls.DSMDeclaration[idx]
%addtorecord ::CompiledModel.SubModelGlobalDSMDeclarations Declarations %<decl>
%endforeach
%endif
%assign subModelSFcns = blkInterface.NonInlinedSFcnNames
%if(! ISEMPTY(subModelSFcns))
%if(! ISFIELD(::CompiledModel, "SubModelNonInlinedSFunctions"))
%addtorecord ::CompiledModel SubModelNonInlinedSFunctions {}
%endif
%assign numSFcns = SIZE(subModelSFcns.Function, 1)
%foreach idx = numSFcns
%assign sfcn = subModelSFcns.Function[idx]
%addtorecord ::CompiledModel.SubModelNonInlinedSFunctions Function %<sfcn>
%endforeach
%endif
%if blkInterface.NeedsGlobalTimingEngine
%assign ::tMdlRefTimingBridgeAccessed = TLC_TRUE
%endif
%if !blkInterface.SupportsMultiThreading
%assign ::CompiledModel.ContainsMultiThreadBlocker = 1
%endif
%if(ISFIELD(blkInterface, "CodeVariants"))
%assign subModelCodeVariants = blkInterface.CodeVariants
%if(! ISEMPTY(subModelCodeVariants))
%if(! ISFIELD(::CompiledModel, "SubModelCodeVariants"))
%addtorecord ::CompiledModel SubModelCodeVariants {}
%endif
%createrecord VariantData {}
%if(ISFIELD(subModelCodeVariants.VariantControl, "Variant"))
%assign numVariants = SIZE(subModelCodeVariants.VariantControl.Variant, 1)
%foreach idx = numVariants
%assign variant = subModelCodeVariants.VariantControl.Variant[idx]
%addtorecord VariantData Variant %<variant>
%endforeach
%endif
%addtorecord ::CompiledModel.SubModelCodeVariants VariantControl VariantData
%createrecord ParamData {}
%if(ISFIELD(subModelCodeVariants.VariantParameter, "Pair"))
%assign numParams = SIZE(subModelCodeVariants.VariantParameter.Pair, 1)
%foreach idx = numParams
%assign pair = subModelCodeVariants.VariantParameter.Pair[idx]
%addtorecord ParamData Pair %<pair>
%endforeach
%endif
%addtorecord ::CompiledModel.SubModelCodeVariants VariantParameter ParamData
%endif
%endif
%endfunction
%function GetBuildStartDir() Output
%assign buildStartDir = FEVAL("rtwprivate","rtwattic","getStartDir")
%return buildStartDir
%endfunction
%function CacheModelrefInterfaceInMatInfoFile(mdlref, type, interface) void
%if !IsModelReferenceTarget()
%assign targetType = "NONE"
%else
%assign targetType = IsModelReferenceSimTarget() ? "SIM" : "RTW"
%endif
%assign rtwinfomat = FEVAL("coder.internal.infoMATFileMgr", type,...
"binfo", "%<mdlref>", ...
"%<targetType>", interface)
%endfunction
%function LoadModelrefInterfaceInMatInfoFile(mdlref, buildStartDir)
%if IsModelReferenceSimTarget() || Accelerator || isRAccel
%assign targetType = "SIM"
%else
%assign targetType = "RTW"
%endif
%assign modelInterface = FEVAL("coder.internal.infoMATFileMgr", ...
"loadInterface", "binfo", mdlref, targetType)
%return modelInterface
%endfunction
%function LoadModelrefInterfaceInMatInfoFileSpecificTarget(mdlref, targetType)
%assign modelInterface = FEVAL("coder.internal.infoMATFileMgr", ...
"loadInterface", "binfo", mdlref, targetType)
%return modelInterface
%endfunction
%function LoadRTWInfoMatFileforTLC() void
%assign FILESEP = FEVAL("filesep")
%assign targetType = ::CompiledModel.ModelReferenceTargetType
%assign infoStruct = FEVAL("coder.internal.infoMATFileMgr", "loadforTLC", "binfo", LibGetModelName(), targetType)
%assign rootFolder = FEVAL("coder.internal.infoMATFileMgr", "getAnchorDir", "binfo", LibGetModelName(), targetType)
%addtorecord ::CompiledModel RTWInfoMatFile infoStruct
%assign ::CompiledModel.RTWInfoMatFile.sharedSourcesDir = FEVAL("fullfile", rootFolder, ::CompiledModel.RTWInfoMatFile.sharedSourcesDir, FILESEP)
%endfunction
%function GetModelrefHasMdlInitPort(blk)
%assert (TYPE(blk.Type) == "Identifier" && blk.Type == "ModelReference")
%if ISFIELD(blk.ParamSettings, "ModelEventPortNames")
%foreach mweIdx = SIZE(blk.ParamSettings.ModelEventPortNames, 1)
%if blk.ParamSettings.ModelEventPortNames[mweIdx] == "initialize"
%return TLC_TRUE
%endif
%endforeach
%endif
%return TLC_FALSE
%endfunction
%function GetModelrefHasMdlTermPort(blk)
%assert (TYPE(blk.Type) == "Identifier" && blk.Type == "ModelReference")
%if ISFIELD(blk.ParamSettings, "ModelEventPortNames")
%foreach mweIdx = SIZE(blk.ParamSettings.ModelEventPortNames, 1)
%if blk.ParamSettings.ModelEventPortNames[mweIdx] == "terminate"
%return TLC_TRUE
%endif
%endforeach
%endif
%return TLC_FALSE
%endfunction
%function GetModelrefHasMdlResetPort(blk)
%assert (TYPE(blk.Type) == "Identifier" && blk.Type == "ModelReference")
%if ISFIELD(blk.ParamSettings, "ModelEventPortTypes")
%foreach mweIdx = SIZE(blk.ParamSettings.ModelEventPortTypes, 1)
%if blk.ParamSettings.ModelEventPortTypes[mweIdx] == "RESET"
%return TLC_TRUE
%endif
%endforeach
%endif
%return TLC_FALSE
%endfunction
%function GetModelrefHasMdlPeriodicPort(blk)
%assert (TYPE(blk.Type) == "Identifier" && blk.Type == "ModelReference")
%if ISFIELD(blk.ParamSettings, "ModelEventPortTypes")
%foreach mweIdx = SIZE(blk.ParamSettings.ModelEventPortTypes, 1)
%if blk.ParamSettings.ModelEventPortTypes[mweIdx] == "PERIODIC"
%return TLC_TRUE
%endif
%endforeach
%endif
%return TLC_FALSE
%endfunction
%function GetChildFirstMdlEventTIDForEventType(blk, eventPortType)
%assert (TYPE(blk.Type) == "Identifier" && blk.Type == "ModelReference")
%if ISFIELD(blk.ParamSettings, "ModelEventPortTypes")
%foreach mweIdx = SIZE(blk.ParamSettings.ModelEventPortTypes, 1)
%if blk.ParamSettings.ModelEventPortTypes[mweIdx] == eventPortType
%return blk.ParamSettings.ModelEventPortTIDs[mweIdx]
%endif
%endforeach
%endif
%return -1
%endfunction
%function GetFcnCallParentTIDForChildTID(block, childTID)
%assign fcChildTidToParentMap = block.ParamSettings.ChildTidToParentTidMap
%assign numFcChildTids = SIZE(fcChildTidToParentMap, 1)/2
%foreach fcTID = numFcChildTids
%if childTID == fcChildTidToParentMap[fcTID]
%return fcChildTidToParentMap[fcTID + numFcChildTids]
%endif
%endforeach
%return -1
%endfunction
%function GetModelrefInterface(blk)
%assert (TYPE(blk.Type) == "Identifier" && blk.Type == "ModelReference")
%assign mdlName = blk.ParamSettings.ReferencedModelName
%assert(EXISTS(::CompiledModel.ModelReferenceInterfaces.%<mdlName>Interface))
%return ::CompiledModel.ModelReferenceInterfaces.%<mdlName>Interface
%endfunction
%function IsBaseSystem(system)
%assign isBase = 0
%if IsModelReferenceTarget()
%assign isBase = IsModelReferenceBaseSys(system)
%elseif system.Type == "root"
%assign isBase = 1
%endif
%return isBase
%endfunction
%function GetDataCFile()
%assign dataFile = SLibAddModelFile("SystemBody","Simulink", "%<Name>_data")
%return dataFile
%endfunction
%function GetPrivateHFile()
%assign privFile = SLibAddModelFile("SystemHeader","Simulink", "%<Name>_private")
%return privFile
%endfunction
%function skipCanonicalSideInput(aSystemInterace,function , aArgIdx) void
%assign ci = aSystemInterace.CanonicalInputArgDef[aArgIdx]
%assign isOutputFcn = TYPE(function)=="String" && (function == "OutputFcn" || function == "UpdateFcn" || function == "OutputUpdateFcn")
%return isOutputFcn && GenerateClassInterface && ci.ConnectedToSimulinkFunction == "yes" && !IsModelReferenceTarget()
%endfunction
%function skipCanonicalSideOutput(aSystemInterace,function , aArgIdx) void
%assign co = aSystemInterace.CanonicalOutputArgDef[aArgIdx]
%assign isOutputFcn = TYPE(function)=="String" && (function == "OutputFcn" || function == "UpdateFcn" || function == "OutputUpdateFcn")
%return isOutputFcn && GenerateClassInterface && co.ConnectedToSimulinkFunction == "yes" && !IsModelReferenceTarget()
%endfunction
%function IsMultiInstanceERTOrModelReference() void
%return MultiInstanceERTCode || IsModelReferenceTarget()
%endfunction
%function GetModelRefRegistrationFcnName() void
%return ::CompiledModel.System[GetBaseSystemIdx()].ModelInitializeFcn
%endfunction
%function CreateVectorWithValue(numElm, value)
%assign vec = []
%foreach idx = numElm
%assign vec = vec + value
%endforeach
%return vec
%endfunction
%function MapParentTID2ChildTID(block, parentTid)
%assign childTid = -1
%assign blockInterface = GetModelrefInterface(block)
%if ISFIELD(block.ParamSettings, "ChildTidToParentTidMap")
%assign childTidToParentMap = block.ParamSettings.ChildTidToParentTidMap
%if SLibNonInlinedIRTEventTID(parentTid) && ISFIELD(blockInterface, "ModelWideEvents")
%assign eventId = CompiledModel.SampleTime[parentTid].EventSourceName
%assign mwe = blockInterface.ModelWideEvents
%foreach mweIdx = SIZE(mwe,1)
%if SIZE(mwe,1) == 1
%assign subId = mwe.id
%assign subTid = mwe.tid
%else
%assign subId = mwe[mweIdx].id
%assign subTid = mwe[mweIdx].tid
%endif
%if ISEQUAL(subId, eventId)
%assign childTid = CAST("Number", subTid)
%break
%endif
%endforeach
%else
%assign numTids = SIZE(childTidToParentMap,1)/2
%foreach tidIdx = numTids
%if ISEQUAL(childTidToParentMap[tidIdx + numTids], parentTid)
%assign childTid = childTidToParentMap[tidIdx]
%break
%endif
%endforeach
%endif
%else
%assign blockTid = FcnEffectiveTid(block)
%if TYPE(blockTid) != "Identifier"
%if TYPE(blockTid) == "Number"
%if ISEQUAL(blockTid, parentTid)
%assign childTid = 0
%endif
%elseif TYPE(blockTid) == "Vector"
%foreach tidIdx = SIZE(blockTid,1)
%if ISEQUAL(blockTid[tidIdx], parentTid)
%assign childTid = tidIdx
%break
%endif
%endforeach
%else
%assert(0)
%endif
%endif
%endif
%return childTid
%endfunction
%function FcnMapTIDForRateGrouping(block, tid) void
%assign output_tid = tid
%if (TYPE(tid) == "Vector")
%assign output_tid = []
%foreach i = SIZE(tid,1)
%if tid[i] != -2
%assign output_tid = output_tid + tid[i]
%endif
%endforeach
%if TYPE(output_tid) == "Vector" && SIZE(output_tid,1) == 1
%assign output_tid = output_tid[0]
%endif
%assign intf = GetModelrefInterface(block)
%if (SIZE(output_tid, 1) == 2) && intf.Tid01Eq
%assign output_tid = 0
%endif
%endif
%return output_tid
%endfunction
%function GetNumberOfNoncontSignalsFeedingDerivPorts() void
%if ISFIELD(::CompiledModel,"SolverResetInfo")
%return ::CompiledModel.SolverResetInfo.NumNonContDerivSignals
%else
%return 0
%endif
%endfunction
%function HasNonContSigFeedingOutport() void
%assert (IsModelReferenceTarget())
%assign hasNonContOutput = TLC_FALSE
%if IsModelReferenceForASimstructBasedTarget()
%foreach idx = ::CompiledModel.ExternalOutputs.NumExternalOutputs
%if ::CompiledModel.ExternalOutputs.ExternalOutput[idx].NonContinuous
%assign hasNonContOutput = TLC_TRUE
%break
%endif
%endforeach
%endif
%return hasNonContOutput
%endfunction
%function GetNonContOutputPorts() void
%assert (IsModelReferenceTarget())
%assign nonContPorts = []
%if IsModelReferenceForASimstructBasedTarget()
%foreach idx = ::CompiledModel.ExternalOutputs.NumExternalOutputs
%if ::CompiledModel.ExternalOutputs.ExternalOutput[idx].NonContinuous
%assign numNonCont = ...
::CompiledModel.SolverResetInfo.NonContOutputSignals.NonContOutput[idx].NumNonContOutputSignals
%assign nonContPorts = nonContPorts + %<numNonCont>
%else
%assign nonContPorts = nonContPorts + 0
%endif
%endforeach
%endif
%return nonContPorts
%endfunction
%function SLibGetGlobalTimingBridge() void
%assert (IsModelReferenceTarget() || HasModelReferenceBlocks())
%assign ::tMdlRefTimingBridgeAccessed = TLC_TRUE
%if RTMTimingBridgeIsReqFcn()
%return RTMGet("timingBridge")
%else
%return ::tMdlRefTimingBridge
%endif
%endfunction
%function SLibModelNeedsTriggerTIDArg() void
%assert (IsModelReferenceTarget() || HasModelReferenceBlocks())
%return RTMMdlRefTriggerTIDIsReqFcn() || ...
::CompiledModel.ModelBlockNeedsTriggerTID
%endfunction
%function SLibMdlRefSystemPreprocessorCondition(block) void
%assign condition = ""
%assign condition = block.ParamSettings.NetPreprocessorCondition
%return condition
%endfunction
%function SLibMdlRefNetInlineVariantPreprocessorCondition(sysIdx, instIdx, blockIdx)
%assign vcRecord = SLibVariantConditionRecord()
%assign blockSystem = ::CompiledModel.System[sysIdx]
%assign block = ::CompiledModel.System[sysIdx].Block[blockIdx]
%assign localCond = ""
%assign netCond = ""
%assign localCond = block.VariantCondition
%assign conditions = blockSystem.NetInlineVariantPreprocessorInstanceConditions
%assign netCond = ISEMPTY(conditions) ? "" : conditions[instIdx]
%if !ISEMPTY(localCond)
%if ISEMPTY(netCond)
%assign netCond = localCond
%elseif !ISEQUAL(localCond,netCond)
%assign netCond = "(" + netCond + ") && (" + localCond + ")"
%endif
%endif
%if ISEMPTY(netCond)
%assign netCond = block.ParamSettings.NetPreprocessorCondition
%endif
%if !ISEMPTY(netCond)
%assign vcRecord.ifCond = "#if %<netCond>"
%assign vcRecord.endIfCond = "#endif"
%assign vcRecord.hasConds = TLC_TRUE
%endif
%return vcRecord
%endfunction
%function LibAppendToModelReferenceUserData(data) void
%if ! LibIsModelReferenceRTWTarget()
%assign errTxt = "To use LibAppendToModelReferenceUserData the target type must be RTW"
%<LibReportError(errTxt)>
%endif
%assign datatype = TYPE(data)
%if ( ISEQUAL(datatype, "Vector") || ISEQUAL(datatype, "Matrix"))
%assign errTxt = "To use LibAppendToModelReferenceUserData the data cannot be a matrix or vector. Instead, create a record with a field containing the vector or matrix data and pass this record into this function."
%<LibReportError(errTxt)>
%endif
%assign targetType = ::CompiledModel.ModelReferenceTargetType
%assign modelName = ::CompiledModel.Name
%assign infoStruct = FEVAL("coder.internal.infoMATFileMgr",...
"appendToUserData", "binfo", ...
"%<modelName>", "%<targetType>", data)
%endfunction
%function LibGetModelReferenceUserData(modelName)
%if LibIsModelReferenceSimTarget()
%assign errTxt = "To use LibGetModelReferenceUserData the target type cannot be SIM"
%<LibReportError(errTxt)>
%endif
%assign size = FEVAL("coder.internal.infoMATFileMgr", ...
"getUserDataSize", "binfo", "%<modelName>", "RTW")
%assign toReturn = []
%foreach idx = size
%assign midx = idx + 1
%assign data = FEVAL("coder.internal.infoMATFileMgr", ...
"getUserData", "binfo", "%<modelName>", "RTW", midx)
%assign toReturn = toReturn + data
%endforeach
%return toReturn
%endfunction
%function LibGetReferencedModelNames()
%if ! HasModelReferenceBlocks()
%createrecord toReturn { }
%addtorecord toReturn NumReferencedModels 0
%addtorecord toReturn ReferencedModel []
%return toReturn
%endif
%assign mdlRefBlks = ::CompiledModel.ModelReferenceBlocks
%assign numMdlRefs = SIZE(mdlRefBlks,0)
%createrecord modelNames { }
%foreach rowIdx = numMdlRefs
%assign mdlRefInfo = mdlRefBlks[rowIdx]
%assign mSysIdx = mdlRefInfo[0]
%assign bIdx = mdlRefInfo[1]
%assign mdlrefBlk = ::CompiledModel.System[mSysIdx].Block[bIdx]
%assign mdlName = mdlrefBlk.ParamSettings.ReferencedModelName
%if !ISFIELD(modelNames, mdlName)
%addtorecord modelNames %<mdlName> 1
%endif
%endforeach
%assign modelNames = FIELDNAMES(modelNames)
%assign numModelNames = SIZE(modelNames, 1)
%createrecord toReturn { }
%addtorecord toReturn NumReferencedModels numModelNames
%foreach nameIdx = numModelNames
%assign modelName = modelNames[nameIdx]
%addtorecord toReturn ReferencedModel { Name "%<modelName>"}
%endforeach
%return toReturn
%endfunction
%function SLibGetSubsysDWorkForCPPMdlRefBlk(blk) void
%assert GenerateClassInterface
%assert blk.Type == "ModelReference"
%assert blk.MdlRefIsCPPClassGenMode
%assert ISFIELD(blk,"CPPObjDWorkIdxInSubsys")
%assign sys = ::CompiledModel.System[blk.BlockIdx[0]]
%assign callSite = sys.CallSites[0]
%assign graphicalSys = ::CompiledModel.System[callSite[2]]
%assign subsysBlk = graphicalSys.Block[callSite[3]]
%assign dworkIdx = subsysBlk.DWork[blk.CPPObjDWorkIdxInSubsys].FirstRootIdx
%return ::CompiledModel.DWorks.DWork[dworkIdx]
%endfunction
%function SLibGetCPPMdlRefObjName(sysIdx,blkIdx) void
%assert GenerateClassInterface
%assert System[sysIdx].Block[blkIdx].Type == "ModelReference"
%assert System[sysIdx].Block[blkIdx].MdlRefIsCPPClassGenMode
%assign blk = System[sysIdx].Block[blkIdx]
%assign blkInterface = GetModelrefInterface(blk)
%if ISFIELD(blk,"CPPObjDWorkIdxInSubsys") && !blkInterface.IsScalableBuild
%assign dwRec = SLibGetSubsysDWorkForCPPMdlRefBlk(blk)
%return LibGetRecordIdentifier(dwRec)
%endif
%assign mdlRefBlks = ISFIELD(::CompiledModel,"ModelReferenceBlocks") ? ...
::CompiledModel.ModelReferenceBlocks : []
%assign mdlRefBlkInd = -1
%if !ISEMPTY(mdlRefBlks)
%foreach rowIdx = SIZE(mdlRefBlks,0)
%assign mdlRefInfo = mdlRefBlks[rowIdx]
%assign mSysIdx = mdlRefInfo[0]
%assign bIdx = mdlRefInfo[1]
%if mSysIdx == sysIdx && bIdx == blkIdx
%assign mdlRefBlkInd = rowIdx
%break
%endif
%endforeach
%endif
%assign mdlRefInstCPPVar = ::CompiledModel.ModelBlock[mdlRefBlkInd].MdlRefInstanceVarName
%return mdlRefInstCPPVar
%endfunction
%function FcnGetModelBlockDWorkCategory(aBlock) void
%assign dworkIdx = SLibGetStructDWorkIdxForModelRefBlk(aBlock)
%assign dwRec = ::CompiledModel.DWorks.DWork[aBlock.DWork[dworkIdx].FirstRootIdx]
%assign dwRecVarGroupIdx = dwRec.VarGroupIdx[0]
%assign dwRecVarGroup = ::CompiledModel.VarGroups.VarGroup[dwRecVarGroupIdx]
%if LibGetVarGroupCategory(dwRecVarGroupIdx) == "DWork"
%assign category = "DWork"
%elseif LibGetVarGroupCategory(dwRecVarGroupIdx) == "HierarchicalCoderData"
%assign category = "CoderDataGroup" + ::CompiledModel.CoderDataGroup[dwRecVarGroup.CoderDataGroupIndex].Name
%else
%assign category = LibGetVarGroupCategory(dwRecVarGroupIdx)
%endif
%return category
%endfunction
%function SLibCalcMdlRefObjSubsysAccessPath(sysIdx,blkIdx,instIdx,sysFcn) void
%assert GenerateClassInterface
%assert System[sysIdx].Block[blkIdx].Type == "ModelReference"
%assert System[sysIdx].Block[blkIdx].MdlRefIsCPPClassGenMode
%assert !LibSystemIsRoot(System[sysIdx]) && ...
!IsModelReferenceBaseSys(System[sysIdx])
%assign locCacheBlockFcn = ::BlockFcn
%assign ::BlockFcn = sysFcn
%assign dworkIdx = SLibGetStructDWorkIdxForModelRefBlk(System[sysIdx].Block[blkIdx])
%assign category = FcnGetModelBlockDWorkCategory(System[sysIdx].Block[blkIdx])
%assign varGroupIdx = FcnSysVarGroupIndex(System[sysIdx], category, instIdx)
%assign baseSysIdx = GetBaseSystemIdx()
%if ISFIELD(System[sysIdx].Block[blkIdx],"ModelInstVarGroupIndex") && ...
System[sysIdx].Block[blkIdx].ModelInstVarGroupIndex > -1
%assign dworkPath = ...
SLibCGIRVarGroupPath(System[sysIdx].Block[blkIdx].ModelInstVarGroupIndex,GetBaseSystemIdx(),TLC_FALSE)
%else
%assign dworkPath = SLibCGIRVarGroupPath(varGroupIdx, baseSysIdx, ...
System[sysIdx].CrossNoArgFcnBound)
%endif
%assign mdlRefInstCPPVar = ...
SLibGetCPPMdlRefObjName(System[sysIdx].SystemIdx,...
System[sysIdx].Block[blkIdx].BlockIdx[2])
%assign cppVarPath = dworkPath + mdlRefInstCPPVar
%assign ::BlockFcn = locCacheBlockFcn
%return cppVarPath
%endfunction
%function SLibModelHierarchyContainsNoninlinedSfcn()
%if ::CompiledModel.NumChildSFunctions > 0 || ...
::CompiledModel.ModelBlocksHaveNonInlinedSfcns
%return TLC_TRUE
%else
%return TLC_FALSE
%endif
%endfunction
%function GetAcceleratorStringForFunction(sysFcn) void
%assign accFunction = ""
%switch (sysFcn)
%case "Initialize"
%assign accFunction = "SS_CALL_MDL_INITIALIZE_CONDITIONS"
%break
%case "SetupRuntimeResources"
%assign accFunction = "SS_CALL_MDL_SETUP_RUNTIME_RESOURCES"
%break
%case "Enable"
%assign accFunction = "SS_CALL_RTW_GENERATED_ENABLE"
%break
%case "Disable"
%assign accFunction = "SS_CALL_RTW_GENERATED_DISABLE"
%break
%case "Output"
%case "OutputUpdate"
%assign accFunction = "SS_CALL_MDL_OUTPUTS"
%break
%case "Update"
%assign accFunction = "SS_CALL_MDL_UPDATE"
%break
%case "FinalizeDims"
%assign accFunction = "SS_CALL_MDL_FINALIZE_ALL_DIMS"
%break
%case "ZeroCrossing"
%assign accFunction = "SS_CALL_MDL_ZERO_CROSSINGS"
%break
%case "Projection"
%assign accFunction = "SS_CALL_MDL_PROJECTION"
%break
%case "Derivative"
%assign accFunction = "SS_CALL_MDL_DERIVATIVES"
%break
%case "ForcingFunction"
%assign accFunction = "SS_CALL_MDL_FORCINGFUNCTION"
%break
%case "MassMatrix"
%assign accFunction = "SS_CALL_MDL_MASSMATRIX"
%break
%case "Terminate"
%assign accFunction = "SS_CALL_MDL_TERMINATE"
%break
%case "CleanupRuntimeResources"
%assign accFunction = "SS_CALL_MDL_CLEANUP_RUNTIME_RESOURCES"
%break
%endswitch
%return accFunction
%endfunction
%function SLibSerializeFcnArgs(recArgs)
%assign fcnArgs = ""
%foreach idx = SIZE(recArgs,1)
%if idx == 0
%assign fcnArgs = recArgs[idx]
%else
%assign fcnArgs = fcnArgs + ", %"
%endif
%endforeach
%return fcnArgs
%endfunction
%function SLibGetModelArgumentIdentifier(canPrmDef, canPrmIdx)
%if (canPrmDef.IsUsed == "no")
%assign ident = LibGetRecordIdentifier(canPrmDef)
%else
%assign baseIdx = GetBaseSystemIdx()
%assign callSite = System[baseIdx].CallSites[0]
%assign ssBlk = System[callSite[2]].Block[callSite[3]]
%assign childPrmIdx = ...
ssBlk.CallSiteInfo.CanonicalPrmArg[canPrmIdx].ChildPrmArgIdx
%assign canPrm = SLibGetCallSitePrmArg(callSite, childPrmIdx)
%assign ident = LibGetRecordIdentifier(canPrm.ASTNode)
%endif
%return ident
%endfunction
%function SLibGetModelRefGlobalDSMDeclarations() void
%createrecord dsmDeclarations {}
%assign numDWorks = DWorks.NumDWorks
%foreach idx = numDWorks
%assign dwork = DWorks.DWork[idx]
%if dwork.GlobalDSM
%assign type = SLibGetRecordContainerTypeName(dwork)
%assign wide = LibOptionalVectorWidth(LibGetRecordWidth(dwork))
%assign name = dwork.SFcnWrapperDSMName
%assign declaration = "%<type> %<name>%<wide>;"
%addtorecord dsmDeclarations DSMDeclaration { ...
Name STRING(name) ...
Declaration STRING(declaration) ...
ExternNeeded TLC_TRUE ...
}
%endif
%endforeach
%if(ISFIELD(::CompiledModel, "SubModelGlobalDSMDeclarations"))
%assign submodelDecls = ::CompiledModel.SubModelGlobalDSMDeclarations
%assign numDecls = SIZE(submodelDecls.Declarations, 1)
%foreach idx = numDecls
%assign decl = submodelDecls.Declarations[idx]
%assign decl.ExternNeeded = TLC_FALSE
%addtorecord dsmDeclarations DSMDeclaration %<decl>
%endforeach
%endif
%return dsmDeclarations
%endfunction
%function SLibSetModelRefCacheFcnCallInputInfo(portIdx, fcnType, taskName, tid, isAsync, groupIdx, dworkIdx, portName) void
%assert IsModelReferenceTarget() || Accelerator || SLibHasFcnCallRootInport()
%assign mdlRefSys = ::CompiledModel.System[GetBaseSystemIdx()]
%if !LibIsSystemField(mdlRefSys, "FcnCallInputInfo")
%createrecord fcnCallInfo {}
%<LibAddToSystem(mdlRefSys, "FcnCallInputInfo", fcnCallInfo)>
%endif
%assign currField = LibGetSystemField(mdlRefSys, "FcnCallInputInfo")
%if fcnType == "OutputUpdate"
%assign fcnType = "Output"
%endif
%if !ISEMPTY(currField)
%foreach idx = SIZE(currField.FcnCallInfo, 1)
%assign info = currField.FcnCallInfo[idx]
%if info.TaskName == taskName
%return
%endif
%endforeach
%endif
%addtorecord currField FcnCallInfo { ...
FcnType STRING(fcnType); ...
TaskName STRING(taskName); ...
TID tid;...
PortIdx portIdx;...
isAsync isAsync;...
FcnCallPortGroupIndex groupIdx;...
dworkIndex dworkIdx;...
PortName STRING(portName)}
%<LibSetSystemField(mdlRefSys, "FcnCallInputInfo", currField)>
%endfunction
%function SLibSetModelRefCachePeriodicFcnCallInputInfo(portIdx, fcnType, fcnName, tid, dworkIndex, portName) void
%<SLibSetModelRefCacheFcnCallInputInfo(portIdx, fcnType, fcnName, tid, TLC_FALSE, -1, dworkIndex, portName)>
%endfunction
%function SLibSetModelRefCacheAsyncFcnCallInputInfo(taskName, portIdx, tid, fcnType, groupIndex, dworkIndex, portName) void
%<SLibSetModelRefCacheFcnCallInputInfo(portIdx, fcnType, taskName, tid, TLC_TRUE, groupIndex, dworkIndex, portName)>
%endfunction
%function ModelBlockHasAsyncInput(tid, block) void
%return block.ParamSettings.HasAsyncFcnCallInput && ...
LibAsynchronousTriggeredTID(tid) && ...
!SLibNonInlinedModelWideEventTID(tid)
%endfunction
%function SLibIsModelRefAsyncTID(tid)
%return IsModelReferenceTarget() && LibAsynchronousTriggeredTID(tid)
%endfunction
%function SLibCreateWrapperForModelBlockFCI(modelBlock, fcnType) void
%if !ISFIELD(modelBlock.WrapperFcns, "%<fcnType>")
%return ""
%endif
%assign fcnBuffers = modelBlock.WrapperFcns.%<fcnType>
%assign locSS = RTMGetModelSS()
%assign args = ::tSimStructType + " *const " + locSS
%assign args = args + ", int_T " + ::tControlPortIdx
%assign args = args + ", int_T " + ::tTID
%openfile fcnBuf
%foreach idx = SIZE(fcnBuffers,1)
%assign fcnBuffer = modelBlock.WrapperFcns.%<fcnType>[idx]
%assign tid = CAST("Number", fcnBuffer.TID)
%assign isAsync = fcnBuffer.isAsync
%assign fcnPortIdx = fcnBuffer.FcnPortIdx
/*
* Force non-inlined (FNI) function call stub
* for '%<modelBlock.Name>'
*/
ssFcnCallErr_T %<fcnBuffer.FcnName>(%<args>) {
%if isAsync && ...
fcnPortIdx < modelBlock.NumDataInputPorts && ...
modelBlock.ParamSettings.IsTopAsync[fcnBuffer.FcnCallPortGroupIndex] && ...
fcnType == "OutputUpdate"
%<SLibDumpOutputUpdateCodeForAsyncTid(tid)>/
%elseif ISFIELD(modelBlock, "CallerBlkInfo") && ...
modelBlock.CallerBlkInfo[fcnPortIdx].CallerBlkPortEl >= 0
%assign callerBlkIdx = modelBlock.CallerBlkInfo[fcnPortIdx].CallerBlkIdx
%assign sfcnBlkEl = modelBlock.CallerBlkInfo[fcnPortIdx].CallerBlkPortEl
%assign sfcnBlk = System[callerBlkIdx[0]].Block[callerBlkIdx[2]]
%<SLibBlockExecuteSysFcn(sfcnBlk, sfcnBlkEl, fcnType)>/
%else
%<CallModelBlockAsyncFcnCallInput(modelBlock, fcnBuffer.FcnPortIdx, ...
tid, fcnType)>/
%endif
return SS_FCNCALL_NO_ERR;
}
%endforeach
%closefile fcnBuf
%return fcnBuf
%endfunction
%function SLibGenerateFNIStubsForModelBlocks() void
%openfile fcnBuff
%foreach idIdx = ::CompiledModel.NumModelReferenceBlocks
%assign blkIdx = ::CompiledModel.ModelReferenceBlocks[idIdx]
%assign mdlBlock = ::CompiledModel.System[blkIdx[0]].Block[blkIdx[1]]
%if ISFIELD(mdlBlock, "WrapperFcns")
%<SLibCreateWrapperForModelBlockFCI(mdlBlock, "OutputUpdate")>/
%<SLibCreateWrapperForModelBlockFCI(mdlBlock, "Enable")>/
%<SLibCreateWrapperForModelBlockFCI(mdlBlock, "Disable")>/
%endif
%endforeach
%closefile fcnBuff
%return fcnBuff
%endfunction
%function SLibCallModelBlockFcnCallInput(blkFcn, sysIdx, blkIdx, portIdx, ...
tid, callTaskTopBlk, modIdx, fcnIdx, blkFcnIdx) void
%assign isOutputs = (blkFcn == "Outputs")
%assign prevGenOutputs = ::CompiledModel.GeneratingOutputsCode
%assign prevBlockFcnIdx = ::CurrentBlockFcnIdx
%assign prevModuleIdx = ::CurrentModuleIdx
%assign prevFunctionIdx = ::CurrentFunctionIdx
%assign prevRollThreshold = ::CompiledModel.RollThreshold
%assign ::CurrentBlockFcnIdx = blkFcnIdx
%assert ::CurrentModuleIdx == modIdx
%assign ::CurrentModuleIdx = modIdx
%assert ::CurrentFunctionIdx == fcnIdx
%assign ::CurrentFunctionIdx = fcnIdx
%assign ::CompiledModel.GeneratingOutputsCode = isOutputs
%openfile fcnBuff
%if callTaskTopBlk
%assign blkIdx = [%<sysIdx>, %<blkIdx>, %<portIdx>]
%assign taskTopBlock = FcnGetTaskTopSfcnBlock(tid)
%<SLibGetAsyncSysCodeForTaskTopBlk(taskTopBlock, tid, ...
"ModelReference", blkIdx)>/
%else
%assign system = System[sysIdx]
%with system
%assign block = Block[blkIdx]
%if isOutputs
%assign block.OutputBlockFcnIdx = blkFcnIdx
%endif
%with block
%assign blkcode = CallModelBlockAsyncFcnCallInput(block, portIdx, tid, blkFcn)
%if !ISEMPTY(blkcode)
%<SLibIfVariantCondition(block)>
%<CallModelBlockAsyncFcnCallInput(block, portIdx, tid, blkFcn)>/
%<SLibEndIfVariantCondition(block)>
%endif
%endwith
%endwith
%endif
%closefile fcnBuff
%assign ::CompiledModel.GeneratingOutputsCode = prevGenOutputs
%assign ::CurrentModuleIdx = prevModuleIdx
%assign ::CurrentFunctionIdx = prevFunctionIdx
%assign ::CurrentBlockFcnIdx = prevBlockFcnIdx
%return fcnBuff
%endfunction
%function SLibGetModelBlockFcnCallInputInfo(block, portIdx, fcnType) void
%assign blockInterface = GetModelrefInterface(block)
%assign fcnCallInfo = []
%if fcnType == "OutputUpdate"
%assign fcnType = "Output"
%endif
%assert (portIdx != -1)
%if ISFIELD(blockInterface, "FcnCallInputs")
%foreach idx = SIZE(blockInterface.FcnCallInputs, 1)
%assign locCallInfo = blockInterface.FcnCallInputs[idx]
%if locCallInfo.PortIdx == portIdx && ...
locCallInfo.FcnType == fcnType
%assign fcnCallInfo = locCallInfo
%break
%endif
%endforeach
%endif
%return fcnCallInfo
%endfunction
%function CallModelBlockInitializePortFunction(block, blockInterface, localTid) void
%assign fcnCall = ""
%if ISFIELD(blockInterface, "RegistrationFcn")
%assign fcnCall = fcnCall + SLibCallModelBlockFunction([], block, ...
"RegistrationFcn", blockInterface, ...
blockInterface.RegistrationFcn, 0, localTid, 0, "")
%endif
%if ISFIELD(block.ParamSettings, "InitRestoreDataDWorkIdx")
%assign restoreDataDWorkIdx = block.ParamSettings.InitRestoreDataDWorkIdx
%assert(restoreDataDWorkIdx != -1)
%if SLibModelBlockRTMAllocateInParent(block, blockInterface)
%assign rtmArg = block.Identifier
%assign fcnCall = fcnCall + ...
"memcpy((void *) &(%<rtmArg>), " + ...
"(void *) &(%<LibBlockDWork(block.DWork[restoreDataDWorkIdx],"","",0)>.rtm), " + ...
"sizeof(%<rtmArg>));"
%else
%assign fcnCall = fcnCall + ...
"memcpy((void *) &(%<LibBlockDWork(block.DWork[0],"","",0)>), " + ...
"(void *) &(%<LibBlockDWork(block.DWork[restoreDataDWorkIdx],"","",0)>), " + ...
"sizeof(%<LibBlockDWork(block.DWork[0],"","",0)>));/n"
%endif
%endif
%if blockInterface.HasPrivateDWork
%assign mdlName = block.ParamSettings.ReferencedModelName
%assign fcnCall = fcnCall + ...
SLibGetCopyFromInitRestoreDataFcnNameForModel(mdlName) + "();"
%endif
%with block
%assign needIterVar = TLC_FALSE
%foreach portIdx = NumDataOutputPorts
%if LibBlockOutputSignalWidth(portIdx) > 1
%assign needIterVar = TLC_TRUE
%break
%endif
%endforeach
%assign fcnCall = fcnCall + "{/n"
%assign iterVar = "i_%_%"
%if needIterVar
%assign fcnCall = fcnCall + "int_T %<iterVar>;/n"
%endif
%foreach portIdx = NumDataOutputPorts
%assign dTypeId = LibBlockOutputSignalAliasedThruDataTypeId(portIdx)
%assign groundVal = LibGetGroundValueFromId(dTypeId)
%assign portWidth = LibBlockOutputSignalWidth(portIdx)
%assign isComplex = LibBlockOutputSignalIsComplex(portIdx)
%if portWidth > 1
%assign fcnCall = fcnCall + ...
"for (%<iterVar> = 0; %<iterVar> < %<portWidth>; %<iterVar>++) {/n"
%if isComplex
%assign fcnCall = fcnCall + ...
"%<LibBlockOutputSignal(portIdx, iterVar, "", 0)>.re = %<groundVal>;/n"
%assign fcnCall = fcnCall + ...
"%<LibBlockOutputSignal(portIdx, iterVar, "", 0)>.im = %<groundVal>;/n"
%else
%assign fcnCall = fcnCall + ...
"%<LibBlockOutputSignal(portIdx, iterVar, "", 0)> = %<groundVal>;/n"
%endif
%assign fcnCall = fcnCall + "}/n"
%else
%if isComplex
%assign fcnCall = fcnCall + ...
"%<LibBlockOutputSignal(portIdx, "", "", 0)>.re = %<groundVal>;/n"
%assign fcnCall = fcnCall + ...
"%<LibBlockOutputSignal(portIdx, "", "", 0)>.im = %<groundVal>;/n"
%else
%assign fcnCall = fcnCall + ...
"%<LibBlockOutputSignal(portIdx, "", "", 0)> = %<groundVal>;/n"
%endif
%endif
%endforeach
%assign fcnCall = fcnCall + "}/n"
%endwith
%if ISFIELD(blockInterface, "StartFcn")
%assign fcnCall = fcnCall + SLibCallModelBlockFunction([], block, ...
"StartFcn", blockInterface, ...
blockInterface.StartFcn, 0, localTid, 0, "")
%endif
%if ISFIELD(blockInterface, "SystemInitializeFcn")
%assign fcnCall = fcnCall + SLibCallModelBlockFunction([], block, ...
"SystemInitializeFcn", ...
blockInterface, ...
blockInterface.SystemInitializeFcn, 0, localTid, 0, "")
%endif
%if ISFIELD(blockInterface, "EnableFcn")
%assign fcnCall = fcnCall + SLibCallModelBlockFunction([], block, ...
"EnableFcn", blockInterface, ...
blockInterface.EnableFcn, 0, localTid, 0, "")
%endif
%assign prmEventFcnInfo = GetModelWideEventFcnInfo( ...
blockInterface, "ParameterChangeEvent", "")
%if prmEventFcnInfo.eventTid != -1 && !ISEMPTY(prmEventFcnInfo.fcnName)
%assign fcnCall = fcnCall + SLibCallModelBlockFunction([], block, ...
"OutputFcn", blockInterface, ...
GETFIELD(blockInterface, prmEventFcnInfo.fcnName), 0, prmEventFcnInfo.eventTid, 0, "")
%endif
%assign initStatDWorkIdx = block.ParamSettings.InitStatusDWorkIdx
%assign fcnCall = fcnCall + "%<LibBlockDWork(block.DWork[initStatDWorkIdx],"","",0)> = 1U;/n"
%return fcnCall
%endfunction
%function GetModelWideEventFcnInfo(blockInterface, eventType, eventID) void
%assign tid = -1
%assign fcn = ""
%if ISFIELD(blockInterface, "ModelWideEvents")
%foreach mweIdx = SIZE(blockInterface.ModelWideEvents, 1)
%if (eventType == blockInterface.ModelWideEvents[mweIdx].eventType) && ...
((eventType != "ResetEvent" && eventType != "ResetWithInitEvent") || ...
eventID == blockInterface.ModelWideEvents[mweIdx].id)
%assign tid = blockInterface.ModelWideEvents[mweIdx].tid
%assign outFcn = "OutputTID" + SPRINTF("%d", tid) + "Fcn"
%assign outUpdateFcn = "OutputUpdateTID" + SPRINTF("%d", tid) + "Fcn"
%if ISFIELD(blockInterface, outFcn)
%assign fcn = outFcn
%elseif ISFIELD(blockInterface, outUpdateFcn)
%assign fcn = outUpdateFcn
%endif
%break
%endif
%endforeach
%endif
%createrecord retVal {eventTid tid; fcnName fcn}
%return retVal
%endfunction
%function CallModelBlockTerminatePortFunction(block, blockInterface, localTid) void
%assign fcnCall = ""
%assign termInfo = GetModelWideEventFcnInfo(blockInterface, "PowerDownEvent", "")
%if termInfo.eventTid != -1 && !ISEMPTY(termInfo.fcnName)
%assign fcnCall = fcnCall + SLibCallModelBlockFunction([], block, ...
"OutputFcn", blockInterface, ...
GETFIELD(blockInterface, termInfo.fcnName), 0, termInfo.eventTid, 0, "")
%endif
%if ISFIELD(blockInterface, "TerminateFcn")
%assign fcnCall = fcnCall + SLibCallModelBlockFunction([], block, ...
"TerminateFcn", blockInterface, ...
blockInterface.TerminateFcn, 0, localTid, 0, "")
%endif
%assign initStatDWorkIdx = block.ParamSettings.InitStatusDWorkIdx
%assign fcnCall = fcnCall + "%<LibBlockDWork(block.DWork[initStatDWorkIdx],"","",0)> = 0U;/n"
%return fcnCall
%endfunction
%function CallModelBlockResetPortFunction(block, blockInterface, eventPortName, localTid) void
%assign fcnCall = ""
%assign resetInfo = GetModelWideEventFcnInfo(blockInterface, "ResetEvent", eventPortName)
%if resetInfo.eventTid != -1 && !ISEMPTY(resetInfo.fcnName)
%assign fcnCall = fcnCall + SLibCallModelBlockFunction([], block, ...
"OutputFcn", blockInterface, ...
GETFIELD(blockInterface, resetInfo.fcnName), 0, resetInfo.eventTid, 0, "")
%else
%assign resetWithInitInfo = GetModelWideEventFcnInfo(blockInterface, "ResetWithInitEvent", eventPortName)
%if resetWithInitInfo.eventTid != -1 && !ISEMPTY(resetWithInitInfo.fcnName)
%assign fcnCall = fcnCall + SLibCallModelBlockFunction([], block, ...
"OutputFcn", blockInterface, ...
GETFIELD(blockInterface, resetWithInitInfo.fcnName), 0, resetWithInitInfo.eventTid, 0, "")
%endif
%endif
%assign prmEventFcnInfo = GetModelWideEventFcnInfo( ...
blockInterface, "ParameterChangeEvent", "")
%if prmEventFcnInfo.eventTid != -1 && !ISEMPTY(prmEventFcnInfo.fcnName)
%assign fcnCall = fcnCall + SLibCallModelBlockFunction([], block, ...
"OutputFcn", blockInterface, ...
GETFIELD(blockInterface, prmEventFcnInfo.fcnName), 0, prmEventFcnInfo.eventTid, 0, "")
%endif
%return fcnCall
%endfunction
%function CallModelBlockOutputUpdateFunction( ...
block, blockInterface, childTID, useTIDinFcnName) void
%assign fcnCall = ""
%if useTIDinFcnName
%assign outputUpdateFcn = "OutputUpdateTID" + SPRINTF("%d", childTID) + "Fcn"
%else
%assign outputUpdateFcn = "OutputUpdateFcn"
%endif
%if ISFIELD(blockInterface, outputUpdateFcn)
%assign fcnCall = fcnCall + SLibCallModelBlockFunction([], block, "OutputUpdateFcn", ...
blockInterface, GETFIELD(blockInterface, outputUpdateFcn), 0, childTID, 0,"")
%else
%if useTIDinFcnName
%assign outputFcn = "OutputTID" + SPRINTF("%d", childTID) + "Fcn"
%else
%assign outputFcn = "OutputFcn"
%endif
%if ISFIELD(blockInterface, outputFcn)
%assign fcnCall = fcnCall + SLibCallModelBlockFunction([], block, "OutputFcn", ...
blockInterface, GETFIELD(blockInterface, outputFcn), 0, childTID, 0,"")
%endif
%if useTIDinFcnName
%assign updateFcn = "UpdateTID" + SPRINTF("%d", childTID) + "Fcn"
%else
%assign updateFcn = "UpdateFcn"
%endif
%if ISFIELD(blockInterface, updateFcn)
%assign fcnCall = fcnCall + SLibCallModelBlockFunction([], block, "UpdateFcn", ...
blockInterface, GETFIELD(blockInterface, updateFcn), 0, childTID, 0,"")
%endif
%endif
%return fcnCall
%endfunction
%function CallModelBlockPeriodicEventPortFunction(block, blockInterface, childTID) void
%assign fcnCall = ...
CallModelBlockOutputUpdateFunction(block, blockInterface, childTID, TLC_TRUE)
%if ISEMPTY(fcnCall) && childTID == 0
%assign fcnCall = ...
CallModelBlockOutputUpdateFunction(block, blockInterface, childTID, TLC_FALSE)
%endif
%return fcnCall
%endfunction
%function CallModelBlockModelEventPortFunction(block, eventPortName, eventPortType, localTid) void
%assign fcnCall = ""
%assign blockInterface = GetModelrefInterface(block)
%if eventPortType == "INITIALIZE"
%if ISFIELD(block.ParamSettings, "InitStatusDWorkIdx")
%assign initStatDWorkIdx = block.ParamSettings.InitStatusDWorkIdx
%assert(initStatDWorkIdx != -1)
%assign fcnCall = fcnCall + "if (%<LibBlockDWork(block.DWork[initStatDWorkIdx],"","",0)> == 1U) {/n"
%if !GetModelrefHasMdlTermPort(block)
%assign fcnCall = fcnCall + ...
CallModelBlockTerminatePortFunction(block, blockInterface, localTid)
%else
%assign fcnCall = fcnCall + ...
"void *errMsg = CreateDiagnosticAsVoidPtr_wrapper(/n" + ...
"/"Simulink:FcnCall:InvalidMdlInitFcnCall/", 2,/n" + ...
"CODEGEN_SUPPORT_ARG_STRING_TYPE, /"%<LibGetFormattedBlockPath(block)>/",/n" + ...
"CODEGEN_SUPPORT_ARG_REAL_TYPE, %<LibGetT()>);/n"
%assign fcnCall = fcnCall + "_ssSet_slErrMsg(%<::tSimStruct>, errMsg);/n"
%assign fcnCall = fcnCall + "return;/n"
%endif
%assign fcnCall = fcnCall + "}/n"
%endif
%assign fcnCall = fcnCall + ...
CallModelBlockInitializePortFunction(block, blockInterface, localTid)
%elseif eventPortType == "TERMINATE"
%if ISFIELD(block.ParamSettings, "InitStatusDWorkIdx")
%assign initStatDWorkIdx = block.ParamSettings.InitStatusDWorkIdx
%assert(initStatDWorkIdx != -1)
%assign fcnCall = fcnCall + "if (%<LibBlockDWork(block.DWork[initStatDWorkIdx],"","",0)> == 0U) {/n"
%assign fcnCall = fcnCall + ...
"void *errMsg = CreateDiagnosticAsVoidPtr_wrapper(/n" + ...
"/"Simulink:FcnCall:InvalidMdlTermFcnCall/", 2,/n" + ...
"CODEGEN_SUPPORT_ARG_STRING_TYPE, /"%<LibGetFormattedBlockPath(block)>/",/n" + ...
"CODEGEN_SUPPORT_ARG_REAL_TYPE, %<LibGetT()>);/n"
%assign fcnCall = fcnCall + "_ssSet_slErrMsg(%<::tSimStruct>, errMsg);/n"
%assign fcnCall = fcnCall + "return;/n"
%assign fcnCall = fcnCall + "}/n"
%endif
%assign fcnCall = fcnCall + ...
CallModelBlockTerminatePortFunction(block, blockInterface, localTid)
%elseif eventPortType == "RESET"
%if ISFIELD(block.ParamSettings, "InitStatusDWorkIdx")
%assign initStatDWorkIdx = block.ParamSettings.InitStatusDWorkIdx
%assert(initStatDWorkIdx != -1)
%assign fcnCall = fcnCall + "if (%<LibBlockDWork(block.DWork[initStatDWorkIdx],"","",0)> == 0U) {/n"
%assign fcnCall = fcnCall + ...
"void *errMsg = CreateDiagnosticAsVoidPtr_wrapper(/n" + ...
"/"Simulink:FcnCall:InvalidMdlResetFcnCall/", 3,/n" + ...
"CODEGEN_SUPPORT_ARG_STRING_TYPE, /"%<eventPortName>/",/n" + ...
"CODEGEN_SUPPORT_ARG_STRING_TYPE, /"%<LibGetFormattedBlockPath(block)>/",/n" + ...
"CODEGEN_SUPPORT_ARG_REAL_TYPE, %<LibGetT()>);/n"
%assign fcnCall = fcnCall + "_ssSet_slErrMsg(%<::tSimStruct>, errMsg);/n"
%assign fcnCall = fcnCall + "return;/n"
%assign fcnCall = fcnCall + "}/n"
%endif
%assign fcnCall = fcnCall + ...
CallModelBlockResetPortFunction(block, blockInterface, eventPortName, localTid)
%else
%if ISFIELD(block.ParamSettings, "InitStatusDWorkIdx")
%assign initStatDWorkIdx = block.ParamSettings.InitStatusDWorkIdx
%assert (initStatDWorkIdx != -1)
%assign fcnCall = fcnCall + "if (%<LibBlockDWork(block.DWork[initStatDWorkIdx],"","",0)> == 0U) {/n"
%assign fcnCall = fcnCall + ...
"void *errMsg = CreateDiagnosticAsVoidPtr(/n" + ...
"/"Simulink:FcnCall:InvalidNonMdlEventFcnCall/", 4, /n" + ...
"CODEGEN_SUPPORT_ARG_STRING_TYPE, /"%<eventPortName>/", /n" + ...
"CODEGEN_SUPPORT_ARG_STRING_TYPE, /"%<LibGetFormattedBlockPath(block)>/", /n" + ...
"CODEGEN_SUPPORT_ARG_REAL_TYPE, %<LibGetT()>);/n"
%assign fcnCall = fcnCall + "_ssSet_slErrMsg(%<::tSimStruct>, errMsg);/n"
%assign fcnCall = fcnCall + "return;/n"
%assign fcnCall = fcnCall + "}/n"
%endif
%assign childTid = -1
%foreach mweIdx = SIZE(block.ParamSettings.ModelEventPortNames, 1)
%if block.ParamSettings.ModelEventPortTypes[mweIdx] == "PERIODIC" && ...
block.ParamSettings.ModelEventPortNames[mweIdx] == eventPortName
%assign childTid = block.ParamSettings.ModelEventPortTIDs[mweIdx]
%break
%endif
%endforeach
%if childTid != -1
%assign fcnCall = fcnCall + ...
CallModelBlockPeriodicEventPortFunction(block, blockInterface, childTid)
%endif
%endif
%return fcnCall
%endfunction
%function ModelRefInitStatusCheckForFunctionCaller(sysIdx, blkIdx, fcnName) void
%assign block = System[sysIdx].Block[blkIdx]
%assign initStatDWorkIdx = block.ParamSettings.InitStatusDWorkIdx
%assert(initStatDWorkIdx != -1)
%assign fcnCall = "if (%<LibBlockDWork(block.DWork[initStatDWorkIdx],"","",0)> == 0U) {/n"
%assign fcnCall = fcnCall + ...
"void *errMsg = CreateDiagnosticAsVoidPtr_wrapper(/n" + ...
"/"Simulink:FcnCall:InvalidNonMdlEventSimulinkFcn/", 3,/n" + ...
"CODEGEN_SUPPORT_ARG_STRING_TYPE, /"%<fcnName>/",/n" + ...
"CODEGEN_SUPPORT_ARG_STRING_TYPE, /"%<LibGetFormattedBlockPath(block)>/",/n" + ...
"CODEGEN_SUPPORT_ARG_REAL_TYPE, %<LibGetT()>);/n"
%assign fcnCall = fcnCall + "_ssSet_slErrMsg(%<::tSimStruct>, errMsg);/n"
%assign fcnCall = fcnCall + "return;/n"
%assign fcnCall = fcnCall + "}"
%return fcnCall
%endfunction
%function CallModelBlockAsyncFcnCallInput(block, portIdx, localTid, ...
fcnType) void
%assign blockInterface = GetModelrefInterface(block)
%assign fcnCall = ""
%if portIdx >= block.NumDataInputPorts && ...
ISFIELD(block.ParamSettings, "ModelEventPortNames")
%if (fcnType == "Output" || fcnType == "OutputUpdate")
%if Accelerator
%assign fcnCall = SLibCallModelBlockFcnCallInputInSimulink(block, portIdx, ...
localTid, fcnType)
%else
%assign eventPortIdx = portIdx - block.NumDataInputPorts
%assign eventPortName = block.ParamSettings.ModelEventPortNames[eventPortIdx]
%assign eventPortType = block.ParamSettings.ModelEventPortTypes[eventPortIdx]
%assign fcnCall = CallModelBlockModelEventPortFunction(block, eventPortName, eventPortType, localTid)
%endif
%endif
%else
%assign fcnCallInfo = SLibGetModelBlockFcnCallInputInfo(block, portIdx, fcnType)
%if !ISEMPTY(fcnCallInfo)
%if Accelerator
%assign fcnCall = SLibCallModelBlockFcnCallInputInSimulink(block, portIdx, ...
localTid, fcnType)
%else
%if ISFIELD(block.ParamSettings, "InitStatusDWorkIdx")
%assign initStatDWorkIdx = block.ParamSettings.InitStatusDWorkIdx
%assert(initStatDWorkIdx != -1)
%assign fcnCall = fcnCall + "if (%<LibBlockDWork(block.DWork[initStatDWorkIdx],"","",0)> == 0U) {/n"
%assign fcnCall = fcnCall + ...
"void *errMsg = CreateDiagnosticAsVoidPtr_wrapper(/n" + ...
"/"Simulink:FcnCall:InvalidNonMdlEventFcnCall/", 3,/n" + ...
"CODEGEN_SUPPORT_ARG_STRING_TYPE, /"%<fcnCallInfo.PortName>/",/n" + ...
"CODEGEN_SUPPORT_ARG_STRING_TYPE, /"%<LibGetFormattedBlockPath(block)>/",/n" + ...
"CODEGEN_SUPPORT_ARG_REAL_TYPE, %<LibGetT()>);/n"
%assign fcnCall = fcnCall + "_ssSet_slErrMsg(%<::tSimStruct>, errMsg);/n"
%assign fcnCall = fcnCall + "return;/n"
%assign fcnCall = fcnCall + "}/n"
%endif
%assign fcnCall = fcnCall + SLibCallModelBlockFunction([], block, fcnCallInfo.TaskName, ...
blockInterface, fcnCallInfo.TaskFcnInfo.FcnRec, 0, localTid, 0, "")
%endif
%endif
%endif
%return fcnCall
%endfunction
%function CppEncapMdlrefTimingDecArgs() void
%assert(::GenerateClassInterface && IsModelReferenceRTWTarget())
%assign decArgs = []
%if !IsModelReferenceForASimstructBasedTarget() && ...
::tMdlRefTimingBridgeAccessed
%assign decArgs = decArgs + "const rtTimingBridge *timingBridge"
%endif
%if ::tMdlRefGlobalTIDMapAccessed
%assign decArgs = AddCppEncapMdlrefTIDArgs(decArgs)
%endif
%return decArgs
%endfunction
%function AddCppEncapMdlrefTIDArgs(decArgs) void
%assert(::GenerateClassInterface && IsModelReferenceRTWTarget())
%if ::tMdlRefNeedTIDArgs
%if !MdlRefIsConstSampleBlock() || MdlRefHasParameterRate()
%assign numTIDs = SLibGetNumTIDsForGlobalTIDMap()
%foreach idx = numTIDs
%if SLibIsServiceTaskTID(idx)
%continue
%endif
%assign decArgs = decArgs + "int_T mdlref_TID%<idx>"
%endforeach
%else
%assign decArgs = decArgs + "int_T mdlref_TID0"
%endif
%endif
%if SLibModelNeedsTriggerTIDArg()
%assign decArgs = decArgs + "int_T mdlref_TriggerTID"
%endif
%return decArgs
%endfunction
%function IsSystemReusableParentBaseSys(sysIdx)
%return IsBaseSystem(System[System[sysIdx].ReusedParentSystemIdx])
%endfunction
%function SLibGetNumTIDsForGlobalTIDMap() void
%return NumRuntimeExportedRates + ...
NumAsynchronousSampleTimes + NumExplictTasksInUnionSampleTimes
%endfunction
%function SLibGetProtectedBlockPath() void
%return "Block_in_protected_model"
%endfunction
%function SLibIsGeneratingSimTargetForProtectedModel() void
%return IsModelReferenceSimTarget() && CompiledModel.GenProtectedModelOrSubmodel
%endfunction
%endif