in source/portable/os/ota_os_posix.c [244:317]
OtaOsStatus_t Posix_OtaStartTimer( OtaTimerId_t otaTimerId,
const char * const pTimerName,
const uint32_t timeout,
OtaTimerCallback_t callback )
{
OtaOsStatus_t otaOsStatus = OtaOsSuccess;
/* Create the timer structures. */
struct sigevent sgEvent;
struct itimerspec timerAttr;
( void ) pTimerName;
/* clear everything in the structures. */
( void ) memset( &sgEvent, 0, sizeof( struct sigevent ) );
( void ) memset( &timerAttr, 0, sizeof( struct itimerspec ) );
/* Set attributes. */
sgEvent.sigev_notify = SIGEV_THREAD;
sgEvent.sigev_value.sival_ptr = ( void * ) otaTimers[ otaTimerId ];
sgEvent.sigev_notify_function = timerCallback[ otaTimerId ];
/* Set OTA lib callback. */
otaTimerCallback = callback;
/* Set timeout attributes.*/
timerAttr.it_value.tv_sec = ( time_t ) timeout / 1000;
/* Create timer if required.*/
if( pOtaTimers[ otaTimerId ] == NULL )
{
errno = 0;
if( timer_create( CLOCK_REALTIME, &sgEvent, &otaTimers[ otaTimerId ] ) == -1 )
{
otaOsStatus = OtaOsTimerCreateFailed;
LogError( ( "Failed to create OTA timer: "
"timer_create returned error: "
"OtaOsStatus_t=%i "
",errno=%s",
otaOsStatus,
strerror( errno ) ) );
}
else
{
pOtaTimers[ otaTimerId ] = &otaTimers[ otaTimerId ];
}
}
/* Set timeout.*/
if( pOtaTimers[ otaTimerId ] != NULL )
{
errno = 0;
if( timer_settime( otaTimers[ otaTimerId ], 0, &timerAttr, NULL ) == -1 )
{
otaOsStatus = OtaOsTimerStartFailed;
LogError( ( "Failed to set OTA timer timeout: "
"timer_settime returned error: "
"OtaOsStatus_t=%i "
",errno=%s",
otaOsStatus,
strerror( errno ) ) );
}
else
{
LogDebug( ( "OTA Timer started." ) );
}
}
return otaOsStatus;
}