Skip to content

Commit bc35b13

Browse files
yashimbolivar-nordic
authored andcommitted
doc: uart: Make sure uart_poll_in is non-blocking
The documentation has wrongly stated that the function uart_poll_in() is also a blocking function. The uart_poll_out() is indeed a blocking function but uart_poll_in() has never been since day one. Make it clear that the uart_poll_in() is a NON-blocking function, and uart_poll_out() IS a blocking. This fixes #45468. Signed-off-by: Yasushi SHOJI <[email protected]>
1 parent f089f96 commit bc35b13

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

doc/hardware/peripherals/uart.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ on the method, different API functions are used according to below sections:
1313
2. :ref:`uart_interrupt_api`
1414
3. :ref:`uart_async_api` using :ref:`dma_api`
1515

16-
Polling is the most basic method to access the UART peripheral. The functions
17-
are blocking and the thread waits until a character is sent or received.
16+
Polling is the most basic method to access the UART peripheral. The reading
17+
function, `uart_poll_in`, is a non-blocking function and returns a character
18+
or `-1` when no valid data is available. The writing function,
19+
`uart_poll_out`, is a blocking function and the thread waits until the given
20+
character is sent.
1821

1922
With the Interrupt-driven API, possibly slow communication can happen in the
2023
background while the thread continues with other tasks. The Kernel's

include/zephyr/drivers/uart.h

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,13 @@ static inline int z_impl_uart_err_check(const struct device *dev)
493493
*/
494494

495495
/**
496-
* @brief Poll the device for input.
496+
* @brief Read a character from the device for input.
497+
*
498+
* This routine checks if the receiver has valid data. When the
499+
* receiver has valid data, it reads a character from the device,
500+
* stores to the location pointed to by p_char, and returns 0 to the
501+
* calling thread. It returns -1, otherwise. This function is a
502+
* non-blocking call.
497503
*
498504
* @param dev UART device instance.
499505
* @param p_char Pointer to character.
@@ -520,7 +526,13 @@ static inline int z_impl_uart_poll_in(const struct device *dev,
520526
}
521527

522528
/**
523-
* @brief Poll the device for wide data input.
529+
* @brief Read a 16-bit datum from the device for input.
530+
*
531+
* This routine checks if the receiver has valid data. When the
532+
* receiver has valid data, it reads a 16-bit datum from the device,
533+
* stores to the location pointed to by p_u16, and returns 0 to the
534+
* calling thread. It returns -1, otherwise. This function is a
535+
* non-blocking call.
524536
*
525537
* @param dev UART device instance.
526538
* @param p_u16 Pointer to 16-bit data.
@@ -554,11 +566,12 @@ static inline int z_impl_uart_poll_in_u16(const struct device *dev,
554566
}
555567

556568
/**
557-
* @brief Output a character in polled mode.
569+
* @brief Write a character to the device for output.
558570
*
559-
* This routine checks if the transmitter is empty.
560-
* When the transmitter is empty, it writes a character to the data
561-
* register.
571+
* This routine checks if the transmitter is full. When the
572+
* transmitter is not full, it writes a character to the data
573+
* register. It waits and blocks the calling thread, otherwise. This
574+
* function is a blocking call.
562575
*
563576
* To send a character when hardware flow control is enabled, the handshake
564577
* signal CTS must be asserted.
@@ -579,11 +592,12 @@ static inline void z_impl_uart_poll_out(const struct device *dev,
579592
}
580593

581594
/**
582-
* @brief Output wide data in polled mode.
595+
* @brief Write a 16-bit datum to the device for output.
583596
*
584-
* This routine checks if the transmitter is empty.
585-
* When the transmitter is empty, it writes a datum to the data
586-
* register.
597+
* This routine checks if the transmitter is full. When the
598+
* transmitter is not full, it writes a 16-bit datum to the data
599+
* register. It waits and blocks the calling thread, otherwise. This
600+
* function is a blocking call.
587601
*
588602
* To send a datum when hardware flow control is enabled, the handshake
589603
* signal CTS must be asserted.

0 commit comments

Comments
 (0)