예제 #1
0
/**
  * @brief  This function handles IRDA Communication Timeout.
  * @param  hirda: Pointer to a IRDA_HandleTypeDef structure that contains
  *                the configuration information for the specified IRDA module.
  * @param  Flag: specifies the IRDA flag to check.
  * @param  Status: The new Flag status (SET or RESET).
  * @param  Timeout: Timeout duration
  * @retval HAL status
  */
static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
{
  uint32_t tickstart = 0;

  /* Get tick */
  tickstart = HAL_GetTick();

  /* Wait until flag is set */
  if(Status == RESET)
  {
    while(__HAL_IRDA_GET_FLAG(hirda, Flag) == RESET)
    {
      /* Check for the Timeout */
      if(Timeout != HAL_MAX_DELAY)
      {
        if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
        {
          /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
          __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
          __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
          __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
          __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);

          hirda->State= HAL_IRDA_STATE_READY;

          /* Process Unlocked */
          __HAL_UNLOCK(hirda);

          return HAL_TIMEOUT;
        }
      }
    }
  }
  else
  {
    while(__HAL_IRDA_GET_FLAG(hirda, Flag) != RESET)
    {
      /* Check for the Timeout */
      if(Timeout != HAL_MAX_DELAY)
      {
        if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
        {
          /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
          __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
          __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
          __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
          __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);

          hirda->State= HAL_IRDA_STATE_READY;

          /* Process Unlocked */
          __HAL_UNLOCK(hirda);
        
          return HAL_TIMEOUT;
        }
      }
    }
  }
  return HAL_OK;
}
예제 #2
0
/**
  * @brief  Handle IRDA Communication Timeout.
  * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
  *               the configuration information for the specified IRDA module.
  * @param  Flag Specifies the IRDA flag to check.
  * @param  Status the new flag status (SET or RESET). The function is locked in a while loop as long as the flag remains set to Status.
  * @param  Tickstart Tick start value
  * @param  Timeout Timeout duration
  * @retval HAL status
  */
static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
{
  /* Wait until flag is set */
  while((__HAL_IRDA_GET_FLAG(hirda, Flag) ? SET : RESET) == Status)
  {
    /* Check for the Timeout */
    if(Timeout != HAL_MAX_DELAY)
    {
      if((Timeout == 0) || ((HAL_GetTick()-Tickstart) > Timeout))
      {
        /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
        CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE));
        CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);

        hirda->gState= HAL_IRDA_STATE_READY;
        hirda->RxState= HAL_IRDA_STATE_READY;

        /* Process Unlocked */
        __HAL_UNLOCK(hirda);

        return HAL_TIMEOUT;
      }
    }
  }
  return HAL_OK;
}
예제 #3
0
/**
  * @brief  This function handles IRDA interrupt request.
  * @param  hirda: Pointer to a IRDA_HandleTypeDef structure that contains
  *                the configuration information for the specified IRDA module.
  * @retval None
  */
void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda)
{
  uint32_t  tmp_flag = 0, tmp_it_source = 0;
  
  tmp_flag = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_PE);
  tmp_it_source = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_PE);
  /* IRDA parity error interrupt occurred -----------------------------------*/
  if((tmp_flag != RESET) && (tmp_it_source != RESET))
  {
    hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
  }

  tmp_flag = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_FE);
  tmp_it_source = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR);
  /* IRDA frame error interrupt occurred ------------------------------------*/
  if((tmp_flag != RESET) && (tmp_it_source != RESET))
  {
    hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
  }

  tmp_flag = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_NE);
  /* IRDA noise error interrupt occurred ------------------------------------*/
  if((tmp_flag != RESET) && (tmp_it_source != RESET))
  {
    hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
  }

  tmp_flag = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_ORE);
  /* IRDA Over-Run interrupt occurred ---------------------------------------*/
  if((tmp_flag != RESET) && (tmp_it_source != RESET))
  {
    hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
  }

  /* Call the Error call Back in case of Errors */
  if(hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
  {
    /* Disable PE and ERR interrupt */
    __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
    __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
    __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
    
    /* Clear all the error flag at once */
    __HAL_IRDA_CLEAR_PEFLAG(hirda);

    /* Set the IRDA state ready to be able to start again the process */
    hirda->State = HAL_IRDA_STATE_READY;
    HAL_IRDA_ErrorCallback(hirda);
  }

  tmp_flag = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_RXNE);
  tmp_it_source = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_RXNE);
  /* IRDA in mode Receiver --------------------------------------------------*/
  if((tmp_flag != RESET) && (tmp_it_source != RESET))
  {
    IRDA_Receive_IT(hirda);
  }

  tmp_flag = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_TXE);
  tmp_it_source = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_TXE);
  /* IRDA in mode Transmitter -----------------------------------------------*/
  if((tmp_flag != RESET) && (tmp_it_source != RESET))
  {
    IRDA_Transmit_IT(hirda);
  }

  tmp_flag = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_TC);
  tmp_it_source = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_TC);
  /* IRDA in mode Transmitter (transmission end) -----------------------------*/
  if((tmp_flag != RESET) && (tmp_it_source != RESET))
  {
    IRDA_EndTransmit_IT(hirda);
  }   
  
}
예제 #4
0
/**
  * @brief  This function handles IRDA interrupt request.
  * @param  hirda: pointer to a IRDA_HandleTypeDef structure that contains
  *                the configuration information for the specified IRDA module.
  * @retval None
  */
void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda)
{
  uint32_t  tmp1 = 0, tmp2 =0;
  
  tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_PE);
  tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_PE);
  /* IRDA parity error interrupt occurred -------------------------------------*/
  if((tmp1 != RESET) && (tmp2 != RESET))
  { 
    __HAL_IRDA_CLEAR_PEFLAG(hirda);
    hirda->ErrorCode |= HAL_IRDA_ERROR_PE; 
  }
  
  tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_FE);
  tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR);
  /* IRDA frame error interrupt occurred --------------------------------------*/
  if((tmp1 != RESET) && (tmp2 != RESET))
  { 
    __HAL_IRDA_CLEAR_FEFLAG(hirda);
    hirda->ErrorCode |= HAL_IRDA_ERROR_FE; 
  }
  
  tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_NE);
  tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR);
  /* IRDA noise error interrupt occurred --------------------------------------*/
  if((tmp1 != RESET) && (tmp2 != RESET))
  { 
    __HAL_IRDA_CLEAR_NEFLAG(hirda);
    hirda->ErrorCode |= HAL_IRDA_ERROR_NE; 
  }
  
  tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_ORE);
  tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR);
  /* IRDA Over-Run interrupt occurred -----------------------------------------*/
  if((tmp1 != RESET) && (tmp2 != RESET))
  { 
    __HAL_IRDA_CLEAR_OREFLAG(hirda);
    hirda->ErrorCode |= HAL_IRDA_ERROR_ORE; 
  }

  /* Call the Error call Back in case of Errors */
  if(hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
  {
    /* Set the IRDA state ready to be able to start again the process */
    hirda->State = HAL_IRDA_STATE_READY;
    HAL_IRDA_ErrorCallback(hirda);
  }

  tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_RXNE);
  tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_RXNE);
  /* IRDA in mode Receiver ---------------------------------------------------*/
  if((tmp1 != RESET) && (tmp2 != RESET))
  { 
    IRDA_Receive_IT(hirda);
  }
  
  tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_TXE);
  tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_TXE);
  /* IRDA in mode Transmitter ------------------------------------------------*/
  if((tmp1 != RESET) &&(tmp2 != RESET))
  {
    IRDA_Transmit_IT(hirda);
  }
}