STM32L4xx_HAL_Driver  1.14.0
USARTEx Private Functions

Functions

static void USARTEx_SetNbDataToProcess (USART_HandleTypeDef *husart)
 Calculate the number of data to process in RX/TX ISR. More...
 

Detailed Description

Function Documentation

◆ USARTEx_SetNbDataToProcess()

static void USARTEx_SetNbDataToProcess ( USART_HandleTypeDef husart)
static

Calculate the number of data to process in RX/TX ISR.

Note
The RX FIFO depth and the TX FIFO depth is extracted from the USART configuration registers.
Parameters
husartUSART handle.
Return values
None

Definition at line 504 of file stm32l4xx_hal_usart_ex.c.

505 {
506  uint8_t rx_fifo_depth;
507  uint8_t tx_fifo_depth;
508  uint8_t rx_fifo_threshold;
509  uint8_t tx_fifo_threshold;
510  /* 2 0U/1U added for MISRAC2012-Rule-18.1_b and MISRAC2012-Rule-18.1_d */
511  uint8_t numerator[] = {1U, 1U, 1U, 3U, 7U, 1U, 0U, 0U};
512  uint8_t denominator[] = {8U, 4U, 2U, 4U, 8U, 1U, 1U, 1U};
513 
514  if (husart->FifoMode == USART_FIFOMODE_DISABLE)
515  {
516  husart->NbTxDataToProcess = 1U;
517  husart->NbRxDataToProcess = 1U;
518  }
519  else
520  {
521  rx_fifo_depth = RX_FIFO_DEPTH;
522  tx_fifo_depth = TX_FIFO_DEPTH;
523  rx_fifo_threshold = (uint8_t)((READ_BIT(husart->Instance->CR3, USART_CR3_RXFTCFG) >> USART_CR3_RXFTCFG_Pos) & 0xFFU);
524  tx_fifo_threshold = (uint8_t)((READ_BIT(husart->Instance->CR3, USART_CR3_TXFTCFG) >> USART_CR3_TXFTCFG_Pos) & 0xFFU);
525  husart->NbTxDataToProcess = ((uint16_t)tx_fifo_depth * numerator[tx_fifo_threshold]) / (uint16_t)denominator[tx_fifo_threshold];
526  husart->NbRxDataToProcess = ((uint16_t)rx_fifo_depth * numerator[rx_fifo_threshold]) / (uint16_t)denominator[rx_fifo_threshold];
527  }
528 }