in source/ota.c [3169:3231]
OtaState_t OTA_Shutdown( uint32_t ticksToWait,
uint8_t unsubscribeFlag )
{
OtaEventMsg_t eventMsg = { 0 };
uint32_t ticks = ticksToWait;
LogDebug( ( "Number of ticks to idle while the OTA Agent shuts down: "
"ticks=%u",
ticks ) );
if( otaAgent.state == OtaAgentStateInit )
{
/* When in init state, the OTA state machine is not running yet. So directly set state to
* stopped. */
otaAgent.state = OtaAgentStateStopped;
}
else if( ( otaAgent.state != OtaAgentStateStopped ) && ( otaAgent.state != OtaAgentStateShuttingDown ) ) /* LCOV_EXCL_BR_LINE */
{
otaAgent.unsubscribeOnShutdown = unsubscribeFlag;
/* Stop and delete the request timer. */
( void ) otaAgent.pOtaInterface->os.timer.stop( OtaRequestTimer );
( void ) otaAgent.pOtaInterface->os.timer.delete( OtaRequestTimer );
/* Stop and delete the self-test timer. */
( void ) otaAgent.pOtaInterface->os.timer.stop( OtaSelfTestTimer );
( void ) otaAgent.pOtaInterface->os.timer.delete( OtaSelfTestTimer );
/*
* Send shutdown signal to OTA Agent task.
*/
eventMsg.eventId = OtaAgentEventShutdown;
/* Send signal to OTA task. */
if( OTA_SignalEvent( &eventMsg ) == false )
{
LogError( ( "Failed to signal the OTA Agent to shutdown: "
"OTA_SignalEvent returned false." ) );
}
else
{
/*
* Wait for the OTA agent to complete shutdown, if requested.
*/
while( ( ticks > 0U ) && ( otaAgent.state != OtaAgentStateStopped ) ) /* LCOV_EXCL_BR_LINE */
{
ticks--;
}
}
}
else
{
LogDebug( ( "Ignoring request to shutdown OTA Agent: "
"OTA Agent is already in state [%s]",
pOtaAgentStateStrings[ otaAgent.state ] ) );
}
LogDebug( ( "Number of ticks remaining when OTA Agent shutdown: "
"ticks=%u",
ticks ) );
return otaAgent.state;
}