%selectfile NULL_FILE
%if EXISTS("_ERT_EXTMODE_") == 0
%assign _ERT_EXTMODE_ = 1
%function SLibErtGenExtModeCode(buffsRec, isPeriodicRateGrouping) void
%assign ::BlockFcn = "Output"
%openfile extModeHeader
%if (ExtMode == 1) && (TargetOS != "VxWorksExample") && !EXISTS(C6000_EXT_MODE) && (!ExtModeXCP || ExtModeXCPClassicInterface)
/* External mode */
{
boolean_T rtmStopReq = %;
rtExtModePauseIfNeeded(%<RTMGet("RTWExtModeInfo")>, ...
%<NumRuntimeExportedRates>, ...
&rtmStopReq);
if (rtmStopReq) {
%<RTMSetStopRequested("true")>;
}
if (%<RTMGetStopRequested()> == %) {
%if !GenerateGRTWrapper
%<RTMSetErrStat("/"Simulation finished/"")>;
%endif
break;
}
}
%endif
%closefile extModeHeader
%addtorecord buffsRec ExtModeHeader extModeHeader
%assign ::BlockFcn = "RootUpdate"
%if ExtMode == 1
%if !isPeriodicRateGrouping
%openfile extModeTrailer
%if (!ExtModeXCP || ExtModeXCPClassicInterface)
/* External mode */
rtExtModeUploadCheckTrigger(%<NumRuntimeExportedRates>);
%endif
%foreach tidIdx = NumRuntimeExportedRates
%if ::IncludeLoggingInstrumentation
%<FcnGenerateTidGuardOpenCode(tidIdx)>
%else
%<FcnGenerateTidGuardOpenCodeInMain(tidIdx)>
%endif
%if (!ExtModeXCP || ExtModeXCPClassicInterface)
rtExtModeUpload(%<tidIdx>, (real_T)%<RTMGetTaskTimeForTID(tidIdx)>);
%else
%if (NumRuntimeExportedRates != 1) || !CombineOutputUpdateFcns
extmodeErrorCode_T errorCode = EXTMODE_SUCCESS;
extmodeSimulationTime_T currentTime = (extmodeSimulationTime_T) %<RTMGetTaskTimeForTID(tidIdx)>;
/* Trigger External Mode event */
errorCode = extmodeEvent(%<tidIdx>,currentTime);
if (errorCode != EXTMODE_SUCCESS) {
/* Code to handle External Mode event errors
may be added here */
}
%endif
%endif
%<FcnGenerateTidGuardCloseCode(tidIdx)>
%endforeach
%closefile extModeTrailer
%addtorecord buffsRec ExtModeTrailer extModeTrailer
%else
%openfile extModeTrailer0
%if (!ExtModeXCP || ExtModeXCPClassicInterface)
/* External mode */
rtExtModeUploadCheckTrigger(%<NumRuntimeExportedRates>);
%endif
%closefile extModeTrailer0
%assign tid01Eq = FixedStepOpts.TID01EQ
%foreach tidIdx = NumRuntimeExportedRates
%openfile tmpBuff
%if tidIdx == 0
%<extModeTrailer0>
%endif
%if (!ExtModeXCP || ExtModeXCPClassicInterface)
%if tid01Eq && tidIdx == 0
rtExtModeUpload(%<tid01Eq>, (real_T)%<RTMGetTaskTimeForTID(tidIdx)>);
%else
rtExtModeUpload(%<tidIdx>, (real_T)%<RTMGetTaskTimeForTID(tidIdx)>);
%endif
%else
%if (NumContStates > 0) && (tidIdx == 0)
{
extmodeErrorCode_T returnCode = EXTMODE_SUCCESS;
%if tid01Eq
/* Trigger External Mode event */
returnCode = extmodeEvent(%<tid01Eq>,%<RTMGetTaskTimeForTID(tidIdx)>);
%else
/* Trigger External Mode event */
returnCode = extmodeEvent(%<tidIdx>,%<RTMGetTaskTimeForTID(tidIdx)>);
%endif
if (returnCode != EXTMODE_SUCCESS) {
/* Code to handle External Mode event errors
may be added here */
}
}
%endif
%endif
%closefile tmpBuff
%addtorecord buffsRec ExtModeTrailer%<tidIdx> tmpBuff
%endforeach
%endif
%endif
%endfunction
%function SLibGenERTExtModeInit() void
%openfile extModeInitBuf
%if (!ExtModeXCP || ExtModeXCPClassicInterface)
/* External mode */
%if !PurelyIntegerCode
rtSetTFinalForExtMode(&%<RTMGet("TFinal")>);
%else
rtSetTFinalForExtMode(rteiGetPtrTFinalTicks(%<RTMGet("RTWExtModeInfo")>));
%endif
%if TargetOS != "VxWorksExample" && !EXISTS(C6000_EXT_MODE)
rtExtModeCheckInit(%<NumRuntimeExportedRates>);
{
boolean_T rtmStopReq = %;
rtExtModeWaitForStartPkt(%<RTMGet("RTWExtModeInfo")>, ...
%<NumRuntimeExportedRates>, ...
&rtmStopReq);
if (rtmStopReq) {
%<RTMSetStopRequested("true")>;
}
}
%endif
rtERTExtModeStartMsg();
%else
/* External Mode initialization */
%if !PurelyIntegerCode
errorCode = extmodeInit(%<RTMGet">RTMGet("RTWExtModeInfo")>, &%<RTMGet">RTMGet("TFinal")>);
%else
errorCode = extmodeInit(%<RTMGet">RTMGet("RTWExtModeInfo")>, (extmodeSimulationTime_T *)rteiGetPtrTFinalTicks(%<RTMGet">RTMGet("RTWExtModeInfo")>));
%endif
if (errorCode != EXTMODE_SUCCESS) {
/* Code to handle External Mode initialization errors
may be added here */
}
if (errorCode == EXTMODE_SUCCESS) {
/* Wait until a Start or Stop Request has been received from the Host */
extmodeWaitForHostRequest(EXTMODE_WAIT_FOREVER);
if (extmodeStopRequested()) {
%<RTMSetStopRequested("true")>;
}
}
%endif
%closefile extModeInitBuf
%return extModeInitBuf
%endfunction
%function FcnGenerateExtModeOneStep() void
%openfile retBuf
%if (!ExtModeXCP || ExtModeXCPClassicInterface)
/* External mode */
%if TargetOS != "VxWorksExample" && !EXISTS(C6000_EXT_MODE)
{
boolean_T rtmStopReq = %;
rtExtModeOneStep(%<RTMGet("RTWExtModeInfo")>, ...
%<NumRuntimeExportedRates>, ...
&rtmStopReq);
if (rtmStopReq) {
%<RTMSetStopRequested("true")>;
}
}
%endif
%else
/* Run External Mode background activities */
errorCode = extmodeBackgroundRun();
if (errorCode != EXTMODE_SUCCESS) {
/* Code to handle External Mode background task errors
may be added here */
}
%endif
%closefile retBuf
%return retBuf
%endfunction
%endif