%if (EXISTS("_CIINFO_") == 0)
%assign _CIINFO_ = 1
%assign rightClickBuildFeature = CGMODEL_ACCESS("CGModel.RightClickBuild")
%include "%<::CompiledModel.Name>_codeIRInfo.tlc"
%include "codeinfolib.tlc"
%<SLibResetCodeInfoLib()>
%include "codeinfodatalib.tlc"
%include "codeinfofcnlib.tlc"
%include "codeinfomdlreflib.tlc"
%include "autosarsup.tlc"
%selectfile NULL_FILE
%realformat "CONCISE"
%assign fcnName = "writeCodeInfoFcn"
%assign timingSubfcnName = "getIndexFromTimingInternalId"
%assign iDataSubfcnName = "getInternalDataByName"
%assign iDataSubfcnVariableName = "getInternalDataByVariableName"
%assign nameChkfcnName = "checkDataGraphicalNames"
%assign uniquifyDataInterfaces = "uniquifyDataAccess"
%selectfile NULL_FILE
%openfile ModelCI = "%<fcnName>.m"
%assign comment = "% Autogenerated file: %<::CompiledModel.GeneratedOn>"
%<comment>
function %<fcnName>
%assign componentObj = "codeInfo"
%assign expInportsObj = "expInports"
%assign comment = "% Load a ComponentInterface object from IR"
%<comment>
%<FcnLoadCodeIRInfo()>
%if SLibAutosarActive()
%assign map = FcnGetAutosarDataMap()
%<componentObj>.Name = '%<map.ComponentName>';
%if SLibAutosarIsAR4()
%<SLibCreateStaticMemory()>
%<SLibAddAutosarVarInfo()>
%endif
%endif
%assign buildDir = FEVAL("rtwprivate", "rtwattic", "getBuildDir")
%assign mf0CodeDescriptor = CGMODEL_ACCESS("CGModel.GenerateMF0CodeDescriptor")
%assign subsystemInterfaceForLibraryCodegen = CGMODEL_ACCESS("CGModel.SubsystemInterfaceForLibraryCodegen")
%if mf0CodeDescriptor > 0
wr = coder.internal.writeMF0DataInterfacesToCodeDescriptor("%<::CompiledModel.Name>","%<buildDir>") ;
wr.writeName(%<componentObj>.Name);
fr = wr;
%else
wr = coder.internal.writeDataInterfacesToCodeDescriptor("%<::CompiledModel.Name>","%<buildDir>") ;
fr = coder.internal.writeFunctionInterfacesToCodeDescriptor("%<::CompiledModel.Name>", "%<buildDir>") ;
%endif
%<SLibCreateInportInterfaces()>
%<SLibCreateOutportInterfaces()>
skippedParameters = [];
%<SLibCreateParameterInterfaces()>
%assign prmArgs = SLibCreateParameterArguments()
%<SLibCreateDataStoreInterfaces()>
%<SLibCreateExternalBlockOutputInterfaces()>
%<SLibCreateDWorkInterfaces()>
%if !GenerateClassInterface
%if !IsModelReferenceTarget()
%<SLibCreateModelFunctionInterface(componentObj, "Initialize", "")>
%if UsingMalloc
%<SLibCreateModelFunctionInterface(componentObj, "Registration", "")>
%endif
%if LibIsDeploymentDiagram()
%<SLibDeploymentGenerateCodeInfo(componentObj)>
%elseif (ExportFunctionsMode != 0) || (SLibAutosarActive() && !(SLibIsExportFcnDiagram()) && SLibIsAsyncTaskOnlyModel())
%if SLibAutosarActive()
%if SLibIsAsyncTaskOnlyModel() && !(SLibIsExportFcnDiagram())
%<SLibCreateModelFunctionInterface(componentObj, "OutputUpdate", "")>
%endif
%<SLibCreateRunnables(componentObj)>
%else
%<SLibCreateExportFunctions(componentObj)>
%endif
%elseif (SLibIsAsyncTaskOnlyModel() == TLC_FALSE || SLibIsExportFcnDiagram())
%if (SLibIsExportFcnDiagram() && SLibAutosarActive())
%<SLibCreateRunnables(componentObj)>
%else
%assign isAsyncExportFcn = SLibIsExportFcnDiagram() && SLibIsAsyncTaskOnlyModel()
%assign isPeriodicExportFcn = SLibIsExportFcnDiagram() && !SLibIsAsyncTaskOnlyModel()
%assign isPeriodicRateGrouping = SLibIsMultiRateAndPeriodicRateGrouping(System[NumSystems-1])
%assign updateCState = (NumContStates > 0)
%if isPeriodicRateGrouping || isAsyncExportFcn
%assign maxSampleTime = NumRuntimeExportedRates
%if SLibIsExportFcnDiagram()
%assign maxSampleTime = NumSampleTimes
%endif
%foreach tid = maxSampleTime
%assign tidIdx = tid
%if SLibIsExportFcnDiagram()
%assign tidIdx = maxSampleTime - tid - 1
%endif
%if (tidIdx==1) && FixedStepOpts.TID01EQ
%continue
%endif
%if SLibIsExportFcnDiagram()
%assign expFcnName = SLibGenExporFunctionName(tidIdx)
%if WHITE_SPACE(expFcnName)
%continue
%else
%assign rootSystem = System[NumSystems-1]
%assign thisModule = ::CompiledModel.RTWCGModules.RTWCGModule[rootSystem.CGIRModuleIdx]
%if ISFIELD(thisModule, "SystemFunctions") && ...
ISFIELD(thisModule.SystemFunctions, expFcnName)
%assign fcnIndex = GETFIELD(thisModule.SystemFunctions, expFcnName)
%assign thisFcn = thisModule.Function[fcnIndex]
%if ISFIELD(thisFcn,"IsRateGroupedSLFcn") && thisFcn.IsRateGroupedSLFcn == TLC_TRUE
%continue
%endif
%endif
%endif
%endif
%if isAsyncExportFcn && ...
(tidIdx < NumRuntimeExportedRates)
%continue
%endif
%assign tid = tidIdx
%if !CombineOutputUpdateFcns && !SLibIsExportFcnDiagram()
%assign outString = "Output"
%if updateCState
%assign updateString = "UpdateContStates"
%else
%assign updateString = "RootUpdate"
%endif
%<SLibCreateModelFunctionInterface(componentObj, outString, tid)>
%<SLibCreateModelFunctionInterface(componentObj, updateString, tid)>
%else
%if updateCState
%assign outString = "UpdateContStates"
%else
%assign outString = "OutputUpdate"
%endif
%<SLibCreateModelFunctionInterface(componentObj, outString, tid)>
%endif
%assign updateCState = TLC_FALSE
%endforeach
%if !SLibIsExportFcnDiagram() && !SLibIsAsyncTaskOnlyModel() && !SLibAutosarActive()
%foreach tid = NumSampleTimes
%if SLibResetOrResetWithInitEventTID(tid)
%<SLibCreateModelFunctionInterface(componentObj, "OutputUpdate", tid)>
%endif
%endforeach
%endif
%elseif !SLibIsExportFcnDiagram()
%if !CombineOutputUpdateFcns
%assign outString = "Output"
%if updateCState
%assign updateString = "UpdateContStates"
%else
%assign updateString = "RootUpdate"
%endif
%<SLibCreateModelFunctionInterface(componentObj, outString, "")>
%<SLibCreateModelFunctionInterface(componentObj, updateString, "")>
%else
%if updateCState
%assign outString = "UpdateContStates"
%else
%assign outString = "OutputUpdate"
%endif
%<SLibCreateModelFunctionInterface(componentObj, outString, "")>
%endif
%if !SLibAutosarActive()
%foreach tid = NumSampleTimes
%if SLibResetOrResetWithInitEventTID(tid)
%<SLibCreateModelFunctionInterface(componentObj, "OutputUpdate", tid)>
%endif
%endforeach
%endif
%endif
%endif
%if !SLibAutosarActive()
%if !SLibIsExportFcnDiagram()
%<AddFunctionCallInputInformation(componentObj)>
%endif
%<AddExternalInportMappingInfo(expInportsObj)>
%else
%if !SLibIsExportFcnDiagram() && (NumAsynchronousSampleTimes > 0)
%<SLibCreateRunnables(componentObj)>
%endif
%endif
%elseif SLibIsAsyncTaskOnlyModel()
%<AddFunctionCallInputInformation(componentObj)>
%<AddExternalInportMappingInfo(expInportsObj)>
%if !GenerateSampleERTMain
%<SLibCreateModelFunctionInterface(componentObj, "OutputUpdate", "")>
%endif
%else
%endif
%if EXISTS("IncludeMdlDerivativeFcn") && IncludeMdlDerivativeFcn == TLC_TRUE
%<SLibCreateModelFunctionInterface(componentObj, "Derivative", "")>
%endif
%if IncludeMdlTerminateFcn
%<SLibCreateModelFunctionInterface(componentObj, "Terminate", "")>
%endif
%else
%<SLibCreateModelReferenceFunctionInterfaces(componentObj)>
%<AddExternalInportMappingInfo(expInportsObj)>
%endif
%else
%if (SLibIsAsyncTaskOnlyModel() && ...
SLibIsERTTarget() && ...
!IsModelReferenceRTWTarget())
codeInfo.OutputFunctions = [];
%endif
%if !IsModelReferenceRTWTarget() && SLibIsExportFcnDiagram()
tmpArgs = [];
tmpActualArgs = [];
tmpRet = coder.types.Argument.empty;
tmpActualReturn = RTW.DataInterface.empty;
%<AddFunctionCallInputInformation(componentObj)>
%<AddExternalInportMappingInfo(expInportsObj)>
%endif
%if IsModelReferenceRTWTarget()
%<SLibCreateModelReferenceFunctionInterfaces(componentObj)>
%<AddExternalInportMappingInfo(expInportsObj)>
for i=1 : length(codeInfo.OutputFunctions)
codeInfo.OutputFunctions(i).Owner = codeInfo.InternalData(1).Implementation;
end
%elseif NumRuntimeExportedRates > 1 && SLibIsPeriodicRateGrouping() && !SLibIsExportFcnDiagram()
fcnVec = [];
%foreach tid = NumRuntimeExportedRates
%if (tid==1) && FixedStepOpts.TID01EQ
%continue
%endif
%assign timeObj = SLibGetRTWTimingObject(tid)
fcnTemp = codeInfo.OutputFunctions(1);
tmpImpl = coder.types.Prototype;
tmpImpl.Name = [fcnTemp.Prototype.Name,'%<tid>'];
tmpImpl.HeaderFile = fcnTemp.Prototype.HeaderFile;
tmpImpl.SourceFile = fcnTemp.Prototype.SourceFile;
tmpFcn = RTW.FunctionInterface;
tmpFcn.Prototype = tmpImpl;
tmpFcn.Timing = %<timeObj>;
tmpFcn.Owner = fcnTemp.Owner;
fcnVec = [fcnVec, tmpFcn];
%endforeach
codeInfo.OutputFunctions = fcnVec;
%endif
%if !SLibAutosarActive()
%foreach tid = NumSampleTimes
%if SLibResetOrResetWithInitEventTID(tid)
%<SLibCreateModelFunctionInterface(componentObj, "OutputUpdate", tid)>
%endif
%endforeach
%endif
%endif
%if !(IsModelReferenceSimTarget())
%<AddSimulinkFunctionInfo(componentObj)>
%endif
%if GenerateClassInterface || SLibFcnProtoCtrlActive()
%<UpdateReusableArgsCodeInfoByFPC(componentObj)>
%endif
%if !LibCoderDataGroupStructsAreEmpty() && SLibMultiInstance()
%if !SLibAutosarActive() && !GenerateClassInterface && FcnHasRTMOrSelf()
%assign rtMType = FcnGetInternalTypeObj("RTModel", ::tSimStructType, "")
%assign rtMPtrType = FcnGetPointerTypeObj(rtMType, 1, 0)
%if SLibAutosarActive()
%<rtMType>.Name = '%<::CompiledModel.GlobalScope.tSimStructTypeTag>';
%endif
%assign rtmTgtVarObj = ...
SLibGetRTWVariableObject("RTModel", rtMType,"%<::tSimStruct>_", "", "", "")
%assign rtmVarObj = ...
SLibGetRTWPointerVariableObject("RTModel", rtMPtrType,"%<::tSimStruct>", rtmTgtVarObj)
%assign rtmDataObj = ...
FcnGetInternalDataObject("RTModel", "", "RTModel", rtmVarObj, [])
%endif
%foreach idx = ::CompiledModel.NumCoderDataGroups
%assign group = ::CompiledModel.CoderDataGroup[idx]
%assign groupNeeded = SLibHaveRootDataGroupVarGroup(group) && ...
(group.AsStructure == "InParent") && !SLibIsGroupSelfCoderGroup(group)
%if groupNeeded
%assert EXISTS(rtmVarObj) || GenerateClassInterface || FcnHasRTMOrSelf()
%assign typeObjName = group.Name + "Type"
%assign groupType = FcnGetInternalTypeObj(typeObjName, SLibCoderDataGroupType(group), "")
%assign groupPtrType = FcnGetPointerTypeObj(groupType, 0, 0)
%assign groupVarId = "rt_" + group.Name
%assign groupVar = SLibGetCoderDataGroupVariable(group)
%assign desc = "Storage class " + group.Name
%if !SLibAutosarActive() && !GenerateClassInterface && FcnHasRTMOrSelf()
%assign groupPtrExpr = ...
FcnCreateRTMMemberObject(groupVarId, SLibCoderDataGroupRTMFieldName(group), ...
groupPtrType, rtmVarObj, groupVar)
%assign groupDataObj = ...
FcnGetInternalDataObject(groupVarId, "", desc, groupPtrExpr, [])
%elseif GenerateClassInterface && group.ContainsInstanceSpecificParameter && ...
CGMODEL_ACCESS("CGModel.getParameterMemberVisibility") == "public"
%if IsModelReferenceTarget()
%assign modelVarName = "ModelMDLOBJ"
%else
%assign modelVarName = "%<::CompiledModel.GlobalScope.tModelObject>"
%endif
%assign modelVarObj = "Var_" + modelVarName
%<modelVarObj> = codeInfo.InternalData(1).Implementation;
%assign groupPtrExpr = ...
FcnCreateRTMMemberObject(groupVarId, SLibCoderDataGroupRTMFieldName(group), ...
groupPtrType, modelVarObj, groupVar)
%assign groupDataObj = ...
FcnGetInternalDataObject(groupVarId, "", desc, groupPtrExpr, [])
%else
%assign groupdDataObj = ...
FcnGetInternalDataObject(groupVarId, "", desc, groupVar, [])
%endif
%endif
%endforeach
%endif
%<SLibCreateInstanceSpecificParameterInterfaces()>
%if mf0CodeDescriptor < 1
wr.closeRepo();
%endif
%if GenerateClassInterface
%<SLibCreateModelConstructorActualArgs()>
%endif
if ~isempty(skippedParameters)
fr.removeSkippedParameters(codeInfo.Parameters(skippedParameters));
codeInfo.Parameters(skippedParameters) = [];
end
%assign internalData = FIELDNAMES(CodeInfoMap.InternalDataMap)
%foreach idx = SIZE(internalData,1)
%if (idx == 0)
%<componentObj>.InternalData = [%<componentObj>.InternalData, %];
%else
%<componentObj>.InternalData(end+1) = %;
%endif
fr.addInternalData(%);
%endforeach
%assign comment = "% Handling Right-Click Builds"
%<comment>
ss = rtwprivate('getSourceSubsystemHandle',codeInfo.GraphicalPath);
%assign comment = "% Check if Rt-Click build, then re-map SIDs"
%<comment>
if ~isempty(ss) && rtwprivate('rtwattic','hasSIDMap')
codeInfo = modifyCodeInfoForSubsystemBuild(ss, codeInfo, wr);
end
%if mf0CodeDescriptor > 0
%if subsystemInterfaceForLibraryCodegen > 0
%<FcnRemoveUnusedArgumentsFromSubsystemInterface()>
%endif
%endif
fr.writeFunctionInterfaces(%<componentObj>);
fr.writeServerCallPoints(%<componentObj>);
%if GenerateClassInterface
fr.InstanceSpecificParameterConstructorFixup;
%<FcnAddModelBlockInstanceVariableName()>
%endif
%if ISFIELD(::CompiledModel, "CodeDescriptorAsyncFunctions")
%assign fieldNames = FIELDNAMES(::CompiledModel.CodeDescriptorAsyncFunctions)
%foreach idx = SIZE(fieldNames, 1)
%assign cur = GETFIELD(::CompiledModel.CodeDescriptorAsyncFunctions,fieldNames[idx])
fr.addAsyncFunctionInterfaces("%<cur.functionName>", %<cur.taskIndex>, %<cur.priority>);
%endforeach
%endif
%if mf0CodeDescriptor > 0
%if subsystemInterfaceForLibraryCodegen > 0
wr.copyTimingInterfacesForLibraryCodegen();
%endif
wr.closeRepo();
%endif
%if !IsModelReferenceTarget()
if exist('%<expInportsObj>', 'var')
save codeInfo.mat %<componentObj> %<expInportsObj>;
else
save codeInfo.mat %<componentObj>;
end
%else
%assert IsModelReferenceRTWTarget() || (IsModelReferenceSimTarget())
if exist('%<expInportsObj>', 'var')
save %<::CompiledModel.Name>_mr_codeInfo.mat %<componentObj> %<expInportsObj>;
else
save %<::CompiledModel.Name>_mr_codeInfo.mat %<componentObj>;
end
%endif
returnVal = 1;
%assign comment = "% End Function"
%<comment>: %<fcnName>
function data = %<uniquifyDataInterfaces>(list)
data = RTW.DataInterface.empty;
for idx=1:numel(list)
if ~isPresentDI(data, list(idx))
data(end+1) = list(idx); %#ok
end
end
%<comment>: %<uniquifyDataInterfaces>
function isPresent = isPresentDI(list, di)
isPresent = false;
for idx = 1:numel(list)
if isequal(list(idx), di)
isPresent = true;
break
end
end
function idx = %<timingSubfcnName>(internalIdVec, internalId)
idx = find(internalIdVec == internalId);
if (isempty(idx) || (length(idx) > 1))
ciMsg = 'Time object cannot be empty';
ciExc = MException('RTW:buildProcess:CodeInfoInternalError',ciMsg);
throw(ciExc);
end
%<comment>: %<timingSubfcnName>
function %<nameChkfcnName>(ciName, rtwName)
if (strcmp(ciName, rtwName) ~= 1)
ciMsg = ['Name mismatch: ', ciName, ' and ', rtwName];
ciExc = MException('RTW:buildProcess:CodeInfoInternalError',ciMsg);
throw(ciExc);
end
%<comment>: %<nameChkfcnName>
function iData = %<iDataSubfcnName>(iDataVec, iDataName)
iData = RTW.DataInterface.empty;
for idxData = 1:numel(iDataVec)
if strcmp(iDataName, iDataVec(idxData).GraphicalName)
iData(end+1) = iDataVec(idxData);
break
end
end
if (isempty(iData) || (length(iData) > 1))
ciMsg = 'Internal Data object cannot be empty';
ciExc = MException('RTW:buildProcess:CodeInfoInternalError',ciMsg);
throw(ciExc);
end
%<comment>: %<iDataSubfcnName>
function iData = %<iDataSubfcnVariableName>(iDataVec, iDataVariableName)
iData = RTW.DataInterface.empty;
for idxData = 1:numel(iDataVec)
if strcmp(iDataVariableName, iDataVec(idxData).Implementation.VariableName)
iData = iDataVec(idxData);
break
end
end
if isempty(iData)
ciMsg = 'Internal Data object cannot be empty';
ciExc = MException('RTW:buildProcess:CodeInfoInternalError',ciMsg);
throw(ciExc);
end
%<comment>: %<iDataSubfcnVariableName>
function codeInfo = modifyCodeInfoForSubsystemBuild(ss, codeInfo, wr)
%if rightClickBuildFeature==0
%assign comment = "% Extract Subsystem Build Map from AtticData"
%<comment>
Subsystem_Build_Mapping = rtwprivate('rtwattic','getSIDMap');
%assign comment = "% Parameters"
%<comment>
for i = 1:length(codeInfo.Parameters)
sid = codeInfo.Parameters(i).SID;
sid = Simulink.ID.getSubsystemBuildSID(sid,ss, Subsystem_Build_Mapping);
codeInfo.Parameters(i).SID = sid;
wr.updateSIDForSubsystemBuild("Parameter", i, sid, codeInfo.Parameters(i));
end
%assign comment = "% Data Stores"
%<comment>
for i = 1:length(codeInfo.DataStores)
sid = codeInfo.DataStores(i).SID;
sid = Simulink.ID.getSubsystemBuildSID(sid,ss, Subsystem_Build_Mapping);
codeInfo.DataStores(i).SID = sid;
wr.updateSIDForSubsystemBuild("DataStore", i, sid);
end
%assign comment = "% Inports"
%<comment>
for i = 1:length(codeInfo.Inports)
sid = codeInfo.Inports(i).SID;
sid = Simulink.ID.getSubsystemBuildSID(sid,ss, Subsystem_Build_Mapping);
codeInfo.Inports(i).SID = sid;
wr.updateSIDForSubsystemBuild("Inport", i, sid);
end
%assign comment = "% Outports"
%<comment>
for i = 1:length(codeInfo.Outports)
sid = codeInfo.Outports(i).SID;
sid = Simulink.ID.getSubsystemBuildSID(sid,ss, Subsystem_Build_Mapping);
codeInfo.Outports(i).SID = sid;
wr.updateSIDForSubsystemBuild("Outport", i, sid);
end
%endif
%closefile ModelCI
%endif