%if EXISTS("_ERT_SYSGRAPHMAP_LIB_") == 0
%assign _ERT_SYSGRAPHMAP_LIB_ = 1
%function SLibGetNumSubsystemInterfaces() void
%if ISFIELD(::CompiledModel,"SystemGraphicalMap")
%assign sysGrMap = ::CompiledModel.SystemGraphicalMap
%assign numSys = sysGrMap.NumSubsystemInterfaces
%return numSys
%else
%assign errTxt = "SystemGraphicalMap does not exist"
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetSubsystemInterface(subsysIdx) void
%if ISFIELD(::CompiledModel,"SystemGraphicalMap")
%assign sysGrMap = ::CompiledModel.SystemGraphicalMap
%assign numSys = sysGrMap.NumSubsystemInterfaces
%if subsysIdx < numSys
%return sysGrMap.SubsystemInterface[subsysIdx]
%else
%assign errTxt = "Specified subsystem index is out of range"
%<LibReportFatalError(errTxt)>
%endif
%else
%assign errTxt = "SystemGraphicalMap does not exist"
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetNumExportedFunctions() void
%if ISFIELD(::CompiledModel,"SystemGraphicalMap")
%assign sysGrMap = ::CompiledModel.SystemGraphicalMap
%assign numSys = sysGrMap.NumExportedFunctions
%return numSys
%else
%assign errTxt = "Subsystem Graphical Interface does not exist"
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetExportedFunction(fcnIdx) void
%if ISFIELD(::CompiledModel,"SystemGraphicalMap")
%assign sysGrMap = ::CompiledModel.SystemGraphicalMap
%assign numFcns = sysGrMap.NumExportedFunctions
%if fcnIdx < numFcns
%return sysGrMap.ExportedFunction[fcnIdx]
%else
%assign errTxt = "Specified Function Index is out of range"
%<LibReportFatalError(errTxt)>
%endif
%else
%assign errTxt = "SystemGraphicalMap does not exist"
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetRootInterface() void
%if ISFIELD(::CompiledModel,"SystemGraphicalMap")
%assign sysGrMap = ::CompiledModel.SystemGraphicalMap
%if ISFIELD(sysGrMap, "RootModelInterface")
%return sysGrMap.RootModelInterface
%else
%assign errTxt = "Root Model's graphical interface is not mapped."
%<LibReportFatalError(errTxt)>
%endif
%else
%assign errTxt = "SystemGraphicalMap does not exist"
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetNumInports(system) void
%if ISFIELD(system, "NumInports")
%return system.NumInports
%else
%assign errTxt = ...
"Specified system does not have graphical inports mapped."
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetInport(system, inportIdx) void
%if ISFIELD(system, "NumInports") && (inportIdx < system.NumInports)
%return system.Inport[inportIdx]
%else
%assign errTxt = ...
"Specified system inport is not mapped or is out of range"
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetNumFunctionInputsInInport(inport) void
%if ISFIELD(inport, "FunctionInputIdx")
%return SIZE(inport.FunctionInputIdx)[1]
%else
%assign errTxt = ...
"Specified inport's function inputs are not mapped"
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetFunctionInputOfInport(system, inport, functionInIdx) void
%if ISFIELD(inport, "FunctionInputIdx") && ...
(functionInIdx < SLibGetNumFunctionInputsInInport(inport) )
%return system.FunctionInput[inport.FunctionInputIdx[functionInIdx]]
%else
%assign errTxt = ...
"Specified inport is not mapped in SystemGraphicalMap record"
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetNumDataStores(system) void
%if ISFIELD(system, "NumDataStores")
%return system.NumDataStores
%else
%assign errTxt = ...
"Specified system does not have DataStores mapped."
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetDataStore(system, dsIdx) void
%if ISFIELD(system, "NumDataStores") && (dsIdx < system.NumDataStores)
%return system.DataStore[dsIdx]
%else
%assign errTxt = ...
"Specified system is not mapped in SystemGraphicalMap record"
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetNumDiscStates(system) void
%if ISFIELD(system, "NumDiscStates")
%return system.NumDiscStates
%else
%assign errTxt = ...
"Specified system does not have DiscStates mapped."
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetDiscState(system, dsIdx) void
%if ISFIELD(system, "NumDiscStates") && (dsIdx < system.NumDiscStates)
%return system.DiscState[dsIdx]
%else
%assign errTxt = ...
"Specified system is not mapped in SystemGraphicalMap record"
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetNumOutports(system) void
%if ISFIELD(system, "NumOutports")
%return system.NumOutports
%else
%assign errTxt = ...
"Specified system does not have its graphical outports mapped"
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetOutport(system, outportIdx) void
%if ISFIELD(system, "NumOutports") && (outportIdx < system.NumOutports)
%return system.Outport[outportIdx]
%else
%assign errTxt = ...
"Specified system is not mapped in SystemGraphicalMap record"
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetNumFunctionOutputsInOutport(outport) void
%if ISFIELD(outport, "FunctionOutputIdx")
%return SIZE(outport.FunctionOutputIdx)[1]
%else
%assign errTxt = ...
"Specified outport is not mapped in SystemGraphicalMap record"
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetFunctionOutputOfOutport(system, outport, functionOutIdx) void
%if ISFIELD(outport, "FunctionOutputIdx") && ...
(functionOutIdx < SLibGetNumFunctionOutputsInOutport(outport))
%return system.FunctionOutput[outport.FunctionOutputIdx[functionOutIdx]]
%else
%assign errTxt = ...
"Specified outport is not mapped in SystemGraphicalMap record"
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function SLibGetFunctionIODimensions(functionIO) void
%if ISFIELD(functionIO, "Dimensions")
%return functionIO.Dimensions
%endif
%endfunction
%function SLibGetFunctionIOWidth(functionIO) void
%assign width = 1
%assign dims = SLibGetFunctionIODimensions(functionIO)
%assign numDims = SIZE(dims)[1]
%assign width = dims[numDims-1]
%foreach dimIdx = numDims-1
%assign width = width*dims[dimIdx]
%endforeach
%return width
%endfunction
%function SLibCreateSystemGraphicalMap(mode) void
%if ISFIELD(::CompiledModel,"SystemGraphicalMap")
%return ""
%endif
%assert (!IsModelReferenceTarget())
%addtorecord ::CompiledModel /
SystemGraphicalMap { /
NumSubsystemInterfaces 0 /
NumExportedFunctions 0 /
}
%assign sysGrMap = ::CompiledModel.SystemGraphicalMap
%with ::CompiledModel.BlockHierarchyMap
%foreach subsysIdx = NumSubsystems
%with Subsystem[subsysIdx]
%if mode == "all"
%foreach subsysBlkIdx = NumSubsystemBlocks
%assign blk = Block[SubsystemBlocks[subsysBlkIdx]]
%assign systemRec = FcnGetSubsysSystemRecord(blk)
%if !ISEMPTY(systemRec) && !ISFIELD(systemRec,"RTWSystemCodeOptIntf") && ...
!ISFIELD(systemRec, "RTWSystemWithReturnValue")
%assign isFcnCall = (systemRec.Type == "function-call")
%if isFcnCall && ISFIELD(systemRec, "Exported") && ...
(systemRec.Exported == "yes")
%assert (ExportFunctionsMode != 0)
%assign expFcn = FcnAddExpFcnToInterface(sysGrMap, systemRec)
%assign expSystem = System[expFcn.SystemIdx]
%if ISFIELD(expSystem, "ExternalInputs")
%assign numInputs = SIZE(expSystem.ExternalInputs,1)
%foreach inIdx = numInputs
%assign extInIdx = expSystem.ExternalInputs[inIdx]
%<FcnAddInputToExportFunction(extInIdx, expFcn)>
%endforeach
%endif
%if ISFIELD(expSystem, "ExternalOutputs")
%assign numOutputs = SIZE(expSystem.ExternalOutputs,1)
%foreach outIdx = numOutputs
%assign extOutIdx = expSystem.ExternalOutputs[outIdx]
%<FcnAddOutputToExportFunction(extOutIdx, expFcn)>
%endforeach
%endif
%else
%assign ssInterface = ...
FcnAddSubsysToInterface(sysGrMap, systemRec, blk)
%foreach inIdx = blk.NumDataInputPorts
%assign inputPort = blk.DataInputPort[inIdx]
%<FcnAddInportToInterface(ssInterface, inputPort)>
%endforeach
%foreach oIdx = blk.NumDataOutputPorts
%assign outputPort = blk.DataOutputPort[oIdx]
%<FcnAddOutportToInterface(ssInterface, outputPort)>
%endforeach
%<FcnAddDataStoresToSSInterface(ssInterface, systemRec)>
%assign childSystem = Subsystem[ChildSubsystems[subsysBlkIdx]]
%<FcnAddDiscStatesToSSInterface(ssInterface, childSystem)>
%endif
%endif
%endforeach
%endif
%if Subsystem[subsysIdx].Type == "root"
%assign rootSystem = System[NumSystems-1]
%assign rootInterface= FcnAddRootToInterface(sysGrMap, rootSystem)
%foreach inIdx = NumInportBlocks
%assign inportBlk = Block[InportBlocks[inIdx]]
%assert (inportBlk.NumDataOutputPorts == 1)
%assign inport = inportBlk.DataOutputPort[0]
%if ISEMPTY(inport.SLName)
%assign inport.SLName = inportBlk.SLName
%endif
%<FcnAddInportToInterface(rootInterface, inport)>
%endforeach
%foreach outIdx = NumOutportBlocks
%assign outportBlk = Block[OutportBlocks[outIdx]]
%assign outport = outportBlk.DataInputPort[0]
%if ISEMPTY(outport.SLName)
%assign outport.SLName = outportBlk.SLName
%endif
%<FcnAddOutportToInterface(rootInterface, outport)>
%endforeach
%foreach dsIdx = NumDataStoreBlocks
%assign dsBlk = Block[DataStoreBlocks[dsIdx]]
%<FcnAddDataStoresToRootInterface(rootInterface, dsBlk)>
%endforeach
%<FcnAddDiscStatesToSSInterface(rootInterface, Subsystem[subsysIdx])>
%endif
%endwith
%endforeach
%endwith
%endfunction
%function FcnGetSubsysSystemRecord(grBlock) void
%if (grBlock.NumDataInputPorts == 0) && ...
(grBlock.NumDataOutputPorts == 0) && ...
(grBlock.NumControlInputPorts == 0) && ...
(grBlock.NumDataStores == 0)
%return []
%endif
%if SLibSystemBlockExist(grBlock) || (grBlock.Virtual == 0)
%assign blockIndex = SLibGetSystemBlockIdx(grBlock)
%with ::CompiledModel
%assign system = System[blockIndex[0]]
%assign block = system.Block[blockIndex[2]]
%assert (block.Type == "SubSystem")
%assign subsystem = System[block.CallSiteInfo.SystemIdx]
%assign isSingleRate = LibIsSingleRateSystem(subsystem)
%assign isAtomic = (subsystem.Type == "atomic")
%assign isFcnCall = (subsystem.Type == "function-call")
%assign isSupported = (isAtomic || isFcnCall)
%assign isInlined = LibSystemIsInlined(subsystem)
%if isSupported && !isInlined && isSingleRate
%assign isOutputFcnEmpty = LibSystemFcnIsEmpty(subsystem,"Output")
%assign needsCPI = LibSystemFcnNeedsCPI(subsystem, "OutputUpdate")
%if !isOutputFcnEmpty && !needsCPI
%return subsystem
%endif
%endif
%endwith
%endif
%return []
%endfunction
%function FcnGetCallSiteIdx(grBlock) void
%if ISFIELD(grBlock, "_callsiteidx")
%return grBlock._callsiteidx
%else
%assign errTxt = "CallSite Idx not available for graphical block"
%<LibReportFatalError(errTxt)>
%endif
%endfunction
%function FcnGetSubsystemBlockPath(grBlock) void
%return grBlock.Name
%endfunction
%function FcnAddSubsysToInterface(sysGrMap, systemRec, blk) void
%assert (!LibSystemIsInlined(systemRec))
%assign csIdx = FcnGetCallSiteIdx(blk)
%assign instIdx = blk._blkref[1]
%assign blkPath = FcnGetSubsystemBlockPath(blk)
%assign numSubsys = sysGrMap.NumSubsystemInterfaces
%assign hdrFile = "%<systemRec.SystemHeaderFileName>.h"
%if LibSystemIsReusedFcn(systemRec)
%assign subsysName = LibGetRecordIdentifier(systemRec) + "_%"
%else
%assign subsysName = LibGetRecordIdentifier(systemRec)
%endif
%addtorecord sysGrMap /
SubsystemInterface { /
InterfaceType "Subsystem" /
BlockPath blkPath /
Name subsysName /
SystemIdx systemRec.SystemIdx /
CallSiteIdx csIdx /
HeaderFile hdrFile /
NumInports 0 /
NumOutports 0 /
NumControlPorts 0 /
NumDataStores 0 /
NumFunctionInputs 0 /
NumFunctionOutputs 0 /
NumDiscStates 0 /
}
%assign sysGrMap.NumSubsystemInterfaces = numSubsys + 1
%return sysGrMap.SubsystemInterface[numSubsys]
%endfunction
%function FcnAddExpFcnToInterface(sysGrMap, systemRec) void
%assert (!LibSystemIsInlined(systemRec))
%assign numExpFcns = sysGrMap.NumExportedFunctions
%assign hdrFile = "%<systemRec.SystemHeaderFileName>.h"
%addtorecord sysGrMap /
ExportedFunction { /
InterfaceType "ExportedFunction" /
Name LibGetRecordIdentifier(systemRec) /
SystemIdx systemRec.SystemIdx /
HeaderFile hdrFile /
NumDataStores 0 /
NumFunctionInputs 0 /
NumFunctionOutputs 0 /
}
%assign sysGrMap.NumExportedFunctions = numExpFcns + 1
%return sysGrMap.ExportedFunction[numExpFcns]
%endfunction
%function FcnAddRootToInterface(sysGrMap, rootSystem) void
%assert (rootSystem.RTWSystemCode > 0)
%assign hdrFile = "%<rootSystem.SystemHeaderFileName>.h"
%addtorecord sysGrMap /
RootModelInterface { /
InterfaceType "RootModel" /
ModelName ::CompiledModel.Name /
BlockPath "" /
SystemIdx rootSystem.SystemIdx /
HeaderFile hdrFile /
NumInports 0 /
NumOutports 0 /
NumDataStores 0 /
NumDiscStates 0 /
NumControlPorts 0 /
NumFunctionInputs 0 /
NumFunctionOutputs 0 /
}
%return sysGrMap.RootModelInterface
%endfunction
%function FcnAddInportToInterface(interface, inputPort) void
%if (inputPort.NumRegions > 0) && ...
(IDNUM(inputPort.Region[0]._Source[0])[0] == "F")
%return
%endif
%assign slName = "rt_" + STRING(inputPort.SLName)
%assign slName = FcnConvertNameToIdentifier(slName)
%if (TYPE(slName) == "Number")
%assign portNum = interface.NumInports + 1
%assign slName = "rt_" + "In" + STRING(portNum)
%endif
%assign blkPath = "'%<interface.BlockPath>/%<inputPort.SLName>'"
%addtorecord interface /
Inport{ /
Name slName /
BlockPath blkPath /
DataType "real_T" /
IsStruct TLC_FALSE /
IsBus TLC_FALSE /
Dimensions [1, 1] /
FunctionInputIdx [] /
VirtualTypeDef "" /
TID 0 /
}
%assign inport = interface.Inport[interface.NumInports]
%assign typeDefCode = ""
%assign needsTypedef = TLC_FALSE
%if (inputPort.NumRegions > 1)
%assign needsTypedef = TLC_TRUE
%endif
%assign isRoot = (interface.InterfaceType == "RootModel") ? 1 : 0
%if isRoot
%assign isReusable = ConfigSet.MultiInstanceERTCode
%else
%assign isReusable = LibSystemIsReusedFcn(System[interface.SystemIdx])
%endif
%foreach regIdx = inputPort.NumRegions
%assign region = inputPort.Region[regIdx]
%assign offset = region.Offset
%assign sigRec = FcnGetSigRecFromRegion(region)
%if ISEMPTY(sigRec)
%assign sigTID = 0
%elseif !ISFIELD(sigRec, "TID")
%assign sigTID = 0
%else
%if TYPE(sigRec.TID) == "Identifier"
%if sigRec.TID == "constant"
%assign sigTID = 0
%elseif sigRec.TID == "trigger"
%assign sysRecord = System[interface.SystemIdx]
%assign sigTID = LibGetSubsystemTID(sysRecord, TLC_TRUE)
%endif
%elseif TYPE(sigRec.TID) == "Vector"
%assign sigTID = sigRec.TID[0]
%else
%assign sigTID = sigRec.TID
%endif
%assign inport.TID = sigTID
%endif
%assign dataAttrib = FcnGetDataAttribFromRecord(sigRec, isReusable)
%assign dataAttrib = FcnUpdateDataAttribBasedOnBusSelElIdx(region, dataAttrib)
%if !ISEMPTY(dataAttrib)
%if LibIsStructDataType(dataAttrib.DataTypeIdx)
%assign regIsBus = TLC_TRUE
%else
%assign regIsBus = TLC_FALSE
%endif
%if dataAttrib.IsComplex
%assign regDType = ...
LibGetDataTypeComplexNameFromId(dataAttrib.DataTypeIdx)
%assign regIsStruct = TLC_TRUE
%else
%assign regDType = LibGetDataTypeNameFromId(dataAttrib.DataTypeIdx)
%assign regIsStruct = TLC_FALSE
%endif
%assign regWidth = SLibGetFunctionIOWidth(region)
%assign directAccess = dataAttrib.Symbol
%if offset > 0
%assign castPrefix = dataAttrib.IsComplex ? "(%<regDType> *)" : ""
%assign addr = "&((%<castPrefix>%<dataAttrib.BaseAddress>)[%<offset>])"
%else
%assign addr = dataAttrib.BaseAddress
%endif
%if needsTypedef
%assign optArray = (regWidth > 1) ? "[%<regWidth>]" : ""
%assign ptr = ""
%assign memName = "Element%<regIdx>"
%assign memberDecl = "%<regDType> %<memName>%<optArray>;" + "/n"
%assign typeDefCode = typeDefCode + memberDecl
%assign member = ".%<memName>"
%assign inport.IsStruct = TLC_TRUE
%else
%assign member = ""
%assign ptr = ""
%assign inport.DataType = regDType
%assign inport.Dimensions = region.Dimensions
%assign inport.IsStruct = regIsStruct
%assign inport.IsBus = regIsBus
%endif
%assign argIdx = region.FunctionArgumentIdx
%if !isRoot && LibSystemIsReusedFcn(System[interface.SystemIdx]) && (argIdx == -1)
%continue
%endif
%if dataAttrib.Access == "Unconnected"
%continue
%endif
%addtorecord interface /
FunctionInput { /
Access dataAttrib.Access /
SLName "%<ptr>%<inport.Name>%<member>" /
Address addr /
DataType regDType /
DataIsStruct regIsStruct /
DataIsBus regIsBus /
Dimensions region.Dimensions /
FunctionArgIdx argIdx /
TID sigTID /
Symbol directAccess /
}
%assign numIn = interface.NumFunctionInputs
%if offset > 0
%addtorecord interface.FunctionInput[numIn] Offset offset
%endif
%assign inport.FunctionInputIdx = inport.FunctionInputIdx + numIn
%if (argIdx >= 0)
%if !ISFIELD(interface, "FunctionInputHash")
%addtorecord interface FunctionInputHash /
{FuncIn%<argIdx> interface.FunctionInput[numIn]}
%else
%if !ISFIELD(interface.FunctionInputHash, "FuncIn%<argIdx>")
%addtorecord interface.FunctionInputHash /
FuncIn%<argIdx> interface.FunctionInput[numIn]
%endif
%endif
%endif
%if ISFIELD(dataAttrib, "Value")
%addtorecord interface.FunctionInput[numIn] /
Value dataAttrib.Value
%endif
%assign interface.NumFunctionInputs = numIn + 1
%endif
%endforeach
%if needsTypedef
%assign inDataType = "%<interface.Name>_In%<interface.NumInports>Type"
%openfile typedef
typedef struct {
%<typeDefCode>
} %<inDataType>; /* Inport: %<inport.BlockPath> */
%closefile typedef
%assign inport.VirtualTypeDef = typedef
%assign inport.DataType = inDataType
%assign inport.Dimensions = [1, 1]
%endif
%assign interface.NumInports = interface.NumInports + 1
%endfunction
%function FcnAddOutportToInterface(interface, outputPort) void
%if (outputPort.NumRegions > 0) && ...
(IDNUM(outputPort.Region[0]._Source[0])[0] == "F")
%return
%endif
%assign slName = "rt_" + STRING(outputPort.SLName)
%assign slName = FcnConvertNameToIdentifier(slName)
%if (TYPE(slName) == "Number")
%assign portNum = interface.NumOutports + 1
%assign slName = "rt_" + "Out" + STRING(portNum)
%endif
%assign blkPath = "'%<interface.BlockPath>/%<outputPort.SLName>'"
%addtorecord interface /
Outport { /
Name slName /
BlockPath blkPath /
DataType "real_T" /
IsStruct TLC_FALSE /
IsBus TLC_FALSE /
Dimensions [1, 1] /
VirtualTypeDef "" /
FunctionOutputIdx [] /
TID 0 /
}
%assign output = interface.Outport[interface.NumOutports]
%assign MoreThanOneRegions = TLC_FALSE
%if (outputPort.NumRegions > 1)
%assign MoreThanOneRegions = TLC_TRUE
%assign elementsWidthSoFar = 0
%endif
%assign typeDefCode = ""
%assign needsTypedef = TLC_FALSE
%if MoreThanOneRegions
%if interface.InterfaceType == "Subsystem"
%assign needsTypedef = TLC_TRUE
%endif
%endif
%assign preRegDataType=""
%foreach regIdx = outputPort.NumRegions
%assign region = outputPort.Region[regIdx]
%assign offset = region.Offset
%assign sigRec = FcnGetSigRecFromRegion(region)
%assign isRoot = (interface.InterfaceType == "RootModel") ? 1 : 0
%if isRoot
%assign isReusable = ConfigSet.MultiInstanceERTCode
%else
%assign isReusable = LibSystemIsReusedFcn(System[interface.SystemIdx])
%endif
%if isRoot
%assign dataAttrib = FcnGetDataAttribOfRootOutput(...
sigRec, isReusable, interface.NumOutports, regIdx)
%elseif !isReusable && (outputPort.Connected == 0) && !ISEMPTY(sigRec)
%assign access = "ConstInlined"
%assign addr = ""
%assign dataTypeIdx = LibGetRecordDataTypeId(sigRec)
%assign dimensions = [%<LibGetRecordWidth(sigRec)>]
%assign isComplex = LibGetRecordIsComplex(sigRec)
%if ISFIELD(sigRec, "InitialValue") && !ISEMPTY(sigRec.InitialValue)
%assign value = sigRec.InitialValue
%else
%assign value = []
%endif
%createrecord dataAttrib { /
Access access /
BaseAddress addr /
DataTypeIdx dataTypeIdx /
IsComplex isComplex /
Dimensions dimensions /
Value value /
}
%else
%assign dataAttrib = FcnGetDataAttribFromRecord(sigRec, isReusable)
%assign dataAttrib = FcnUpdateDataAttribBasedOnBusSelElIdx(region, dataAttrib)
%endif
%if ISEMPTY(sigRec)
%assign sigTID = 0
%elseif !ISFIELD(sigRec, "TID")
%assign sigTID = 0
%else
%if TYPE(sigRec.TID) == "Identifier"
%if sigRec.TID == "constant"
%assign sigTID = 0
%elseif sigRec.TID == "trigger"
%assign sysRecIdx = SLibGetSystemAndCallSideIndex(sigRec)[0]
%assign sigTID = LibGetSubsystemTID(System[sysRecIdx], TLC_TRUE)
%endif
%elseif TYPE(sigRec.TID) == "Vector"
%assign sigTID = sigRec.TID[0]
%else
%assign sigTID = sigRec.TID
%endif
%assign output.TID = sigTID
%endif
%if !ISEMPTY(dataAttrib)
%if dataAttrib.IsComplex
%assign regDType = ...
LibGetDataTypeComplexNameFromId(dataAttrib.DataTypeIdx)
%assign regIsStruct = TLC_TRUE
%else
%assign regDType = LibGetDataTypeNameFromId(dataAttrib.DataTypeIdx)
%assign regIsStruct = TLC_FALSE
%endif
%assign isBus = LibDataTypeIsBus(dataAttrib.DataTypeIdx)
%assign output.IsBus = isBus
%assign regWidth = SLibGetFunctionIOWidth(region)
%if ISFIELD(dataAttrib, "Symbol")
%assign directAccess = dataAttrib.Symbol
%else
%assign directAccess = ""
%endif
%if !(isRoot && !ISEMPTY(sigRec) && sigRec.MemoryMapIdx[2] == -1) ...
&& offset > 0
%assign castPrefix = dataAttrib.IsComplex ? "(%<regDType> *)" : ""
%assign addr = "&((%<castPrefix>%<dataAttrib.BaseAddress>)[%<offset>])"
%assign realOffset = offset
%if ISFIELD(dataAttrib, "Offset")
%assign realOffset = offset + dataAttrib.Offset
%endif
%else
%assign addr = dataAttrib.BaseAddress
%assign realOffset = ""
%if ISFIELD(dataAttrib, "Offset")
%assign realOffset = dataAttrib.Offset
%elseif ISFIELD(dataAttrib, "NeedsIndex") && dataAttrib.NeedsIndex == 1
%assign realOffset = 0
%endif
%endif
%if needsTypedef
%assign optArray = (regWidth > 1) ? "[%<regWidth>]" : ""
%assign ptr = (dataAttrib.Access == "ConstInlined") ? "" : "&"
%assign memName = "Element%<regIdx>"
%assign memberDecl = "%<regDType> %<memName>%<optArray>;" + "/n"
%assign typeDefCode = typeDefCode + memberDecl
%assign member = "->%<memName>"
%assign output.IsStruct = TLC_TRUE
%assign elementOffset = ""
%elseif MoreThanOneRegions
%assign ptr = (dataAttrib.Access == "ConstInlined") ? "" : "&"
%assign output.IsStruct = TLC_FALSE
%if !(ISEMPTY(preRegDataType) || (preRegDataType == regDType))
%<LibReportFatalError("Root outport regions have mixed data types.")>
%endif
%assign output.DataType = regDType
%assign preRegDataType = regDType
%assign elementOffset = elementsWidthSoFar
%assign elementsWidthSoFar = elementsWidthSoFar + regWidth
%assign member = "[%<elementOffset>]"
%else
%assign ptr = ((dataAttrib.Access == "ConstInlined") && ...
(regWidth == 1)) ? "*" : ""
%assign output.DataType = regDType
%assign output.Dimensions = region.Dimensions
%assign output.IsStruct = regIsStruct
%assign elementOffset = ""
%assign member = ""
%endif
%if dataAttrib.Access == "Unconnected" && ...
!System[interface.SystemIdx].AllOutputsCanonical
%continue
%endif
%if region.FunctionArgumentIdx > -1
%assign argIdx = region.FunctionArgumentIdx
%assign dataAttrib.Access = "OutputArgument"
%assign canOut = System[interface.SystemIdx].Interface.CanonicalOutputArgDef[argIdx]
%assign xWidth = LibCGTypeWidth(canOut.CGTypeIdx)
%if (xWidth > SLibGetFunctionIOWidth(region))
%assign regDims = [%<xWidth>, 1]
%else
%assign regDims = region.Dimensions
%endif
%else
%assign regDims = region.Dimensions
%assign argIdx = -1
%endif
%addtorecord interface /
FunctionOutput { /
SLName "%<ptr>%<output.Name>%<member>" /
Access dataAttrib.Access /
Address addr /
DataType regDType /
Dimensions regDims /
ElementOffset elementOffset /
DataIsStruct regIsStruct /
FunctionArgIdx argIdx /
TID sigTID /
Symbol directAccess /
}
%assign numOut = interface.NumFunctionOutputs
%assign output.FunctionOutputIdx = output.FunctionOutputIdx + numOut
%if !ISEMPTY(realOffset)
%addtorecord interface.FunctionOutput[numOut] Offset realOffset
%endif
%if (argIdx >= 0)
%if !ISFIELD(interface, "FunctionOutputHash")
%addtorecord interface FunctionOutputHash /
{FuncOut%<argIdx> interface.FunctionOutput[numOut]}
%else
%if !ISFIELD(interface.FunctionOutputHash, "FuncOut%<argIdx>")
%addtorecord interface.FunctionOutputHash /
FuncOut%<argIdx> interface.FunctionOutput[numOut]
%endif
%endif
%endif
%if ISFIELD(dataAttrib, "Value")
%addtorecord interface.FunctionOutput[numOut] /
Value dataAttrib.Value
%endif
%assign interface.NumFunctionOutputs = numOut + 1
%endif
%endforeach
%if (interface.InterfaceType == "RootModel")
%assign intName = interface.ModelName
%else
%assign intName = interface.Name
%endif
%if needsTypedef
%assign outDataType = "%<intName>_Out%<interface.NumOutports>Type"
%openfile typedef
typedef struct {
%<typeDefCode>
} %<outDataType>; /* Outport: %<output.BlockPath> */
%closefile typedef
%assign output.VirtualTypeDef = typedef
%assign output.DataType = outDataType
%assign output.Dimensions = [1, 1]
%elseif MoreThanOneRegions
%assign output.Dimensions[0] = elementsWidthSoFar
%endif
%assign interface.NumOutports = interface.NumOutports + 1
%endfunction
%function FcnAddDataStoresToSSInterface(ssInterface, systemRec) void
%if LibSystemIsReusedFcn(systemRec) || (systemRec.StandaloneSubsystem == 1)
%foreach dsIdx = systemRec.Interface.NumCanonicalDWorkArgDefs
%assign canDW = systemRec.Interface.CanonicalDWorkArgDef[dsIdx]
%assign dWRec = DWorks.DWork[canDW.FirstSignalSrc]
%assign dWAttrib = ...
FcnGetDataAttribFromRecord(dWRec, LibSystemIsReusedFcn(systemRec))
%if !ISEMPTY(dWAttrib)
%if dWAttrib.IsComplex
%assign regDType= LibGetDataTypeComplexNameFromId(dWAttrib.DataTypeIdx)
%assign regIsStruct = TLC_TRUE
%else
%assign regDType = LibGetDataTypeNameFromId(dWAttrib.DataTypeIdx)
%assign regIsStruct = TLC_FALSE
%endif
%assign blkPath = "%<SLibGrBlockCommentName(dWRec.GrSrc)>"
%addtorecord ssInterface /
DataStore { /
Name "rt_ds_%<LibGetRecordIdentifier(dWRec)>" /
Access dWAttrib.Access /
Address dWAttrib.BaseAddress /
BlockPath blkPath /
DataType regDType /
DataIsStruct regIsStruct /
Dimensions dWAttrib.Dimensions /
TID dWRec.TID /
}
%assign ssInterface.NumDataStores = ssInterface.NumDataStores + 1
%endif
%endforeach
%elseif LibSystemIsNonReusedFcn(systemRec)
%assign sysIdx = systemRec.CallSites[0][2]
%assign blkIdx = systemRec.CallSites[0][3]
%assign ssBlock = System[sysIdx].Block[blkIdx]
%foreach dsIdx = ssBlock.CallSiteInfo.NumCanonicalDWorkArgs
%assign canDW = ssBlock.CallSiteInfo.CanonicalDWorkArg[dsIdx]
%assign portObj = SLibCreateDummyPortRecord()
%assign idNum = IDNUM(canDW.SignalSrc)
%if idNum[0] == "dp"
%assert (System[sysIdx].Type != "Root")
%assign callInterface = System[sysIdx].Interface
%assign callerDWork = callInterface.CanonicalDWorkArgDef[idNum[1]]
%assign dWRec = DWorks.DWork[callerDWork.FirstSignalSrc]
%elseif (idNum[0] == "D" || idNum[0] == "d")
%assign portObj.SignalSrc = [%<canDW.SignalSrc>]
%assign dWRec = SLibGetSourceRecord(portObj, 0)
%else
%<LibReportFatalError("Invalid DWork record")>
%endif
%assign dWAttrib = FcnGetDataAttribFromRecord(dWRec, TLC_FALSE)
%if !ISEMPTY(dWAttrib)
%if dWAttrib.IsComplex
%assign regDType= LibGetDataTypeComplexNameFromId(dWAttrib.DataTypeIdx)
%assign regIsStruct = TLC_TRUE
%else
%assign regDType = LibGetDataTypeNameFromId(dWAttrib.DataTypeIdx)
%assign regIsStruct = TLC_FALSE
%endif
%assign blkPath = "%<SLibGrBlockCommentName(dWRec.GrSrc)>"
%addtorecord ssInterface /
DataStore { /
Name "rt_ds_%<LibGetRecordIdentifier(dWRec)>" /
Access dWAttrib.Access /
Address dWAttrib.BaseAddress /
BlockPath blkPath /
DataType regDType /
DataIsStruct regIsStruct /
Dimensions dWAttrib.Dimensions /
TID dWRec.TID /
}
%assign ssInterface.NumDataStores = ssInterface.NumDataStores + 1
%endif
%endforeach
%endif
%endfunction
%function FcnAddDiscStatesToSSInterface(ssInterface, chSystem) void
%with chSystem
%foreach blkIdx = NumBlocks
%with Block[blkIdx]
%if Type == "ModelReference"
%assert NumDiscStates == 0
%continue
%endif
%if Block[blkIdx].Virtual != 0
%continue
%endif
%foreach dStateIdx = NumDiscStates
%assign dWorkIdx = DiscState[dStateIdx]._idx
%if dWorkIdx < 0
%continue
%endif
%assert (dWorkIdx < ::CompiledModel.DWorks.NumDWorks)
%assign dWork = ::CompiledModel.DWorks.DWork[dWorkIdx]
%assign dWAttrib = FcnGetDataAttribFromRecord(dWork, TLC_FALSE)
%if !ISEMPTY(dWAttrib)
%if dWAttrib.IsComplex
%assign regDType = ...
LibGetDataTypeComplexNameFromId(dWAttrib.DataTypeIdx)
%assign regIsComplex = TLC_TRUE
%else
%assign regDType = ...
LibGetDataTypeNameFromId(dWAttrib.DataTypeIdx)
%assign regIsComplex = TLC_FALSE
%endif
%assign blkPath = "%<SLibGrBlockCommentName(dWork.GrSrc)>"
%addtorecord ssInterface /
DiscState { /
Name "rt_dw_%<LibGetRecordIdentifier(dWork)>" /
Access dWAttrib.Access /
Address dWAttrib.BaseAddress /
BlockPath blkPath /
DataType regDType /
DataIsComplex regIsComplex /
Dimensions dWAttrib.Dimensions /
TID dWork.TID /
}
%assign ssInterface.NumDiscStates = ssInterface.NumDiscStates + 1
%endif
%endforeach
%endwith
%endforeach
%endwith
%endfunction
%function FcnAddDataStoresToRootInterface(rootInterface, dsBlk) void
%assign dsStore = dsBlk.DataStore
%assign mmi = DWorks.DWork[dsStore._idx].MemoryMapIdx
%assign data = SLibGetGlobalMemoryDataRecord(mmi)
%if !ISEMPTY(data)
%if (mmi[0] != -1) && (mmi[1] != -1)
%with ::CompiledModel.GlobalMemoryMap
%assign dataTypeIdx = StructuredData[mmi[0]].Section[mmi[1]].DataTypeIdx
%assign isComplex = StructuredData[mmi[0]].Section[mmi[1]].IsComplex
%endwith
%else
%assign dataTypeIdx = data.DataTypeIdx
%assign isComplex = data.IsComplex
%if (mmi[0] == -1) && (data.Class == "other")
%return []
%endif
%endif
%if isComplex
%assign dType = LibGetDataTypeComplexNameFromId(dataTypeIdx)
%assign isStruct = TLC_TRUE
%else
%assign dType = LibGetDataTypeNameFromId(dataTypeIdx)
%assign isStruct = TLC_FALSE
%endif
%if ISFIELD(data, "NumRows")
%assign dimensions = [%<data.NumRows>, %<data.NumCols>]
%elseif data.NumDimensions > -1
%assign dimensions = data.Dimensions
%else
%assign dimensions = -1
%endif
%if MultiInstanceERTCode
%assign access = "Argument"
%else
%assign access = "Global"
%endif
%assign blkPath = "%<SLibGrBlockCommentName(DWorks.DWork[dsStore._idx].GrSrc)>"
%addtorecord rootInterface /
DataStore { /
Name "rt_ds_%<dsStore.MemoryName>" /
Access access /
BlockPath blkPath /
DataType dType /
Dimensions dimensions /
DataIsStruct isStruct /
Address data.BaseAddr /
TID DWorks.DWork[dsStore._idx].TID /
}
%assign rootInterface.NumDataStores = rootInterface.NumDataStores + 1
%endif
%endfunction
%function FcnGetSigRecFromRegion(region)
%assign portObj = SLibCreateDummyPortRecord()
%assign portObj.SignalSrc = region._Source
%assign offset = region.Offset
%assign portObj.SignalOffset = offset
%assign sigRec = SLibGetSourceRecord(portObj, 0)
%return sigRec
%endfunction
%function FcnUpdateDataAttribBasedOnBusSelElIdx(region, dataAttrib)
%if ISFIELD(region, "BusSelElCGTypeId") && ...
(!ISEQUAL(region.BusSelElCGTypeId, -1))
%assign portObj = SLibCreateDummyPortRecord()
%assign portObj.SignalSrc = region._Source
%assign portObj.SignalOffset = region.Offset
%assign portObj.BusSelElIdx = region.BusSelElIdx
%assign portObj.BusSelElCGTypeId = region.BusSelElCGTypeId
%assign rec = SLibGetSourceRecordAndMapInfo(portObj, 0, TLC_FALSE, TLC_FALSE)
%createrecord tmpRec {CGTypeIdx rec.busSelElCGTypeId}
%assign dataAttrib.DataTypeIdx = LibGetRecordDataTypeId(tmpRec)
%assign dataAttrib.Dimensions = [%<LibGetRecordWidth(tmpRec)>]
%assign dataAttrib.IsComplex = LibGetRecordIsComplex(tmpRec)
%endif
%return dataAttrib
%endfunction
%function FcnGetDataAttribFromRecord(sigRec, isReusable) void
%assign retArg = []
%if !ISEMPTY(sigRec)
%if isReusable
%assign access = "Argument"
%if (sigRec.RecordType == "DWork") && (sigRec.StorageClass != "Auto")
%assign access = "Global"
%endif
%else
%if ((sigRec.RecordType == "BlockOutput") && ...
(sigRec.Invariant == "yes"))
%assign access = "ConstGlobal"
%else
%assign access = "Global"
%endif
%endif
%assign idName = ""
%assign needsIndex = 0
%assign memoryMapIdx = sigRec.MemoryMapIdx
%if memoryMapIdx[2] == -1
%if (sigRec.RecordType == "BlockOutput") && ...
(TYPE(sigRec.SigConnected) == "Identifier") && (sigRec.SigConnected == "none")
%assign access = "Unconnected"
%assign addr = ""
%assign dataTypeIdx = LibGetRecordDataTypeId(sigRec)
%assign dimensions = [%<LibGetRecordWidth(sigRec)>]
%assign isComplex = LibGetRecordIsComplex(sigRec)
%elseif !isReusable
%if ((sigRec.RecordType == "BlockOutput") && ...
((sigRec.ConstExpr) || (sigRec.Invariant == "yes")))
%if InlineParameters == 1
%assign access = "ConstInlined"
%assign addr = ""
%assign dataTypeIdx = LibGetRecordDataTypeId(sigRec)
%assign dimensions = [%<LibGetRecordWidth(sigRec)>]
%assign isComplex = LibGetRecordIsComplex(sigRec)
%else
%assign access = "Global"
%assign sigSrc = sigRec.SigSrc
%assign srcBlock = System[sigSrc[0]].Block[sigSrc[2]]
%with srcBlock
%assign addr = LibBlockOutputSignalAddr(sigSrc[3], "", "", 0)
%endwith
%assign dataTypeIdx = LibGetRecordDataTypeId(sigRec)
%assign dimensions = [%<LibGetRecordWidth(sigRec)>]
%assign isComplex = LibGetRecordIsComplex(sigRec)
%endif
%elseif ( (sigRec.RecordType == "BlockOutput") && ...
ISEQUAL(sigRec.DrivesRootOutport, "yes") )
%assign oPortIdx = -1
%assign regIdx = -1
%with ::CompiledModel.BlockHierarchyMap.Subsystem[0]
%foreach oIdx = SIZE(OutportBlocks,1)
%foreach rIdx = Block[OutportBlocks[oIdx]].DataInputPort.NumRegions
%assign oReg = Block[OutportBlocks[oIdx]].DataInputPort.Region[rIdx]
%if ISEQUAL(oReg._Source[0], sigRec.LogicalSrc)
%assign oPortIdx = oIdx
%assign regIdx = rIdx
%break
%endif
%endforeach
%endforeach
%endwith
%if (oPortIdx != -1)
%return FcnGetDataAttribOfRootOutput(sigRec, isReusable, oPortIdx, regIdx)
%else
%<LibReportFatalError("Subsystem Interface error: subsystem outports driving root outports")>
%endif
%else
%assign access = "Local"
%assign addr = ""
%assign dataTypeIdx = LibGetRecordDataTypeId(sigRec)
%assign dimensions = [%<LibGetRecordWidth(sigRec)>]
%assign isComplex = LibGetRecordIsComplex(sigRec)
%endif
%else
%assign access = "Local"
%assign addr = ""
%assign dataTypeIdx = LibGetRecordDataTypeId(sigRec)
%assign dimensions = [%<LibGetRecordWidth(sigRec)>]
%assign isComplex = LibGetRecordIsComplex(sigRec)
%endif
%else
%assign structIdx = memoryMapIdx[0]
%assign secIdx = memoryMapIdx[1]
%assign dataIdx = memoryMapIdx[2]
%with ::CompiledModel.GlobalMemoryMap
%if secIdx == -1
%assign data = UnstructuredData.Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%elseif structIdx == -1
%assign data = CustomData[secIdx].Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%if data.Class == "other"
%return []
%endif
%else
%assign section = ...
StructuredData[structIdx].Section[secIdx]
%assign data = section.Data[dataIdx]
%assign dataTypeIdx = section.DataTypeIdx
%assign isComplex = section.IsComplex
%endif
%endwith
%if ISFIELD(data, "NumRows")
%assign dimensions = [%<data.NumRows>, %<data.NumCols>]
%elseif data.NumDimensions > -1
%assign dimensions = data.Dimensions
%else
%assign dimensions = -1
%endif
%assign addr = data.BaseAddr
%if ISFIELD(data, "Name")
%assign idName = data.Name
%endif
%if ISFIELD(data,"Class")
%if data.Class == "vector" || data.Class == "col-mat" || ...
data.Class == "row-mat" || data.Class == "col-mat-nd"
%assign needsIndex = 1
%endif
%endif
%endif
%createrecord dataAttrib { /
Access access /
BaseAddress addr /
DataTypeIdx dataTypeIdx /
IsComplex isComplex /
Dimensions dimensions /
Symbol idName /
NeedsIndex needsIndex /
}
%if access == "ConstInlined"
%addtorecord dataAttrib Value sigRec.InitialValue
%endif
%return dataAttrib
%else
%endif
%return retArg
%endfunction
%function GetBlockDstSignalSymbolAndOffset(sigIdx) void
%assign tmpVect = SLibGetReimAndIdx(sigIdx)
%assign reim = tmpVect[0]
%assign idx = tmpVect[1]
%if reim == tImagPart && !LibBlockInputSignalIsComplex(0)
%createrecord result { /
Symbol "" /
}
%return result
%endif
%assign inputWidth = LibBlockInputSignalWidth(0)
%assign sigIndexer = SLibGet1DArrayIndexer(inputWidth, "", "", idx)
%assign symbol = ""
%assign offset = ""
%assign outPortNum = LibBlockParamSetting("Outport", "PortNumber") - 1
%if !(CodeFormat == "S-Function")
%assign ans = "%<LibGetExternalOutputStruct()>%<YQualifier>%<Identifier>%<sigIndexer>"
%if !MultiInstanceERTCode
%assign symbol = "%<LibGetExternalOutputStruct()>%<YQualifier>%<Identifier>"
%if !ISEMPTY(sigIndexer)
%assign offset = sigIdx
%endif
%if reim != "" && LibBlockInputSignalIsComplex(0)
%assign ans = ans + ".%<reim>"
%assign symbol = ans
%endif
%endif
%endif
%if !ISEMPTY(offset)
%createrecord result { /
Symbol symbol /
Offset offset /
}
%else
%createrecord result { /
Symbol symbol /
}
%endif
%return result
%endfunction
%function FcnGetDataAttribOfRootOutput(sigRec, isReusable, ...
outportIdx, regionIdx) void
%assign retVal = []
%if ISEMPTY(sigRec) || (sigRec.MemoryMapIdx[2] == -1)
%assign grSystem = ::CompiledModel.BlockHierarchyMap.Subsystem[0]
%if outportIdx >= grSystem.NumOutportBlocks
%<LibReportFatalError("Subsystem Interface error in root outports")>
%endif
%assign grOutBlock = grSystem.Block[grSystem.OutportBlocks[outportIdx]]
%if SLibSystemBlockExist(grOutBlock)
%assign blockIndex = SLibGetSystemBlockIdx(grOutBlock)
%with ::CompiledModel
%assign system = System[blockIndex[0]]
%assign outBlock = system.Block[blockIndex[2]]
%with outBlock
%assign rollRegionMtrx = LibRollRegions2StartEndMatrix(RollRegions)
%if regionIdx >= SIZE(rollRegionMtrx, 1)
%<LibReportFatalError("Subsystem Interface error in root outports")>
%endif
%assign offsetIdx = CAST("Number", rollRegionMtrx[0][regionIdx])
%assign outSignalAddr = ...
LibBlockDstSignalLocation("outportblk", "", "", offsetIdx)
%assign outSignalSymAndOffset = ...
GetBlockDstSignalSymbolAndOffset(offsetIdx)
%assign dataTypeIdx = LibBlockInputSignalDataTypeId(0)
%assign dimensions = [%<LibBlockInputSignalWidth(0)>]
%assign isComplex = LibBlockInputSignalIsComplex(0)
%assign access = isReusable ? "Argument" : "Global"
%createrecord dataAttrib { /
Access access /
BaseAddress "&(%<outSignalAddr>)" /
DataTypeIdx dataTypeIdx /
IsComplex isComplex /
Dimensions dimensions /
Symbol "%<outSignalSymAndOffset.Symbol>" /
}
%if ISFIELD(outSignalSymAndOffset, "Offset")
%addtorecord dataAttrib Offset outSignalSymAndOffset.Offset
%endif
%return dataAttrib
%endwith
%endwith
%endif
%else
%return FcnGetDataAttribFromRecord(sigRec, isReusable)
%endif
%return retVal
%endfunction
%function FcnAddInputToExportFunction(extInIdx, expFcn) void
%assign extInp = ::CompiledModel.ExternalInputs.ExternalInput[extInIdx]
%assign slName = "rt_" + LibGetRecordIdentifier(extInp)
%assign memoryMapIdx = extInp.MemoryMapIdx
%if memoryMapIdx[2] == -1
%assign errTxt = "A exported function I/O's memory is undefined"
%<LibReportFatalError(errTxt)>
%else
%assign structIdx = memoryMapIdx[0]
%assign secIdx = memoryMapIdx[1]
%assign dataIdx = memoryMapIdx[2]
%with ::CompiledModel.GlobalMemoryMap
%if secIdx == -1
%assign data = UnstructuredData.Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%elseif structIdx == -1
%assign data = CustomData[secIdx].Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%if data.Class == "other"
%return
%endif
%else
%assign section = StructuredData[structIdx].Section[secIdx]
%assign data = section.Data[dataIdx]
%assign dataTypeIdx = section.DataTypeIdx
%assign isComplex = section.IsComplex
%endif
%endwith
%if ISFIELD(data, "NumRows")
%assign dimensions = [%<data.NumRows>, %<data.NumCols>]
%elseif data.NumDimensions > -1
%assign dimensions = data.Dimensions
%else
%assign dimensions = -1
%endif
%assign addr = data.BaseAddr
%endif
%if isComplex
%assign dType = LibGetDataTypeComplexNameFromId(dataTypeIdx)
%else
%assign dType = LibGetDataTypeNameFromId(dataTypeIdx)
%endif
%addtorecord expFcn /
FunctionInput { /
Access "Global" /
SLName slName /
Address data.BaseAddr /
DataType dType /
DataIsStruct isComplex /
DataIsBus data.IsStruct /
Dimensions dimensions /
FunctionArgIdx -1 /
TID extInp.TID /
}
%assign expFcn.NumFunctionInputs = expFcn.NumFunctionInputs + 1
%endfunction
%function FcnAddOutputToExportFunction(extInIdx, expFcn) void
%assign extOut = ::CompiledModel.ExternalOutputs.ExternalOutput[extInIdx]
%assign sysIdx = extOut.Block[0]
%assign blkIdx = extOut.Block[1]
%assign outportBlock = System[sysIdx].Block[blkIdx]
%assign tid = outportBlock.TID
%assign slName = "rt_" + LibGetRecordIdentifier(outportBlock)
%if SLibExternalOutputIsVirtual(outportBlock)
%with outportBlock
%assign src = LibBlockInputSignalAddr(0, "", "", 0)
%assign portWidth = LibBlockInputSignalWidth(0)
%assign dTypeId = LibBlockInputSignalDataTypeId(0)
%assign dType = LibBlockInputSignalDataTypeName(0, "")
%assign isStruct = LibIsStructDataType(dTypeId)
%assign isComplex = LibBlockInputSignalIsComplex(0)
%endwith
%addtorecord expFcn /
FunctionOutput { /
Access "Global" /
SLName slName /
Address src /
DataType dType /
DataIsStruct isComplex /
DataIsBus isStruct /
Dimensions [%<portWidth>] /
FunctionArgIdx -1 /
TID tid /
}
%assign expFcn.NumFunctionOutputs = expFcn.NumFunctionOutputs + 1
%else
%assign memoryMapIdx = extOut.MemoryMapIdx
%if memoryMapIdx[2] == -1
%assign errTxt = "A exported function I/O's memory is undefined"
%<LibReportFatalError(errTxt)>
%else
%assign structIdx = memoryMapIdx[0]
%assign secIdx = memoryMapIdx[1]
%assign dataIdx = memoryMapIdx[2]
%with ::CompiledModel.GlobalMemoryMap
%if secIdx == -1
%assign data = UnstructuredData.Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%elseif structIdx == -1
%assign data = CustomData[secIdx].Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%if data.Class == "other"
%return
%endif
%else
%assign section = StructuredData[structIdx].Section[secIdx]
%assign data = section.Data[dataIdx]
%assign dataTypeIdx = section.DataTypeIdx
%assign isComplex = section.IsComplex
%endif
%endwith
%if ISFIELD(data, "NumRows")
%assign dimensions = [%<data.NumRows>, %<data.NumCols>]
%elseif data.NumDimensions > -1
%assign dimensions = data.Dimensions
%else
%assign dimensions = -1
%endif
%assign addr = data.BaseAddr
%endif
%if isComplex
%assign dType = LibGetDataTypeComplexNameFromId(dataTypeIdx)
%else
%assign dType = LibGetDataTypeNameFromId(dataTypeIdx)
%endif
%addtorecord expFcn /
FunctionOutput { /
Access "Global" /
SLName slName /
Address data.BaseAddr /
DataType dType /
DataIsStruct isComplex /
DataIsBus data.IsStruct /
Dimensions dimensions /
FunctionArgIdx -1 /
TID tid /
}
%assign expFcn.NumFunctionOutputs = expFcn.NumFunctionOutputs + 1
%endif
%endfunction
%function FcnConvertNameToIdentifier(s) void
%assign str = "char(bitor(bitand('%<s>'>='0','%<s>'<='9')," + ...
"bitor(bitand('%<s>'>='a','%<s>'<='z'),bitand('%<s>'>='A'," + ...
"'%<s>'<='Z'))).*'%<s>' + ~bitor(bitand('%<s>'>='0','%<s>'<='9')" + ...
",bitor(bitand('%<s>'>='a','%<s>'<='z'),bitand('%<s>'>='A'," + ...
"'%<s>'<='Z'))).*'_')"
%return FEVAL("eval", str)
%endfunction
%endif