Example #1
0
/**
  * @brief  Rx Transfer completed callback
  * @param  None
  * @retval None
  */
void rs232RxCpltCallback()
{
	if (prvRxBuffer1State != BUFFERState_Reading && prvRxBuffer1Count < RX_BUFFER_SIZE)
	{
		prvRxBuffer1State = BUFFERState_Writing;
		prvRxBuffer1[prvRxBuffer1CurrentIndex++] = prvReceivedByte;
		prvRxBuffer1Count++;
		/* Start the timer which will clear the buffer if it's not already started */
		if (xTimerIsTimerActive(prvBuffer1ClearTimer) == pdFALSE)
			xTimerStartFromISR(prvBuffer1ClearTimer, NULL);
	}
	else if (prvRxBuffer2State != BUFFERState_Reading && prvRxBuffer2Count < RX_BUFFER_SIZE)
	{
		prvRxBuffer2State = BUFFERState_Writing;
		prvRxBuffer2[prvRxBuffer2CurrentIndex++] = prvReceivedByte;
		prvRxBuffer2Count++;
		/* Start the timer which will clear the buffer if it's not already started */
		if (xTimerIsTimerActive(prvBuffer2ClearTimer) == pdFALSE)
			xTimerStartFromISR(prvBuffer2ClearTimer, NULL);
	}
	else
	{
		/* No buffer available, something has gone wrong */
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
	}

	/* Continue receiving data */
	HAL_UART_Receive_IT(&UART_Handle, &prvReceivedByte, 1);
	/* Give back the semaphore now that we are done */
	xSemaphoreGiveFromISR(xSemaphore, NULL);
}
Example #2
0
/**
  * @brief  Rx Transfer completed callback
  * @param  None
  * @retval None
  */
void can2RxCpltCallback()
{
//	if ((CAN_Handle.pRxMsg->StdId == 0x321) && (CAN_Handle.pRxMsg->IDE == CAN_ID_STD) && (CAN_Handle.pRxMsg->DLC == 2))
//	{
//		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
//		volatile uint8_t test1 = CAN_Handle.pRxMsg->Data[0];
//		volatile uint8_t test2 = CAN_Handle.pRxMsg->Data[1];
//	}

	if (prvRxBuffer1State != CANBufferState_Reading && prvRxBuffer1Count < RX_BUFFER_SIZE)
	{
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
		prvRxBuffer1State = CANBufferState_Writing;
		/* Save the message */
		prvRxBuffer1[prvRxBuffer1CurrentIndex].id = CAN_Handle.pRxMsg->StdId;
		prvRxBuffer1[prvRxBuffer1CurrentIndex].dlc = CAN_Handle.pRxMsg->DLC;
		for (uint32_t i = 0; i < CAN_Handle.pRxMsg->DLC; i++)
			prvRxBuffer1[prvRxBuffer1CurrentIndex].data[i] = CAN_Handle.pRxMsg->Data[i];

		/* Increment the counters */
		prvRxBuffer1CurrentIndex++;
		prvRxBuffer1Count++;

		/* Start the timer which will clear the buffer if it's not already started */
		if (xTimerIsTimerActive(prvBuffer1ClearTimer) == pdFALSE)
			xTimerStartFromISR(prvBuffer1ClearTimer, NULL);
	}
	else if (prvRxBuffer2State != CANBufferState_Reading && prvRxBuffer2Count < RX_BUFFER_SIZE)
	{
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
		prvRxBuffer2State = CANBufferState_Writing;
		/* Save the message */
		prvRxBuffer2[prvRxBuffer1CurrentIndex].id = CAN_Handle.pRxMsg->StdId;
		prvRxBuffer2[prvRxBuffer1CurrentIndex].dlc = CAN_Handle.pRxMsg->DLC;
		for (uint32_t i = 0; i < CAN_Handle.pRxMsg->DLC; i++)
			prvRxBuffer2[prvRxBuffer1CurrentIndex].data[i] = CAN_Handle.pRxMsg->Data[i];

		/* Increment the counters */
		prvRxBuffer2CurrentIndex++;
		prvRxBuffer2Count++;

		/* Start the timer which will clear the buffer if it's not already started */
		if (xTimerIsTimerActive(prvBuffer2ClearTimer) == pdFALSE)
			xTimerStartFromISR(prvBuffer2ClearTimer, NULL);
	}
	else
	{
		/* No buffer available, something has gone wrong */
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
	}


	/* Receive */
	if (HAL_CAN_Receive_IT(&CAN_Handle, CAN_FIFO1) != HAL_OK)
	{
		/* Reception Error */
//		Error_Handler();
	}
}
Example #3
0
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;
}
// Achtung: auf stm32f429i-discovery ist es EXTI0_IRQHandler, nicht EXTI15_10_IRQHandler
extern "C" void
EXTI0_IRQHandler(void)
{
	// ENTER_ISR;
	portBASE_TYPE TaskWoken = pdFALSE;

	/* reset both EXTI I/O interrupt latches,
	* as both buttons share the same interrupt
	* and we don't know which one triggered */
	__HAL_GPIO_EXTI_CLEAR_IT( KEY_BUTTON_PIN);

	/* disable further interrupts for a while */
	BSP_PB_Init (BUTTON_KEY, BUTTON_MODE_GPIO);

	/* trigger timer callback */
	// undefined reference to `xTimerGenericCommand'
	// Siehe [A]
	xTimerStartFromISR(de_bounce_timer, &TaskWoken);

	/* wake up task */
	xQueueSendFromISR( EXTIqueue, 0, &TaskWoken);

	/* preempt the active task if necessary */
	portEND_SWITCHING_ISR(TaskWoken);
}
Example #5
0
/// 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;
}
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;
}
Example #7
0
/**@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;
}
Example #8
0
bool SoftTimer::startFromISR( int32_t *pxHigherPriorityTaskWoken )
{
	return xTimerStartFromISR(_hnd, pxHigherPriorityTaskWoken) == pdPASS;
}
Example #9
0
/**
* @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;
}