%if EXISTS("_STANDALONESYSVAR_") == 0
%assign _STANDALONESYSVAR_ = 1
%function FcnEmitCoderGroupForStandaloneSystem(system, groupIdx, buffer, definition) void
%assign varGroupIdx = SLibGetVarGroupIdxForCoderGroup(system.SystemIdx, groupIdx)
%assign varGroup = ::CompiledModel.VarGroups.VarGroup[varGroupIdx]
%if definition
%assign fileToEmitTo = FcnVarGroupDefinitionFile(varGroup, system)
%if ISEMPTY(fileToEmitTo)
%assign fileToEmitTo = system.SystemSourceFileName
%endif
%assign defFile = SLibAddModelFile("SystemBody", "Simulink", fileToEmitTo)
%if !ISEMPTY(defFile)
%<SLibSetModelFileAttribute(defFile, "Definitions", buffer)>
%<SLibSetModelFileAttribute(defFile, "Group", "data")>
%assign declFile = FcnVarGroupHeaderFile(varGroup, system)
%if !ISEMPTY(declFile)
%assign declFile = declFile + ".h"
%<FcnAddDependentHeaderForCoderGroup(defFile, declFile)>
%endif
%endif
%else
%assign fileToEmitTo = FcnVarGroupHeaderFile(varGroup, system)
%if ISEMPTY(fileToEmitTo)
%assign fileToEmitTo = system.SystemSourceFileName
%endif
%assign declFile = SLibAddModelFile("SystemHeader", "Simulink", fileToEmitTo)
%if !ISEMPTY(declFile)
%<SLibSetModelFileAttribute(declFile, "Declarations", buffer)>
%<SLibSetModelFileAttribute(declFile, "Group", "data")>
%endif
%endif
%endfunction
%function SLibDeclareStandaloneVarsForDynamicInitCoderGroups(system, extern) void
%foreach idx = ::CompiledModel.NumCoderDataGroups
%assign group = ::CompiledModel.CoderDataGroup[idx]
%if group.IsLegacyStorageClass
%continue
%endif
%if SLibDataGroupStaticInit(group)
%continue
%endif
%openfile tmpBuf
%assign groupName = group.Name
%assign grouptoken = "CoderDataGroup" + groupName
%if system.Has%<grouptoken>Arg
%<SLibDeclareStandaloneVarType(system, group, grouptoken, extern)>
%else
%assign varGroupIndex = FcnSysVarGroupIndex(system, "CoderDataGroup" + group.Name, 0)
%if varGroupIndex != -1 && !SLibVarGroupIsStruct(varGroupIndex)
%<SLibDeclareStandaloneUnstructVarType(system, group, varGroupIndex, extern)>
%endif
%endif
%closefile tmpBuf
%if !ISEMPTY(tmpBuf)
%if ISEMPTY(extern)
%assign definition = TLC_TRUE
%else
%assign definition = TLC_FALSE
%endif
%<FcnEmitCoderGroupForStandaloneSystem(system, idx, tmpBuf, definition)>
%endif
%endforeach
%endfunction
%function SLibDeclareStandloneVarsForStaticInitForCoderGroups(system) void
%foreach idx = ::CompiledModel.NumCoderDataGroups
%assign group = ::CompiledModel.CoderDataGroup[idx]
%if group.IsLegacyStorageClass
%continue
%endif
%if SLibDataGroupStaticInit(group) && !SLibCoderDataGroupIsImported(group)
%assign groupName = group.Name
%assign groupToken = "CoderDataGroup" + groupName
%if system.Has%<groupToken>Arg
%assign typeName = FcnSysVarGroupType(system, groupToken)
%assign identifier = FcnSysVarGroupNonreusedName(system, groupToken)
%<SLibDeclareStandaloneVarStaticInit(system, group, identifier, typeName, idx)>
%else
%assign varGroupIndex = FcnSysVarGroupIndex(system, groupToken, 0)
%if varGroupIndex != -1 && !SLibVarGroupIsStruct(varGroupIndex)
%assign numVars = SLibVarGroupNumElements(varGroupIndex)
%foreach varIdx = numVars
%assign typeIndex = SLibVarGroupElementType(varGroupIndex, varIdx)
%assign typeName = SLibGetTypeNameFromCGType(typeIndex)
%assign identifier = SLibVarGroupElementName(varGroupIndex, varIdx) + LibCGTypeSymbolicVectorDims(typeIndex)
%<SLibDeclareStandaloneVarStaticInit(system, group, identifier, typeName, idx)>
%endforeach
%endif
%endif
%endif
%endforeach
%endfunction
%function SLibInitializeStandaloneDataForStructCoderGroups(system, group, groupToken, idx) void
%assign rtp = LibGetSystemField(system, "Standalone" + groupToken + "Init")
%assign identifier = FcnSysVarGroupNonreusedName(system,groupToken)
%if SLibAutosarCompilerAbstractionRequired()
%openfile definition
%<SLibAutosarCompilerAbstractionForDataDecl(SLibDataGroupMemorySectionConst(group), FcnSysVarGroupType(system,groupToken), TLC_FALSE, TLC_FALSE, identifier, "DataGlobal")> = { ...
%<rtp>
};/
%closefile definition
%else
%openfile definition
%<FcnSysVarGroupType(system,groupToken)> ...
%<identifier> = {
%<rtp>
};/
%closefile definition
%endif
%openfile tmpBuf
%<SLibApplyMemSecToDataDefnForGroup(definition, group, identifier, system, TLC_FALSE)>/
%closefile tmpBuf
%if !ISEMPTY(tmpBuf)
%<FcnEmitCoderGroupForStandaloneSystem(system, idx, tmpBuf, TLC_TRUE)>
%endif
%return tmpBuf
%endfunction
%function SLibInitializeStandaloneDataForUnstructCoderGroups(system, group, groupToken, idx) void
%assign varGroupIndex = FcnSysVarGroupIndex(system, groupToken, 0)
%if varGroupIndex != -1 && !SLibVarGroupIsStruct(varGroupIndex)
%assign rtp = LibGetSystemField(system, "Standalone" + groupToken + "Init")
%assign numVars = SLibVarGroupNumElements(varGroupIndex)
%foreach varIdx = numVars
%assign typeIndex = SLibVarGroupElementType(varGroupIndex, varIdx)
%assign typeName = SLibGetTypeNameFromCGType(typeIndex)
%assign identifier = SLibVarGroupElementName(varGroupIndex, varIdx) + LibCGTypeSymbolicVectorDims(typeIndex)
%assign val = rtp[varIdx]
%if SLibAutosarCompilerAbstractionRequired()
%openfile definition
%<SLibAutosarCompilerAbstractionForDataDecl(SLibDataGroupMemorySectionConst(group), typeName, TLC_FALSE, TLC_FALSE, identifier, "DataGlobal")> = ...
%<val>;/
%closefile definition
%else
%openfile definition
%<typeName> %<identifier> = %<val>;/
%closefile definition
%endif
%openfile tmpBuf
%<SLibApplyMemSecToDataDefnForGroup(definition, group, identifier, system, TLC_FALSE)>/
%closefile tmpBuf
%if !ISEMPTY(tmpBuf)
%<FcnEmitCoderGroupForStandaloneSystem(system, idx, tmpBuf, TLC_TRUE)>
%endif
%endforeach
%return tmpBuf
%endif
%endfunction
%function SLibInitializeStandaloneDataForCoderGroups(system) void
%foreach idx = ::CompiledModel.NumCoderDataGroups
%assign group = ::CompiledModel.CoderDataGroup[idx]
%if SLibDataGroupStaticInit(group) && !SLibCoderDataGroupIsImported(group)
%assign groupName = group.Name
%assign groupToken = "CoderDataGroup" + groupName
%if system.Has%<groupToken>Arg
%<SLibInitializeStandaloneDataForStructCoderGroups(system, group, groupToken, idx)>
%else
%<SLibInitializeStandaloneDataForUnstructCoderGroups(system, group, groupToken, idx)>
%endif
%endif
%endforeach
%endfunction
%function SLibInitializeStandaloneData(system) void
%openfile tmpbuf
%with system.Interface
%if system.HasParametersArg
%assign rtp = LibGetSystemField(system, "StandaloneParameterInit")
%assign identifier = FcnSysVarGroupNonreusedName(system,"Parameter")
%if SLibAutosarCompilerAbstractionRequired()
%openfile definition
%<SLibAutosarCompilerAbstractionForDataDecl(TLC_FALSE, FcnSysVarGroupType(system,"Parameter"), TLC_FALSE, TLC_FALSE, identifier, "DataGlobal")> = { ...
%<rtp>
};/
%closefile definition
%else
%openfile definition
%<FcnSysVarGroupType(system,"Parameter")> ...
%<identifier> = {
%<rtp>
};/
%closefile definition
%endif
%<SLibApplyMemSecToDataDefnForSystem(definition, "MemSecDataParameters", identifier, system, TLC_FALSE)>/
%endif
%if system.HasConstBlockIOArg
%assign constbo = LibGetSystemField(system, "StandaloneConstBlockIOInit")
%assign identifier = FcnSysVarGroupNonreusedName(system,"ConstBlockIO")
%if SLibAutosarCompilerAbstractionRequired()
%openfile definition
%assign canBeConst = SLibCanConstBlockIOBeConst()
%<SLibAutosarCompilerAbstractionForDataDecl(canBeConst, FcnSysVarGroupType(system,"ConstBlockIO"), TLC_FALSE, TLC_FALSE, identifier, "DataGlobal")> = { ...
%<constbo>
};/
%closefile definition
%else
%assign qualifiers = SLibGetConstBlockIOForSystemQualifiers(system)
%openfile definition
%<qualifiers> %<FcnSysVarGroupType(system,"ConstBlockIO")>
%<identifier> = {
%<constbo>
};/
%closefile definition
%endif
%<SLibApplyMemSecToDataDefnForSystem(definition, "MemSecDataConstants", identifier, system, TLC_FALSE)>/
%endif
%endwith
%closefile tmpbuf
%if NotRootFileName(system) && !ISEMPTY(tmpbuf)
%assign fileName = SLibGetSystemOutputSrcFileBaseName(system)
%assign dataFile = SLibDoesModelFileExist("SystemBody", "%<fileName>_data")
%if ISEMPTY(dataFile)
%openfile dataBanBuf
/*
* %<fileName>_data.%<LangFileExt>
*
%<SLibCommonHeaderInfo()>/
*/
%closefile dataBanBuf
%assign rootFileName = GetRootSystemHeaderFileName()
%openfile inclBuf
#include "%<rootFileName>.h"
%<SLibIncludePrivateHeader()>
%closefile inclBuf
%<SLibCacheSystemCodeToFile("sysdata_src_ban", system, dataBanBuf)>
%undef dataBanBuf
%<SLibCacheSystemCodeToFile("sysdata_src_incl", system, inclBuf)>
%undef inclBuf
%endif
%<SLibCacheSystemCodeToFile("sysdata_data_defn", system, tmpbuf)>
%else
%if !ISEMPTY(tmpbuf)
%<LibSetSystemField(system, "StandaloneDataInit", tmpbuf)>
%endif
%endif
%<SLibInitializeStandaloneDataForCoderGroups(system)>
%endfunction
%function SLibDeclareStandaloneVarType(system, group, aVarGroupType, extern) void
%openfile tmpbuf
%assign typeName = FcnSysVarGroupType(system, aVarGroupType)
%assign identifier = FcnSysVarGroupNonreusedName(system, aVarGroupType)
%<SLibDeclareStandaloneVarDynamicInit(system, group, identifier, typeName, extern)>
%closefile tmpbuf
%return tmpbuf
%endfunction
%function SLibDeclareStandaloneUnstructVarType(system, group, varGroupIndex, extern) void
%openfile tmpbuf
%assign numVars = SLibVarGroupNumElements(varGroupIndex)
%foreach varIdx = numVars
%assign typeIndex = SLibVarGroupElementType(varGroupIndex, varIdx)
%assign typeName = SLibGetTypeNameFromCGType(typeIndex)
%assign identifier = SLibVarGroupElementName(varGroupIndex, varIdx) + LibCGTypeSymbolicVectorDims(typeIndex)
%<SLibDeclareStandaloneVarDynamicInit(system, group, identifier, typeName, extern)>
%endforeach
%closefile tmpbuf
%return tmpbuf
%endfunction
%function SLibDeclareStandaloneVarDynamicInit(system, group, identifier, typeName, extern) void
%openfile tmpbuf
%openfile definition
%if SLibAutosarCompilerAbstractionRequired()
%<SLibAutosarCompilerAbstractionForDataDecl(TLC_FALSE, ...
typeName, TLC_FALSE, TLC_FALSE, identifier,"DataGlobal")>;/
%else
%<typeName> %<identifier>;/
%endif
%closefile definition
%if ISEMPTY(group)
%<FcnApplyMemSecToDataDefnForSystem(definition, ...
"MemSecDataInternal", identifier, system, TLC_FALSE, !ISEMPTY(extern))>
%else
%<FcnApplyMemSecToDataDefnForGroup(definition, group, identifier, system, TLC_FALSE, !ISEMPTY(extern), TLC_TRUE, TLC_TRUE)>
%endif
%closefile tmpbuf
%return tmpbuf
%endfunction
%function SLibDeclareStandaloneVarStaticInit(system, group, identifier, typeName, idx) void
%openfile decls
%if SLibAutosarCompilerAbstractionRequired()
%<SLibAutosarCompilerAbstractionForDataDecl(TLC_FALSE, ...
typeName, TLC_FALSE, TLC_FALSE, ...
identifier,"DataGlobal")>;/
%else
%<typeName> %<identifier>;/
%endif
%closefile decls
%openfile tmpBuf
%<SLibApplyMemSecToDataDeclForGroup(decls, group, ...
identifier, ::CompiledModel.ConfigSet, TLC_TRUE)>
%closefile tmpBuf
%if !ISEMPTY(tmpBuf)
%<FcnEmitCoderGroupForStandaloneSystem(system, idx, tmpBuf, TLC_FALSE)>
%endif
%endfunction
%function SLibDeclareStandaloneVars(system, extern) void
%assert system.StandaloneSubsystem
%openfile tmpbuf
%with system.Interface
%if system.HasBlockIOArg
%<SLibDeclareStandaloneVarType(system, [], "BlockIO", extern)>
%endif
%if system.HasDWorkArg
%<SLibDeclareStandaloneVarType(system, [], "DWork", extern)>
%endif
%<SLibDeclareStandaloneVarsForDynamicInitCoderGroups(system, extern)>
%if ISEMPTY(extern)
%<SLibInitializeStandaloneData(system)>
%else
%if system.HasParametersArg
%openfile decls
%if SLibAutosarCompilerAbstractionRequired()
%<SLibAutosarCompilerAbstractionForDataDecl(TLC_FALSE, ...
FcnSysVarGroupType(system, "Parameter"), TLC_FALSE, TLC_FALSE, ...
FcnSysVarGroupNonreusedName(system,"Parameter"),"DataGlobal")>;
%else
%<FcnSysVarGroupType(system, "Parameter")> ...
%<FcnSysVarGroupNonreusedName(system,"Parameter")>;
%endif
%closefile decls
%<SLibApplyMemSecToDataDeclForSystem(decls, ...
"MemSecDataParameters", FcnSysVarGroupNonreusedName(system,"Parameter"), system, TLC_FALSE)>
%endif
%<SLibDeclareStandloneVarsForStaticInitForCoderGroups(system)>
%if system.HasConstBlockIOArg
%assign qualifiers = SLibGetConstBlockIOForSystemQualifiers(system)
%openfile decls
%if SLibAutosarCompilerAbstractionRequired()
%<SLibAutosarCompilerAbstractionForDataDecl(SLibCanConstBlockIOForSystemBeConst(system), ...
FcnSysVarGroupType(system, "ConstBlockIO"), TLC_FALSE, TLC_FALSE, ...
FcnSysVarGroupNonreusedName(system,"ConstBlockIO"),"DataGlobal")>;
%else
%<qualifiers> %<FcnSysVarGroupType(system,"ConstBlockIO")> ...
%<FcnSysVarGroupNonreusedName(system,"ConstBlockIO")>;
%endif
%closefile decls
%<SLibApplyMemSecToDataDeclForSystem(decls, ...
"MemSecDataConstants", FcnSysVarGroupNonreusedName(system,"ConstBlockIO"), system, TLC_FALSE)>
%endif
%endif
%if system.HasZCEventArg
%<SLibDeclareStandaloneVarType(system, [], "ZCEvent", extern)>
%endif
%assert (NumCanonicalInputArgDefs == 0 || ISFIELD(system,"RTWSystemCodeOptIntf"))
%assert (NumCanonicalOutputArgDefs == 0 || ISFIELD(system,"RTWSystemCodeOptIntf"))
%assert (NumCanonicalPrmArgDefs == 0)
%endwith
%closefile tmpbuf
%return tmpbuf
%endfunction
%function SLibExternStandaloneData() void
%foreach idx = NumSystems
%assign system = System[idx]
%if system.StandaloneSubsystem
%assign externBuf = SLibDeclareStandaloneVars(system, "extern")
%if !WHITE_SPACE(externBuf)
%openfile tmpBuf
%assign sysInfo = GetSystemNameForComments(system)
%<GetHideChildDefineSymbol("ifndef")>/
/* Extern declarations of internal data for %<sysInfo> */
%<externBuf>
%<GetHideChildDefineSymbol("endif")>/
%closefile tmpBuf
%<SLibCacheSystemCodeToFile("sys_standalone_extern_data_decl", system, tmpBuf)>
%endif
%endif
%endforeach
%endfunction
%function SLibDumpStandaloneVarDeclarationsForSystem(system) void
%assign globalBuf = ""
%if system.StandaloneSubsystem
%assert (StandaloneSSSupported)
%assign buf = SLibDeclareStandaloneVars(system,"")
%if !WHITE_SPACE(buf)
%assign sysInfo = GetSystemNameForComments(system)
%openfile globalBuf
/* Declare variables for internal data of %<sysInfo> */
%<buf>/
%closefile globalBuf
%endif
%endif
%return globalBuf
%endfunction
%endif