/// Start or restart a timer. /// \param[in] timer_id timer ID obtained by \ref osTimerCreate. /// \param[in] millisec time delay value of the timer. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS. osStatus osTimerStart (osTimerId timer_id, uint32_t millisec) { portBASE_TYPE taskWoken = pdFALSE; osStatus result = osOK; portTickType ticks = millisec / portTICK_RATE_MS; if (ticks == 0) { ticks = 1; } if (inHandlerMode()) { if (xTimerChangePeriodFromISR(timer_id, ticks, &taskWoken) == pdPASS) { xTimerStartFromISR(timer_id, &taskWoken); portEND_SWITCHING_ISR(taskWoken); } } else { //TODO: add timeout support if (xTimerChangePeriod(timer_id, ticks, 0) != pdPASS) { result = osErrorOS; } else { if (xTimerStart(timer_id, 0) != pdPASS) { result = osErrorOS; } } } return result; }
int os_timer_change(os_timer_t timer, os_timer_change_t change, bool fromISR, unsigned period, unsigned block, void* reserved) { portBASE_TYPE woken; switch (change) { case OS_TIMER_CHANGE_START: if (fromISR) return xTimerStartFromISR(timer, &woken)!=pdPASS; else return xTimerStart(timer, block)!=pdPASS; case OS_TIMER_CHANGE_RESET: if (fromISR) return xTimerResetFromISR(timer, &woken)!=pdPASS; else return xTimerReset(timer, block)!=pdPASS; case OS_TIMER_CHANGE_STOP: if (fromISR) return xTimerStopFromISR(timer, &woken)!=pdPASS; else return xTimerStop(timer, block)!=pdPASS; case OS_TIMER_CHANGE_PERIOD: if (fromISR) return xTimerChangePeriodFromISR(timer, period, &woken)!=pdPASS; else return xTimerChangePeriod(timer, period, block)!=pdPASS; } return -1; }
void FreeRTOSTimer::changePeriodFromISR(TIME_MS t) { portBASE_TYPE higherPrTaskWoken = 0; xTimerChangePeriodFromISR(mTimerHandle, t, &higherPrTaskWoken); if( higherPrTaskWoken ) { vPortYieldFromISR(); } }
bool SoftTimer::setPeriodFromISR(uint32_t new_period, int32_t *pxHigherPriorityTaskWoken ) { if (xTimerChangePeriodFromISR(_hnd, new_period, pxHigherPriorityTaskWoken) == pdPASS) { _period = new_period; return true; } else { return false; } }
uint32_t app_timer_start(app_timer_id_t timer_id, uint32_t timeout_ticks, void * p_context) { app_timer_info_t * pinfo = (app_timer_info_t*)(timer_id); TimerHandle_t hTimer = pinfo->osHandle; uint32_t rtc_prescaler = portNRF_RTC_REG->PRESCALER + 1; /* Get back the microseconds to wait */ uint32_t timeout_corrected = ROUNDED_DIV(timeout_ticks * m_prescaler, rtc_prescaler); if (hTimer == NULL) { return NRF_ERROR_INVALID_STATE; } if (pinfo->active && (xTimerIsTimerActive(hTimer) != pdFALSE)) { // Timer already running - exit silently return NRF_SUCCESS; } pinfo->argument = p_context; if (__get_IPSR() != 0) { BaseType_t yieldReq = pdFALSE; if (xTimerChangePeriodFromISR(hTimer, timeout_corrected, &yieldReq) != pdPASS) { return NRF_ERROR_NO_MEM; } if ( xTimerStartFromISR(hTimer, &yieldReq) != pdPASS ) { return NRF_ERROR_NO_MEM; } portYIELD_FROM_ISR(yieldReq); } else { if (xTimerChangePeriod(hTimer, timeout_corrected, APP_TIMER_WAIT_FOR_QUEUE) != pdPASS) { return NRF_ERROR_NO_MEM; } if (xTimerStart(hTimer, APP_TIMER_WAIT_FOR_QUEUE) != pdPASS) { return NRF_ERROR_NO_MEM; } } pinfo->active = true; return NRF_SUCCESS; }
/**@brief Start a FreeRTOS timer. * * @param[in] p_timer_id Id of timer. * @param[in] timeout_ticks The timer period in [ms]. * @param[in] p_contex This pointer should be always NULL. * * @return NRF_SUCCESS on success, otherwise error code. */ uint32_t app_timer_start(TimerHandle_t timer_id, uint32_t timeout_ticks, void * p_context) { if (__get_IPSR() != 0) { if( xTimerChangePeriodFromISR( timer_id, timeout_ticks, &xHigherPriorityTaskWoken) != pdPASS ) { if( xTimerStartFromISR( timer_id, &xHigherPriorityTaskWoken ) != pdPASS ) return NRF_ERROR_NOT_FOUND; } else return NRF_SUCCESS; } else { xTimerChangePeriod(timer_id, timeout_ticks, NULL); if( xTimerStart(timer_id, NULL) != pdPASS ) return NRF_ERROR_NOT_FOUND; else return NRF_SUCCESS; } return NRF_ERROR_NOT_FOUND; }
/** * @brief Start or restart a timer. * @param timer_id timer ID obtained by \ref osTimerCreate. * @param millisec time delay value of the timer. * @retval status code that indicates the execution status of the function * @note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS. */ osStatus osTimerStart (osTimerId timer_id, uint32_t millisec) { osStatus result = osOK; #if (configUSE_TIMERS == 1) portBASE_TYPE taskWoken = pdFALSE; TickType_t ticks = millisec / portTICK_PERIOD_MS; if (xTimerIsTimerActive(timer_id) != pdFALSE) { if (inHandlerMode()) { if(xTimerResetFromISR(timer_id, &taskWoken) != pdPASS) { result = osErrorOS; } else { portEND_SWITCHING_ISR(taskWoken); result = osOK; } } else { if (xTimerReset(timer_id, 0) != pdPASS) result = osErrorOS; else result = osOK; } } else { if (ticks == 0) ticks = 1; if (inHandlerMode()) { if (xTimerChangePeriodFromISR(timer_id, ticks, &taskWoken) != pdPASS) result = osErrorOS; else { xTimerStartFromISR(timer_id, &taskWoken); portEND_SWITCHING_ISR(taskWoken); result = osOK; } } else { if (xTimerChangePeriod(timer_id, ticks, 0) != pdPASS) result = osErrorOS; else { if (xTimerStart(timer_id, 0) != pdPASS) result = osErrorOS; } } } #else result = osErrorOS; #endif return result; }