%assign tempSLfeature = CGMODEL_ACCESS("CGModel.CAPIEmitMethod")
%if EXISTS("_CAPI_") == 0
%assign _CAPI_ = 1
%include "capilib.tlc"
%function SLibWriteToCAPIFilesCpp() void
%assign isMultiInstanceERTOrModelReference = IsMultiInstanceERTOrModelReference()
%assign isModelReferenceSimTarget = IsModelReferenceSimTarget()
%assign fcnDynamicAPI = FcnDynamicAPI()
%assign fcnCAPIRootIOSupport = FcnCAPIRootIOSupport()
%with ::CompiledModel.GlobalMemoryMap
%with BlockHierarchyMap
%assign useDatasetLoggingHier = TLC_FALSE
%assign numLogHierSigs = 0
%if IsModelReferenceSimTarget() && EXISTS(NumSignalHierLoggingInfo) && (NumSignalHierLoggingInfo > 0)
%assign useDatasetLoggingHier = TLC_TRUE
%assign numLogHierSigs = NumSignalHierLoggingInfo
%endif
%if IsModelReferenceSimTarget() && EXISTS(NumStateflowSigLogInfo) && (NumStateflowSigLogInfo > 0)
%assign numStateflowLoggedSigs = NumStateflowSigLogInfo
%assign stateflowLoggedSigsName = "rtStateflowChartLoggingInfo"
%else
%assign numStateflowLoggedSigs = 0
%assign stateflowLoggedSigsName = SLibGetNullDefinitionFromTfl()
%endif
%assign sysRanDWorkLen = SIZE(SubsystemRanBC.SysRanDWork, 1)
%assign existsNumSignalHierarchyDescriptors = EXISTS(NumSignalHierarchyDescriptors)
%endwith
%endwith
%assign ::tempRepo = FEVAL("genCapiInCpp","%<::CompiledModel.Name>",isMultiInstanceERTOrModelReference,...
isModelReferenceSimTarget,fcnDynamicAPI,RTWCAPISignals,RTWCAPIParams,RTWCAPIStates,...
RTWCAPIRootIO,UsingMalloc,useDatasetLoggingHier,numLogHierSigs,numStateflowLoggedSigs,...
stateflowLoggedSigsName,sysRanDWorkLen,fcnCAPIRootIOSupport,existsNumSignalHierarchyDescriptors,"")
%endfunction
%function SLibWriteToCAPIFiles() void
%realformat "CONCISE"
%<SetCurrentUtilsIncludesIdx("capi_src_util_incl")>
%openfile includesBuf
#include "rtw_modelmap.h"
%closefile includesBuf
%<SLibCacheCodeToFile("baseMdl_hdr_incl", includesBuf)>
%assign HeaderFile = LibGetMdlCapiHdrBaseName()
%openfile includesBuf
%if ((::CompiledModel.RTWStatesLogging==1) || (RTWCAPISignals==1)) && ...
MatFileLogging
#include "rt_logging_mmi.h"
%endif
#include "%<HeaderFile>.h"
%closefile includesBuf
%<SLibCacheCodeToFile("baseMdl_src_incl", includesBuf)>
%if ((::CompiledModel.RTWStatesLogging==1) || (RTWCAPISignals==1)) && ...
MatFileLogging
%<SLibAddToStaticSources("rt_logging_mmi.c")>
%<SLibAddToStaticSources("rtw_modelmap_utils.c")>
%endif
%<SLibMapData()>
%assign baseSysIdx = GetBaseSystemIdx()
%assign baseName = SLibGetSystemOutputHdrFileBaseName(System[baseSysIdx])
%openfile tmpCAPI_C_Includes
%<FcnWriteCAPIHeadersandDefines(baseName)>
%closefile tmpCAPI_C_Includes
%<SLibCacheCodeToFile("capi_src_incl", tmpCAPI_C_Includes)>
%if SLibIsERTTarget()
%if (WriteCAPIUsingTemplates == 0)
%assign useTemplates = TLC_FALSE
%else
%assign useTemplates = TLC_TRUE
%endif
%else
%assign useTemplates = TLC_FALSE
%endif
%if tempSLfeature==1 || tempSLfeature==2
%assign useTemplates = TLC_TRUE
%endif
%if tempSLfeature==1
%assign isMultiInstanceERTOrModelReference = IsMultiInstanceERTOrModelReference()
%assign isModelReferenceSimTarget = IsModelReferenceSimTarget()
%assign fcnDynamicAPI = FcnDynamicAPI()
%assign fcnCAPIRootIOSupport = FcnCAPIRootIOSupport()
%with ::CompiledModel.GlobalMemoryMap
%with BlockHierarchyMap
%assign useDatasetLoggingHier = TLC_FALSE
%assign numLogHierSigs = 0
%if IsModelReferenceSimTarget() && EXISTS(NumSignalHierLoggingInfo) && (NumSignalHierLoggingInfo > 0)
%assign useDatasetLoggingHier = TLC_TRUE
%assign numLogHierSigs = NumSignalHierLoggingInfo
%endif
%if IsModelReferenceSimTarget() && EXISTS(NumStateflowSigLogInfo) && (NumStateflowSigLogInfo > 0)
%assign numStateflowLoggedSigs = NumStateflowSigLogInfo
%assign stateflowLoggedSigsName = "rtStateflowChartLoggingInfo"
%else
%assign numStateflowLoggedSigs = 0
%assign stateflowLoggedSigsName = SLibGetNullDefinitionFromTfl()
%endif
%assign sysRanDWorkLen = SIZE(SubsystemRanBC.SysRanDWork, 1)
%assign existsNumSignalHierarchyDescriptors = EXISTS(NumSignalHierarchyDescriptors)
%endwith
%endwith
%assign ::tempRepo = FEVAL("genCapiInCpp","%<::CompiledModel.Name>",isMultiInstanceERTOrModelReference,...
isModelReferenceSimTarget,fcnDynamicAPI,RTWCAPISignals,RTWCAPIParams,RTWCAPIStates,...
RTWCAPIRootIO,UsingMalloc,useDatasetLoggingHier,numLogHierSigs,numStateflowLoggedSigs,...
stateflowLoggedSigsName,sysRanDWorkLen,fcnCAPIRootIOSupport,existsNumSignalHierarchyDescriptors,"")
%endif
%if (useTemplates)
%openfile tmpCAPI_Functions
%<FcnWriteCAPIStructures(tmpCAPI_Functions)>
%closefile tmpCAPI_Functions
%<SLibCacheCodeToFile("capi_fcn_defn", tmpCAPI_Functions)>
%else
%assign FileName = SLibGetFileNameForCode("mdl_capi_src") + ".%<::LangFileExt>"
%assign FileType = "source"
%<LibWriteToStandardOutput("### Writing %<FileType> file %<FileName>")>
%openfile outputFile = FileName
/*
* %<FileName>
*
%<SLibCommonHeaderInfo()>/
*/
%<tmpCAPI_C_Includes>/
%<FcnWriteCAPIStructures(outputFile)>
/* EOF: %<FileName> */
%closefile outputFile
%assign capiCFile = SLibGetFileRecForCode("mdl_capi_src")
%<SLibSetModelFileAttribute(capiCFile, "Filter", 1)>
%<SLibAddGeneratedFileToList(FileName,"interface","source","")>
%endif
%<SetCurrentUtilsIncludesIdx("")>
%assign baseSysIdx = GetBaseSystemIdx()
%assign baseName = SLibGetSystemOutputHdrFileBaseName(System[baseSysIdx])
%openfile tmpCAPI_H_Includes
#include "%<baseName>.h"
%closefile tmpCAPI_H_Includes
%<SLibCacheCodeToFile("capi_hdr_incl", tmpCAPI_H_Includes)>
%assign curBlockFcn = ::BlockFcn
%assign ::BlockFcn = "InitializeDataMapInfo"
%openfile tmpCAPI_H_Extern
%assign args = ::CompiledModel.CAPIFunctionArgs
%assign typePrefix = SLibGetModelTypesNamespacePrefix()
%if IsModelReferenceSimTarget()
%assign dwDecl = ""
%if args.isDwArgDeclSame
%assign dwDecl = args.dwArg
%endif
%<LibExternInFcnDecls()>void %<::CompiledModel.Name>_InitializeDataMapInfo(%<typePrefix>%<::tSimStructType> *const %<::tSimStruct>
%<args.uArg>%<args.bArg>%<args.pArg>%<dwDecl>%<args.xArg>%<args.ssArg>, void *sysRanPtr, int contextTid);
%else
%assign simstructDecl = ""
%if (::isRAccel || isRSim) && !IsModelReferenceTarget()
%else
%if MultiInstanceERTCode || IsModelReferenceTarget()
%assign simstructDecl = "%<typePrefix>%<::tSimStructType> *const %<::tSimStruct>"
%endif
%endif
%assign dwDecl = ""
%if args.isDwArgDeclSame
%assign dwDecl = args.dwArg
%endif
%assign fcnArgs = "%<simstructDecl>%<args.uArg>%<args.bArg>%<args.pArg>%<dwDecl>%<args.xArg>%<args.ssArg>"
%if ISEMPTY(fcnArgs)
%assign fcnArgs = "void"
%endif
%<LibExternInFcnDecls()>void %<::CompiledModel.Name>_InitializeDataMapInfo(%<fcnArgs>);
%endif
%closefile tmpCAPI_H_Extern
%assign ::BlockFcn = curBlockFcn
%<SLibCacheCodeToFile("capi_ext_fcn_decl", tmpCAPI_H_Extern)>
%if EXISTS(::HostCAPINeeded)
%<FcnWriteHostHeader()>
%endif
%if (useTemplates)
%else
%assign capiHFile = SLibGetFileRecForCode("mdl_capi_hdr")
%assign hFileIdx = capiHFile.Index
%assign HeaderFile = LibGetMdlCapiHdrBaseName()
%assign FileName = "%<HeaderFile>.h"
%assign FileType = "header"
%assign FileTag = LibGetModelFileTag(hFileIdx)
%<LibWriteToStandardOutput("### Writing %<FileType> file %<FileName>")>
%openfile outputFile = FileName
/*
* %<FileName>
*
%<SLibCommonHeaderInfo()>/
*/
#ifndef RTW_HEADER_%<FileTag>
#define RTW_HEADER_%<FileTag>
%<tmpCAPI_H_Includes>/
%<tmpCAPI_H_Extern>/
#endif /* RTW_HEADER_%<FileTag> */
/* EOF: %<FileName> */
%closefile outputFile
%<SLibSetModelFileAttribute(capiHFile, "Filter", 1)>
%<SLibAddGeneratedFileToList(FileName,"interface","header","")>
%endif
%endfunction
%function FcnSetAddrMapInfoWithLogging(im, addr, loggingFcn, comments, ppIf, ppFi, incNumActiveSignals) void
%assign im.NumDataAddr = im.NumDataAddr + 1
%assign im.AddrMap = im.AddrMap + addr
%assign im.LoggingFcns = im.LoggingFcns + loggingFcn
%assign im.AddrMapComments = im.AddrMapComments + comments
%assign im.AddrMapIf = im.AddrMapIf + ppIf
%assign im.AddrMapEndIf = im.AddrMapEndIf + ppFi
%assign im.NumActiveSignalsDuringCodegen = im.NumActiveSignalsDuringCodegen + incNumActiveSignals
%endfunction
%function FcnSetAddrMapInfo(im, addr, comments, ppIf, ppFi, incNumActiveSignals) void
%assign im.NumDataAddr = im.NumDataAddr + 1
%assign im.AddrMap = im.AddrMap + addr
%assign im.AddrMapComments = im.AddrMapComments + comments
%assign im.AddrMapIf = im.AddrMapIf + ppIf
%assign im.AddrMapEndIf = im.AddrMapEndIf + ppFi
%assign im.NumActiveSignalsDuringCodegen = im.NumActiveSignalsDuringCodegen + incNumActiveSignals
%endfunction
%function FcnWriteCAPIStructures(capiFile) Output
%createrecord /
InstMap { /
DataTypeMap []; /
DimensionMap []; /
DimensionMapIf []; /
DimensionMapEndIf []; /
AddrMap []; /
LoggingFcns []; /
AddrMapComments []; /
AddrMapIf []; /
AddrMapEndIf []; /
FixPointMap []; /
LogSignalsBuf []; /
DimArray []; /
DimArrayComments []; /
ElemMap []; /
SampleTimeMap []; /
DoublesMap []; /
GroundsMap []; /
NumBlockParams 0; /
NumVariableParams 0; /
NumBIOSignals 0; /
NumBlockStates 0; /
NumRootInputs 0; /
NumRootOutputs 0; /
NumFixPoint 1; /
NumDataTypes 0; /
NumDimensionMaps 0; /
NumDimArray 0; /
NumDataAddr 0; /
NumActiveSignalsDuringCodegen -1; /
NumLogSignals 0; /
NumElements 1; /
NumSampleTimes 0; /
NumDoubles 0; /
NumGrounds 0; /
VarDimsAddrMap []; /
VarDimsAddrMapIf []; /
VarDimsAddrMapEndIf []; /
NumVarDimsAddr 0; /
FxpKeys { /
} /
DTypeKeys { /
} /
DimKeys { /
} /
DimArrayKeys { /
} /
ElementKeys { /
} /
STimeKeys { /
} /
DoubleKeys { /
} /
VarDimsAddrKeys { /
} /
GroundKeys{ /
} /
}
%assign im = InstMap
%createrecord InCAPI { /
NumBlockParams 0; /
NumVariableParams 0; /
NumBIOSignals 0; /
NumGrndSignals 0; /
NumExtInputs 0; /
NumSFLocals 0; /
NumDiscStates 0; /
NumContStates 0; /
NumVarDimsSignals 0; /
NumRootInputs 0; /
NumRootOutputs 0 /
}
%addtorecord InCAPI NumDataGroupElements ...
Vector(%<::CompiledModel.NumCoderDataGroups>) [0@%<::CompiledModel.NumCoderDataGroups>]
%assign CAPIHooks = FcnCAPIHookInit()
%assign loggingInfoStartIdx = []
%assign loggingInfoBlockPath = []
%assign loggingInfoPortIndex = []
%assign loggingInfoSysNum = []
%assign nulldef = SLibGetNullDefinitionFromTfl()
%assign addrMapIndex = "addressMapIndex"
%assign addrMapIndexPP = addrMapIndex + "++"
%assign dynamicInit = ""
%assign numSignals = "mmiStatic.Signals.numSignals"
%assign numStates = "mmiStatic.States.numStates"
%assign numBlockParams = "mmiStatic.Params.numBlockParameters"
%assign numModelParams = "mmiStatic.Params.numModelParameters"
%assign numRootInputs = "mmiStatic.Signals.numRootInputs"
%assign numRootOutputs = "mmiStatic.Signals.numRootOutputs"
%assign numSignalsPP = numSignals + "++"
%assign numStatesPP = numStates + "++"
%assign numBlockParamsPP = numBlockParams + "++"
%assign numModelParamsPP = numModelParams + "++"
%assign numRootInputsPP = numRootInputs + "++"
%assign numRootOutputsPP = numRootOutputs + "++"
%assign constKeyword = IsMultiInstanceERTOrModelReference() || FcnDynamicAPI() ? ...
"" : "const"
%assign needsAddressMapIndexVar = TLC_FALSE
%assign isRM = %
%assign prefix = (::PrefixModelToStructs) ? "%<Name>_" : ""
%assign ::skipSubSystem = TLC_FALSE
%assign ::skipwideFxPt = TLC_FALSE
%assign ::skipComplex = TLC_FALSE
%assign ::skipStruct = TLC_FALSE
%assign ::skipBusCreator = TLC_FALSE
%assign ::skipIsProtected = TLC_FALSE
%if EXISTS(slrt)
%
%endif
%with ::CompiledModel.GlobalMemoryMap
%with BlockHierarchyMap
%if RTWCAPISignals == 1
%if EXISTS("capiSigTestFile")
%include "%<capiSigTestFile>"
%endif
%if tempSLfeature==1 || tempSLfeature==2
%openfile datalogging
%endif
%assign useDatasetLoggingHier = TLC_FALSE
%if IsModelReferenceSimTarget() && EXISTS(NumSignalHierLoggingInfo) && (NumSignalHierLoggingInfo > 0)
%assign useDatasetLoggingHier = TLC_TRUE
%assign numLogHierSigs = NumSignalHierLoggingInfo
%<FcnWriteDatasetLoggingHier()>
%endif
%if IsModelReferenceSimTarget() && EXISTS(NumStateflowSigLogInfo) && (NumStateflowSigLogInfo > 0)
%assign numStateflowLoggedSigs = NumStateflowSigLogInfo
%<FcnWriteDatasetLoggingSFSignals()>
%assign stateflowLoggedSigsName = "rtStateflowChartLoggingInfo"
%else
%assign numStateflowLoggedSigs = 0
%assign stateflowLoggedSigsName = nulldef
%endif
%if tempSLfeature==1 || tempSLfeature==2
%closefile datalogging
%<SLibCacheCodeToFile("capi_struct_defn", datalogging)>
%endif
%if tempSLfeature==0 || tempSLfeature==2
%if tempSLfeature==2
%openfile filterBlkOutputbuf
%endif
/* Block output signal information */
static %<constKeyword> %<tBlockSignalsType> %<tBlockSignals>[] = {
/* addrMapIndex, sysNum, blockPath,
* signalName, portNumber, dataTypeIndex, dimIndex, fxpIndex, sTimeIndex
*/
%assign portObj = SLibCreateDummyPortRecord()
%assign busIdx = 0
%assign busHier = TLC_FALSE
%assign firstTime = TLC_TRUE
%if IsModelReferenceSimTarget() && !useDatasetLoggingHier && EXISTS(NumSignalHierarchyDescriptors)
%assign busHier = TLC_TRUE
%assign busIndexVector = Matrix(1,2) [ [-1, -1] ]
%endif
%if busHier
%foreach shdIdx = NumSignalHierarchyDescriptors
%with SignalHierarchyDescriptor[shdIdx]
%if ISFIELD(SignalHierarchyDescriptor[shdIdx], "Virtual")
%assign virtBlock = (SignalHierarchyDescriptor[shdIdx].Virtual > 0)
%else
%assign virtBlock = TLC_FALSE
%endif
%assign sysIdx = SubsystemIdx
%if NumHierarchyNodes != 1
%
%endif
%foreach hnIdx = NumHierarchyNodes
%with HierarchyNode[hnIdx]
%if NumRegions > 1 || Type == "BusCreator" || ISFIELD(Region[0], "SigHierIdx")
%addtorecord HierarchyNode[hnIdx] rtwCAPIBusIdx busIdx
%assign busIdx = busIdx + 1
%if firstTime
%assign busIndexVector[0] = [%<shdIdx>, 0]
%assign firstTime = TLC_FALSE
%else
%assign busIndexVector = busIndexVector + [%<shdIdx>, 0]
%endif
%continue
%endif
%assign portObj.SignalSrc = Region[0]._Source
%assert !ISFIELD(Region[0],"BusSelElIdx")
%assign regionOffset = Region[0].Offset
%assign regionDimensions = Region[0].Dimensions
%assign sigRec = SLibGetSourceRecord(portObj, 0)
%assign regionIsGround = TLC_FALSE
%assign constString = ""
%assign ppIf = ""
%assign ppFi = ""
%if (::skipIsProtected)
%continue
%endif
%if !(ISEMPTY(sigRec))
%if (RTWCAPITestPtSignals == 1) && ...
(sigRec.TestPoint !="yes")
%continue
%endif
%if (sigRec.Invariant == "yes") && ...
!IsMultiInstanceERTOrModelReference()
%assign constString = "(void *) "
%endif
%if TYPE(sigRec.TID) != "Number" && ...
TYPE(sigRec.TID) == "String"
%if sigRec.TID != "constant" && ...
sigRec.TID != "trigger"
%continue
%endif
%endif
%if sigRec.MemoryMapIdx[2] == -1
%continue
%else
%assign structIdx = sigRec.MemoryMapIdx[0]
%assign secIdx = sigRec.MemoryMapIdx[1]
%assign dataIdx = sigRec.MemoryMapIdx[2]
%if secIdx == -1
%assign data = UnstructuredData.Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%assign isPointer = (data.Access == "indirect") ? 1 : 0
%elseif structIdx == -1
%assign data = CustomData[secIdx].Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%assign isPointer = (data.Access == "indirect") ? 1 : 0
%assign constString = "(void *) "
%else
%assign section = ...
StructuredData[structIdx].Section[secIdx]
%assign data = section.Data[dataIdx]
%assign dataTypeIdx = section.DataTypeIdx
%assign isComplex = section.IsComplex
%assign isPointer = TLC_FALSE
%endif
%assign ppIf = data.PPIf
%assign ppFi = data.PPEndIf
%endif
%if data.IsStruct
%if ISFIELD(Region[0], "IsComplex")
%assign isComplex = 1
%endif
%if ISFIELD(Region[0], "DataTypeId")
%assign dataTypeIdx = Region[0].DataTypeId
%endif
%endif
%if !FcnDataSupportsCAPI(data)
%continue
%endif
%assign dataAddress = data.BaseAddr
%assign dataIsFixPt = data.IsFixedPoint
%assign dataIsStruct = data.IsStruct
%elseif ISFIELD(Region[0], "GroundDataTypeIdx")
%assign regionIsGround = TLC_TRUE
%assign dataTypeIdx = Region[0].GroundDataTypeIdx
%assign isComplex = Region[0].GroundIsComplex
%assign isPointer = TLC_FALSE
%assign dataAddress = ...
FcnGetCAPIGroundAddr(im, dataTypeIdx, isComplex, regionDimensions)
%assign dataIsFixPt = TLC_FALSE
%assign dataIsStruct = TLC_FALSE
%else
%continue
%endif
%<FcnOptionallyAddModelRefCanonicalInputNeededByCAPIFlag(sigRec)>
%assign addrMapIdx = im.NumDataAddr
%assert !ISFIELD(HierarchyNode[hnIdx], "rtwCAPIAddrMapIdx")
%addtorecord HierarchyNode[hnIdx] rtwCAPIAddrMapIdx addrMapIdx
%if isPointer
%assign sigAddress = dataAddress
%assign comments = "%<im.NumDataAddr>: Signal Pointer"
%elseif (regionOffset > 0)
%if isComplex
%assign regionOffset = regionOffset*2
%endif
%assign castString = ""
%if dataIsStruct
%assign castString = "(char *)"
%endif
%assign sigAddress = "%<castString> %<dataAddress>"
%if !WHITE_SPACE(castString)
%assign sigAddress = FcnReplaceCCastWithStaticCastForCPP(sigAddress)
%endif
%assign sigAddress = constString + ...
"(%<sigAddress> + %<regionOffset>)"
%assign comments = "%<im.NumDataAddr>: Signal"
%else
%assign sigAddress = constString + dataAddress
%assign comments = "%<im.NumDataAddr>: Signal"
%endif
%if !(regionIsGround && Region[0].GroundIsSynthesized)
%if GrSrc[0] != -1
%assign grPath = SLibMangledGrBlockPath(GrSrc)
%else
%assert ISFIELD(SignalHierarchyDescriptor[shdIdx], "FullBlockPath") == TLC_TRUE
%assign grPath = FullBlockPath
%endif
%assign blkPath = FcnReturnCompliantBlockPath(grPath, "Signal")
%else
%assign grPath = ""
%assign blkPath = ""
%endif
%assign isActiveDuringCodegen = 1
%if(!ISEMPTY(sigRec) && ISFIELD(sigRec,"isActiveDuringCodegen"))
%assign isActiveDuringCodegen = sigRec.isActiveDuringCodegen
%endif
%if isRM
%<FcnSetAddrMapInfoWithLogging(im, sigAddress, "", comments, ppIf, ppFi, isActiveDuringCodegen)>
%else
%<FcnSetAddrMapInfo(im, sigAddress, comments, ppIf, ppFi, isActiveDuringCodegen)>
%endif
%assign sigLabel = HierarchyNode[hnIdx].SignalLabel
%assign dataTypeMapIdx = ...
FcnGetDataTypeMapIdx(dataTypeIdx,isComplex,isPointer,im)
%if virtBlock || ISFIELD(Region[0], "PartialSrcRegion")
%assign dimMapIdx = ...
FcnGetVirtSigDimensionMapIdx(regionDimensions,im, ppIf, ppFi)
%else
%assign dimMapIdx = FcnGetDimensionMapIdx(data,im, ppIf, ppFi)
%endif
%if dataIsFixPt
%assign fxpMapIdx = FcnGetFxpMapIdx(data,im)
%else
%assign fxpMapIdx = 0
%endif
%if !ISEMPTY(sigRec) && (sigRec.FrameData == "yes")
%assign isFrame = 1
%else
%assign isFrame = 0
%endif
%if !ISEMPTY(sigRec)
%if TYPE(sigRec.TID) == "Number"
%assign tID = sigRec.TID
%assign sTimeIdx = FcnGetSampTimeIdx(tID,isFrame,im)
%elseif sigRec.TID == "constant"
%assign tID = -2
%assign sTimeIdx = FcnGetSampTimeIdx(tID,isFrame,im)
%elseif sigRec.TID == "trigger"
%assign tID = -1
%assign sTimeIdx = FcnGetSampTimeIdx(tID,isFrame,im)
%else
%<SLibReportErrorWithId("RTW:tlc:TIDType")>
%endif
%assign sysNum = sigRec.SysNum
%else
%assign tID = -2
%assign sTimeIdx = FcnGetSampTimeIdx(tID,isFrame,im)
%assign sysNum = ::CompiledModel.NumSystems-1
%endif
%if FcnDynamicAPI()
%assign needsAddressMapIndexVar = TLC_TRUE
%assign entryIndex = 0
%assign dynamicInit = dynamicInit + ppIf + "/n" + tBlockSignals + ...
"[" + numSignals + "].addrMapIndex = " + addrMapIndex + ...
";/n" + numSignalsPP + ";/n" + addrMapIndexPP + ";/n" + ...
ppFi + "/n"
%else
%assign entryIndex = addrMapIdx
%endif
%<ppIf>
{%<entryIndex>, %<sysNum>, TARGET_STRING("%<blkPath>"),
TARGET_STRING("%<sigLabel>"), %<OutputPortIdx>, %<dataTypeMapIdx>, /
%<dimMapIdx>, %<fxpMapIdx>, %<sTimeIdx>},
%<ppFi>
%if IsModelReferenceSimTarget()
%assign loggingInfoStartIdx = ...
loggingInfoStartIdx + regionOffset
%assign loggingInfoBlockPath = ...
loggingInfoBlockPath + ...
STRING(grPath)
%assign loggingInfoPortIndex = loggingInfoPortIndex + %<hnIdx>
%assign loggingInfoSysNum = ...
loggingInfoSysNum + %
%endif
%if !ISEMPTY(sigRec)
%if ISFIELD(sigRec, "VarGroupIdx") && ...
LibGetVarGroupCategory(sigRec.VarGroupIdx[0]) == "HierarchicalCoderData"
%assign groupIdx = ::CompiledModel.VarGroups.VarGroup[sigRec.VarGroupIdx[0]].CoderDataGroupIndex
%assign InCAPI.NumDataGroupElements[groupIdx] = InCAPI.NumDataGroupElements[groupIdx] + 1
%elseif (sigRec.RecordType == "ExternalInput")
%assign InCAPI.NumExtInputs = InCAPI.NumExtInputs + 1
%if IsMultiInstanceERTOrModelReference()
%<SLibAccessThisSysFcnArgHelper(sigRec, "Registration", "", "", TLC_TRUE)>
%endif
%else
%assign InCAPI.NumBIOSignals = InCAPI.NumBIOSignals + 1
%endif
%if SLibGetArgIsVarDims(sigRec)
%assign InCAPI.NumVarDimsSignals = InCAPI.NumVarDimsSignals + 1
%endif
%endif
%if regionIsGround
%assign InCAPI.NumGrndSignals = InCAPI.NumGrndSignals + 1
%endif
%endwith
%endforeach
%endwith
%endforeach
%endif
%foreach subsysIdx = NumSubsystems
%with Subsystem[subsysIdx]
%assign isRootSys = (Subsystem[subsysIdx].Type == "root") ? 1 : 0
%foreach blkIdx = NumBlocks
%with Block[blkIdx]
%assign virtBlock = (Block[blkIdx].Virtual > 0)
%assign isInport = (Block[blkIdx].Type == "Inport") ? 1 : 0
%assign rootInport= (isRootSys && isInport) ? 1: 0
%assign isTestPointedForEachParitionedInport = ISFIELD(Block[blkIdx], "IsTestPointedForEachPartitionedInport") && ...
(Block[blkIdx].IsTestPointedForEachPartitionedInport > 0)
%assign isSubsystem = (Block[blkIdx].Type == "SubSystem") ? 1 : 0
%if (skipSubSystem && isSubsystem)
%continue
%endif
%assign isBusCreator = (Block[blkIdx].Type == "BusCreator") ? 1 : 0
%if (skipBusCreator && isBusCreator )
%continue
%endif
%if (skipIsProtected)
%continue
%endif
%if ((!virtBlock) || (IsModelReferenceTarget()) ...
|| rootInport || (virtBlock && isSubsystem) || isTestPointedForEachParitionedInport)
%foreach portIdx = NumDataOutputPorts
%assign ppIf = ""
%assign ppFi = ""
%with DataOutputPort[portIdx]
%if IsModelReferenceSimTarget() && TestPoint == 1 && MdlRefSimLoggableTestPoint == 0
%continue
%endif
%if busHier && NumRegions > 1
%continue
%endif
%foreach regIdx = NumRegions
%if (virtBlock && (TestPoint == 0) && !isTestPointedForEachParitionedInport)
%continue
%endif
%assign portObj.SignalSrc = Region[regIdx]._Source
%if ISFIELD(Region[regIdx],"BusSelElIdx")
%assign portObj.BusSelElIdx = Region[regIdx].BusSelElIdx[0]
%assign portObj.BusSelElCGTypeId = Region[regIdx].BusSelElCGTypeId[0]
%endif
%assign regionOffset = Region[regIdx].Offset
%assign regionDimensions = Region[regIdx].Dimensions
%assign sigRec = SLibGetSourceRecord(portObj, 0)
%assign regionIsGround = TLC_FALSE
%assign constString = ""
%if !(ISEMPTY(sigRec))
%if sigRec.RecordType == "ExternalOutput" || ...
sigRec.RecordType == "ContState"
%continue
%endif
%if (RTWCAPITestPtSignals == 1) && ...
(sigRec.TestPoint !="yes")
%continue
%endif
%if (sigRec.Invariant == "yes") && ...
!IsMultiInstanceERTOrModelReference()
%assign constString = "(void *) "
%endif
%if TYPE(sigRec.TID) != "Number" && ...
TYPE(sigRec.TID) == "String"
%if sigRec.TID != "constant" && ...
sigRec.TID != "trigger"
%continue
%endif
%endif
%if sigRec.MemoryMapIdx[2] == -1
%continue
%else
%assign structIdx = sigRec.MemoryMapIdx[0]
%assign secIdx = sigRec.MemoryMapIdx[1]
%assign dataIdx = sigRec.MemoryMapIdx[2]
%if secIdx == -1
%assign data = UnstructuredData.Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%assign isPointer = (data.Access == "indirect") ? 1 : 0
%if sigRec.StorageTypeQualifier=="volatile"
%assign constString = "(void *) "
%endif
%elseif structIdx == -1
%assign data = CustomData[secIdx].Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%assign isPointer = (data.Access == "indirect") ? 1 : 0
%assign constString = "(void *) "
%else
%assign section = ...
StructuredData[structIdx].Section[secIdx]
%assign data = section.Data[dataIdx]
%assign dataTypeIdx = section.DataTypeIdx
%assign isComplex = section.IsComplex
%assign isPointer = TLC_FALSE
%endif
%assign ppIf = data.PPIf
%assign ppFi = data.PPEndIf
%if (skipComplex && isComplex)
%continue
%endif
%endif
%if !FcnDataSupportsCAPI(data)
%continue
%endif
%assign dataAddress = data.BaseAddr
%assign dataIsFixPt = data.IsFixedPoint
%assign dataIsStruct = data.IsStruct
%if (skipStruct && dataIsStruct)
%continue
%endif
%elseif ISFIELD(Region[regIdx], "GroundDataTypeIdx")
%assign regionIsGround = TLC_TRUE
%assign dataTypeIdx = Region[regIdx].GroundDataTypeIdx
%assign isComplex = Region[regIdx].GroundIsComplex
%assign isPointer = TLC_FALSE
%assign dataAddress = ...
FcnGetCAPIGroundAddr(im, dataTypeIdx, isComplex, regionDimensions)
%assign dataIsFixPt = TLC_FALSE
%assign dataIsStruct = TLC_FALSE
%if (skipStruct && dataIsStruct)
%continue
%endif
%else
%continue
%endif
%<FcnOptionallyAddModelRefCanonicalInputNeededByCAPIFlag(sigRec)>
%createrecord recordToUseWithFxpMapIdx { }
%if ISFIELD(Region[regIdx],"BusSelElIdx")
%assign busSelElIdx = Region[regIdx].BusSelElIdx[0]
%assert !ISEMPTY(busSelElIdx)
%assign dataTypeIdx = LibCGTypeToSLType(Region[regIdx].BusSelElCGTypeId[0])
%assign isComplex = LibCGTypeIsComplex(Region[regIdx].BusSelElCGTypeId[0])
%assign dataAddress = FEVAL("regexprep", dataAddress, "//[//d+//]$", "")
%if busSelElIdx[0] != "." || LibDoesStringContainDotOrArrow(dataAddress)
%assign dataAddress = FEVAL("regexprep", ...
dataAddress, "&(.*)", "&($1" + busSelElIdx + ")")
%else
%assign dataAddress = FEVAL("regexprep", ...
dataAddress, "&(.*)", "&((*$1)" + busSelElIdx + ")")
%endif
%assign dataIsStruct = LibIsStructDataType(dataTypeIdx)
%assign dataIsFixPt = LibIsDataTypeFixpt(dataTypeIdx)
%if dataIsFixPt
%assign fxpIdx = FcnGetUniformFixPtTypeInGMM(DataTypes.DataType[dataTypeIdx])
%addtorecord recordToUseWithFxpMapIdx /
FixedPointInfo GlobalMemoryMap.FixedPointMaps.FixPtRecord[fxpIdx]
%endif
%endif
%assign addrMapIdx = im.NumDataAddr
%addtorecord Region[regIdx] CAPIAddrMapIdx addrMapIdx
%if busHier
%if !ISEMPTY(sigRec) && !ISFIELD(sigRec, "rtwCAPIAddrMapIdx")
%with sigRec
%addtorecord sigRec rtwCAPIAddrMapIdx addrMapIdx
%endwith
%else
%endif
%endif
%if isPointer
%assign sigAddress = dataAddress
%assign comments = "%<im.NumDataAddr>: Signal Pointer"
%elseif (regionOffset > 0)
%if isComplex
%assign regionOffset = regionOffset*2
%endif
%assign castString = ""
%if dataIsStruct
%assign castString = "(char *)"
%endif
%assign sigAddress = "%<castString> %<dataAddress>"
%if !WHITE_SPACE(castString)
%assign sigAddress = FcnReplaceCCastWithStaticCastForCPP(sigAddress)
%endif
%assign sigAddress = constString + ...
"(%<sigAddress> + %<regionOffset>)"
%assign comments = "%<im.NumDataAddr>: Signal"
%else
%assign sigAddress = constString + dataAddress
%assign comments = "%<im.NumDataAddr>: Signal"
%endif
%if !(regionIsGround && Region[regIdx].GroundIsSynthesized)
%assign grBlkIdx = [%<subsysIdx>, %<blkIdx>]
%assign blkPath = SLibMangledGrBlockPath(grBlkIdx)
%assign blkPath = FcnReturnCompliantBlockPath(blkPath, "Signal")
%else
%assign blkPath = ""
%endif
%assign isActiveDuringCodegen = 1
%if(!ISEMPTY(sigRec) && ISFIELD(sigRec,"isActiveDuringCodegen"))
%assign isActiveDuringCodegen = sigRec.isActiveDuringCodegen
%endif
%if isRM
%<FcnSetAddrMapInfoWithLogging(im, sigAddress, "", comments, ppIf, ppFi, isActiveDuringCodegen)>
%else
%<FcnSetAddrMapInfo(im, sigAddress, comments, ppIf, ppFi, isActiveDuringCodegen)>
%endif
%if NumRegions == 1
%assign sigLabel = STRING(SignalLabel)
%else
%if !ISEMPTY(sigRec) && sigRec.SigLabel != ""
%assign sigLabel = STRING(sigRec.SigLabel)
%elseif ISFIELD(Region[regIdx], "GroundLabel")
%assign sigLabel = Region[regIdx].GroundLabel
%else
%assign sigLabel = ""
%endif
%endif
%assign dataTypeMapIdx = ...
FcnGetDataTypeMapIdx(dataTypeIdx,isComplex,isPointer,im)
%assign virtSigDimensions = regionIsGround || !FcnRegionDimsEqualDataDims(regionDimensions, data)
%if virtSigDimensions
%assign dimMapIdx = ...
FcnGetVirtSigDimensionMapIdx(regionDimensions,im, ppIf, ppFi)
%else
%assign dimMapIdx = FcnGetDimensionMapIdx(data,im, ppIf, ppFi)
%endif
%if dataIsFixPt
%if (skipwideFxPt)
%if (data.FixedPointInfo.NumBits > 52)
%continue
%endif
%endif
%if !ISEMPTY(recordToUseWithFxpMapIdx)
%assign fxpMapIdx = FcnGetFxpMapIdx(recordToUseWithFxpMapIdx,im)
%else
%assign fxpMapIdx = FcnGetFxpMapIdx(data,im)
%endif
%else
%assign fxpMapIdx = 0
%endif
%if !ISEMPTY(sigRec) && (sigRec.FrameData == "yes")
%assign isFrame = 1
%else
%assign isFrame = 0
%endif
%if !ISEMPTY(sigRec)
%if TYPE(sigRec.TID) == "Number"
%if ::CompiledModel.SampleTime[sigRec.TID].IsUnionTs == "yes"
%assign tID = -1
%else
%assign tID = sigRec.TID
%endif
%assign sTimeIdx = FcnGetSampTimeIdx(tID,isFrame,im)
%elseif sigRec.TID == "constant"
%assign tID = -2
%assign sTimeIdx = FcnGetSampTimeIdx(tID,isFrame,im)
%elseif sigRec.TID == "trigger"
%assign tID = -1
%assign sTimeIdx = FcnGetSampTimeIdx(tID,isFrame,im)
%else
%<SLibReportErrorWithId("RTW:tlc:TIDType")>
%endif
%assign sysNum = sigRec.SysNum
%else
%assign tID = -2
%assign sTimeIdx = FcnGetSampTimeIdx(tID,isFrame,im)
%assign sysNum = ::CompiledModel.NumSystems-1
%endif
%if !ISEMPTY(sigRec) && (!virtBlock || rootInport) && (NumRegions == 1) && ...
!(ISFIELD(data, "IsVarDims") && (data.IsVarDims)) && ...
!virtSigDimensions
%assign blkSID = ""
%assign portNum = ""
%if ISFIELD(Block[blkIdx],"OrigInlineVarBlkSID") && ISFIELD(Block[blkIdx],"OrigInlineVarPortNum")
%assign blkSID = Block[blkIdx].OrigInlineVarBlkSID
%assign portNum = Block[blkIdx].OrigInlineVarPortNum - 1
%else
%assign blkSID = Block[blkIdx].SID
%assign portNum = portIdx
%endif
%assign capiHookTID = sigRec.TID
%if (TYPE(sigRec.TID) != "Number") && ...
sigRec.TID == "trigger"
%assign nonTrigTID = []
%assign systemAndInstanceIdx = SLibGetSystemAndCallSideIndex(sigRec)
%assign systemIdx = systemAndInstanceIdx[0]
%assign instanceIdx = systemAndInstanceIdx[1]
%with System[systemIdx]
%if (Type == "function-call") || (Type == "atomic")
%assert DescSysIdx[instanceIdx] == sysNum
%assign nonTrigTID = DescSysNonTrigTID[instanceIdx]
%endif
%endwith
%if !ISEMPTY(nonTrigTID) && (nonTrigTID >= 0)
%assign capiHookTID = nonTrigTID
%endif
%endif
%if(ISFIELD(sigRec,"isActiveDuringCodegen") && sigRec.isActiveDuringCodegen == 1)
%<FcnCAPIHookAddSignal(CAPIHooks, /
portNum, /
im.NumActiveSignalsDuringCodegen, /
isPointer, /
sigRec.StorageClass, /
sigRec.CGTypeIdx, /
sigRec.FrameData, /
capiHookTID, /
blkSID, /
sigLabel)>
%endif
%endif
%if FcnDynamicAPI()
%assign needsAddressMapIndexVar = TLC_TRUE
%assign entryIndex = 0
%assign dynamicInit = dynamicInit + ppIf + "/n" + ...
tBlockSignals + "[" + numSignals + "].addrMapIndex = " + ...
addrMapIndex + ";/n" + numSignalsPP + ";/n" + ...
addrMapIndexPP + ";/n" + ppFi + "/n"
%else
%assign entryIndex = addrMapIdx
%endif
%if EXISTS(slrt)
%assign blkPath = slrtSignalHook(capiFile, sigRec, blkPath, sigLabel, portIdx, NumDataOutputPorts)
%endif
%<ppIf>
{%<entryIndex>, %<sysNum>, TARGET_STRING("%<blkPath>"),
TARGET_STRING("%<sigLabel>"), %<portIdx>, %<dataTypeMapIdx>, /
%<dimMapIdx>, %<fxpMapIdx>, %<sTimeIdx>},
%<ppFi>
%if (ISEMPTY(sigRec) || ...
((sigRec.RecordType == "ExternalInput") && ...
(!ISFIELD(sigRec, "GrSrc"))) )
%assign grSrc = [%<subsysIdx>,%<blkIdx>,%<portIdx>]
%else
%assign grSrc = sigRec.GrSrc
%endif
%if IsModelReferenceSimTarget()
%assign loggingInfoStartIdx = ...
loggingInfoStartIdx + regionOffset
%assign loggingInfoBlockPath = ...
loggingInfoBlockPath + ...
STRING(SLibMangledGrBlockPath(grSrc))
%assign loggingInfoPortIndex = ...
loggingInfoPortIndex + grSrc[2]
%assign loggingInfoSysNum = ...
loggingInfoSysNum + %<SLContextSysNum>
%endif
%if !ISEMPTY(sigRec)
%if ISFIELD(sigRec, "VarGroupIdx") && ...
LibGetVarGroupCategory(sigRec.VarGroupIdx[0]) == "HierarchicalCoderData"
%assign groupIdx = ::CompiledModel.VarGroups.VarGroup[sigRec.VarGroupIdx[0]].CoderDataGroupIndex
%assign InCAPI.NumDataGroupElements[groupIdx] = InCAPI.NumDataGroupElements[groupIdx] + 1
%elseif (sigRec.RecordType == "ExternalInput")
%assign InCAPI.NumExtInputs = InCAPI.NumExtInputs + 1
%if IsMultiInstanceERTOrModelReference()
%<SLibAccessThisSysFcnArgHelper(sigRec, "Registration", "","", TLC_TRUE)>
%endif
%else
%assign InCAPI.NumBIOSignals = InCAPI.NumBIOSignals + 1
%endif
%if SLibGetArgIsVarDims(sigRec)
%assign InCAPI.NumVarDimsSignals = InCAPI.NumVarDimsSignals + 1
%endif
%endif
%if regionIsGround
%assign InCAPI.NumGrndSignals = InCAPI.NumGrndSignals + 1
%endif
%endforeach
%endwith
%endforeach
%endif
%if Block[blkIdx].Type == "Stateflow" && ISFIELD(Block[blkIdx],"ChartData")
%foreach dwkIdx = Block[blkIdx].ChartData.NumChartData
%if Block[blkIdx].ChartData.ChartData[dwkIdx].IsTestPoint
%assign dwRec = ::CompiledModel.DWorks.DWork[Block[blkIdx].DWork[dwkIdx]._idx]
%assign chartData = Block[blkIdx].ChartData.ChartData[dwkIdx]
%assign structIdx = dwRec.MemoryMapIdx[0]
%assign secIdx = dwRec.MemoryMapIdx[1]
%assign dataIdx = dwRec.MemoryMapIdx[2]
%assign loggingFcnPtr = ""
%if ISFIELD(dwRec, "PreprocessingFcnPtr")
%assign loggingFcnPtr = dwRec.PreprocessingFcnPtr
%endif
%if secIdx == -1
%assign data = UnstructuredData.Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%assign isPointer = (data.Access == "indirect") ? 1 : 0
%elseif structIdx == -1
%assign data = CustomData[secIdx].Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%assign isPointer = (data.Access == "indirect") ? 1 : 0
%else
%assign section = ...
StructuredData[structIdx].Section[secIdx]
%assign data = section.Data[dataIdx]
%assign dataTypeIdx = section.DataTypeIdx
%assign isComplex = section.IsComplex
%assign isPointer = TLC_FALSE
%endif
%assign addrMapIdx = im.NumDataAddr
%if isPointer
%assign sigAddress = data.BaseAddr
%assign comments = "%<im.NumDataAddr>: Stateflow Chart Data Pointer"
%else
%assign sigAddress = data.BaseAddr
%assign comments = "%<im.NumDataAddr>: Stateflow Chart Data"
%endif
%assign ppIf = data.PPIf
%assign ppFi = data.PPEndIf
%assign grBlkIdx = [%<subsysIdx>, %<blkIdx>]
%assign blkPath = SLibMangledGrBlockPath(grBlkIdx) + ...
"/" + chartData.Path
%if EXISTS(slrt)
%assign blkPath = SLibMangledGrBlockPath(grBlkIdx) + ...
":" + chartData.Path
%endif
%assign blkPath = FcnReturnCompliantBlockPath(blkPath, "Stateflow data")
%assign isActiveDuringCodegen = 0
%if isRM
%<FcnSetAddrMapInfoWithLogging(im, sigAddress, loggingFcnPtr, comments, ppIf, ppFi, isActiveDuringCodegen)>
%else
%<FcnSetAddrMapInfo(im, sigAddress, comments, ppIf, ppFi, isActiveDuringCodegen)>
%endif
%assign sigLabel = chartData.SFName
%assign dataTypeMapIdx = ...
FcnGetDataTypeMapIdx(dataTypeIdx,isComplex,isPointer,im)
%assign dimMapIdx = FcnGetDimensionMapIdx(data,im, ppIf, ppFi)
%if data.IsFixedPoint
%if (skipwideFxPt)
%if (data.FixedPointInfo.NumBits > 52)
%continue
%endif
%endif
%assign fxpMapIdx = FcnGetFxpMapIdx(data,im)
%else
%assign fxpMapIdx = 0
%endif
%assign tID = dwRec.TID
%if TYPE(tID) != "Number"
%if tID == "triggered"
%assign tID = -1
%elseif tID == "constant"
%assign tID = -2
%elseif tID == "trigger"
%assign tID = -1
%else
%<SLibReportErrorWithId("RTW:tlc:TIDType")>
%endif
%endif
%assign sTimeIdx = FcnGetSampTimeIdx(tID, 0, im)
%assign sysNum = 0
%if FcnDynamicAPI()
%assign needsAddressMapIndexVar = TLC_TRUE
%assign entryIndex = 0
%assign dynamicInit = dynamicInit + tBlockSignals + ppIf + "/n" + ...
"[" + numSignals + "].addrMapIndex = " + addrMapIndex + ";/n" + ...
numSignalsPP + ";/n" + addrMapIndexPP + ";/n" + ppFi + "/n"
%else
%assign entryIndex = addrMapIdx
%endif
%if EXISTS(slrt)
%assign blkPath = slrtSignalChartDataHook(capiFile,dwRec,blkPath, sigLabel)
%endif
%<ppIf>
{%<entryIndex>, %<sysNum>, TARGET_STRING("%<blkPath>"),
TARGET_STRING("%<sigLabel>"), 0, %<dataTypeMapIdx>, /
%<dimMapIdx>, %<fxpMapIdx>, %<sTimeIdx>},
%<ppFi>
%assign InCAPI.NumSFLocals = InCAPI.NumSFLocals + 1
%if IsModelReferenceSimTarget()
%assign loggingInfoStartIdx = loggingInfoStartIdx + 0
%assign loggingInfoBlockPath = loggingInfoBlockPath + ""
%assign loggingInfoPortIndex = loggingInfoPortIndex + 0
%assign loggingInfoSysNum = loggingInfoSysNum + 0
%endif
%endif
%endforeach
%endif
%endwith
%endforeach
%endwith
%endforeach
%undef portobj
{
0, 0, %<nulldef>, %<nulldef>, 0, 0, 0, 0, 0
}
};
%if tempSLfeature==2
%closefile filterBlkOutputbuf
%endif
%if busHier
/* Virtual bus elements */
%createrecord busInfo { }
%assign busOffset = 0
%assign NumBusSignals = SIZE(busIndexVector, 0)
%foreach busEl = NumBusSignals
%assign busIndex = busIndexVector[busEl]
%if ISEQUAL(busIndex, [-1, -1])
%continue
%endif
%with SignalHierarchyDescriptor[busIndex[0]]
%if busIndex[1] != 0
%<LibBlockReportFatalError([], "More than one HierarchyNode found for an SHD")>
%endif
%assign sysIdx = SubsystemIdx
%assign portIdx = OutputPortIdx
%with HierarchyNode[0]
%if GrSrc[0] != -1
%assign blkPath = SLibMangledGrBlockPath(GrSrc)
%else
%assert ISFIELD(SignalHierarchyDescriptor[busIndex[0]], "FullBlockPath") == TLC_TRUE
%assign blkPath = FullBlockPath
%endif
%assign blkPath = FcnReturnCompliantBlockPath(blkPath, "Signal")
%assign busOffset = %<FcnDumpBusElements(busInfo, busOffset, blkPath, portIdx)>
%endwith
%endwith
%endforeach
%if ISEMPTY(busInfo)
%assign numBusElements = 0
%else
%assign numBusElements = SIZE(busInfo.busElements, 1)
%endif
static %<constKeyword> rtwCAPI_LoggingBusElement rtBusElements[] = {
%foreach busElIdx = numBusElements
%assign numSigs = SIZE(busInfo.busElements[busElIdx].indicies.elements, 1)
%foreach sigIdx = numSigs
%assign elIndex = busInfo.busElements[busElIdx].indicies.elements[sigIdx].index
%assign elType = busInfo.busElements[busElIdx].indicies.elements[sigIdx].type
{%<elIndex>, %<elType>},
%endforeach
%endforeach
{0, rtwCAPI_signal}
};
static %<constKeyword> rtwCAPI_LoggingBusSignals rtBusSignals[] = {
/*
* Signal label, Block path, Port Index, CAPI index, num elements
*/
%if ISEMPTY(busInfo)
%assign numBusElements = 0
%else
%assign numBusElements = SIZE(busInfo.busElements, 1)
%endif
%foreach busElIdx = numBusElements
%assign busElStr = busInfo.busElements[busElIdx].str
%<busElStr>
%endforeach
{%<nulldef>, %<nulldef>, 0, 0, %<nulldef>}
};
%endif
%endif
%endif
%if tempSLfeature==0 || tempSLfeature==2
%if RTWCAPIParams == 1
%if EXISTS("ParameterTuningTestFile")
%include "%<ParameterTuningTestFile>"
%endif
%switch InlineParameters
%case 0
/* Tunable block parameters */
%break
%case 1
/* Individual block tuning is not valid when inline parameters is *
* selected. An empty map is produced to provide a consistent *
* interface independent of inlining parameters. *
*/
%break
%case 2
%break
%endswitch
static %<constKeyword> %<tBlockParamsType> %<tBlockParams>[] = {
/* addrMapIndex, blockPath,
* paramName, dataTypeIndex, dimIndex, fixPtIdx
*/
%if InlineParameters != 1
%foreach subsysIdx = NumSubsystems
%with Subsystem[subsysIdx]
%foreach blkIdx = NumBlocks
%with Block[blkIdx]
%foreach paramIdx = NumParameters
%if (skipIsProtected)
%continue
%endif
%assign mParam = Parameter[paramIdx]
%if mParam._idx < 0
%continue
%endif
%if mParam.IsReference == 1
%continue
%endif
%assign param = ...
::CompiledModel.ModelParameters.Parameter[mParam._idx]
%if (param.MemoryMapIdx[2] == -1) || (param.Tunable == "no")
%continue
%elseif (!ISEMPTY(param.WorkspaceVarName))
%continue
%else
%assign structIdx = param.MemoryMapIdx[0]
%assign secIdx = param.MemoryMapIdx[1]
%assign dataIdx = param.MemoryMapIdx[2]
%if (secIdx == -1)
%assign data = UnstructuredData.Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%if (skipComplex && isComplex)
%continue
%endif
%else
%if structIdx == -1
%assign data = CustomData[secIdx].Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%else
%assert(structIdx != -1)
%assign section=StructuredData[structIdx].Section[secIdx]
%assign data = section.Data[dataIdx]
%assign dataTypeIdx= section.DataTypeIdx
%assign isComplex = section.IsComplex
%endif
%if (skipComplex && isComplex)
%continue
%endif
%endif
%assign isReadOnly = data.Permission == "ro"
%if isReadOnly
%continue
%endif
%if !FcnDataSupportsCAPI(data)
%continue
%endif
%assign addrMapIdx = im.NumDataAddr
%assign paramAddr = data.BaseAddr
%if Type == "SubSystem"
%assign comments = "%<im.NumDataAddr>: Mask Parameter"
%else
%assign comments = "%<im.NumDataAddr>: Block Parameter"
%endif
%assign grBlkIdx = [%<subsysIdx>, %<blkIdx>]
%assign blkPath = SLibMangledGrBlockPath(grBlkIdx)
%assign blkPath = FcnReturnCompliantBlockPath(blkPath, "Parameter")
%assign ppIf = data.PPIf
%assign ppFi = data.PPEndIf
%assign isActiveDuringCodegen = 0
%if isRM
%<FcnSetAddrMapInfoWithLogging(im, paramAddr, "", comments, ppIf, ppFi, isActiveDuringCodegen)>
%else
%<FcnSetAddrMapInfo(im, paramAddr, comments, ppIf, ppFi, isActiveDuringCodegen)>
%endif
%assign paramName = mParam.Name
%assign isPointer = TLC_FALSE
%assign dataTypeMapIdx = ...
FcnGetDataTypeMapIdx(dataTypeIdx,isComplex,isPointer,im)
%assign dimMapIdx = FcnGetDimensionMapIdx(data, im, ppIf, ppFi)
%if data.IsFixedPoint
%if (skipwideFxPt)
%if (data.FixedPointInfo.NumBits > 52)
%continue
%endif
%endif
%assign fxpMapIdx = FcnGetFxpMapIdx(data,im)
%else
%assign fxpMapIdx = 0
%endif
%if FcnDynamicAPI()
%assign needsAddressMapIndexVar = TLC_TRUE
%assign entryIndex = 0
%assign dynamicInit = dynamicInit + ppIf + "/n" + ...
tBlockParams + "[" + numBlockParams + "].addrMapIndex = " + ...
addrMapIndex + ";/n" + numBlockParamsPP + ...
";/n" + addrMapIndexPP + ";/n" + ppFi + "/n"
%else
%assign entryIndex = addrMapIdx
%endif
%if EXISTS(slrt)
%createrecord paramInfo { ...
data data ...
section section ...
blkPath blkPath ...
paramName paramName ...
dataTypeIdx dataTypeIdx ...
isComplex isComplex ...
}
%assign blkPath = slrtParameterHook(capiFile, paramInfo)
%endif
%<ppIf>
{%<entryIndex>, TARGET_STRING("%<blkPath>"),
TARGET_STRING("%<paramName>"), %<dataTypeMapIdx>, %<dimMapIdx>, %<fxpMapIdx>},
%<ppFi>
%if ISFIELD(param, "VarGroupIdx") && ...
LibGetVarGroupCategory(param.VarGroupIdx[0]) == "HierarchicalCoderData"
%assign groupIdx = ::CompiledModel.VarGroups.VarGroup[param.VarGroupIdx[0]].CoderDataGroupIndex
%assign InCAPI.NumDataGroupElements[groupIdx] = InCAPI.NumDataGroupElements[groupIdx] + 1
%else
%assign InCAPI.NumBlockParams = InCAPI.NumBlockParams + 1
%endif
%endif
%endforeach
%endwith
%endforeach
%endwith
%endforeach
%endif
{
0, %<nulldef>, %<nulldef>, 0, 0, 0
}
};
%endif
%if RTWCAPIStates == 1
/* Block states information */
static %<constKeyword> %<tBlockStatesType> %<tBlockStates>[] = {
/* addrMapIndex, contStateStartIndex, blockPath,
* stateName, pathAlias, dWorkIndex, dataTypeIndex, dimIndex,
* fixPtIdx, sTimeIndex, isContinuous, hierInfoIdx, flatElemIdx
*/
%foreach subsysIdx = NumSubsystems
%with Subsystem[subsysIdx]
%foreach blkIdx = NumBlocks
%assign dwOwner = Block[blkIdx]
%if Block[blkIdx].Type == "ModelReference"
%assert Block[blkIdx].NumDiscStates == 0
%continue
%endif
%if ISFIELD(Block[blkIdx],"ShadowBlock")
%assign dwOwner = Block[blkIdx].ShadowBlock.Block
%endif
%if dwOwner.Virtual != 0
%continue
%endif
%assign grBlkIdx = [%<subsysIdx>, %<blkIdx>]
%if SLibIsGeneratingSimTargetForProtectedModel()
%assign blkPath = SLibGetProtectedBlockPath()
%else
%assign blkPath = SLibGrBlockPath(grBlkIdx)
%assign blkPath = FcnReturnCompliantBlockPath(blkPath, "State")
%endif
%with dwOwner
%foreach dStateIdx = NumDiscStates
%assign dWorkIdx = DiscState[dStateIdx]._idx
%if dWorkIdx < 0
%continue
%endif
%assert (dWorkIdx < ::CompiledModel.DWorks.NumDWorks)
%assign dWork = ::CompiledModel.DWorks.DWork[dWorkIdx]
%if !dWork.DataLoggingOn
%continue
%endif
%assign constString = ""
%if dWork.MemoryMapIdx[2] == -1
%continue
%else
%assign structIdx = dWork.MemoryMapIdx[0]
%assign secIdx = dWork.MemoryMapIdx[1]
%assign dataIdx = dWork.MemoryMapIdx[2]
%assign loggingFcnPtr = ""
%if ISFIELD(dwRec, "PreprocessingFcnPtr")
%assign loggingFcnPtr = dwRec.PreprocessingFcnPtr
%endif
%if secIdx == -1
%assign data = UnstructuredData.Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%assign isPointer = (data.Access == "indirect") ? 1 : 0
%if dWork.StorageTypeQualifier=="volatile"
%assign constString = "(void *) "
%endif
%elseif structIdx == -1
%assign data = CustomData[secIdx].Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%assign isPointer = (data.Access == "indirect") ? 1 : 0
%else
%assign section = ...
StructuredData[structIdx].Section[secIdx]
%assign data = section.Data[dataIdx]
%assign dataTypeIdx = section.DataTypeIdx
%assign isComplex = section.IsComplex
%assign isPointer = TLC_FALSE
%endif
%endif
%if !FcnDataSupportsCAPI(data)
%continue
%endif
%assign ppIf = data.PPIf
%assign ppFi = data.PPEndIf
%assign addrMapIdx = im.NumDataAddr
%if isPointer
%assign stateAddress = data.BaseAddr
%assign comments = "%<im.NumDataAddr>: Discrete State Pointer"
%else
%assign stateAddress = constString + data.BaseAddr
%assign comments = "%<im.NumDataAddr>: Discrete State"
%endif
%assign isActiveDuringCodegen = 0
%if isRM
%<FcnSetAddrMapInfoWithLogging(im, stateAddress, loggingFcnPtr, comments, ppIf, ppFi, isActiveDuringCodegen)>
%else
%<FcnSetAddrMapInfo(im, stateAddress, comments, ppIf, ppFi, isActiveDuringCodegen)>
%endif
%assign stateName = dWork.LogStateName
%assign dataTypeMapIdx = ...
FcnGetDataTypeMapIdx(dataTypeIdx, isComplex, isPointer, im)
%assign dimMapIdx = FcnGetDimensionMapIdx(data,im, ppIf, ppFi)
%if data.IsFixedPoint
%assign fxpMapIdx = FcnGetFxpMapIdx(data,im)
%else
%assign fxpMapIdx = 0
%endif
%if TYPE(dWork.TID) == "Vector"
%assign tID = dWork.TID[0]
%else
%assign tID = dWork.TID
%endif
%if TYPE(tID) == "Number"
%assign sTimeIdx = FcnGetSampTimeIdx(tID,0,im)
%elseif tID == "triggered"
%assign tID = -1
%assign sTimeIdx = FcnGetSampTimeIdx(tID,0,im)
%elseif tID == "constant"
%assign tID = -2
%assign sTimeIdx = FcnGetSampTimeIdx(tID, 0 ,im)
%else
%<SLibReportErrorWithIdAndArgs("RTW:tlc:TIDTypeState", "%<dWork.TID>")>
%endif
%assign hierInfoIdx = dWork.hierInfoIdx
%assign flatElemIdx = dWork.flatElemIdx
%if FcnDynamicAPI()
%assign needsAddressMapIndexVar = TLC_TRUE
%assign entryIndex = 0
%assign dynamicInit = dynamicInit + ppIf + "/n" + ...
tBlockStates + "[" ...
+ numStates + "].addrMapIndex = " + ...
addrMapIndex + ";/n" + numStatesPP + ";/n" ...
+ addrMapIndexPP + ";/n" + ppFi + "/n"
%else
%assign entryIndex = addrMapIdx
%endif
%<ppIf>
{%<entryIndex>, -1, TARGET_STRING("%<blkPath>"),
TARGET_STRING("%<stateName>"), "", 0, %<dataTypeMapIdx>, %<dimMapIdx>, /
%<fxpMapIdx>, %<sTimeIdx>, 0, %<hierInfoIdx>, %<flatElemIdx>},
%<ppFi>
%if ISFIELD(dWork, "VarGroupIdx") && ...
LibGetVarGroupCategory(dWork.VarGroupIdx[0]) == "HierarchicalCoderData"
%assign groupIdx = ::CompiledModel.VarGroups.VarGroup[dWork.VarGroupIdx[0]].CoderDataGroupIndex
%assign InCAPI.NumDataGroupElements[groupIdx] = InCAPI.NumDataGroupElements[groupIdx] + 1
%else
%assign InCAPI.NumDiscStates = InCAPI.NumDiscStates + 1
%endif
%endforeach
%assert (NumContStates == NumDerivatives)
%foreach cStateIdx = NumContStates
%assign cSIdx = ContState[cStateIdx]._idx
%assert (cSIdx < ::CompiledModel.ContStates.NumContStates)
%assign contState = ::CompiledModel.ContStates.ContState[cSIdx]
%if contState.MemoryMapIdx[2] == -1 || !contState.DataLoggingOn
%continue
%else
%assign structIdx = contState.MemoryMapIdx[0]
%assign secIdx = contState.MemoryMapIdx[1]
%assign dataIdx = contState.MemoryMapIdx[2]
%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
%else
%assign section = ...
StructuredData[structIdx].Section[secIdx]
%assign data = section.Data[dataIdx]
%assign dataTypeIdx = section.DataTypeIdx
%assign isComplex = section.IsComplex
%endif
%endif
%assign offset = 0
%assign name = section.Data[dataIdx].Name
%foreach recIdx = contState.Partitions.NumPartitions
%if offset>0
%assert ( LibGetDataWidth(contState)>1 )
%assign offsetAddr = "&%<name>[%<offset>]"
%else
%assign offsetAddr = data.BaseAddr
%endif
%assign ppIf = data.PPIf
%assign ppFi = data.PPEndIf
%assign addrMapIdx = im.NumDataAddr
%assign comments = "%<im.NumDataAddr>: Continuous State"
%assign isActiveDuringCodegen = 0
%if isRM
%<FcnSetAddrMapInfoWithLogging(im, offsetAddr, "", comments, ppIf, ppFi, isActiveDuringCodegen)>
%else
%<FcnSetAddrMapInfo(im, offsetAddr, comments, ppIf, ppFi, isActiveDuringCodegen)>
%endif
%assign stateName = contState.Partitions.Partition[recIdx].Name
%assign pathAlias = contState.Partitions.Partition[recIdx].PathAlias
%assign pathAlias = FcnReturnCompliantBlockPath(pathAlias, "State")
%assign isPointer = TLC_FALSE
%assign dataTypeMapIdx = ...
FcnGetDataTypeMapIdx(dataTypeIdx,isComplex,isPointer,im)
%assign dataNumRows = data.NumRows
%copyrecord partitionData data
%assign partitionData.NumRows = ...
contState.Partitions.Partition[recIdx].Width
%assert (dataNumRows == data.NumRows)
%assign dimMapIdx = FcnGetDimensionMapIdx(partitionData,im, ppIf, ppFi)
%if data.IsFixedPoint
%assign fxpMapIdx = FcnGetFxpMapIdx(data,im)
%else
%assign fxpMapIdx = 0
%endif
%assign sTimeIdx = FcnGetSampTimeIdx(0, 0, im)
%if FcnDynamicAPI()
%assign needsAddressMapIndexVar = TLC_TRUE
%assign entryIndex = 0
%assign dynamicInit = dynamicInit + ppIf + "/n" + ...
tBlockStates + "[" ...
+ numStates + "].addrMapIndex = " + addrMapIndex + ...
";/n" + numStatesPP + ";/n" + addrMapIndexPP + ...
";/n" + ppFi + "/n"
%else
%assign entryIndex = addrMapIdx
%endif
%<ppIf>
{%<entryIndex>, ...
%, ...
TARGET_STRING("%<blkPath>"),
TARGET_STRING("%<stateName>"),
TARGET_STRING("%<pathAlias>"),
0, %<dataTypeMapIdx>, %<dimMapIdx>, /
%<fxpMapIdx>, %<sTimeIdx>, 1, -1, 0},
%<ppFi>
%if ISFIELD(contState, "VarGroupIdx") && ...
LibGetVarGroupCategory(contState.VarGroupIdx[0]) == "HierarchicalCoderData"
%assign groupIdx = ::CompiledModel.VarGroups.VarGroup[contState.VarGroupIdx[0]].CoderDataGroupIndex
%assign InCAPI.NumDataGroupElements[groupIdx] = InCAPI.NumDataGroupElements[groupIdx] + 1
%else
%assign InCAPI.NumContStates = InCAPI.NumContStates + 1
%endif
%assign offset = offset+contState.Partitions.Partition[recIdx].Width
%endforeach
%endforeach
%endwith
%endforeach
%endwith
%endforeach
{
0, -1, %<nulldef>, %<nulldef>, %<nulldef>, 0, 0, 0, 0, 0, 0, -1, 0
}
};
%endif
%if RTWCAPIRootIO == 1 && !FcnCAPIRootIOSupport() && ...
MultiInstanceERTCode && ...
!IsModelReferenceTarget() && ...
!SLibFcnProtoCtrlActive() && ...
!SLibAutosarActive() && ...
!GenerateClassInterface
%if !UsingMalloc || (::CompiledModel.RootIOFormat ...
!= "Part of model data structure")
%<SLibReportWarningWithIdAndArgs("RTW:tlc:CAPIRootIOSupport", ::CompiledModel.Name)>
%endif
%endif
%if RTWCAPIRootIO == 1 && FcnCAPIRootIOSupport()
/* Root Inputs information */
static %<constKeyword> %<tBlockSignalsType> %<tRootInputs>[] = {
/* addrMapIndex, sysNum, blockPath,
* signalName, portNumber, dataTypeIndex, dimIndex, fxpIndex, sTimeIndex
*/
%assign portObj = SLibCreateDummyPortRecord()
%assign subsysIdx = 0
%with Subsystem[subsysIdx]
%foreach inpBlkIdx = NumInportBlocks
%assign blkIdx = InportBlocks[inpBlkIdx]
%with Block[blkIdx]
%foreach portIdx = NumDataOutputPorts
%with DataOutputPort[portIdx]
%assign regIdx = 0
%assign portObj.SignalSrc = Region[regIdx]._Source
%if ISFIELD(Region[regIdx],"BusSelElIdx")
%assign portObj.BusSelElIdx = Region[regIdx].BusSelElIdx[0]
%assign portObj.BusSelElCGTypeId = Region[regIdx].BusSelElCGTypeId[0]
%endif
%assign eiRec = SLibGetSourceRecord(portObj, 0)
%assign constString = ""
%if ISEMPTY(eiRec)
%continue
%endif
%if SLibIsCoderGroupUseAccessFcnForDataRecord(eiRec)
%continue
%endif
%if ISFIELD(eiRec,"Inactive")
%continue
%endif
%if (NumRegions > 1) || ...
TYPE(eiRec.TID) != "Number" || ...
eiRec.MemoryMapIdx[2] == -1
%assign errTxt = "Unhandled condition for C API Root IO"
%<LibReportError(errTxt)>
%endif
%assign structIdx = eiRec.MemoryMapIdx[0]
%assign secIdx = eiRec.MemoryMapIdx[1]
%assign dataIdx = eiRec.MemoryMapIdx[2]
%if secIdx == -1
%assign data = UnstructuredData.Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%assign isPointer = (data.Access == "indirect") ? 1 : 0
%if eiRec.StorageTypeQualifier=="volatile"
%assign constString = "(void *) "
%endif
%elseif structIdx == -1
%assign data = CustomData[secIdx].Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%assign isPointer = (data.Access == "indirect") ? 1 : 0
%assign constString = "(void *) "
%else
%assign section = ...
StructuredData[structIdx].Section[secIdx]
%assign data = section.Data[dataIdx]
%assign dataTypeIdx = section.DataTypeIdx
%assign isComplex = section.IsComplex
%assign isPointer = TLC_FALSE
%endif
%if !FcnDataSupportsCAPI(data)
%continue
%endif
%<FcnOptionallyAddModelRefCanonicalInputNeededByCAPIFlag(eiRec)>
%assign dataAddress = data.BaseAddr
%assign dataIsFixPt = data.IsFixedPoint
%createrecord recordToUseWithFxpMapIdx { }
%if ISFIELD(Region[regIdx],"BusSelElIdx")
%assign busSelElIdx = Region[regIdx].BusSelElIdx[0]
%assert !ISEMPTY(busSelElIdx)
%assign dataTypeIdx = LibCGTypeToSLType(Region[regIdx].BusSelElCGTypeId[0])
%assign isComplex = LibCGTypeIsComplex(Region[regIdx].BusSelElCGTypeId[0])
%assign dataAddress = FEVAL("regexprep", dataAddress, "//[//d+//]$", "")
%if busSelElIdx[0] != "." || LibDoesStringContainDotOrArrow(dataAddress)
%assign dataAddress = FEVAL("regexprep", ...
dataAddress, "&(.*)", "&($1" + busSelElIdx + ")")
%else
%assign dataAddress = FEVAL("regexprep", ...
dataAddress, "&(.*)", "&((*$1)" + busSelElIdx + ")")
%endif
%assign dataIsStruct = LibIsStructDataType(dataTypeIdx)
%assign dataIsFixPt = LibIsDataTypeFixpt(dataTypeIdx)
%if dataIsFixPt
%assign fxpIdx = FcnGetUniformFixPtTypeInGMM(DataTypes.DataType[dataTypeIdx])
%addtorecord recordToUseWithFxpMapIdx /
FixedPointInfo GlobalMemoryMap.FixedPointMaps.FixPtRecord[fxpIdx]
%endif
%endif
%assign addrMapIdx = im.NumDataAddr
%if !ISFIELD(Region[regIdx],"CAPIAddrMapIdx")
%addtorecord Region[regIdx] CAPIAddrMapIdx addrMapIdx
%endif
%if isPointer
%assign sigAddress = dataAddress
%assign comments = "%<im.NumDataAddr>: Root Input Pointer"
%else
%assign sigAddress = constString + dataAddress
%assign comments = "%<im.NumDataAddr>: Root Input"
%endif
%assign varCond = eiRec.VariantCondition
%if !ISEMPTY(varCond)
%assign ppIf = SLibIfVariantConditionForm(varCond)
%assign ppFi = SLibEndIfVariantConditionForm(varCond)
%else
%assign ppIf = data.PPIf
%assign ppFi = data.PPEndIf
%endif
%assign grBlkIdx = [%<subsysIdx>, %<blkIdx>]
%assign blkPath = SLibMangledGrBlockPath(grBlkIdx)
%assign blkPath = FcnReturnCompliantBlockPath(blkPath, "Signal")
%assign isActiveDuringCodegen = 1
%if isRM
%<FcnSetAddrMapInfoWithLogging(im, sigAddress, "", comments, ppIf, ppFi, isActiveDuringCodegen)>
%else
%<FcnSetAddrMapInfo(im, sigAddress, comments, ppIf, ppFi, isActiveDuringCodegen)>
%endif
%if eiRec.SigLabel != ""
%assign sigLabel = STRING(eiRec.SigLabel)
%else
%assign sigLabel = ""
%endif
%assign dataTypeMapIdx = ...
FcnGetDataTypeMapIdx(dataTypeIdx,isComplex,isPointer,im)
%assign dimMapIdx = FcnGetDimensionMapIdx(data,im, ppIf, ppFi)
%if dataIsFixPt
%if !ISEMPTY(recordToUseWithFxpMapIdx)
%assign fxpMapIdx = FcnGetFxpMapIdx(recordToUseWithFxpMapIdx,im)
%else
%assign fxpMapIdx = FcnGetFxpMapIdx(data,im)
%endif
%else
%assign fxpMapIdx = 0
%endif
%if eiRec.FrameData == "yes"
%assign isFrame = 1
%else
%assign isFrame = 0
%endif
%assign tID = eiRec.TID
%assign sTimeIdx = FcnGetSampTimeIdx(tID,isFrame,im)
%assign sysNum = eiRec.SysNum
%if FcnDynamicAPI()
%assign needsAddressMapIndexVar = TLC_TRUE
%assign entryIndex = 0
%assign dynamicInit = dynamicInit + ppIf + "/n" + tRootInputs + ...
"[" + numRootInputs + "].addrMapIndex = " + addrMapIndex + ...
";/n" + numRootInputsPP + ";/n" + addrMapIndexPP + ";/n" + ...
ppFi + "/n"
%else
%assign entryIndex = addrMapIdx
%endif
%assign portNum = inpBlkIdx + 1
%<ppIf>
{%<entryIndex>, %<sysNum>, TARGET_STRING("%<blkPath>"),
TARGET_STRING("%<sigLabel>"), %<portNum>, %<dataTypeMapIdx>, /
%<dimMapIdx>, %<fxpMapIdx>, %<sTimeIdx>},
%<ppFi>
%if ISFIELD(eiRec, "VarGroupIdx") && ...
LibGetVarGroupCategory(eiRec.VarGroupIdx[0]) == "HierarchicalCoderData"
%assign groupIdx = ::CompiledModel.VarGroups.VarGroup[eiRec.VarGroupIdx[0]].CoderDataGroupIndex
%assign InCAPI.NumDataGroupElements[groupIdx] = InCAPI.NumDataGroupElements[groupIdx] + 1
%else
%assign InCAPI.NumRootInputs = InCAPI.NumRootInputs + 1
%endif
%endwith
%endforeach
%endwith
%endforeach
%endwith
{
0, 0, %<nulldef>, %<nulldef>, 0, 0, 0, 0, 0
}
};
/* Root Outputs information */
static %<constKeyword> %<tBlockSignalsType> %<tRootOutputs>[] = {
/* addrMapIndex, sysNum, blockPath,
* signalName, portNumber, dataTypeIndex, dimIndex, fxpIndex, sTimeIndex
*/
%assign subsysIdx = 0
%with Subsystem[subsysIdx]
%foreach outBlkIdx = NumOutportBlocks
%assign blkIdx = OutportBlocks[outBlkIdx]
%with Block[blkIdx]
%assign virtBlock = (Block[blkIdx].Virtual > 0)
%if ISFIELD(Block[blkIdx],"ExternalOutputIdx")
%assign eoIdx = Block[blkIdx].ExternalOutputIdx
%assign eoRec = ::CompiledModel.ExternalOutputs.ExternalOutput[eoIdx]
%if ISFIELD(VariantConditions, "CGVCEList")
%assign cgvceList = VariantConditions.CGVCEList
%else
%assign cgvceList = ""
%endif
%else
%continue
%endif
%if ISFIELD(eoRec,"Inactive")
%continue
%endif
%if SLibIsCoderGroupUseAccessFcnForDataRecord(eoRec)
%continue
%endif
%if virtBlock
%assign errTxt = "Unhandled condition for C API Root IO"
%<LibReportError(errTxt)>
%endif
%assign constString = ""
%assign sysBlk = System[_blkref[0]].Block[_blkref[2]]
%assign tid = sysBlk.TID
%if TYPE(tid) != "Number" && ...
TYPE(tid) == "String"
%if tid != "constant" && ...
tid != "trigger"
%continue
%endif
%endif
%if eoRec.MemoryMapIdx[2] == -1
%continue
%else
%assign structIdx = eoRec.MemoryMapIdx[0]
%assign secIdx = eoRec.MemoryMapIdx[1]
%assign dataIdx = eoRec.MemoryMapIdx[2]
%if secIdx == -1
%assign data = UnstructuredData.Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%assign isPointer = (data.Access == "indirect") ? 1 : 0
%elseif structIdx == -1
%assign data = CustomData[secIdx].Data[dataIdx]
%assign isComplex = data.IsComplex
%assign dataTypeIdx = data.DataTypeIdx
%assign isPointer = (data.Access == "indirect") ? 1 : 0
%assign constString = "(void *) "
%else
%assign section = ...
StructuredData[structIdx].Section[secIdx]
%assign data = section.Data[dataIdx]
%assign dataTypeIdx = section.DataTypeIdx
%assign isComplex = section.IsComplex
%assign isPointer = TLC_FALSE
%endif
%if !FcnDataSupportsCAPI(data)
%continue
%endif
%assign dataAddress = data.BaseAddr
%assign dataIsFixPt = data.IsFixedPoint
%assign addrMapIdx = im.NumDataAddr
%if isPointer
%assign sigAddress = dataAddress
%assign comments = "%<im.NumDataAddr>: Root Output Pointer"
%else
%assign sigAddress = constString + dataAddress
%assign comments = "%<im.NumDataAddr>: Root Output"
%endif
%if ISFIELD(eoRec, "LocalCGVCEIdx") && (eoRec.LocalCGVCEIdx != -1)
%assign varCond = cgvceList[eoRec.LocalCGVCEIdx]
%else
%assign varCond = ""
%endif
%if !ISEMPTY(varCond)
%assign ppIf = SLibIfVariantConditionForm(varCond)
%assign ppFi = SLibEndIfVariantConditionForm(varCond)
%else
%assign ppIf = ""
%assign ppFi = ""
%endif
%assign grBlkIdx = [%<subsysIdx>, %<blkIdx>]
%assign blkPath = SLibMangledGrBlockPath(grBlkIdx)
%assign blkPath = FcnReturnCompliantBlockPath(blkPath, "Signal")
%assign isActiveDuringCodegen = 1
%if isRM
%<FcnSetAddrMapInfoWithLogging(im, sigAddress, "", comments, ppIf, ppFi, isActiveDuringCodegen)>
%else
%<FcnSetAddrMapInfo(im, sigAddress, comments, ppIf, ppFi, isActiveDuringCodegen)>
%endif
%if eoRec.SigLabel != ""
%assign sigLabel = STRING(eoRec.SigLabel)
%else
%assign sigLabel = ""
%endif
%assign dataTypeMapIdx = ...
FcnGetDataTypeMapIdx(dataTypeIdx,isComplex,isPointer,im)
%assign dimMapIdx = FcnGetDimensionMapIdx(data,im, ppIf, ppFi)
%if dataIsFixPt
%assign fxpMapIdx = FcnGetFxpMapIdx(data,im)
%else
%assign fxpMapIdx = 0
%endif
%if eoRec.FrameData == "yes"
%assign isFrame = 1
%else
%assign isFrame = 0
%endif
%if TYPE(tid) == "Number"
%assign tID = tid
%assign sTimeIdx = FcnGetSampTimeIdx(tID,isFrame,im)
%elseif tid == "constant"
%assign tID = -2
%assign sTimeIdx = FcnGetSampTimeIdx(tID,isFrame,im)
%elseif tid == "trigger"
%assign tID = -1
%assign sTimeIdx = FcnGetSampTimeIdx(tID,isFrame,im)
%else
%<SLibReportErrorWithId("RTW:tlc:TIDType")>
%endif
%assign sysNum = subsysIdx
%endif
%if FcnDynamicAPI()
%assign needsAddressMapIndexVar = TLC_TRUE
%assign entryIndex = 0
%assign dynamicInit = dynamicInit + ppIf + "/n" + tRootOutputs + ...
"[" + numRootOutputs + "].addrMapIndex = " + addrMapIndex + ...
";/n" + numRootOutputsPP + ";/n" + addrMapIndexPP + ";/n" + ...
ppFi + "/n"
%else
%assign entryIndex = addrMapIdx
%endif
%assign portIdx = outBlkIdx + 1
%<ppIf>
{%<entryIndex>, %<sysNum>, TARGET_STRING("%<blkPath>"),
TARGET_STRING("%<sigLabel>"), %<portIdx>, %<dataTypeMapIdx>, /
%<dimMapIdx>, %<fxpMapIdx>, %<sTimeIdx>},
%<ppFi>
%if ISFIELD(eoRec, "VarGroupIdx") && ...
LibGetVarGroupCategory(eoRec.VarGroupIdx[0]) == "HierarchicalCoderData"
%assign groupIdx = ::CompiledModel.VarGroups.VarGroup[eoRec.VarGroupIdx[0]].CoderDataGroupIndex
%assign InCAPI.NumDataGroupElements[groupIdx] = InCAPI.NumDataGroupElements[groupIdx] + 1
%else
%assign InCAPI.NumRootOutputs = InCAPI.NumRootOutputs + 1
%endif
%endwith
%endforeach
%endwith
{
0, 0, %<nulldef>, %<nulldef>, 0, 0, 0, 0, 0
}
};
%endif
%endif
%endwith
%if tempSLfeature==0 || tempSLfeature==2
%if RTWCAPIParams ==1
/* Tunable variable parameters */
static %<constKeyword> %<tModelParamsType> %<tModelParams>[] = {
/* addrMapIndex, varName, dataTypeIndex, dimIndex, fixPtIndex */
%with ModelParameters
%foreach paramIdx = NumModelParameters
%assign param = ModelParameter[paramIdx]
%foreach instIdx = param.NumInstances
%assign constString = ""
%assign structIdx = param.Instance[instIdx].MemoryMapIdx[0]
%assign secIdx = param.Instance[instIdx].MemoryMapIdx[1]
%assign dataIdx = param.Instance[instIdx].MemoryMapIdx[2]
%if secIdx == -1
%assign data = UnstructuredData.Data[dataIdx]
%assign dTypeIdx = data.DataTypeIdx
%assign isComplex = data.IsComplex
%assign isPointer = (data.Access == "indirect") ? 1 : 0
%assign section = data
%elseif structIdx == -1
%assign data = CustomData[secIdx].Data[dataIdx]
%assign dTypeIdx = data.DataTypeIdx
%assign isComplex = data.IsComplex
%assign isPointer = (data.Access == "indirect") ? 1 : 0
%assign constString = "(void *) "
%assign section = data
%else
%assign section = StructuredData[structIdx].Section[secIdx]
%assign data = section.Data[dataIdx]
%assign dTypeIdx = section.DataTypeIdx
%assign isComplex = section.IsComplex
%assign isPointer = TLC_FALSE
%endif
%if ( (skipComplex && isComplex) || (skipStruct && data.IsStruct) )
%continue
%endif
%if !FcnDataSupportsCAPI(data)
%continue
%endif
%if instIdx == 0
%assign addrMapIdx = im.NumDataAddr
%if isPointer
%assign paramAddress = data.BaseAddr
%assign comments = "%<im.NumDataAddr>: Model Parameter Pointer"
%else
%assign paramAddress = constString + data.BaseAddr
%assign comments = "%<im.NumDataAddr>: Model Parameter"
%endif
%assign ppIf = data.PPIf
%assign ppFi = data.PPEndIf
%assign isActiveDuringCodegen = 0
%if isRM
%<FcnSetAddrMapInfoWithLogging(im, paramAddress, "", comments, ppIf, ppFi, isActiveDuringCodegen)>
%else
%<FcnSetAddrMapInfo(im, paramAddress, comments, ppIf, ppFi, isActiveDuringCodegen)>
%endif
%assign varName = param.Name
%assign dataTypeMapIdx = ...
FcnGetDataTypeMapIdx(dTypeIdx, isComplex, isPointer, im)
%assign dimMapIdx = FcnGetDimensionMapIdx(data, im, "", "")
%if data.IsFixedPoint
%if (skipwideFxPt)
%if (data.FixedPointInfo.NumBits > 52)
%continue
%endif
%endif
%assign fxpMapIdx = FcnGetFxpMapIdx(data,im)
%else
%assign fxpMapIdx = 0
%endif
%if ISFIELD(param, "CoderDataGroupIdx")
%assign groupIdx = param.CoderDataGroupIdx
%assign InCAPI.NumDataGroupElements[groupIdx] = InCAPI.NumDataGroupElements[groupIdx] + 1
%endif
%assign InCAPI.NumVariableParams = InCAPI.NumVariableParams + 1
%if FcnDynamicAPI()
%assign needsAddressMapIndexVar = TLC_TRUE
%assign entryIndex = 0
%assign dynamicInit = dynamicInit + ppIf + "/n" + ...
tModelParams + "[" + numModelParams + "].addrMapIndex = " + ...
addrMapIndex + ";/n" + numModelParamsPP + ";/n" + ...
addrMapIndexPP + ";/n" + ppFi + "/n"
%else
%assign entryIndex = addrMapIdx
%endif
%if EXISTS(slrt)
%createrecord paramInfo { ...
data data ...
section section ...
blkPath "" ...
paramName varName ...
dataTypeIdx dTypeIdx ...
isComplex isComplex ...
}
%
%endif
{%<entryIndex>, TARGET_STRING("%<varName>"), %<dataTypeMapIdx>, %<dimMapIdx>, %<fxpMapIdx>},
%endif
%endforeach
%endforeach
%endwith
{0, %<nulldef>, 0, 0, 0 }
};
%endif
%endif
%endwith
%if tempSLfeature==0 || tempSLfeature==2
%if EXISTS(slrt)
%
%endif
%<LibAddToCompiledModel("NumDataAddrInMap", im.NumDataAddr)>
%endif
%if im.NumGrounds > 0
%foreach idx = im.NumGrounds
%;
%endforeach
%endif
%if tempSLfeature==1
%if SIZE(tempRepo)!=[1, 1]
%assign InCAPI_FromCPP = tempRepo[2]
%assign InCAPI.NumBIOSignals = InCAPI_FromCPP[0]
%assign InCAPI.NumBlockParams = InCAPI_FromCPP[1]
%assign InCAPI.NumDiscStates = InCAPI_FromCPP[4]
%assign InCAPI.NumRootInputs = InCAPI_FromCPP[7]
%assign InCAPI.NumRootOutputs = InCAPI_FromCPP[8]
%assign InCAPI.NumSFLocals = InCAPI_FromCPP[9]
%assign InCAPI.NumVarDimsSignals = InCAPI_FromCPP[10]
%assign InCAPI.NumVariableParams = InCAPI_FromCPP[11]
%endif
%endif
%assign args = FcnCAPIInitializeFcnArgs(InCAPI)
%if tempSLfeature==1 || tempSLfeature==0
%assign ::tempRepo2 = FEVAL("genCapiInCpp","","","","","","","","","","","","","","","","",args)
%endif
%if tempSLfeature==0 || tempSLfeature==2
%if !UsingMalloc
%if !IsMultiInstanceERTOrModelReference()
%if im.NumDataAddr > 0
#ifndef HOST_CAPI_BUILD
/* Declare Data Addresses statically */
static %<tDataAddrType> %<tDataAddrMap>[] = {
%assign needsNullGuard = TLC_TRUE
%foreach idx = im.NumDataAddr
%if needsNullGuard && !WHITE_SPACE(im.AddrMap[idx]) && WHITE_SPACE(im.AddrMapIf[idx])
%assign needsNullGuard = TLC_FALSE
%endif
%
%, /
/* % */
%
%endforeach
%if needsNullGuard || FcnDynamicAPI()
NULL
%endif
};
%else
static %<tDataAddrType> *%<tDataAddrMap> = %<nulldef>;
%endif
%if im.NumVarDimsAddr > 0
/* Declare Data Run-Time Dimension Buffer Addresses statically */
static %<tVarDimsAddrMapType> %<tVarDimsAddrMap>[] = {
%foreach idx = im.NumVarDimsAddr-1
%
%,
%
%endforeach
%
};
#endif
%else
static %<tVarDimsAddrMapType> *%<tVarDimsAddrMap> = %<nulldef>;
%endif
%else
%assign typePrefix = SLibGetModelTypesNamespacePrefix()
%if im.NumDataAddr > 0
%assign fcnName = "%<prefix>InitializeDataAddr"
%assign fcnReturns = "static void"
%assign hasSelfParam = TLC_FALSE
%assign fcnParams = "%<args.dArg>%<args.rtmArg>%<args.uArg>%<args.bArg>%<args.pArg>%<args.dwArg>%<args.xArg>%<args.ssArg>"
%foreach idx = ::CompiledModel.NumCoderDataGroups
%assign fcnParams = fcnParams + args.groupArg[idx]
%endforeach
%if SLibGetDoesSelfHasCoderDataGroup() && !IsModelReferenceSimTarget()
%if !ISEMPTY(args.rtmArg) && SLibSynthesizedRTM()
%assign hasSelfParam = TLC_TRUE
%else
%assign comma = ISEMPTY(fcnParams) ? "" : ", "
%assign fcnParams = "%<typePrefix>%<::tSimStructType> *const %<::tSimStruct>" + "%<comma>" + "%<fcnParams>"
%assign hasSelfParam = TLC_TRUE
%endif
%endif
%assign fcnAbstract = "Initialize Data Address"
%openfile mallocCode
%if !SimstructBasedTarget && !IsModelReferenceTarget() && !GenerateClassInterface ...
&& UsingMalloc
%assign comma = ISEMPTY(fcnParams) ? "" : ", "
%if ~hasSelfParam
%assign fcnParams = "%<typePrefix>%<::tSimStructType> *const %<::tSimStruct>" + "%<comma>" + "%<fcnParams>"
%endif
%assign nDataAddr = im.NumDataAddr
%assign dAddrType = tDataAddrType
%if GenRTModel
%assign capiStructId = RTMGet("DataMapInfo")
%else
%assert isRSim && !IsModelReferenceTarget()
%assign capiStructId = "(*%<RSimRTWCAPIVarPtr>)"
%endif
%endif
%closefile mallocCode
%createrecord fcnRec {Name fcnName; Returns fcnReturns; Params fcnParams; Abstract fcnAbstract; ...
Category "model"; GeneratedBy "capi.tlc"; Type "Initialize"}
#ifndef HOST_CAPI_BUILD
%<SLibDumpFunctionBanner(fcnRec)>
%undef fcnRec
%<SLibGetFcnMemSecPragma(fcnName, "MemSecFuncInitTerm", "Pre")>/
%<fcnReturns> %<fcnName>(%<fcnParams>) {
%<mallocCode>
%if FcnDynamicAPI()
int dataIdx = 0;
%endif
%foreach idx = im.NumDataAddr
%
%assign dataAddress = "(void*) (%)"
%if IsModelRefCanonicalInputNeededByCAPI()
%assign baseSysIdx = GetBaseSystemIdx()
%with System[baseSysIdx].Interface
%foreach ciIdx = NumCanonicalInputArgDefs
%assign ci = CanonicalInputArgDef[ciIdx]
%assign identi = LibGetRecordIdentifier(ci)
%assign dataAddrStr = "%"
%if FEVAL("eval", "contains('%<dataAddrStr>', '%<identi>')")
%assign dataAddress = "(void*) (%)"
%endif
%endforeach
%endwith
%endif
%if FcnDynamicAPI()
dataAddr[dataIdx] = %<dataAddress>;
dataIdx++;
%else
dataAddr[%<idx>] = %<dataAddress>;
%endif
%
%endforeach
%if FcnDynamicAPI()
(void)dataIdx;
%endif
}
%<SLibGetFcnMemSecPragma(fcnName, "MemSecFuncInitTerm", "Post")>/
#endif
%endif
%if im.NumDataAddr > 0
%assign fcnAbstract = "Initialize Data Run-Time Dimension Buffer Address"
%assign fcnName = "%<prefix>InitializeVarDimsAddr"
%assign fcnReturns = "static void"
%if im.NumVarDimsAddr <= 0 || (im.NumVarDimsAddr==1 && ...
ISEQUAL(im.VarDimsAddrMap[0],SLibGetNullDefinitionFromTfl()))
%assign dwDecl = ""
%else
%assign dwDecl = args.dwArg
%endif
%assign fcnParams = "%<args.vArg>%<dwDecl>"
%assign hasSelfParam = !ISEMPTY(args.rtmArg) && SLibSynthesizedRTM()
%if SLibIsSelfStructured() && !IsModelReferenceSimTarget() && !hasSelfParam
%assign comma = ISEMPTY(fcnParams) ? "" : ", "
%assign fcnParams = "%<typePrefix>%<::tSimStructType> *const %<::tSimStruct>" + "%<comma>" + "%<fcnParams>"
%assign hasSelfParam = TLC_TRUE
%endif
%openfile mallocCode
%if !SimstructBasedTarget && !IsModelReferenceTarget() && !GenerateClassInterface && ...
UsingMalloc
%if ISEMPTY(fcnParams)
%assign comma = ""
%else
%assign comma = ", "
%endif
%if !hasSelfParam
%assign fcnParams = "%<typePrefix>%<::tSimStructType> *const %<::tSimStruct>" + "%<comma>" + "%<fcnParams>"
%endif
%assign nVarDimsAddr = im.NumVarDimsAddr
%assign capiStructId = RTMGet("DataMapInfo")
%endif
%closefile mallocCode
%createrecord fcnRec {Name fcnName; Returns fcnReturns; Params fcnParams; Abstract fcnAbstract; ...
Category "model"; GeneratedBy "capi.tlc"; Type "Initialize"}
%<SLibDumpFunctionBanner(fcnRec)>
%undef fcnRec
#ifndef HOST_CAPI_BUILD
%<SLibGetFcnMemSecPragma(fcnName, "MemSecFuncInitTerm", "Pre")>/
%<fcnReturns> %<fcnName>(%<fcnParams>) {
%<mallocCode>
%foreach idx = im.NumVarDimsAddr
%
vardimsAddr[%<idx>] = %;
%
%endforeach
}
%<SLibGetFcnMemSecPragma(fcnName, "MemSecFuncInitTerm", "Post")>/
#endif
%endif
%endif
%endif
%if !UsingMalloc
%if IsMultiInstanceERTOrModelReference()
%if im.NumDataAddr > 0
%assign fcnAbstract = "Initialize logging function pointers"
%assign fcnName = "%<prefix>InitializeLoggingFunctions"
%assign fcnReturns = "static void"
%assign dwDecl = args.dwDeclCache
%assign fcnParams = "RTWLoggingFcnPtr loggingPtrs[]"
#ifndef HOST_CAPI_BUILD
%createrecord fcnRec {Name fcnName; Returns fcnReturns; Params fcnParams; Abstract fcnAbstract; ...
Category "model"; GeneratedBy "capi.tlc"; Type "Initialize"}
%<SLibDumpFunctionBanner(fcnRec)>
%undef fcnRec
%<fcnReturns> %<fcnName>(%<fcnParams>) {
%if ISEMPTY(im.LoggingFcns)
%foreach idx = im.NumDataAddr
loggingPtrs[%<idx>] = %<SLibGetNullDefinitionFromTfl()>;
%endforeach
%else
%foreach idx = im.NumDataAddr
%if im.LoggingFcns[idx] == ""
%assign im.LoggingFcns[idx] = SLibGetNullDefinitionFromTfl()
%endif
loggingPtrs[%<idx>] = %;
%endforeach
%endif
}
#endif
%endif
%endif
%endif
%assign tgtconstKeyword = "TARGET_CONST"
/* Data Type Map - use dataTypeMapIndex to access this structure */
static %<tgtconstKeyword> %<tDataTypeMapType> %<tDataTypeMap>[] = {
/* cName, mwName, numElements, elemMapIndex, dataSize, slDataId, *
* isComplex, isPointer, enumStorageType */
%if im.NumDataTypes > 0
%foreach idx = im.NumDataTypes - 1
%,
%endforeach
%
%else
{
"", "", 0, 0, 0, 0, 0, 0, 0
}
%endif
};
%if EXISTS(slrt)
%
%endif
#ifdef HOST_CAPI_BUILD
#undef sizeof
#endif
/* Structure Element Map - use elemMapIndex to access this structure */
static %<tgtconstKeyword> %<tElementMapType> %<tElementMap>[] = {
/* elementName, elementOffset, dataTypeIndex, dimIndex, fxpIndex */
{%<nulldef>, 0, 0, 0, 0},
%if im.NumElements > 1
%foreach idx = im.NumElements - 2
%,
%endforeach
%
%endif
};
/* Dimension Map - use dimensionMapIndex to access elements of ths structure*/
static %<constKeyword> %<tDimensionMapType> %<tDimensionMap>[] = {
/* dataOrientation, dimArrayIndex, numDims, vardimsIndex */
%if im.NumDimensionMaps > 0
%foreach idx = im.NumDimensionMaps - 1
%,
%endforeach
%
%else
{
rtwCAPI_SCALAR, 0, 0, 0
}
%endif
};
/* Dimension Array- use dimArrayIndex to access elements of this array */
%if im.NumDimArray > 0
static %<constKeyword> %<tDimensionArrayType> %<tDimensionArray>[] = {
%foreach idx = im.NumDimArray - 1
%,/
/* % */
%endforeach
% /
/* % */
};
%else
static %<constKeyword> %<tDimensionArrayType> %<tDimensionArray>[] = {0};
%endif
%if im.NumDoubles > 0
/* C-API stores floating point values in an array. The elements of this *
* are unique. This ensures that values which are shared across the model*
* are stored in the most efficient way. These values are referenced by *
* - %<tFixPtMapType>.fracSlopePtr, *
* - %<tFixPtMapType>.biasPtr, *
* - %<tSampleTimeMapType>.samplePeriodPtr, *
* - %<tSampleTimeMapType>.sampleOffsetPtr */
static const real_T rtcapiStoredFloats[] = {
%foreach idx = im.NumDoubles - 1
%,/
%endforeach
%
};
%endif
/* Fixed Point Map */
static %<constKeyword> %<tFixPtMapType> %<tFixPtMap>[] = {
/* fracSlopePtr, biasPtr, scaleType, wordLength, exponent, isSigned */
{%<nulldef>, %<nulldef>, rtwCAPI_FIX_RESERVED, 0, 0, 0 },
%if im.NumFixPoint > 1
%foreach idx = im.NumFixPoint - 2
%,
%endforeach
%
%endif
};
/* Sample Time Map - use sTimeIndex to access elements of ths structure */
static %<constKeyword> %<tSampleTimeMapType> %<tSampleTimeMap>[] = {
/* samplePeriodPtr, sampleOffsetPtr, tid, samplingMode */
%if im.NumSampleTimes > 0
%foreach idx = im.NumSampleTimes - 1
%,
%endforeach
%
%else
{
%<nulldef>, %<nulldef>, %<::CompiledModel.SampleTime[0].TID>, 0
}
%endif
};
%endif
%if RTWCAPISignals
%assign tempBIOSig = tBlockSignals
%assign tempNumBIOSig = InCAPI.NumBIOSignals + InCAPI.NumExtInputs + ...
InCAPI.NumSFLocals + InCAPI.NumGrndSignals
%else
%assign tempBIOSig = nulldef
%assign tempNumBIOSig = 0
%endif
%if RTWCAPIParams
%assign tempBTuning = tBlockParams
%assign tempVTuning = tModelParams
%assign tempNumBTuning = InCAPI.NumBlockParams
%assign tempNumVTuning = InCAPI.NumVariableParams
%else
%assign tempBTuning = nulldef
%assign tempVTuning = nulldef
%assign tempNumBTuning = 0
%assign tempNumVTuning = 0
%endif
%if RTWCAPIStates
%assign tempBStates = tBlockStates
%assign tempNumBStates = InCAPI.NumDiscStates + InCAPI.NumContStates
%else
%assign tempBStates = nulldef
%assign tempNumBStates = 0
%endif
%if RTWCAPIRootIO && FcnCAPIRootIOSupport()
%assign tempRootInputs = tRootInputs
%if FcnDynamicAPI()
%assign tempNumRootInputs = 0
%else
%assign tempNumRootInputs = InCAPI.NumRootInputs
%endif
%assign tempRootOutputs = tRootOutputs
%if FcnDynamicAPI()
%assign tempNumRootOutputs = 0
%else
%assign tempNumRootOutputs = InCAPI.NumRootOutputs
%endif
%else
%assign tempRootInputs = nulldef
%assign tempNumRootInputs = 0
%assign tempRootOutputs = nulldef
%assign tempNumRootOutputs = 0
%endif
%if IsModelReferenceSimTarget()
%assign tempStaticInfoLogging = "&mmiStaticInfoLogging"
%else
%assign tempStaticInfoLogging = nulldef
%endif
%assign sysRanDWorkLen = SIZE(SubsystemRanBC.SysRanDWork, 1)
%assign tContextSystems = "rtContextSystems"
%assign loggingInfoLen = SIZE(loggingInfoStartIdx, 1)
%if tempSLfeature==0 || tempSLfeature==2
%if IsModelReferenceSimTarget()
/* The context systems array */
static int_T %<tContextSystems>[%<sysRanDWorkLen>];
/* Logging Meta info */
static rtwCAPI_LoggingMetaInfo loggingMetaInfo[] = {
%if loggingInfoLen > 0
%foreach idx=loggingInfoLen-1
{%<idx>, %, "%",...
%, %},
%endforeach
%assign idx = loggingInfoLen-1
{%<idx>, %, "%",...
%, %}
%else
{0, 0, "", 0}
%endif
};
/*
* ModelMapLoggingStaticInfo:
* {numSystems, contextSystems}
*/
static rtwCAPI_ModelMapLoggingStaticInfo mmiStaticInfoLogging = {
%if useDatasetLoggingHier
%<sysRanDWorkLen>, %<tContextSystems>, loggingMetaInfo, 0, NULL, ...
{%<numLogHierSigs>, rtSigHierLoggingInfo, rtSigHierLoggingChildIdxs}, ...
%<numStateflowLoggedSigs>, %<stateflowLoggedSigsName>
%elseif busHier
%<sysRanDWorkLen>, %<tContextSystems>, loggingMetaInfo, %<numBusElements>, rtBusSignals, {0,NULL,NULL}, ...
%<numStateflowLoggedSigs>, %<stateflowLoggedSigsName>
%else
%<sysRanDWorkLen>, %<tContextSystems>, loggingMetaInfo, 0, NULL, {0,NULL,NULL}, ...
%<numStateflowLoggedSigs>, %<stateflowLoggedSigsName>
%endif
};
%endif
static rtwCAPI_ModelMappingStaticInfo mmiStatic = {
/* Signals:{signals, numSignals,
* rootInputs, numRootInputs,
* rootOutputs, numRootOutputs},
* Params: {blockParameters, numBlockParameters,
* modelParameters, numModelParameters},
* States: {states, numStates},
* Maps: {dataTypeMap, dimensionMap, fixPtMap,
* elementMap, sampleTimeMap, dimensionArray},
* TargetType: targetType
*/
%if FcnDynamicAPI()
{%<tempBIOSig>, 0,
%<tempRootInputs>, %<tempNumRootInputs>,
%<tempRootOutputs>, %<tempNumRootOutputs>},
{%<tempBTuning>, 0,
%<tempVTuning>, 0},
{%<tempBStates>, 0},
%else
{%<tempBIOSig>, %<tempNumBIOSig>,
%<tempRootInputs>, %<tempNumRootInputs>,
%<tempRootOutputs>, %<tempNumRootOutputs>},
{%<tempBTuning>, %<tempNumBTuning>,
%<tempVTuning>, %<tempNumVTuning>},
{%<tempBStates>, %<tempNumBStates>},
%endif
{%<tDataTypeMap>, %<tDimensionMap>, %<tFixPtMap>,
%<tElementMap>, %<tSampleTimeMap>, %<tDimensionArray>},
"float",
{%,
%,
%,
%},
%<tempStaticInfoLogging>, 0,
%<::ProtectedModelReferenceTarget>
};
/* Function to get C API Model Mapping Static Info */
const rtwCAPI_ModelMappingStaticInfo*
%<::CompiledModel.Name>_GetCAPIStaticMap(void) {
return &mmiStatic;
}
%endif
%if tempSLfeature==1
%assign im.AddrMap = tempRepo[0]
%assign im.NumDataAddr = SIZE(tempRepo[0],1)
%assign im.VarDimsAddrMap = tempRepo[1]
%assign im.NumVarDimsAddr = SIZE(tempRepo[1],1)
%<LibAddToCompiledModel("NumDataAddrInMap", im.NumDataAddr)>
%endif
%openfile staticMapBuf
/* Function to get C API Model Mapping Static Info */
extern const rtwCAPI_ModelMappingStaticInfo*
%<::CompiledModel.Name>_GetCAPIStaticMap(void);
%closefile staticMapBuf
%<SLibCacheCodeToFile("mdl_fcn_decl", staticMapBuf)>
%assign sysRanDWork = SubsystemRanBC.SysRanDWork
%assign baseIdx = GetBaseSystemIdx()
%if sysRanDWorkLen > 0 && IsModelReferenceSimTarget()
#ifndef HOST_CAPI_BUILD
%assign systemRan = "sysRanDType *systemRan[]"
%assign systemTid = "int_T systemTid[]"
%assign fcnName = "%<prefix>InitializeSystemRan"
%assign fcnReturns = "static void"
%assign fcnParams = ["%<::tSimStructType> *const %<::tSimStruct>, %<systemRan>%<args.dwArg>, ", ...
"%<systemTid>, void *rootSysRanPtr, int rootTid"]
%assign fcnAbstract = "Initialize the system ran breadcrumbs"
%createrecord fcnRec {Name fcnName; Returns fcnReturns; Params fcnParams; Abstract fcnAbstract; ...
Category "model"; GeneratedBy "capi.tlc"; Type "Initialize"}
%<SLibDumpFunctionBanner(fcnRec)>
%undef fcnRec
%<fcnReturns> %<fcnName>(%
%) {
UNUSED_PARAMETER(%<RTMGetModelSS()>);
%if !ISEMPTY(args.dwArg)
UNUSED_PARAMETER(localDW);
%endif
%foreach i = sysRanDWorkLen
%assign dwIdx = sysRanDWork[i]
%if (dwIdx > -1)
%assign dwRec = ::CompiledModel.DWorks.DWork[dwIdx]
%with System[baseIdx]
%assign sysDWork = SLibGetSysRanBCDWork(dwIdx)
%endwith
%assert (dwRec.Name == "SubsysRanBC")
%assign sigAddr = "&"+ sysDWork
systemRan[%<i>] = (sysRanDType *)%<sigAddr>;
%else
%if i==0
systemRan[%<i>] = (sysRanDType *) rootSysRanPtr;
%else
systemRan[%<i>] = %<nulldef>;
%endif
%endif
%endforeach
%foreach i = ::CompiledModel.NumSystems
%with System[i]
%if Type == "root"
systemTid[0] = rootTid;
%else
%assign numDescSys = SIZE(DescSysIdx, 1)
%foreach j = numDescSys
%assign descIdx = DescSysIdx[j]
%assign sysTid = DescSysNonTrigTID[j]
%assert (sysTid != -1)
%if sysTid >= 0
%if MdlRefDisallowSampleTimeInheritance() && ...
!MdlRefIsAPERTriggeredBlock()
systemTid[%<descIdx>] = %<FcnGetMdlRefGlobalTIDMap("")>[%<sysTid>];
%else
systemTid[%<descIdx>] = rootTid;
%endif
%else
%assert ((sysTid == -2)||((sysTid == -5)))
systemTid[%<descIdx>] = %<sysTid>;
%endif
%endforeach
%endif
%endwith
%endforeach
%assign contextSysVector = ::CompiledModel.SubsystemRanBC.ContextSysIdx
%assign sizeVect = SIZE(contextSysVector, 1)
%foreach j = sizeVect
%assign idx = contextSysVector[j]
%<tContextSystems>[%<j>] = %<idx>;
%endforeach
%if ISFIELD(::CompiledModel, "ReusedSubSystemBlockData")
%assign baseSystem = ::CompiledModel.System[baseIdx]
%assign numDW = SIZE(::CompiledModel.ReusedSubSystemBlockData.DWorkIndex,1)
%foreach idx = numDW
%assign sysIdx = %<::CompiledModel.ReusedSubSystemBlockData.DWorkValue[idx]>
%assign dwIdx = ::CompiledModel.ReusedSubSystemBlockData.DWorkIndex[idx]
%assign dwRec = ::CompiledModel.DWorks.DWork[dwIdx]
%assert (dwRec.Name == "sysIdxToRun")
%assign dwRecName = LibGetRecordIdentifier(dwRec)
%assign dwPath = SLibCGIRVarGroupPath(...
dwRec.VarGroupIdx[0], baseIdx, baseSystem.CrossNoArgFcnBound)
%<dwPath>%<dwRecName> = %<sysIdx>;
%endforeach
%endif
}
#endif /* HOST_CAPI_BUILD */
%endif
%assign curBlockFcn = ::BlockFcn
%assign ::BlockFcn = "InitializeDataMapInfo"
%assign fcnAbstract = "Cache pointers into DataMapInfo substructure of RTModel"
%assign fcnName = "%<::CompiledModel.Name>_InitializeDataMapInfo"
%assign fcnReturns = "void"
%assign simstructDecl = ""
%if (::isRAccel || isRSim) && !IsModelReferenceTarget()
%else
%if MultiInstanceERTCode || IsModelReferenceTarget()
%assign simstructDecl = "%<SLibGetModelTypesNamespacePrefix()>%<::tSimStructType> *const %<::tSimStruct>"
%endif
%endif
%assign dwDecl = ""
%if args.isDwArgDeclSame
%assign dwDecl = args.dwArg
%endif
%assign fcnParams = "%<simstructDecl>%<args.uArg>%<args.bArg>%<args.pArg>%<dwDecl>%<args.xArg>%<args.ssArg>"
%if ISEMPTY(fcnParams)
%assign fcnParams = "void"
%endif
%if IsModelReferenceSimTarget()
%assign fcnParams = "%<fcnParams>, void *sysRanPtr, int contextTid"
%endif
%createrecord fcnRec {Name fcnName; Returns fcnReturns; Params fcnParams; Abstract fcnAbstract; ...
Category "model"; GeneratedBy "capi.tlc"; Type "Initialize"}
%<SLibGetFcnMemSecPragma(fcnName, "MemSecFuncInitTerm", "Pre")>/
%<SLibDumpFunctionBanner(fcnRec)>
%undef fcnRec
#ifndef HOST_CAPI_BUILD
%<fcnReturns> %<fcnName>(%<fcnParams>) {
%assign capiStructId =""
%if GenRTModel
%assign capiStructId = RTMGet("DataMapInfo")
%else
%assert isRSim && !IsModelReferenceTarget()
%assign capiStructId = "(*%<RSimRTWCAPIVarPtr>)"
%endif
%if UsingMalloc || CodeFormat == "S-Function"
/* run-time setup of addresses */
%assign nParams = InCAPI.NumBlockParams + InCAPI.NumVariableParams
%assign nDataAddr = im.NumDataAddr
%assign nVarDimsAddr = im.NumVarDimsAddr
%assign dAddrType = tDataAddrType
%assign localStr = CodeFormat == "S-Function" ? "Local" : ""
%assign reqInsts = LibGetSystemField(rootSystem,"ReqRootPrmHdrDataInsts")
%if ( (InCAPI.NumDiscStates > 0) || ...
(InCAPI.NumSFLocals > 0) || ...
((InCAPI.NumBIOSignals > 0) && ::CompiledModel.DWorkAndBlockIOCombined) ) ...
&& !LibDWorkInstanceIsEmpty()
%if ::CompiledModel.HasSimStructVars == 0
%<::tDWorkType> *%<LibGetDWorkStruct()> = (%<tDWorkType> *) /
%<RTMGet("%<localStr>RootDWork")>;
%elseif !WHITE_SPACE(localStr)
%<RTMGet">RTMGet("RootDWork")> = (%<::tDWorkType> *) %<RTMGet">RTMGet("%<localStr>RootDWork")>;
%endif
%endif
%if (InCAPI.NumContStates > 0) && !LibContStatesInstanceIsEmpty()
%if ::CompiledModel.HasSimStructVars == 0
%<::tContStateType> *%<LibGetContinuousStateStruct()> = (%<tContStateType> *) /
%<RTMGet("%<localStr>ContStates")>;
%elseif !WHITE_SPACE(localStr)
%<RTMGet">RTMGet("ContStates")> = (%<::tContStateType> *) %<RTMGet">RTMGet("%<localStr>ContStates")>;
%endif
%endif
%if (nParams) > 0 && !SLibPrmBufferIsEmpty("SimulinkGlobal","Instance") && !FcnParamsAreGlobalStruct()
%if ::CompiledModel.HasSimStructVars == 0
%<::tParametersType> *%<LibGetParametersStruct()> = (%<tParametersType> *) /
%<RTMGet("%<localStr>DefaultParam")>;
%elseif !WHITE_SPACE(localStr)
%<RTMGet">RTMGet("DefaultParam")> = (%<::tParametersType> *) %<RTMGet">RTMGet("%<localStr>DefaultParam")>;
%endif
%endif
%if (InCAPI.NumBIOSignals > 0) && !LibBlockIOInstanceIsEmpty()
%if ::CompiledModel.HasSimStructVars == 0
%<::tBlockIOType> *%<LibGetBlockIOStruct()> = (%<tBlockIOType> *) /
%<RTMGet("%<localStr>BlockIO")>;
%elseif !WHITE_SPACE(localStr)
%<RTMGet">RTMGet("BlockIO")> = (%<::tBlockIOType> *) %<RTMGet">RTMGet("%<localStr>BlockIO")>;
%endif
%endif
%if ((InCAPI.NumExtInputs > 0) && !LibExternalInputsStructIsEmpty()) || ...
((InCAPI.NumRootInputs > 0) && !LibExternalInputsStructIsEmpty())
%if ::CompiledModel.HasSimStructVars == 0
%<::tInputType> *%<LibGetExternalInputStruct()> = (%<::tInputType> *) /
%<RTMGet("%<localStr>U")>;
%elseif !WHITE_SPACE(localStr)
%<RTMGet">RTMGet("U")> = (%<::tInputType> *) %<RTMGet">RTMGet("%<localStr>U")>;
%endif
%endif
%if ((InCAPI.NumRootOutputs > 0) && !LibExternalOutputsStructIsEmpty())
%if ::CompiledModel.HasSimStructVars == 0
%<tOutputType> *%<LibGetExternalOutputStruct()> = (%<tOutputType> *) /
%<RTMGet("%<localStr>Y")>;
%elseif !WHITE_SPACE(localStr)
%<RTMGet">RTMGet("Y")> = (%<tOutputType> *) %<RTMGet">RTMGet("%<localStr>Y")>;
%endif
%endif
%foreach idx = ::CompiledModel.NumCoderDataGroups
%assign coderGroup = ::CompiledModel.CoderDataGroup[idx]
%if !LibCoderDataGroupStructIsEmpty(coderGroup) && !coderGroup.IsSelf && ...
coderGroup.IsInstanceSpecific && FcnIncludeGroup(coderGroup)
%assign varGroupIdx = SLibGetRootVarGroupIdxForCoderGroup(coderGroup)
%if (varGroupIdx>= 0)
%assign varGroup = ::CompiledModel.VarGroups.VarGroup[varGroupIdx]
%assign structTypeName = varGroup.StructureTypeName
%assign structureInstanceName = varGroup.StructureInstanceName
%assign structureReferenceName = varGroup.StructureReferenceName
%assign structureBaseName = ::tSimStruct
%if coderGroup.AsStructure == "InParent"
%<structTypeName> *%<structureInstanceName> = (%<structTypeName> *) /
%<structureBaseName>->%<structureReferenceName>;
%elseif coderGroup.AsStructure == "InSelf"
%<structTypeName> *%<structureInstanceName> = (%<structTypeName> *) /
&%<structureBaseName>->%<structureReferenceName>;
%endif
%endif
%endif
%endforeach
%if (nDataAddr > 0)
%if UsingMalloc
%<dAddrType> *%<tDataAddrMap>;
%else
static %<dAddrType> %<tDataAddrMap>[%<nDataAddr>];
%endif
%else
static %<tDataAddrType> *%<tDataAddrMap> = %<nulldef>;
%endif
%if (nVarDimsAddr > 0)
%if UsingMalloc
%<tVarDimsAddrMapType> *%<tVarDimsAddrMap>;
%else
static %<tVarDimsAddrMapType> %<tVarDimsAddrMap>[%<nVarDimsAddr>];
%endif
%else
static %<tVarDimsAddrMapType> *%<tVarDimsAddrMap> = %<nulldef>;
%endif
%if (nDataAddr > 0)
%if UsingMalloc
rt_FREE( rtwCAPI_GetDataAddressMap( &(%<capiStructId>.mmi) ) ); /
%<tDataAddrMap> = (%<dAddrType>*) /
malloc(%<nDataAddr> * sizeof(%<dAddrType>));
%endif
if((%<tDataAddrMap>) == %<nulldef>) {
%<RTMSetErrStat("RT_MEMORY_ALLOCATION_ERROR")>;
return;
}
%foreach idx = nDataAddr
%<tDataAddrMap>[%<idx>] = (%<dAddrType>)(%);
%endforeach
%endif
%if (nVarDimsAddr > 0)
%if UsingMalloc
rt_FREE( rtwCAPI_GetVarDimsAddressMap( &(%<capiStructId>.mmi) ) ); /
%<tVarDimsAddrMap> = (%<tVarDimsAddrMapType>*) /
malloc(%<nVarDimsAddr> * sizeof(%<tVarDimsAddrMapType>));
%endif
if((%<tVarDimsAddrMap>) == %<nulldef>) {
%<RTMSetErrStat("RT_MEMORY_ALLOCATION_ERROR")>;
return;
}
%foreach idx = nVarDimsAddr
%<tVarDimsAddrMap>[%<idx>] = (%<tVarDimsAddrMapType>)(%);
%endforeach
%endif
%endif
%if FcnDynamicAPI()
/* Initialize dynamic info for code variants */
%if needsAddressMapIndexVar
int %<addrMapIndex> = 0;
%endif
%<numSignals> = 0;
%<numStates> = 0;
%<numBlockParams> = 0;
%<numModelParams> = 0;
%<numRootInputs> = %<tempNumRootInputs>;
%<numRootOutputs> = %<tempNumRootOutputs>;
%<dynamicInit>
%endif
/* Set C-API version */
rtwCAPI_SetVersion(%<capiStructId>.mmi, 1);
/* Cache static C-API data into the Real-time Model Data structure */
rtwCAPI_SetStaticMap(%<capiStructId>.mmi, &mmiStatic);
/* Cache static C-API logging data into the Real-time Model Data structure */
rtwCAPI_SetLoggingStaticMap(%<capiStructId>.mmi, %<tempStaticInfoLogging>);
%if !IsMultiInstanceERTOrModelReference() || GenerateGRTWrapper || ...
UsingMalloc
/* Cache C-API Data Addresses into the Real-Time Model Data structure */
rtwCAPI_SetDataAddressMap(%<capiStructId>.mmi, %<tDataAddrMap>);
/* Cache C-API Data Run-Time Dimension Buffer Addresses into the Real-Time Model Data structure */
rtwCAPI_SetVarDimsAddressMap(%<capiStructId>.mmi, %<tVarDimsAddrMap>);
%if EXISTS(slrt)
%if (tempNumBTuning > 0) && !LibParametersStructIsEmpty()
%assign rtmargName = RTMGetModelSS()
/* Cache C-API rtp Address and size into the Real-Time Model Data structure */
%<capiStructId>.mmi.InstanceMap.rtpAddress = rtmGetDefaultParam(%<rtmargName>);
%<capiStructId>.mmi.staticMap->rtpSize = sizeof(%<::tParametersType>);
%endif
%endif
%else
%if im.NumDataAddr > 0
/* Cache C-API Data Addresses into the Real-Time Model Data structure */
%assign argsdDecl = "%<RTMGet("DataMapInfo")>.dataAddress"
%assign fcnParams = "%<argsdDecl>%<args.rtmDecl>%<args.uDeclCache>%<args.bDeclCache>%<args.pDeclCache>%<args.dwDeclCache>%<args.xDeclCache>%<args.ssDeclCache>"
%foreach idx = ::CompiledModel.NumCoderDataGroups
%assign fcnParams = fcnParams + args.groupDeclCache[idx]
%endforeach
%assign hasSelfParam = !ISEMPTY(args.rtmDecl) && SLibSynthesizedRTM()
%assign comma = ISEMPTY(fcnParams) ? "" : ", "
%if SLibGetDoesSelfHasCoderDataGroup() && !IsModelReferenceSimTarget() && !hasSelfParam
%assign fcnParams = "%<RTMGetModelSS()>" + "%<comma>" + "%<fcnParams>"
%assign hasSelfParam = TLC_TRUE
%endif
%if !SimstructBasedTarget && !IsModelReferenceTarget() && !GenerateClassInterface && ...
UsingMalloc
%assign comma = ISEMPTY(fcnParams) ? "" : ", "
%if ~hasSelfParam
%assign fcnParams = "%<RTMGetModelSS()>" + "%<comma>" + "%<fcnParams>"
%endif
%endif
%<prefix>InitializeDataAddr(%<fcnParams>);
rtwCAPI_SetDataAddressMap(%<capiStructId>.mmi, %<capiStructId>.dataAddress);
/* Cache C-API Data Run-Time Dimension Buffer Addresses into the Real-Time Model Data structure */
%if im.NumVarDimsAddr <= 0 || (im.NumVarDimsAddr==1 && ...
ISEQUAL(im.VarDimsAddrMap[0],SLibGetNullDefinitionFromTfl()))
%assign dwDecl = ""
%else
%assign dwDecl = args.dwDeclCache
%endif
%assign argsvDecl = "%<RTMGet("DataMapInfo")>.vardimsAddress"
%assign fcnParams = "%<argsvDecl>%<dwDecl>"
%assign hasSelfParam = !ISEMPTY(args.rtmDecl) && SLibSynthesizedRTM()
%assign comma = ISEMPTY(fcnParams) ? "" : ", "
%if SLibIsSelfStructured() && !IsModelReferenceSimTarget() && !hasSelfParam
%assign fcnParams = "%<RTMGetModelSS()>" + "%<comma>" + "%<fcnParams>"
%assign hasSelfParam = TLC_TRUE
%endif
%if !SimstructBasedTarget && !IsModelReferenceTarget() && !GenerateClassInterface && ...
UsingMalloc
%if ISEMPTY(fcnParams)
%assign comma = ""
%else
%assign comma = ", "
%endif
%if !hasSelfParam
%assign fcnParams = "%<RTMGetModelSS()>" + "%<comma>" + "%<fcnParams>"
%endif
%endif
%<prefix>InitializeVarDimsAddr(%<fcnParams>);
rtwCAPI_SetVarDimsAddressMap(%<capiStructId>.mmi, %<capiStructId>.vardimsAddress);
%if EXISTS(slrt)
%if !ISEMPTY(args.pArg) && !LibParametersStructIsEmpty()
%<capiStructId>.mmi.InstanceMap.rtpAddress = %<LibGetParametersStruct()>;
%<capiStructId>.mmi.staticMap->rtpSize = sizeof(%<::tParametersType>);
%endif
%endif
%endif
/* Set Instance specific path */
rtwCAPI_SetPath(%<capiStructId>.mmi, %<nulldef>);
rtwCAPI_SetFullPath(%<capiStructId>.mmi, %<nulldef>);
%endif
%if IsMultiInstanceERTOrModelReference() && im.NumDataAddr > 0 && !UsingMalloc
%assign loggingPtrsArray = "%<RTMGet("DataMapInfo")>.loggingPtrs"
/* Cache C-API logging function pointers into the Real-Time Model Data structure */
%<prefix>InitializeLoggingFunctions(%<loggingPtrsArray>);
rtwCAPI_SetLoggingPtrs(%<capiStructId>.mmi, %<loggingPtrsArray>);
%endif
/* Cache the instance C-API logging pointer */
%if IsModelReferenceSimTarget()
rtwCAPI_SetInstanceLoggingInfo(%<capiStructId>.mmi, &%<capiStructId>.mmiLogInstanceInfo);
%else
rtwCAPI_SetInstanceLoggingInfo(%<capiStructId>.mmi, %<nulldef>);
%endif
/* Set reference to submodels */
%if ::NumModelBlocksWithCAPI > 0
rtwCAPI_SetChildMMIArray(%<capiStructId>.mmi, %<capiStructId>.childMMI);
rtwCAPI_SetChildMMIArrayLen(%<capiStructId>.mmi, %<::NumModelBlocksWithCAPI>);
%else
rtwCAPI_SetChildMMIArray(%<capiStructId>.mmi, %<nulldef>);
rtwCAPI_SetChildMMIArrayLen(%<capiStructId>.mmi, 0);
%endif
%if sysRanDWorkLen > 0 && IsModelReferenceSimTarget()
%<prefix>InitializeSystemRan(%<RTMGetModelSS()>,%<capiStructId>.systemRan%<args.dwDecl>,
%<capiStructId>.systemTid, sysRanPtr, contextTid);
rtwCAPI_SetSystemRan(%<capiStructId>.mmi,%<capiStructId>.systemRan);
rtwCAPI_SetSystemTid(%<capiStructId>.mmi,%<capiStructId>.systemTid);
%endif
%if IsModelReferenceSimTarget()
rtwCAPI_SetGlobalTIDMap(%<capiStructId>.mmi, &%<FcnGetMdlRefGlobalTIDMap("")>[0]);
%endif
}
%assign ::BlockFcn = curBlockFcn
#else /* HOST_CAPI_BUILD */
%assign capiStructHostId = "dataMap"
%assign fcnNameHost = "%<::CompiledModel.Name>_host_InitializeDataMapInfo"
%assign fcnParamsHost = "%<::CompiledModel.Name>_host_DataMapInfo_T *dataMap, const char *path"
#ifdef __cplusplus
extern "C" {
#endif
%<fcnReturns> %<fcnNameHost>(%<fcnParamsHost>) {
/* Set C-API version */
rtwCAPI_SetVersion(%<capiStructHostId>->mmi, 1);
/* Cache static C-API data into the Real-time Model Data structure */
rtwCAPI_SetStaticMap(%<capiStructHostId>->mmi, &mmiStatic);
/* host data address map is NULL */
rtwCAPI_SetDataAddressMap(%<capiStructHostId>->mmi, NULL);
/* host vardims address map is NULL */
rtwCAPI_SetVarDimsAddressMap(%<capiStructHostId>->mmi, NULL);
/* Set Instance specific path */
rtwCAPI_SetPath(%<capiStructHostId>->mmi, path);
rtwCAPI_SetFullPath(%<capiStructHostId>->mmi, NULL);
/* Set reference to submodels */
%if ::NumModelBlocksWithCAPI > 0
%assign mdlRefBlks = ::CompiledModel.ModelReferenceBlocks
%assign nMdlRefBlks = SIZE(mdlRefBlks,0)
%assign mdlBlkIdx = 0
%foreach rowIdx = nMdlRefBlks
%assign mdlRefInfo = mdlRefBlks[rowIdx]
%assign mSysIdx = mdlRefInfo[0]
%assign bIdx = mdlRefInfo[1]
%assign instIdx = mdlRefInfo[2]
%with System[mSysIdx].Block[bIdx]
%assign blk = System[mSysIdx].Block[bIdx]
%if !blk.ParamSettings.SupportsCAPI
%continue
%endif
%assign blockInterface = GetModelrefInterface(blk)
%assign tmpVec = [%, %]
%if SLibIsGeneratingSimTargetForProtectedModel()
%assign bpath = SLibGetProtectedBlockPath()
%else
%assign bpath = STRING(SLibMangledGrBlockPath(tmpVec))
%endif
%assign mdlRefName = STRING(blockInterface.Name)
%if ISFIELD(blockInterface, "RegistrationFcn")
dataMap->childMMI[%<mdlBlkIdx>] = &(dataMap->child%<mdlBlkIdx>.mmi);
%<mdlRefName>_host_InitializeDataMapInfo(&(dataMap->child%<mdlBlkIdx>), "%<bpath>");
%endif
%assign mdlBlkIdx = mdlBlkIdx + 1
%endwith
%endforeach
rtwCAPI_SetChildMMIArray(%<capiStructHostId>->mmi, %<capiStructHostId>->childMMI);
rtwCAPI_SetChildMMIArrayLen(%<capiStructHostId>->mmi, %<::NumModelBlocksWithCAPI>);
%else
rtwCAPI_SetChildMMIArray(%<capiStructHostId>->mmi, %<nulldef>);
rtwCAPI_SetChildMMIArrayLen(%<capiStructHostId>->mmi, 0);
%endif
}
#ifdef __cplusplus
}
#endif
#endif /* HOST_CAPI_BUILD */
%<SLibGetFcnMemSecPragma(fcnName, "MemSecFuncInitTerm", "Post")>/
%<FcnCAPIHookExecute(CAPIHooks)>
%endfunction
%function FcnCAPIInitializeFcnArgs(inCAPI) void
%createrecord /
CAPI_FunctionArgs { /
uArg ""; /
uDecl ""; /
uDeclCache ""; /
dArg ""; /
dDecl ""; /
dDeclCache ""; /
vArg ""; /
vDecl ""; /
vDeclCache ""; /
pArg ""; /
pDecl ""; /
pDeclCache ""; /
bArg ""; /
bDecl ""; /
bDeclCache ""; /
dwArg ""; /
dwDecl ""; /
dwDeclCache ""; /
xArg ""; /
xDecl ""; /
xDeclCache ""; /
ssArg ""; /
ssDecl ""; /
ssDeclCache ""; /
isDwArgDeclSame 0 /
rtmArg ""; /
rtmDecl ""; /
rtmDeclCache "" /
}
%assign args = CAPI_FunctionArgs
%assign emptyString = ""
%addtorecord args groupArg ...
Vector(%<::CompiledModel.NumCoderDataGroups>) [""@%<::CompiledModel.NumCoderDataGroups>]
%addtorecord args groupDecl ...
Vector(%<::CompiledModel.NumCoderDataGroups>) [""@%<::CompiledModel.NumCoderDataGroups>]
%addtorecord args groupDeclCache ...
Vector(%<::CompiledModel.NumCoderDataGroups>) [""@%<::CompiledModel.NumCoderDataGroups>]
%assign addressPrefix = ""
%if GenerateClassInterface
%assign addressPrefix = "&"
%endif
%if !UsingMalloc
%assign rootSystem = System[NumSystems-1]
%assign reqInsts = LibGetSystemField(rootSystem,"ReqRootPrmHdrDataInsts")
%assign typePrefix = SLibGetModelTypesNamespacePrefix()
%if IsMultiInstanceERTOrModelReference()
%assign args.dArg = "void* dataAddr[]"
%assign args.dDecl = "%<RTMGet("DataMapInfo")>.dataAddress"
%assign args.dDeclCache = args.dDecl
%assign args.vArg = "int32_T* vardimsAddr[]"
%assign args.vDecl = "%<RTMGet("DataMapInfo")>.vardimsAddress"
%assign args.vDeclCache = args.vDecl
%if RTWCAPIParams == 1
%if (!reqInsts.ParamsInst || GenerateClassInterface) && ...
(!IsModelRefScalableBuild() || GenerateClassInterface) && ...
!SLibPrmBufferIsEmpty("SimulinkGlobal","Instance") && ...
((inCAPI.NumBlockParams + inCAPI.NumVariableParams) > 0)
%assign args.pArg = ", %<typePrefix>%<::tParametersType> *%<LibGetParametersStruct()>"
%if SLibUseBackwardCompatibleReusableInterface() || ...
GenerateClassInterface || IsModelReferenceTarget()
%assign args.pDecl = ", %<addressPrefix>%<LibGetParametersStruct()>"
%assign args.pDeclCache = ", %<LibGetParametersStruct()>"
%else
%assign args.pDecl = ", %<addressPrefix>%<SLibGetParamPointerFromRTM(0)>"
%assign args.pDeclCache = ", %<SLibGetParamPointerFromRTM(0)>"
%endif
%endif
%if SLibHasGroupedModelArgFromChildModel()
%assign args.rtmArg = ", %<typePrefix>%<::tSimStructType> *const %<::tSimStruct>"
%assign args.rtmDecl = GenerateClassInterface ? ...
", %<::tSimStruct>" : ", %<addressPrefix>%<RTMGetModelSS()>"
%assign args.rtmDeclCache = ", %<RTMGetModelSS()>"
%endif
%endif
%if RTWCAPISignals == 1
%assign selfAccess = SLibGetUseRTMcgType() && !GenerateClassInterface
%assign boRequired = !reqInsts.BlockIOInst && (inCAPI.NumBIOSignals > 0)
%if boRequired && !LibBlockIOInstanceIsEmpty() && !selfAccess ...
&& (!IsModelRefScalableBuild() || GenerateClassInterface)
%if IsModelReferenceTarget() && !GenerateClassInterface
%assign baseSysIdx = GetBaseSystemIdx()
%assign dataType = FcnSysVarGroupType(System[baseSysIdx],"BlockIO")
%assign args.bArg = ", " + dataType + " *localB"
%assign args.bDecl = ", localB"
%assign args.bDeclCache = args.bDecl
%assign curBlockFcn = ::BlockFcn
%assign ::BlockFcn = "InitializeDataMapInfo"
%<SLibAccessArgHelper(System[baseSysIdx].Interface.BlockIOArgDef,"","")>
%assign ::BlockFcn = curBlockFcn
%else
%assign args.bArg = ", %<typePrefix>%<::tBlockIOType> *%<LibGetBlockIOStruct()>"
%if SLibUseBackwardCompatibleReusableInterface() || GenerateClassInterface
%assign args.bDecl = ", %<addressPrefix>%<LibGetBlockIOStruct()>"
%assign args.bDeclCache = ", %<LibGetBlockIOStruct()>"
%else
%assign args.bDecl = ", %<addressPrefix>%<SLibGetBlockIOPointerFromRTM(0)>"
%assign args.bDeclCache = ", %<SLibGetBlockIOPointerFromRTM(0)>"
%endif
%endif
%endif
%assign selfAccess = SLibGetUseRTMcgType() && !GenerateClassInterface
%assign dwRequired = !reqInsts.DworkInst && ...
((inCAPI.NumVarDimsSignals > 0) || IsModelReferenceSimTarget())
%if !LibDWorkInstanceIsEmpty() && !selfAccess && ...
(!IsModelRefScalableBuild() || GenerateClassInterface) && ...
(dwRequired || (boRequired && ::CompiledModel.DWorkAndBlockIOCombined))
%if IsModelReferenceTarget() && !GenerateClassInterface
%assign baseSysIdx = GetBaseSystemIdx()
%assign dataType = FcnSysVarGroupType(System[baseSysIdx],"DWork")
%assign args.dwArg = ", %<dataType> *localDW"
%assign args.dwDecl = ", localDW"
%assign args.dwDeclCache = args.dwDecl
%assign args.isDwArgDeclSame = TLC_TRUE
%assign curBlockFcn = ::BlockFcn
%assign ::BlockFcn = "InitializeDataMapInfo"
%<SLibAccessArgHelper(System[baseSysIdx].Interface.DWorkArgDef,"","")>
%assign ::BlockFcn = curBlockFcn
%else
%assign args.dwArg = ", %<typePrefix>%<::tDWorkType> *%<LibGetDWorkStruct()>"
%if SLibUseBackwardCompatibleReusableInterface() || GenerateClassInterface
%assign args.dwDecl = ", %<addressPrefix>%<LibGetDWorkStruct()>"
%assign args.dwDeclCache = ", %<LibGetDWorkStruct()>"
%assign args.isDwArgDeclSame = TLC_TRUE
%else
%assign args.dwDecl = ", %<addressPrefix>%<SLibGetDWorkPointerFromRTM(0)>"
%assign args.dwDeclCache = ", %<SLibGetDWorkPointerFromRTM(0)>"
%assign args.isDwArgDeclSame = TLC_FALSE
%endif
%endif
%endif
%if !reqInsts.ExtInpsInst && ...
!LibExternalInputsStructIsEmpty() && (inCAPI.NumExtInputs > 0)
%assign isPeriodicRateGrouping = ...
SLibSystemFcnPeriodicRateGrouping(rootSystem, ::BlockFcn)
%if IsModelReferenceTarget()
%assign baseSysIdx = GetBaseSystemIdx()
%with System[baseSysIdx].Interface
%foreach argIdx = NumCanonicalInputArgDefs
%assign ci = CanonicalInputArgDef[argIdx]
%if FcnArgNeeded(ci, rootSystem.CurrentTID, isPeriodicRateGrouping)
%assign identi = LibGetRecordIdentifier(ci)
%assign dataType = SLibGetRecordDataTypeName(ci, "")
%assign optStar = (LibGetRecordWidth(ci) == 1 && ...
!(IsModelReferenceRTWTarget() && !FcnPassCanonicalInputByPtr(ci))) ...
? " *" : " "
%assign optWidth = LibOptionalVectorWidth(LibGetRecordWidth(ci))
%assign dataType = "const %<dataType>"
%assign argDef = dataType + optStar + identi + optWidth
%assign args.uArg = args.uArg + ", " + argDef
%assign args.uDecl = args.uDecl + ", " + identi
%assign args.uDeclCache = args.uDecl
%endif
%if SLibGetCanIOIsVarDims(ci)
%assign cdwIdx = SLibGetCanDimSizeDWIdxForArg(ci)
%assign canDWork = CanonicalDWorkArgDef[cdwIdx]
%if FcnArgNeeded(ci, rootSystem.CurrentTID, isPeriodicRateGrouping)
%assign identi = LibGetRecordIdentifier(canDWork)
%assign dwIdx = canDWork.FirstSignalSrc
%assign dwRec = ::CompiledModel.DWorks.DWork[dwIdx]
%assign dwWidth = SLibDWorkWidth(dwRec)
%assign dataType = "const int "
%assign argDef = dataType + identi + "[%<dwWidth>]"
%assign args.uArg = args.uArg + ", " + argDef
%assign args.uDecl = args.uDecl + ", " + identi
%assign args.uDeclCache = args.uDecl
%endif
%endif
%endforeach
%endwith
%elseif (MultiInstanceERTCode && (RootIOStructures || SLibHasGlobalExternalInputsWithFPC()))
%assign args.uArg = args.uArg + ", " + "%<typePrefix>%<::tInputType> *%<LibGetExternalInputStruct()>"
%if SLibUseBackwardCompatibleReusableInterface() || ...
GenerateClassInterface || ...
::CompiledModel.RootIOFormat != "Part of model data structure"
%assign args.uDecl = args.uDecl + ", " + "%<addressPrefix>%<LibGetExternalInputStruct()>"
%assign args.uDeclCache = args.uDeclCache + ", " + "%<LibGetExternalInputStruct()>"
%else
%assign args.uDecl = args.uDecl + ", " + "%<addressPrefix>%<RTMGet("U")>"
%assign args.uDeclCache = args.uDeclCache + ", " + "%<RTMGet("U")>"
%endif
%else
%foreach idx = ExternalInputs.NumExternalInputs
%assign extInp = ExternalInputs.ExternalInput[idx]
%with extInp
%if extInp.StorageClass != "Auto" || ...
!FcnArgNeeded(extInp,rootSystem.CurrentTID,isPeriodicRateGrouping)
%continue
%endif
%assign id = LibGetRecordIdentifier(extInp)
%assign passByRef = PassExtInpByRef(extInp)
%assign args.uDecl = args.uDecl + ", " + ...
"%<LibGetExternalInputStruct()>%<UQualifier>%<id>"
%assign args.uDeclCache = args.uDecl
%assign optStar = passByRef ? "*" : ""
%assign dataType = SLibGetRecordDataTypeName(extInp, "")
%if LibGetRecordWidth(extInp) > 1
%assign args.uArg = args.uArg + ", " + ...
"%<dataType> %<LibGetExternalInputStruct()>%<UQualifier>%<id>[%< LibGetRecordWidth(extInp)>]"
%else
%assign args.uArg = args.uArg + ", " + ...
"%<dataType> %<optStar>%<LibGetExternalInputStruct()>%<UQualifier>%<id>"
%endif
%endwith
%endforeach
%endif
%endif
%assign selfAccess = SLibGetUseRTMcgType() && !GenerateClassInterface
%if !reqInsts.DworkInst && !LibDWorkInstanceIsEmpty() && !selfAccess && ...
(!IsModelRefScalableBuild() || GenerateClassInterface) && ...
((inCAPI.NumSFLocals > 0) || IsModelReferenceSimTarget())
%if IsModelReferenceTarget() && !GenerateClassInterface
%assign baseSysIdx = GetBaseSystemIdx()
%assign dataType = FcnSysVarGroupType(System[baseSysIdx],"DWork")
%assign args.dwArg = ", %<dataType> *localDW"
%assign args.dwDecl = ", localDW"
%assign args.dwDeclCache = args.dwDecl
%assign args.isDwArgDeclSame = TLC_TRUE
%assign curBlockFcn = ::BlockFcn
%assign ::BlockFcn = "InitializeDataMapInfo"
%<SLibAccessArgHelper(System[baseSysIdx].Interface.DWorkArgDef,"","")>
%assign ::BlockFcn = curBlockFcn
%else
%assign args.dwArg = ", %<typePrefix>%<::tDWorkType> *%<LibGetDWorkStruct()>"
%if SLibUseBackwardCompatibleReusableInterface() || GenerateClassInterface
%assign args.dwDecl = ", %<addressPrefix>%<LibGetDWorkStruct()>"
%assign args.dwDeclCache = ", %<LibGetDWorkStruct()>"
%assign args.isDwArgDeclSame = TLC_TRUE
%else
%assign args.dwDecl = ", %<addressPrefix>%<SLibGetDWorkPointerFromRTM(0)>"
%assign args.dwDeclCache = ", %<SLibGetDWorkPointerFromRTM(0)>"
%assign args.isDwArgDeclSame = TLC_FALSE
%endif
%endif
%endif
%endif
%if RTWCAPIStates == 1
%assign selfAccess = SLibGetUseRTMcgType() && !GenerateClassInterface
%if !reqInsts.DworkInst && !LibDWorkInstanceIsEmpty() && !selfAccess && ...
(!IsModelRefScalableBuild() || GenerateClassInterface) && ...
((inCAPI.NumDiscStates > 0) || IsModelReferenceSimTarget())
%if IsModelReferenceTarget() && !GenerateClassInterface
%assign baseSysIdx = GetBaseSystemIdx()
%assign dataType = FcnSysVarGroupType(System[baseSysIdx],"DWork")
%assign args.dwArg = ", %<dataType> *localDW"
%assign args.dwDecl = ", localDW"
%assign args.dwDeclCache = args.dwDecl
%assign args.isDwArgDeclSame = TLC_TRUE
%assign curBlockFcn = ::BlockFcn
%assign ::BlockFcn = "InitializeDataMapInfo"
%<SLibAccessArgHelper(System[baseSysIdx].Interface.DWorkArgDef,"","")>
%assign ::BlockFcn = curBlockFcn
%else
%assign args.dwArg = ", %<typePrefix>%<::tDWorkType> *%<LibGetDWorkStruct()>"
%if SLibUseBackwardCompatibleReusableInterface() || GenerateClassInterface
%assign args.dwDecl = ", %<addressPrefix>%<LibGetDWorkStruct()>"
%assign args.dwDeclCache = ", %<LibGetDWorkStruct()>"
%assign args.isDwArgDeclSame = TLC_TRUE
%else
%assign args.dwDecl = ", %<addressPrefix>%<SLibGetDWorkPointerFromRTM(0)>"
%assign args.dwDeclCache = ", %<SLibGetDWorkPointerFromRTM(0)>"
%assign args.isDwArgDeclSame = TLC_FALSE
%endif
%endif
%endif
%if !reqInsts.ContStatesInst && !LibContStatesInstanceIsEmpty() && ...
(inCAPI.NumContStates > 0)
%if IsModelReferenceTarget()
%assign baseSysIdx = GetBaseSystemIdx()
%assign dataType = "%<FcnSysVarGroupType(System[baseSysIdx],"ContStates")> "
%assign args.xArg = ", %<dataType> *localX"
%assign args.xDecl = ", localX"
%assign args.xDeclCache = args.xDecl
%assign curBlockFcn = ::BlockFcn
%assign ::BlockFcn = "InitializeDataMapInfo"
%<SLibAccessArgHelper(System[baseSysIdx].Interface.ContStatesArgDef,"","")>
%assign ::BlockFcn = curBlockFcn
%else
%assign args.xArg = ", %<typePrefix>%<::tContStateType> *%<LibGetContinuousStateStruct()>"
%if SLibUseBackwardCompatibleReusableInterface() || GenerateClassInterface
%assign args.xDecl = ", %<addressPrefix>%<LibGetContinuousStateStruct()>"
%assign args.xDeclCache = ", %<LibGetContinuousStateStruct()>"
%else
%assign args.xDecl = ", (%<typePrefix>%<::tContStateType> *)%<addressPrefix>%<SLibGetContStatesPointerFromRTM(0)>"
%assign args.xDeclCache = ", (%<typePrefix>%<::tContStateType> *)%<SLibGetContStatesPointerFromRTM(0)>"
%endif
%endif
%endif
%endif
%endif
%assign mdlRef = IsModelReferenceTarget()
%assign multiOrMdlref = MultiInstanceERTCode || mdlRef
%if multiOrMdlref
%foreach idx = ::CompiledModel.NumCoderDataGroups
%assign group = ::CompiledModel.CoderDataGroup[idx]
%if !LibCoderDataGroupStructIsEmpty(group) && ...
group.IsInstanceSpecific && FcnIncludeGroup(group) && ...
((inCAPI.NumDataGroupElements[idx] > 0) || IsModelReferenceSimTarget())
%if IsModelReferenceTarget() && !GenerateClassInterface
%assign baseSysIdx = GetBaseSystemIdx()
%assign dataType = SLibCoderDataGroupType(group)
%assign groupToken = "CoderDataGroup" + group.Name
%assign varGroupIdx = FcnSysVarGroupIndex(System[baseSysIdx], groupToken, 0)
%if varGroupIdx < 0
%continue
%endif
%assign varGroup = ::CompiledModel.VarGroups.VarGroup[varGroupIdx]
%assign varName = varGroup.LocalName
%assign args.groupArg[idx] = ", %<dataType> *%<varName>"
%if SLibAccessGroupThroughSelf(group)
%assign args.groupDecl[idx] = ", %<addressPrefix>%<SLibGetCoderDataGroupPointerFromRTM(group, 0)>"
%assign args.groupDeclCache[idx] = ", %<SLibGetCoderDataGroupPointerFromRTM(group, 0)>"
%else
%assign args.groupDecl[idx] = ", %<addressPrefix>%<SLibCoderDataGroupInstance(group)>"
%assign args.groupDeclCache[idx] = ", &%<SLibCoderDataGroupInstance(group)>"
%endif
%assign argDef = groupToken + "ArgDef"
%assign curBlockFcn = ::BlockFcn
%assign ::BlockFcn = "InitializeDataMapInfo"
%assign accessHelper = SLibAccessArgHelper(System[baseSysIdx].Interface.%<argDef>,"","")
%assign ::BlockFcn = curBlockFcn
%<accessHelper>
%else
%assign args.groupArg[idx] = ", %<SLibCoderDataGroupType(group)>* %<LibGetCoderDataGroupStruct(group)>"
%if SLibAccessGroupThroughSelf(group)
%assign args.groupDecl[idx] = ", %<addressPrefix>%<SLibGetCoderDataGroupPointerFromRTM(group, 0)>"
%assign args.groupDeclCache[idx] = ", %<SLibGetCoderDataGroupPointerFromRTM(group, 0)>"
%else
%assign args.groupDecl[idx] = ", %<addressPrefix>%<SLibCoderDataGroupInstance(group)>"
%assign args.groupDeclCache[idx] = ", &%<SLibCoderDataGroupInstance(group)>"
%endif
%endif
%endif
%endforeach
%endif
%if GenerateClassInterface && SLibGetDoesSelfExist()
%assign selfVG = ::CompiledModel.VarGroups.VarGroup[SLibGetSelfVarGroupIndex()]
%assign selfGroupIdx = SLibGetSelfCoderDataGroupIndex()
%assign ssargs = ""
%assign ssdecls = ""
%foreach elemIdx = selfVG.NumVarGroupElements
%assign elem = IDNUM(selfVG.VarGroupElements[elemIdx])
%if elem[0] == "VG"
%assign elemVG = ::CompiledModel.VarGroups.VarGroup[elem[1]]
%if elemVG.CoderDataGroupIndex == selfGroupIdx
%assign typename = SLibGetTypeNameFromCGType(elemVG.CGTypeIdx)
%assign symbolicDims = LibCGTypeSymbolicVectorDims(elemVG.CGTypeIdx)
%assign refOp = ISEMPTY(symbolicDims) ? "& " : " "
%assign ssargs = ssargs + ", " + "%<typePrefix>%<typename>" + "%<refOp>" + elemVG.Name + symbolicDims
%assign ssdecls = ssdecls + ", " + elemVG.Name
%endif
%endif
%endforeach
%assign args.ssArg = ssargs
%assign args.ssDecl = ssdecls
%assign args.ssDeclCache = ssdecls
%endif
%endif
%<LibAddToCompiledModel("CAPIFunctionArgs", args)>
%return args
%endfunction
%function FcnIncludeGroup(group) void
%if group.ContainsInstanceSpecificParameter
%return RTWCAPIParams
%else
%return RTWCAPISignals || RTWCAPIStates || RTWCAPIRootIO
%endif
%endfunction
%function FcnReturnCompliantBlockPath(blkPath, type) void
%assign blkPath = STRING(blkPath)
%assign strLen = SIZE(blkPath, 1)
%if (strLen > %<RTWMaxStringLength>)
%assign warnStr= "C-API %<type> BlockPath length of '%<strLen>' " + ...
"is greater than the length '509' ISO C89 compilers are required " + ...
"to support. An empty BlockPath will be placed in the C-API structure./n" + ...
"BlockPath: " + blkPath
%<LibReportWarning(warnStr)>
%assign blkPath = ""
%endif
%return blkPath
%endfunction
%function FcnDataSupportsCAPI(data) void
%if (TYPE(data) == "Scope")
%assign rtwRecord = LibRTWRecord(data)
%if !ISEMPTY(rtwRecord) && (rtwRecord.StorageClass == "Custom" || SLibIsLegacyStorageClassForDataRecord(rtwRecord))
%assign cscDefn = SLibGetCSCDefForData(rtwRecord)
%if (cscDefn.Name == "CalPrm" || cscDefn.Name == "InternalCalPrm" || ...
cscDefn.Name == "PerInstanceMemory")
%return TLC_FALSE
%endif
%endif
%return !SLibIsGlobalMapDataWithNoExternalLinkage(data)
%else
%return TLC_FALSE
%endif
%endfunction
%function FcnWriteDatasetLoggingHier() Output
%assign totalChildIdx = 0
static const rtwCAPI_SignalHierLoggingInfo rtSigHierLoggingInfo[] = {
%foreach shIdx = NumSignalHierLoggingInfo
%assign sigName = SignalHierLoggingInfo[shIdx].SignalName
%assign numChild = SignalHierLoggingInfo[shIdx].NumChildren
%if numChild > 0
%assign childStartIdx = totalChildIdx
%else
%assign childStartIdx = -1
%endif
%assign dynInit = "{ /"%<sigName>/", %<numChild>, %<childStartIdx> }"
%if shIdx < NumSignalHierLoggingInfo - 1
%assign dynInit = dynInit + ","
%endif
%<dynInit>
%assign totalChildIdx = totalChildIdx + numChild
%endforeach
};
%assign curChildCount = 0
static const uint_T rtSigHierLoggingChildIdxs[] = {
%foreach shIdx = NumSignalHierLoggingInfo
%foreach cIdx = SignalHierLoggingInfo[shIdx].NumChildren
%assign curChildIdx = SignalHierLoggingInfo[shIdx].Children[cIdx]
%assign dynInit = "%<curChildIdx>"
%if curChildCount < totalChildIdx - 1
%assign dynInit = dynInit + ","
%endif
%<dynInit>
%assign curChildCount = curChildCount + 1
%endforeach
%endforeach
};
%endfunction
%function FcnWriteDatasetLoggingSFSignals() Output
static const rtwCAPI_StateflowSignalLoggingInfo rtStateflowChartLoggingInfo[] = {
%foreach sigIdx = NumStateflowSigLogInfo
%assign signalName = STRING(StateflowSigLogInfo[sigIdx].SignalName)
%assign bpath = STRING(StateflowSigLogInfo[sigIdx].BlockPath)
%assign loggingName = STRING(StateflowSigLogInfo[sigIdx].LoggingName)
%assign maxPoints = StateflowSigLogInfo[sigIdx].MaxPoints
%assign decimation = StateflowSigLogInfo[sigIdx].Decimation
%if StateflowSigLogInfo[sigIdx].UseCustomName
%assign useCustomName = TLC_TRUE
%else
%assign useCustomName = TLC_FALSE
%endif
%assign dynInit = "{ /"%<signalName>/", /"%<bpath>/", /"%<loggingName>/", %<maxPoints>, %<decimation>, %<useCustomName> }"
%if sigIdx < NumStateflowSigLogInfo - 1
%assign dynInit = dynInit + ","
%endif
%<dynInit>
%endforeach
};
%endfunction
%function FcnWriteCAPIHeadersandDefines(baseName) Output
%assign HostHeaderFile = LibGetMdlCapiHostHdrBaseName()
%assign HeaderFile = LibGetMdlCapiHdrBaseName()
#include "rtw_capi.h"
#ifdef HOST_CAPI_BUILD
#include "%<HostHeaderFile>.h"
#define sizeof(s) ((size_t)(0xFFFF))
#undef rt_offsetof
#define rt_offsetof(s,el) ((uint16_T)(0xFFFF))
#define TARGET_CONST
#define TARGET_STRING(s) (s)
%<LibDumpFixptOddSizeTypedefs()>
#else /* HOST_CAPI_BUILD */
#include "%<SLibCoderBuiltinTypeidTypesFilename()>"
#include "%<baseName>.h"
#include "%<HeaderFile>.h"
%<SLibIncludePrivateHeader()>
%if EXISTS(::LightWeightRTWCAPINeeded)
#define LIGHT_WEIGHT_CAPI
%endif
#ifdef LIGHT_WEIGHT_CAPI
#define TARGET_CONST
#define TARGET_STRING(s) (NULL)
#else
#define TARGET_CONST const
#define TARGET_STRING(s) (s)
#endif
#endif /* HOST_CAPI_BUILD */
%endfunction
%function () Output
%assign ModelHeaderFile = LibGetMdlPubHdrBaseName()
%assign HostHeaderFile = LibGetMdlCapiHostHdrBaseName()
%assign FileNameHost = "%<HostHeaderFile>.h"
%assign FileTagHost = "%<ModelHeaderFile>_cap_host_h_"
%openfile outputFileHost = FileNameHost
#ifndef RTW_HEADER_%<FileTagHost>
#define RTW_HEADER_%<FileTagHost>
#ifdef HOST_CAPI_BUILD
#include "rtw_capi.h"
#include "rtw_modelmap.h"
%if ::NumModelBlocksWithCAPI > 0
%assign mdlRefBlks = ::CompiledModel.ModelReferenceBlocks
%assign nMdlRefBlks = SIZE(mdlRefBlks,0)
%foreach rowIdx = nMdlRefBlks
%assign mdlRefInfo = mdlRefBlks[rowIdx]
%assign mSysIdx = mdlRefInfo[0]
%assign bIdx = mdlRefInfo[1]
%assign instIdx = mdlRefInfo[2]
%with System[mSysIdx].Block[bIdx]
%assign blk = System[mSysIdx].Block[bIdx]
%if !blk.ParamSettings.SupportsCAPI
%continue
%endif
%assign blockInterface = GetModelrefInterface(blk)
%assign tmpVec = [%, %]
%assign mdlRefName = STRING(blockInterface.Name)
%if ISFIELD(blockInterface, "RegistrationFcn")
#include "%<mdlRefName>_capi_host.h"
%endif
%endwith
%endforeach
%endif
typedef struct {
rtwCAPI_ModelMappingInfo mmi;
%if ::NumModelBlocksWithCAPI > 0
%assign mdlRefBlks = ::CompiledModel.ModelReferenceBlocks
%assign nMdlRefBlks = SIZE(mdlRefBlks,0)
rtwCAPI_ModelMappingInfo *childMMI[%<nMdlRefBlks>];
%assign mdlBlkIdx = 0
%foreach rowIdx = nMdlRefBlks
%assign mdlRefInfo = mdlRefBlks[rowIdx]
%assign mSysIdx = mdlRefInfo[0]
%assign bIdx = mdlRefInfo[1]
%assign instIdx = mdlRefInfo[2]
%with System[mSysIdx].Block[bIdx]
%assign blk = System[mSysIdx].Block[bIdx]
%if !blk.ParamSettings.SupportsCAPI
%continue
%endif
%assign blockInterface = GetModelrefInterface(blk)
%assign tmpVec = [%, %]
%assign mdlRefName = STRING(blockInterface.Name)
%if ISFIELD(blockInterface, "RegistrationFcn")
%<mdlRefName>_host_DataMapInfo_T child%<mdlBlkIdx>;
%endif
%assign mdlBlkIdx = mdlBlkIdx + 1
%endwith
%endforeach
%endif
} %<Name>_host_DataMapInfo_T;
#ifdef __cplusplus
extern "C" {
#endif
void %<::CompiledModel.Name>_host_InitializeDataMapInfo(%<CompiledModel.Name>_host_DataMapInfo_T *dataMap, const char *path);
#ifdef __cplusplus
}
#endif
#endif /* HOST_CAPI_BUILD */
#endif /* RTW_HEADER_%<FileTagHost> */
/* EOF: %<FileNameHost> */
%closefile outputFileHost
%endfunction
%endif