OtaOsStatus_t OtaStartTimer_FreeRTOS()

in source/portable/os/ota_os_freertos.c [208:282]


OtaOsStatus_t OtaStartTimer_FreeRTOS( OtaTimerId_t otaTimerId,
                                      const char * const pTimerName,
                                      const uint32_t timeout,
                                      OtaTimerCallback_t callback )
{
    OtaOsStatus_t otaOsStatus = OtaOsSuccess;
    BaseType_t retVal = pdFALSE;

    configASSERT( callback != NULL );
    configASSERT( pTimerName != NULL );

    /* Set OTA lib callback. */
    otaTimerCallback = callback;

    /* If timer is not created.*/
    if( otaTimer[ otaTimerId ] == NULL )
    {
        /* Create the timer. */
        otaTimer[ otaTimerId ] = xTimerCreate( pTimerName,
                                               pdMS_TO_TICKS( timeout ),
                                               pdFALSE,
                                               NULL,
                                               timerCallback[ otaTimerId ] );

        if( otaTimer[ otaTimerId ] == NULL )
        {
            otaOsStatus = OtaOsTimerCreateFailed;

            LogError( ( "Failed to create OTA timer: "
                        "timerCreate returned NULL "
                        "OtaOsStatus_t=%i ",
                        otaOsStatus ) );
        }
        else
        {
            LogDebug( ( "OTA Timer created." ) );

            /* Start the timer. */
            retVal = xTimerStart( otaTimer[ otaTimerId ], portMAX_DELAY );

            if( retVal == pdTRUE )
            {
                LogDebug( ( "OTA Timer started." ) );
            }
            else
            {
                otaOsStatus = OtaOsTimerStartFailed;

                LogError( ( "Failed to start OTA timer: "
                            "timerStart returned error." ) );
            }
        }
    }
    else
    {
        /* Reset the timer. */
        retVal = xTimerReset( otaTimer[ otaTimerId ], portMAX_DELAY );

        if( retVal == pdTRUE )
        {
            LogDebug( ( "OTA Timer restarted." ) );
        }
        else
        {
            otaOsStatus = OtaOsTimerRestartFailed;

            LogError( ( "Failed to set OTA timer timeout: "
                        "timer_settime returned error: "
                        "OtaOsStatus_t=%i ",
                        otaOsStatus ) );
        }
    }

    return otaOsStatus;
}