基于STM32的窄带物联网图书馆座位智能管理系统

    status =  HAL_ERROR;
    break;
}

}
else
{
/* Update the error code */
hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;

/* Return error status */
status =  HAL_ERROR;

}

/* Release Lock */
__HAL_UNLOCK(hirda);

return status;
}
#endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */

/**

  • @}
    */

/** @defgroup IRDA_Exported_Functions_Group2 IO operation functions

  • @brief IRDA Transmit and Receive functions

@verbatim

                  ##### IO operation functions #####

==============================================================================
[…]
This subsection provides a set of functions allowing to manage the IRDA data transfers.
IrDA is a half duplex communication protocol. If the Transmitter is busy, any data
on the IrDA receive line will be ignored by the IrDA decoder and if the Receiver
is busy, data on the TX from the USART to IrDA will not be encoded by IrDA.
While receiving data, transmission should be avoided as the data to be transmitted
could be corrupted.

(#) There are two modes of transfer:
   (++) Blocking mode: The communication is performed in polling mode.
        The HAL status of all data processing is returned by the same function
        after finishing transfer.
   (++) Non-Blocking mode: The communication is performed using Interrupts
       or DMA, these API's return the HAL status.
       The end of the data processing will be indicated through the
       dedicated IRDA IRQ when using Interrupt mode or the DMA IRQ when
       using DMA mode.
       The HAL_IRDA_TxCpltCallback(), HAL_IRDA_RxCpltCallback() user callbacks
       will be executed respectively at the end of the Transmit or Receive process
       The HAL_IRDA_ErrorCallback() user callback will be executed when a communication error is detected

(#) Blocking mode APIs are :
    (++) HAL_IRDA_Transmit()
    (++) HAL_IRDA_Receive()

(#) Non Blocking mode APIs with Interrupt are :
    (++) HAL_IRDA_Transmit_IT()
    (++) HAL_IRDA_Receive_IT()
    (++) HAL_IRDA_IRQHandler()

(#) Non Blocking mode functions with DMA are :
    (++) HAL_IRDA_Transmit_DMA()
    (++) HAL_IRDA_Receive_DMA()
    (++) HAL_IRDA_DMAPause()
    (++) HAL_IRDA_DMAResume()
    (++) HAL_IRDA_DMAStop()

(#) A set of Transfer Complete Callbacks are provided in Non Blocking mode:
    (++) HAL_IRDA_TxHalfCpltCallback()
    (++) HAL_IRDA_TxCpltCallback()
    (++) HAL_IRDA_RxHalfCpltCallback()
    (++) HAL_IRDA_RxCpltCallback()
    (++) HAL_IRDA_ErrorCallback()

(#) Non-Blocking mode transfers could be aborted using Abort API's :
    (+) HAL_IRDA_Abort()
    (+) HAL_IRDA_AbortTransmit()
    (+) HAL_IRDA_AbortReceive()
    (+) HAL_IRDA_Abort_IT()
    (+) HAL_IRDA_AbortTransmit_IT()
    (+) HAL_IRDA_AbortReceive_IT()

(#) For Abort services based on interrupts (HAL_IRDA_Abortxxx_IT), a set of Abort Complete Callbacks are provided:
    (+) HAL_IRDA_AbortCpltCallback()
    (+) HAL_IRDA_AbortTransmitCpltCallback()
    (+) HAL_IRDA_AbortReceiveCpltCallback()

(#) In Non-Blocking mode transfers, possible errors are split into 2 categories.
    Errors are handled as follows :
    (+) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is
        to be evaluated by user : this concerns Frame Error, Parity Error or Noise Error in Interrupt mode reception .
        Received character is then retrieved and stored in Rx buffer, Error code is set to allow user to identify error type,
        and HAL_IRDA_ErrorCallback() user callback is executed. Transfer is kept ongoing on IRDA side.
        If user wants to abort it, Abort services should be called by user.
    (+) Error is considered as Blocking : Transfer could not be completed properly and is aborted.
        This concerns Overrun Error In Interrupt mode reception and all errors in DMA mode.
        Error code is set to allow user to identify error type, and HAL_IRDA_ErrorCallback() user callback is executed.

@endverbatim

  • @{
    */

/**

  • @brief Sends an amount of data in blocking mode.
  • @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
  •    the sent data is handled as a set of u16. In this case, Size must reflect the number
    
  •    of u16 available through pData.
    
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •          the configuration information for the specified IRDA module.
    
  • @param pData Pointer to data buffer (u8 or u16 data elements).
  • @param Size Amount of data elements (u8 or u16) to be sent.
  • @param Timeout Specify timeout value.
  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
    {
    uint16_t *tmp;
    uint32_t tickstart = 0U;

/* Check that a Tx process is not already ongoing */
if (hirda->gState == HAL_IRDA_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}

/* Process Locked */
__HAL_LOCK(hirda);

hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->gState = HAL_IRDA_STATE_BUSY_TX;

/* Init tickstart for timeout management*/
tickstart = HAL_GetTick();

hirda->TxXferSize = Size;
hirda->TxXferCount = Size;
while (hirda->TxXferCount > 0U)
{
  hirda->TxXferCount--;
  if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
  {
    if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
    {
      return HAL_TIMEOUT;
    }
    tmp = (uint16_t *) pData;
    hirda->Instance->DR = (*tmp & (uint16_t)0x01FF);
    if (hirda->Init.Parity == IRDA_PARITY_NONE)
    {
      pData += 2U;
    }
    else
    {
      pData += 1U;
    }
  }
  else
  {
    if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
    {
      return HAL_TIMEOUT;
    }
    hirda->Instance->DR = (*pData++ & (uint8_t)0xFF);
  }
}

if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
{
  return HAL_TIMEOUT;
}

/* At end of Tx process, restore hirda->gState to Ready */
hirda->gState = HAL_IRDA_STATE_READY;

/* Process Unlocked */
__HAL_UNLOCK(hirda);

return HAL_OK;

}
else
{
return HAL_BUSY;
}
}

/**

  • @brief Receive an amount of data in blocking mode.
  • @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
  •    the received data is handled as a set of u16. In this case, Size must reflect the number
    
  •    of u16 available through pData.
    
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •          the configuration information for the specified IRDA module.
    
  • @param pData Pointer to data buffer (u8 or u16 data elements).
  • @param Size Amount of data elements (u8 or u16) to be received.
  • @param Timeout Specify timeout value
  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
    {
    uint16_t *tmp;
    uint32_t tickstart = 0U;

/* Check that a Rx process is not already ongoing */
if (hirda->RxState == HAL_IRDA_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}

/* Process Locked */
__HAL_LOCK(hirda);

hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->RxState = HAL_IRDA_STATE_BUSY_RX;

/* Init tickstart for timeout management*/
tickstart = HAL_GetTick();

hirda->RxXferSize = Size;
hirda->RxXferCount = Size;

/* Check the remain data to be received */
while (hirda->RxXferCount > 0U)
{
  hirda->RxXferCount--;

  if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
  {
    if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
    {
      return HAL_TIMEOUT;
    }
    tmp = (uint16_t *) pData ;
    if (hirda->Init.Parity == IRDA_PARITY_NONE)
    {
      *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x01FF);
      pData += 2U;
    }
    else
    {
      *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x00FF);
      pData += 1U;
    }
  }
  else
  {
    if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
    {
      return HAL_TIMEOUT;
    }
    if (hirda->Init.Parity == IRDA_PARITY_NONE)
    {
      *pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x00FF);
    }
    else
    {
      *pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x007F);
    }
  }
}

/* At end of Rx process, restore hirda->RxState to Ready */
hirda->RxState = HAL_IRDA_STATE_READY;

/* Process Unlocked */
__HAL_UNLOCK(hirda);

return HAL_OK;

}
else
{
return HAL_BUSY;
}
}

/**

  • @brief Send an amount of data in non blocking mode.

  • @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),

  •    the sent data is handled as a set of u16. In this case, Size must reflect the number
    
  •    of u16 available through pData.
    
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains

  •          the configuration information for the specified IRDA module.
    
  • @param pData Pointer to data buffer (u8 or u16 data elements).

  • @param Size Amount of data elements (u8 or u16) to be sent.

  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t pData, uint16_t Size)
    {
    /
    Check that a Tx process is not already ongoing */
    if (hirda->gState == HAL_IRDA_STATE_READY)
    {
    if ((pData == NULL) || (Size == 0U))
    {
    return HAL_ERROR;
    }

    /* Process Locked */
    __HAL_LOCK(hirda);

    hirda->pTxBuffPtr = pData;
    hirda->TxXferSize = Size;
    hirda->TxXferCount = Size;

    hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
    hirda->gState = HAL_IRDA_STATE_BUSY_TX;

    /* Process Unlocked */
    __HAL_UNLOCK(hirda);

    /* Enable the IRDA Transmit Data Register Empty Interrupt */
    SET_BIT(hirda->Instance->CR1, USART_CR1_TXEIE);

    return HAL_OK;
    }
    else
    {
    return HAL_BUSY;
    }
    }

/**

  • @brief Receive an amount of data in non blocking mode.

  • @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),

  •    the received data is handled as a set of u16. In this case, Size must reflect the number
    
  •    of u16 available through pData.
    
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains

  •          the configuration information for the specified IRDA module.
    
  • @param pData Pointer to data buffer (u8 or u16 data elements).

  • @param Size Amount of data elements (u8 or u16) to be received.

  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t pData, uint16_t Size)
    {
    /
    Check that a Rx process is not already ongoing */
    if (hirda->RxState == HAL_IRDA_STATE_READY)
    {
    if ((pData == NULL) || (Size == 0U))
    {
    return HAL_ERROR;
    }

    /* Process Locked */
    __HAL_LOCK(hirda);

    hirda->pRxBuffPtr = pData;
    hirda->RxXferSize = Size;
    hirda->RxXferCount = Size;

    hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
    hirda->RxState = HAL_IRDA_STATE_BUSY_RX;

    /* Process Unlocked */
    __HAL_UNLOCK(hirda);

    /* Enable the IRDA Parity Error and Data Register Not Empty Interrupts */
    SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE);

    /* Enable the IRDA Error Interrupt: (Frame error, Noise error, Overrun error) */
    SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);

    return HAL_OK;
    }
    else
    {
    return HAL_BUSY;
    }
    }

/**

  • @brief Send an amount of data in DMA mode.
  • @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
  •    the sent data is handled as a set of u16. In this case, Size must reflect the number
    
  •    of u16 available through pData.
    
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •          the configuration information for the specified IRDA module.
    
  • @param pData Pointer to data buffer (u8 or u16 data elements).
  • @param Size Amount of data elements (u8 or u16) to be sent.
  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
    {
    uint32_t *tmp;

/* Check that a Tx process is not already ongoing */
if (hirda->gState == HAL_IRDA_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}

/* Process Locked */
__HAL_LOCK(hirda);

hirda->pTxBuffPtr = pData;
hirda->TxXferSize = Size;
hirda->TxXferCount = Size;

hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->gState = HAL_IRDA_STATE_BUSY_TX;

/* Set the IRDA DMA transfer complete callback */
hirda->hdmatx->XferCpltCallback = IRDA_DMATransmitCplt;

/* Set the IRDA DMA half transfer complete callback */
hirda->hdmatx->XferHalfCpltCallback = IRDA_DMATransmitHalfCplt;

/* Set the DMA error callback */
hirda->hdmatx->XferErrorCallback = IRDA_DMAError;

/* Set the DMA abort callback */
hirda->hdmatx->XferAbortCallback = NULL;

/* Enable the IRDA transmit DMA channel */
tmp = (uint32_t *)&pData;
HAL_DMA_Start_IT(hirda->hdmatx, *(uint32_t *)tmp, (uint32_t)&hirda->Instance->DR, Size);

/* Clear the TC flag in the SR register by writing 0 to it */
__HAL_IRDA_CLEAR_FLAG(hirda, IRDA_FLAG_TC);

/* Process Unlocked */
__HAL_UNLOCK(hirda);

/* Enable the DMA transfer for transmit request by setting the DMAT bit
in the USART CR3 register */
SET_BIT(hirda->Instance->CR3, USART_CR3_DMAT);

return HAL_OK;

}
else
{
return HAL_BUSY;
}
}

/**

  • @brief Receives an amount of data in DMA mode.
  • @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
  •    the received data is handled as a set of u16. In this case, Size must reflect the number
    
  •    of u16 available through pData.
    
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •          the configuration information for the specified IRDA module.
    
  • @param pData Pointer to data buffer (u8 or u16 data elements).
  • @param Size Amount of data elements (u8 or u16) to be received.
  • @note When the IRDA parity is enabled (PCE = 1) the data received contain the parity bit.
  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
    {
    uint32_t *tmp;

/* Check that a Rx process is not already ongoing */
if (hirda->RxState == HAL_IRDA_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}

/* Process Locked */
__HAL_LOCK(hirda);

hirda->pRxBuffPtr = pData;
hirda->RxXferSize = Size;

hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->RxState = HAL_IRDA_STATE_BUSY_RX;

/* Set the IRDA DMA transfer complete callback */
hirda->hdmarx->XferCpltCallback = IRDA_DMAReceiveCplt;

/* Set the IRDA DMA half transfer complete callback */
hirda->hdmarx->XferHalfCpltCallback = IRDA_DMAReceiveHalfCplt;

/* Set the DMA error callback */
hirda->hdmarx->XferErrorCallback = IRDA_DMAError;

/* Set the DMA abort callback */
hirda->hdmarx->XferAbortCallback = NULL;

/* Enable the DMA channel */
tmp = (uint32_t *)&pData;
HAL_DMA_Start_IT(hirda->hdmarx, (uint32_t)&hirda->Instance->DR, *(uint32_t *)tmp, Size);

/* Clear the Overrun flag just before enabling the DMA Rx request: can be mandatory for the second transfer */
__HAL_IRDA_CLEAR_OREFLAG(hirda);

/* Process Unlocked */
__HAL_UNLOCK(hirda);

/* Enable the IRDA Parity Error Interrupt */
SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE);

/* Enable the IRDA Error Interrupt: (Frame error, Noise error, Overrun error) */
SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);

/* Enable the DMA transfer for the receiver request by setting the DMAR bit
in the USART CR3 register */
SET_BIT(hirda->Instance->CR3, USART_CR3_DMAR);

return HAL_OK;

}
else
{
return HAL_BUSY;
}
}

/**

  • @brief Pauses the DMA Transfer.
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •            the configuration information for the specified IRDA module.
    
  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda)
    {
    uint32_t dmarequest = 0x00U;

/* Process Locked */
__HAL_LOCK(hirda);

dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
if ((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest)
{
/* Disable the IRDA DMA Tx request */
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
}

dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
if ((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest)
{
/* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);

/* Disable the IRDA DMA Rx request */
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);

}

/* Process Unlocked */
__HAL_UNLOCK(hirda);

return HAL_OK;
}

/**

  • @brief Resumes the DMA Transfer.
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •            the configuration information for the specified IRDA module.
    
  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef hirda)
    {
    /
    Process Locked */
    __HAL_LOCK(hirda);

if (hirda->gState == HAL_IRDA_STATE_BUSY_TX)
{
/* Enable the IRDA DMA Tx request */
SET_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
}

if (hirda->RxState == HAL_IRDA_STATE_BUSY_RX)
{
/* Clear the Overrun flag before resuming the Rx transfer */
__HAL_IRDA_CLEAR_OREFLAG(hirda);

/* Re-enable PE and ERR (Frame error, noise error, overrun error) interrupts */
SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);

/* Enable the IRDA DMA Rx request */
SET_BIT(hirda->Instance->CR3, USART_CR3_DMAR);

}

/* Process Unlocked */
__HAL_UNLOCK(hirda);

return HAL_OK;
}

/**

  • @brief Stops the DMA Transfer.
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •            the configuration information for the specified IRDA module.
    
  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef hirda)
    {
    uint32_t dmarequest = 0x00U;
    /
    The Lock is not implemented on this API to allow the user application
    to call the HAL IRDA API under callbacks HAL_IRDA_TxCpltCallback() / HAL_IRDA_RxCpltCallback():
    when calling HAL_DMA_Abort() API the DMA TX/RX Transfer complete interrupt is generated
    and the correspond call back is executed HAL_IRDA_TxCpltCallback() / HAL_IRDA_RxCpltCallback()
    */

/* Stop IRDA DMA Tx request if ongoing */
dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
if ((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest)
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);

/* Abort the IRDA DMA Tx channel */
if (hirda->hdmatx != NULL)
{
  HAL_DMA_Abort(hirda->hdmatx);
}
IRDA_EndTxTransfer(hirda);

}

/* Stop IRDA DMA Rx request if ongoing */
dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
if ((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest)
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);

/* Abort the IRDA DMA Rx channel */
if (hirda->hdmarx != NULL)
{
  HAL_DMA_Abort(hirda->hdmarx);
}
IRDA_EndRxTransfer(hirda);

}

return HAL_OK;
}

/**

  • @brief Abort ongoing transfers (blocking mode).
  • @param hirda IRDA handle.
  • @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
  •     This procedure performs following operations :
    
  •       - Disable PPP Interrupts
    
  •       - Disable the DMA transfer in the peripheral register (if enabled)
    
  •       - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
    
  •       - Set handle State to READY
    
  • @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_IRDA_Abort(IRDA_HandleTypeDef hirda)
    {
    /
    Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
    CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
    CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);

/* Disable the IRDA DMA Tx request if enabled */
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);

/* Abort the IRDA DMA Tx channel : use blocking DMA Abort API (no callback) */
if (hirda->hdmatx != NULL)
{
  /* Set the IRDA DMA Abort callback to Null.
     No call back execution at end of DMA abort procedure */
  hirda->hdmatx->XferAbortCallback = NULL;

  HAL_DMA_Abort(hirda->hdmatx);
}

}

/* Disable the IRDA DMA Rx request if enabled */
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);

/* Abort the IRDA DMA Rx channel : use blocking DMA Abort API (no callback) */
if (hirda->hdmarx != NULL)
{
  /* Set the IRDA DMA Abort callback to Null.
     No call back execution at end of DMA abort procedure */
  hirda->hdmarx->XferAbortCallback = NULL;

  HAL_DMA_Abort(hirda->hdmarx);
}

}

/* Reset Tx and Rx transfer counters */
hirda->TxXferCount = 0x00U;
hirda->RxXferCount = 0x00U;

/* Reset ErrorCode */
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;

/* Restore hirda->RxState and hirda->gState to Ready */
hirda->RxState = HAL_IRDA_STATE_READY;
hirda->gState = HAL_IRDA_STATE_READY;

return HAL_OK;
}

/**

  • @brief Abort ongoing Transmit transfer (blocking mode).
  • @param hirda IRDA handle.
  • @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
  •     This procedure performs following operations :
    
  •       - Disable PPP Interrupts
    
  •       - Disable the DMA transfer in the peripheral register (if enabled)
    
  •       - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
    
  •       - Set handle State to READY
    
  • @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_IRDA_AbortTransmit(IRDA_HandleTypeDef hirda)
    {
    /
    Disable TXEIE and TCIE interrupts */
    CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));

/* Disable the IRDA DMA Tx request if enabled */
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);

/* Abort the IRDA DMA Tx channel : use blocking DMA Abort API (no callback) */
if (hirda->hdmatx != NULL)
{
  /* Set the IRDA DMA Abort callback to Null.
     No call back execution at end of DMA abort procedure */
  hirda->hdmatx->XferAbortCallback = NULL;

  HAL_DMA_Abort(hirda->hdmatx);
}

}

/* Reset Tx transfer counter */
hirda->TxXferCount = 0x00U;

/* Restore hirda->gState to Ready */
hirda->gState = HAL_IRDA_STATE_READY;

return HAL_OK;
}

/**

  • @brief Abort ongoing Receive transfer (blocking mode).
  • @param hirda IRDA handle.
  • @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
  •     This procedure performs following operations :
    
  •       - Disable PPP Interrupts
    
  •       - Disable the DMA transfer in the peripheral register (if enabled)
    
  •       - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
    
  •       - Set handle State to READY
    
  • @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_IRDA_AbortReceive(IRDA_HandleTypeDef hirda)
    {
    /
    Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
    CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
    CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);

/* Disable the IRDA DMA Rx request if enabled */
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);

/* Abort the IRDA DMA Rx channel : use blocking DMA Abort API (no callback) */
if (hirda->hdmarx != NULL)
{
  /* Set the IRDA DMA Abort callback to Null.
     No call back execution at end of DMA abort procedure */
  hirda->hdmarx->XferAbortCallback = NULL;

  HAL_DMA_Abort(hirda->hdmarx);
}

}

/* Reset Rx transfer counter */
hirda->RxXferCount = 0x00U;

/* Restore hirda->RxState to Ready */
hirda->RxState = HAL_IRDA_STATE_READY;

return HAL_OK;
}

/**

  • @brief Abort ongoing transfers (Interrupt mode).
  • @param hirda IRDA handle.
  • @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
  •     This procedure performs following operations :
    
  •       - Disable PPP Interrupts
    
  •       - Disable the DMA transfer in the peripheral register (if enabled)
    
  •       - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
    
  •       - Set handle State to READY
    
  •       - At abort completion, call user abort complete callback
    
  • @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
  •     considered as completed only when user abort complete callback is executed (not when exiting function).
    
  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_IRDA_Abort_IT(IRDA_HandleTypeDef *hirda)
    {
    uint32_t AbortCplt = 0x01U;

/* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);

/* If DMA Tx and/or DMA Rx Handles are associated to IRDA Handle, DMA Abort complete callbacks should be initialised
before any call to DMA Abort functions /
/
DMA Tx Handle is valid /
if (hirda->hdmatx != NULL)
{
/
Set DMA Abort Complete callback if IRDA DMA Tx request if enabled.
Otherwise, set it to NULL /
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
{
hirda->hdmatx->XferAbortCallback = IRDA_DMATxAbortCallback;
}
else
{
hirda->hdmatx->XferAbortCallback = NULL;
}
}
/
DMA Rx Handle is valid /
if (hirda->hdmarx != NULL)
{
/
Set DMA Abort Complete callback if IRDA DMA Rx request if enabled.
Otherwise, set it to NULL */
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
{
hirda->hdmarx->XferAbortCallback = IRDA_DMARxAbortCallback;
}
else
{
hirda->hdmarx->XferAbortCallback = NULL;
}
}

/* Disable the IRDA DMA Tx request if enabled /
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
{
/
Disable DMA Tx at IRDA level */
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);

/* Abort the IRDA DMA Tx channel : use non blocking DMA Abort API (callback) */
if (hirda->hdmatx != NULL)
{
  /* IRDA Tx DMA Abort callback has already been initialised :
     will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */

  /* Abort DMA TX */
  if (HAL_DMA_Abort_IT(hirda->hdmatx) != HAL_OK)
  {
    hirda->hdmatx->XferAbortCallback = NULL;
  }
  else
  {
    AbortCplt = 0x00U;
  }
}

}

/* Disable the IRDA DMA Rx request if enabled */
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);

/* Abort the IRDA DMA Rx channel : use non blocking DMA Abort API (callback) */
if (hirda->hdmarx != NULL)
{
  /* IRDA Rx DMA Abort callback has already been initialised :
     will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */

  /* Abort DMA RX */
  if (HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
  {
    hirda->hdmarx->XferAbortCallback = NULL;
    AbortCplt = 0x01U;
  }
  else
  {
    AbortCplt = 0x00U;
  }
}

}

/* if no DMA abort complete callback execution is required => call user Abort Complete callback /
if (AbortCplt == 0x01U)
{
/
Reset Tx and Rx transfer counters */
hirda->TxXferCount = 0x00U;
hirda->RxXferCount = 0x00U;

/* Reset ErrorCode */
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;

/* Restore hirda->gState and hirda->RxState to Ready */
hirda->gState  = HAL_IRDA_STATE_READY;
hirda->RxState = HAL_IRDA_STATE_READY;

/* As no DMA to be aborted, call directly user Abort complete callback */

#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/* Call registered Abort complete callback /
hirda->AbortCpltCallback(hirda);
#else
/
Call legacy weak Abort complete callback /
HAL_IRDA_AbortCpltCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACK */
}

return HAL_OK;
}

/**

  • @brief Abort ongoing Transmit transfer (Interrupt mode).
  • @param hirda IRDA handle.
  • @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
  •     This procedure performs following operations :
    
  •       - Disable IRDA Interrupts (Tx)
    
  •       - Disable the DMA transfer in the peripheral register (if enabled)
    
  •       - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
    
  •       - Set handle State to READY
    
  •       - At abort completion, call user abort complete callback
    
  • @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
  •     considered as completed only when user abort complete callback is executed (not when exiting function).
    
  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_IRDA_AbortTransmit_IT(IRDA_HandleTypeDef hirda)
    {
    /
    Disable TXEIE and TCIE interrupts */
    CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));

/* Disable the IRDA DMA Tx request if enabled */
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);

/* Abort the IRDA DMA Tx channel : use non blocking DMA Abort API (callback) */
if (hirda->hdmatx != NULL)
{
  /* Set the IRDA DMA Abort callback :
     will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
  hirda->hdmatx->XferAbortCallback = IRDA_DMATxOnlyAbortCallback;

  /* Abort DMA TX */
  if (HAL_DMA_Abort_IT(hirda->hdmatx) != HAL_OK)
  {
    /* Call Directly hirda->hdmatx->XferAbortCallback function in case of error */
    hirda->hdmatx->XferAbortCallback(hirda->hdmatx);
  }
}
else
{
  /* Reset Tx transfer counter */
  hirda->TxXferCount = 0x00U;

  /* Restore hirda->gState to Ready */
  hirda->gState = HAL_IRDA_STATE_READY;

  /* As no DMA to be aborted, call directly user Abort complete callback */

#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/* Call registered Abort Transmit Complete Callback /
hirda->AbortTransmitCpltCallback(hirda);
#else
/
Call legacy weak Abort Transmit Complete Callback /
HAL_IRDA_AbortTransmitCpltCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACK /
}
}
else
{
/
Reset Tx transfer counter */
hirda->TxXferCount = 0x00U;

/* Restore hirda->gState to Ready */
hirda->gState = HAL_IRDA_STATE_READY;

/* As no DMA to be aborted, call directly user Abort complete callback */

#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/* Call registered Abort Transmit Complete Callback /
hirda->AbortTransmitCpltCallback(hirda);
#else
/
Call legacy weak Abort Transmit Complete Callback /
HAL_IRDA_AbortTransmitCpltCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACK */
}

return HAL_OK;
}

/**

  • @brief Abort ongoing Receive transfer (Interrupt mode).
  • @param hirda IRDA handle.
  • @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
  •     This procedure performs following operations :
    
  •       - Disable PPP Interrupts
    
  •       - Disable the DMA transfer in the peripheral register (if enabled)
    
  •       - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
    
  •       - Set handle State to READY
    
  •       - At abort completion, call user abort complete callback
    
  • @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
  •     considered as completed only when user abort complete callback is executed (not when exiting function).
    
  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_IRDA_AbortReceive_IT(IRDA_HandleTypeDef hirda)
    {
    /
    Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
    CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
    CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);

/* Disable the IRDA DMA Rx request if enabled */
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);

/* Abort the IRDA DMA Rx channel : use non blocking DMA Abort API (callback) */
if (hirda->hdmarx != NULL)
{
  /* Set the IRDA DMA Abort callback :
     will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
  hirda->hdmarx->XferAbortCallback = IRDA_DMARxOnlyAbortCallback;

  /* Abort DMA RX */
  if (HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
  {
    /* Call Directly hirda->hdmarx->XferAbortCallback function in case of error */
    hirda->hdmarx->XferAbortCallback(hirda->hdmarx);
  }
}
else
{
  /* Reset Rx transfer counter */
  hirda->RxXferCount = 0x00U;

  /* Restore hirda->RxState to Ready */
  hirda->RxState = HAL_IRDA_STATE_READY;

  /* As no DMA to be aborted, call directly user Abort complete callback */

#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/* Call registered Abort Receive Complete Callback /
hirda->AbortReceiveCpltCallback(hirda);
#else
/
Call legacy weak Abort Receive Complete Callback /
HAL_IRDA_AbortReceiveCpltCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACK /
}
}
else
{
/
Reset Rx transfer counter */
hirda->RxXferCount = 0x00U;

/* Restore hirda->RxState to Ready */
hirda->RxState = HAL_IRDA_STATE_READY;

/* As no DMA to be aborted, call directly user Abort complete callback */

#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/* Call registered Abort Receive Complete Callback /
hirda->AbortReceiveCpltCallback(hirda);
#else
/
Call legacy weak Abort Receive Complete Callback /
HAL_IRDA_AbortReceiveCpltCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACK */
}

return HAL_OK;
}

/**

  • @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 isrflags = READ_REG(hirda->Instance->SR);
    uint32_t cr1its = READ_REG(hirda->Instance->CR1);
    uint32_t cr3its = READ_REG(hirda->Instance->CR3);
    uint32_t errorflags = 0x00U;
    uint32_t dmarequest = 0x00U;

/* If no error occurs /
errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE));
if (errorflags == RESET)
{
/
IRDA in mode Receiver -----------------------------------------------*/
if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
{
IRDA_Receive_IT(hirda);
return;
}
}

/* If some errors occur /
if ((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET)))
{
/
IRDA parity error interrupt occurred -------------------------------*/
if (((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET))
{
hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
}

/* IRDA noise error interrupt occurred --------------------------------*/
if (((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
{
  hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
}

/* IRDA frame error interrupt occurred --------------------------------*/
if (((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
{
  hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
}

/* IRDA Over-Run interrupt occurred -----------------------------------*/
if (((isrflags & USART_SR_ORE) != RESET) && (((cr1its & USART_CR1_RXNEIE) != RESET) || ((cr3its & USART_CR3_EIE) != RESET)))
{
  hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
}
/* Call IRDA Error Call back function if need be -----------------------*/
if (hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
{
  /* IRDA in mode Receiver ---------------------------------------------*/
  if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
  {
    IRDA_Receive_IT(hirda);
  }

  /* If Overrun error occurs, or if any error occurs in DMA mode reception,
     consider error as blocking */
  dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
  if (((hirda->ErrorCode & HAL_IRDA_ERROR_ORE) != RESET) || dmarequest)
  {
    /* Blocking error : transfer is aborted
       Set the IRDA state ready to be able to start again the process,
       Disable Rx Interrupts, and disable Rx DMA request, if ongoing */
    IRDA_EndRxTransfer(hirda);

    /* Disable the IRDA DMA Rx request if enabled */
    if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
    {
      CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);

      /* Abort the IRDA DMA Rx channel */
      if (hirda->hdmarx != NULL)
      {
        /* Set the IRDA DMA Abort callback :
        will lead to call HAL_IRDA_ErrorCallback() at end of DMA abort procedure */
        hirda->hdmarx->XferAbortCallback = IRDA_DMAAbortOnError;

        /* Abort DMA RX */
        if (HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
        {
          /* Call Directly XferAbortCallback function in case of error */
          hirda->hdmarx->XferAbortCallback(hirda->hdmarx);
        }
      }
      else
      {

#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/* Call registered user error callback /
hirda->ErrorCallback(hirda);
#else
/
Call legacy weak user error callback /
HAL_IRDA_ErrorCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACK /
}
}
else
{
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/
Call registered user error callback /
hirda->ErrorCallback(hirda);
#else
/
Call legacy weak user error callback /
HAL_IRDA_ErrorCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACK /
}
}
else
{
/
Non Blocking error : transfer could go on.
Error is notified to user through user error callback /
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/
Call registered user error callback /
hirda->ErrorCallback(hirda);
#else
/
Call legacy weak user error callback /
HAL_IRDA_ErrorCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACK */

    hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
  }
}
return;

} /* End if some error occurs */

/* IRDA in mode Transmitter ------------------------------------------------*/
if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
{
IRDA_Transmit_IT(hirda);
return;
}

/* IRDA in mode Transmitter end --------------------------------------------*/
if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
{
IRDA_EndTransmit_IT(hirda);
return;
}
}

/**

  • @brief Tx Transfer complete callback.
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •            the configuration information for the specified IRDA module.
    
  • @retval None
    */
    __weak void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef hirda)
    {
    /
    Prevent unused argument(s) compilation warning */
    UNUSED(hirda);

/* NOTE : This function should not be modified, when the callback is needed,
the HAL_IRDA_TxCpltCallback can be implemented in the user file.
*/
}

/**

  • @brief Tx Half Transfer completed callback.
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •            the configuration information for the specified USART module.
    
  • @retval None
    */
    __weak void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef hirda)
    {
    /
    Prevent unused argument(s) compilation warning */
    UNUSED(hirda);

/* NOTE : This function should not be modified, when the callback is needed,
the HAL_IRDA_TxHalfCpltCallback can be implemented in the user file.
*/
}

/**

  • @brief Rx Transfer complete callback.
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •            the configuration information for the specified IRDA module.
    
  • @retval None
    */
    __weak void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef hirda)
    {
    /
    Prevent unused argument(s) compilation warning */
    UNUSED(hirda);

/* NOTE : This function should not be modified, when the callback is needed,
the HAL_IRDA_RxCpltCallback can be implemented in the user file.
*/
}

/**

  • @brief Rx Half Transfer complete callback.
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •            the configuration information for the specified IRDA module.
    
  • @retval None
    */
    __weak void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef hirda)
    {
    /
    Prevent unused argument(s) compilation warning */
    UNUSED(hirda);

/* NOTE : This function should not be modified, when the callback is needed,
the HAL_IRDA_RxHalfCpltCallback can be implemented in the user file.
*/
}

/**

  • @brief IRDA error callback.
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •            the configuration information for the specified IRDA module.
    
  • @retval None
    */
    __weak void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef hirda)
    {
    /
    Prevent unused argument(s) compilation warning */
    UNUSED(hirda);

/* NOTE : This function should not be modified, when the callback is needed,
the HAL_IRDA_ErrorCallback can be implemented in the user file.
*/
}

/**

  • @brief IRDA Abort Complete callback.
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •            the configuration information for the specified IRDA module.
    
  • @retval None
    */
    __weak void HAL_IRDA_AbortCpltCallback(IRDA_HandleTypeDef hirda)
    {
    /
    Prevent unused argument(s) compilation warning */
    UNUSED(hirda);

/* NOTE : This function should not be modified, when the callback is needed,
the HAL_IRDA_AbortCpltCallback can be implemented in the user file.
*/
}

/**

  • @brief IRDA Abort Transmit Complete callback.
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •            the configuration information for the specified IRDA module.
    
  • @retval None
    */
    __weak void HAL_IRDA_AbortTransmitCpltCallback(IRDA_HandleTypeDef hirda)
    {
    /
    Prevent unused argument(s) compilation warning */
    UNUSED(hirda);

/* NOTE : This function should not be modified, when the callback is needed,
the HAL_IRDA_AbortTransmitCpltCallback can be implemented in the user file.
*/
}

/**

  • @brief IRDA Abort Receive Complete callback.
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •            the configuration information for the specified IRDA module.
    
  • @retval None
    */
    __weak void HAL_IRDA_AbortReceiveCpltCallback(IRDA_HandleTypeDef hirda)
    {
    /
    Prevent unused argument(s) compilation warning */
    UNUSED(hirda);

/* NOTE : This function should not be modified, when the callback is needed,
the HAL_IRDA_AbortReceiveCpltCallback can be implemented in the user file.
*/
}

/**

  • @}
    */

/** @defgroup IRDA_Exported_Functions_Group3 Peripheral State and Errors functions

  • @brief IRDA State and Errors functions

@verbatim

              ##### Peripheral State and Errors functions #####

==============================================================================
[…]
This subsection provides a set of functions allowing to return the State of IrDA
communication process and also return Peripheral Errors occurred during communication process
(+) HAL_IRDA_GetState() API can be helpful to check in run-time the state of the IrDA peripheral.
(+) HAL_IRDA_GetError() check in run-time errors that could be occurred during communication.

@endverbatim

  • @{
    */

/**

  • @brief Return the IRDA state.
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •            the configuration information for the specified IRDA.
    
  • @retval HAL state
    */
    HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda)
    {
    uint32_t temp1 = 0x00U, temp2 = 0x00U;
    temp1 = hirda->gState;
    temp2 = hirda->RxState;

return (HAL_IRDA_StateTypeDef)(temp1 | temp2);
}

/**

  • @brief Return the IRDA error code
  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
  •          the configuration information for the specified IRDA.
    
  • @retval IRDA Error Code
    */
    uint32_t HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda)
    {
    return hirda->ErrorCode;
    }

/**

  • @}
    */

/**

  • @}
    */

/** @defgroup IRDA_Private_Functions IRDA Private Functions

  • @{
    */

#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/**

  • @brief Initialize the callbacks to their default values.
  • @param hirda IRDA handle.
  • @retval none
    */
    void IRDA_InitCallbacksToDefault(IRDA_HandleTypeDef hirda)
    {
    /
    Init the IRDA Callback settings /
    hirda->TxHalfCpltCallback = HAL_IRDA_TxHalfCpltCallback; /
    Legacy weak TxHalfCpltCallback /
    hirda->TxCpltCallback = HAL_IRDA_TxCpltCallback; /
    Legacy weak TxCpltCallback /
    hirda->RxHalfCpltCallback = HAL_IRDA_RxHalfCpltCallback; /
    Legacy weak RxHalfCpltCallback /
    hirda->RxCpltCallback = HAL_IRDA_RxCpltCallback; /
    Legacy weak RxCpltCallback /
    hirda->ErrorCallback = HAL_IRDA_ErrorCallback; /
    Legacy weak ErrorCallback /
    hirda->AbortCpltCallback = HAL_IRDA_AbortCpltCallback; /
    Legacy weak AbortCpltCallback /
    hirda->AbortTransmitCpltCallback = HAL_IRDA_AbortTransmitCpltCallback; /
    Legacy weak AbortTransmitCpltCallback /
    hirda->AbortReceiveCpltCallback = HAL_IRDA_AbortReceiveCpltCallback; /
    Legacy weak AbortReceiveCpltCallback */

}
#endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */

/**

  • @brief DMA IRDA transmit process complete callback.

  • @param hdma Pointer to a DMA_HandleTypeDef structure that contains

  •           the configuration information for the specified DMA.
    
  • @retval None
    */
    static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma)
    {
    IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef )hdma)->Parent;
    /
    DMA Normal mode */
    if ((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U)
    {
    hirda->TxXferCount = 0U;

    /* Disable the DMA transfer for transmit request by resetting the DMAT bit
    in the IRDA CR3 register */
    CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);

    /* Enable the IRDA Transmit Complete Interrupt /
    SET_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
    }
    /
    DMA Circular mode /
    else
    {
    #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
    /
    Call registered Tx complete callback /
    hirda->TxCpltCallback(hirda);
    #else
    /
    Call legacy weak Tx complete callback /
    HAL_IRDA_TxCpltCallback(hirda);
    #endif /
    USE_HAL_IRDA_REGISTER_CALLBACK */
    }
    }

/**

  • @brief DMA IRDA receive process half complete callback
  • @param hdma Pointer to a DMA_HandleTypeDef structure that contains
  •           the configuration information for the specified DMA.
    
  • @retval None
    */
    static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma)
    {
    IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;

#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/* Call registered Tx Half complete callback /
hirda->TxHalfCpltCallback(hirda);
#else
/
Call legacy weak Tx complete callback /
HAL_IRDA_TxHalfCpltCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACK */
}

/**

  • @brief DMA IRDA receive process complete callback.
  • @param hdma Pointer to a DMA_HandleTypeDef structure that contains
  •           the configuration information for the specified DMA.
    
  • @retval None
    */
    static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
    {
    IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;

/* DMA Normal mode */
if ((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U)
{
hirda->RxXferCount = 0U;

/* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);

/* Disable the DMA transfer for the receiver request by resetting the DMAR bit
   in the IRDA CR3 register */
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);

/* At end of Rx process, restore hirda->RxState to Ready */
hirda->RxState = HAL_IRDA_STATE_READY;

}

#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/* Call registered Rx complete callback /
hirda->RxCpltCallback(hirda);
#else
/
Call legacy weak Rx complete callback /
HAL_IRDA_RxCpltCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACKS */
}

/**

  • @brief DMA IRDA receive process half complete callback.
  • @param hdma Pointer to a DMA_HandleTypeDef structure that contains
  •           the configuration information for the specified DMA.
    
  • @retval None
    */
    static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma)
    {
    IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;

#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/Call registered Rx Half complete callback/
hirda->RxHalfCpltCallback(hirda);
#else
/* Call legacy weak Rx Half complete callback /
HAL_IRDA_RxHalfCpltCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACK */
}

/**

  • @brief DMA IRDA communication error callback.
  • @param hdma Pointer to a DMA_HandleTypeDef structure that contains
  •           the configuration information for the specified DMA.
    
  • @retval None
    */
    static void IRDA_DMAError(DMA_HandleTypeDef *hdma)
    {
    uint32_t dmarequest = 0x00U;
    IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;

/* Stop IRDA DMA Tx request if ongoing */
dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
if ((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest)
{
hirda->TxXferCount = 0U;
IRDA_EndTxTransfer(hirda);
}

/* Stop IRDA DMA Rx request if ongoing */
dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
if ((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest)
{
hirda->RxXferCount = 0U;
IRDA_EndRxTransfer(hirda);
}

hirda->ErrorCode |= HAL_IRDA_ERROR_DMA;

#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/* Call registered user error callback /
hirda->ErrorCallback(hirda);
#else
/
Call legacy weak user error callback /
HAL_IRDA_ErrorCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACK */
}

/**

  • @brief This function handles IRDA Communication Timeout.

  • @param hirda Pointer to a IRDA_HandleTypeDef structure that contains

  •            the configuration information for the specified IRDA.
    
  • @param Flag specifies the IRDA flag to check.

  • @param Status The new Flag status (SET or RESET).

  • @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 == 0U) || ((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;
    }

/**

  • @brief End ongoing Tx transfer on IRDA peripheral (following error detection or Transmit completion).
  • @param hirda IRDA handle.
  • @retval None
    */
    static void IRDA_EndTxTransfer(IRDA_HandleTypeDef hirda)
    {
    /
    Disable TXEIE and TCIE interrupts */
    CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));

/* At end of Tx process, restore hirda->gState to Ready */
hirda->gState = HAL_IRDA_STATE_READY;
}

/**

  • @brief End ongoing Rx transfer on IRDA peripheral (following error detection or Reception completion).
  • @param hirda IRDA handle.
  • @retval None
    */
    static void IRDA_EndRxTransfer(IRDA_HandleTypeDef hirda)
    {
    /
    Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
    CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
    CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);

/* At end of Rx process, restore hirda->RxState to Ready */
hirda->RxState = HAL_IRDA_STATE_READY;
}

/**

  • @brief DMA IRDA communication abort callback, when initiated by HAL services on Error
  •     (To be called at end of DMA Abort procedure following error occurrence).
    
  • @param hdma DMA handle.
  • @retval None
    */
    static void IRDA_DMAAbortOnError(DMA_HandleTypeDef *hdma)
    {
    IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
    hirda->RxXferCount = 0x00U;
    hirda->TxXferCount = 0x00U;

#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/* Call registered user error callback /
hirda->ErrorCallback(hirda);
#else
/
Call legacy weak user error callback /
HAL_IRDA_ErrorCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACK */
}

/**

  • @brief DMA IRDA Tx communication abort callback, when initiated by user
  •     (To be called at end of DMA Tx Abort procedure following user abort request).
    
  • @note When this callback is executed, User Abort complete call back is called only if no
  •     Abort still ongoing for Rx DMA Handle.
    
  • @param hdma DMA handle.
  • @retval None
    */
    static void IRDA_DMATxAbortCallback(DMA_HandleTypeDef *hdma)
    {
    IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;

hirda->hdmatx->XferAbortCallback = NULL;

/* Check if an Abort process is still ongoing */
if (hirda->hdmarx != NULL)
{
if (hirda->hdmarx->XferAbortCallback != NULL)
{
return;
}
}

/* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
hirda->TxXferCount = 0x00U;
hirda->RxXferCount = 0x00U;

/* Reset ErrorCode */
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;

/* Restore hirda->gState and hirda->RxState to Ready */
hirda->gState = HAL_IRDA_STATE_READY;
hirda->RxState = HAL_IRDA_STATE_READY;

/* Call user Abort complete callback /
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/
Call registered Abort complete callback /
hirda->AbortCpltCallback(hirda);
#else
/
Call legacy weak Abort complete callback /
HAL_IRDA_AbortCpltCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACK */
}

/**

  • @brief DMA IRDA Rx communication abort callback, when initiated by user
  •     (To be called at end of DMA Rx Abort procedure following user abort request).
    
  • @note When this callback is executed, User Abort complete call back is called only if no
  •     Abort still ongoing for Tx DMA Handle.
    
  • @param hdma DMA handle.
  • @retval None
    */
    static void IRDA_DMARxAbortCallback(DMA_HandleTypeDef *hdma)
    {
    IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;

hirda->hdmarx->XferAbortCallback = NULL;

/* Check if an Abort process is still ongoing */
if (hirda->hdmatx != NULL)
{
if (hirda->hdmatx->XferAbortCallback != NULL)
{
return;
}
}

/* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
hirda->TxXferCount = 0x00U;
hirda->RxXferCount = 0x00U;

/* Reset ErrorCode */
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;

/* Restore hirda->gState and hirda->RxState to Ready */
hirda->gState = HAL_IRDA_STATE_READY;
hirda->RxState = HAL_IRDA_STATE_READY;

/* Call user Abort complete callback /
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/
Call registered Abort complete callback /
hirda->AbortCpltCallback(hirda);
#else
/
Call legacy weak Abort complete callback /
HAL_IRDA_AbortCpltCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACK */
}

/**

  • @brief DMA IRDA Tx communication abort callback, when initiated by user by a call to
  •     HAL_IRDA_AbortTransmit_IT API (Abort only Tx transfer)
    
  •     (This callback is executed at end of DMA Tx Abort procedure following user abort request,
    
  •     and leads to user Tx Abort Complete callback execution).
    
  • @param hdma DMA handle.
  • @retval None
    */
    static void IRDA_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
    {
    IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;

hirda->TxXferCount = 0x00U;

/* Restore hirda->gState to Ready */
hirda->gState = HAL_IRDA_STATE_READY;

最后

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。

因此收集整理了一份《2024年嵌入式&物联网开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上嵌入式&物联网开发知识点,真正体系化!

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新!!

State = HAL_IRDA_STATE_READY;

/* Call user Abort complete callback /
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/
Call registered Abort complete callback /
hirda->AbortCpltCallback(hirda);
#else
/
Call legacy weak Abort complete callback /
HAL_IRDA_AbortCpltCallback(hirda);
#endif /
USE_HAL_IRDA_REGISTER_CALLBACK */
}

/**

  • @brief DMA IRDA Tx communication abort callback, when initiated by user by a call to
  •     HAL_IRDA_AbortTransmit_IT API (Abort only Tx transfer)
    
  •     (This callback is executed at end of DMA Tx Abort procedure following user abort request,
    
  •     and leads to user Tx Abort Complete callback execution).
    
  • @param hdma DMA handle.
  • @retval None
    */
    static void IRDA_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
    {
    IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;

hirda->TxXferCount = 0x00U;

/* Restore hirda->gState to Ready */
hirda->gState = HAL_IRDA_STATE_READY;

最后

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。

因此收集整理了一份《2024年嵌入式&物联网开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

[外链图片转存中…(img-VwAIfuwA-1715685601381)]

[外链图片转存中…(img-AxlcnOxY-1715685601382)]

[外链图片转存中…(img-Dz9iIVNg-1715685601383)]

[外链图片转存中…(img-KWKwvxvq-1715685601383)]

[外链图片转存中…(img-RZSDlOs7-1715685601384)]

[外链图片转存中…(img-dxIZwn9e-1715685601384)]

[外链图片转存中…(img-ugmylO8d-1715685601384)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上嵌入式&物联网开发知识点,真正体系化!

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新!!

  • 25
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值