Skip to content

Commit e3917ce

Browse files
pfalconAnas Nashif
authored andcommitted
drivers: serial: Clarification for uart_fifo_fill()/read() calls
As they are part of interrupt-driver API, they must be called from an ISR. That means that calling it outside IST may not have a desired effect, and vice-versa, not calling them from ISR can lead to issues. The patch also eleborates/fixes description of uart_irq_rx_ready(). Jira: ZEP-2016 Signed-off-by: Paul Sokolovsky <[email protected]>
1 parent 1305ad9 commit e3917ce

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

include/uart.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,15 @@ static inline unsigned char uart_poll_out(struct device *dev,
241241
/**
242242
* @brief Fill FIFO with data.
243243
*
244+
* @details This function is expected to be called from UART
245+
* interrupt handler (ISR), if uart_irq_tx_ready() returns true.
246+
* Result of calling this function not from an ISR is undefined
247+
* (hardware-dependent). Likewise, *not* calling this function
248+
* from an ISR if uart_irq_tx_ready() returns true may lead to
249+
* undefined behavior, e.g. infinite interrupt loops. It's
250+
* mandatory to test return value of this function, as different
251+
* hardware has different FIFO depth (oftentimes just 1).
252+
*
244253
* @param dev UART device structure.
245254
* @param tx_data Data to transmit.
246255
* @param size Number of bytes to send.
@@ -262,6 +271,16 @@ static inline int uart_fifo_fill(struct device *dev, const u8_t *tx_data,
262271
/**
263272
* @brief Read data from FIFO.
264273
*
274+
* @details This function is expected to be called from UART
275+
* interrupt handler (ISR), if uart_irq_rx_ready() returns true.
276+
* Result of calling this function not from an ISR is undefined
277+
* (hardware-dependent). It's unspecified whether "RX ready"
278+
* condition as returned by uart_irq_rx_ready() is level- or
279+
* edge- triggered. That means that once uart_irq_rx_ready() is
280+
* detected, uart_fifo_read() must be called until it reads all
281+
* available data in the FIFO (i.e. until it returns less data
282+
* than was requested).
283+
*
265284
* @param dev UART device structure.
266285
* @param rx_data Data container.
267286
* @param size Container size.
@@ -406,16 +425,21 @@ static inline int __deprecated uart_irq_tx_empty(struct device *dev)
406425
}
407426

408427
/**
409-
* @brief Check if UART RX buffer has a new char
428+
* @brief Check if UART RX buffer has a received char
410429
*
430+
* @details Check if UART RX buffer has at least one pending character
411431
* (i.e. uart_fifo_read() will succeed and return non-zero). This function
412432
* must be called in a UART interrupt handler, or its result is undefined.
413433
* Before calling this function in the interrupt handler, uart_irq_update()
414-
* must be called once per the handler invocation.
434+
* must be called once per the handler invocation. It's unspecified whether
435+
* condition as returned by this function is level- or edge- triggered (i.e.
436+
* if this function returns true when RX FIFO is non-empty, or when a new
437+
* char was received since last call to it). See description of
438+
* uart_fifo_read() for implication of this.
415439
*
416440
* @param dev UART device structure.
417441
*
418-
* @retval 1 If a new received char is ready.
442+
* @retval 1 If a received char is ready.
419443
* @retval 0 Otherwise.
420444
*/
421445
static inline int uart_irq_rx_ready(struct device *dev)

0 commit comments

Comments
 (0)