mirror of
https://github.com/apache/nuttx.git
synced 2026-08-02 04:38:59 +00:00
uart_tcdrain() takes a caller-supplied timeout (e.g. 10s from the
TCDRN ioctl path), but the timeout was only applied to the final
TX-FIFO polling loop. The earlier xmit-buffer drain loop called
nxsem_wait(&dev->xmitsem) with no timeout, so any condition that
prevents the lower half from posting xmitsem (e.g. a stuck DMA
completion path, a wedged hardware-flow-control stall) would block
tcdrain() indefinitely, regardless of the timeout the caller asked
for. The pre-existing comment ("NOTE: There is no timeout on the
following loop. ... the caller should call tcflush() first") openly
acknowledged this hang.
Move the start timestamp before both phases and replace the bare
nxsem_wait() with nxsem_tickwait() using the remaining time, so the
total time spent in tcdrain() honors the caller's timeout regardless
of which phase stalls. When the remaining time is already exhausted,
short-circuit to -ETIMEDOUT without calling into the scheduler. The
existing exit path (drop critical section, skip the FIFO polling
loop, unlock the xmit mutex, leave the cancellation point) handles
the new -ETIMEDOUT propagation correctly without further changes.
Also fold the "Set up for the timeout" comment into the kludge
REVISIT comment, since the timestamp is no longer set up at that
point.
Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
|
||
|---|---|---|
| .. | ||
| CMakeLists.txt | ||
| Kconfig | ||
| Kconfig-16550 | ||
| Kconfig-cmsdk | ||
| Kconfig-lpuart | ||
| Kconfig-pci | ||
| Kconfig-pl011 | ||
| Kconfig-sci | ||
| Kconfig-uart | ||
| Kconfig-usart | ||
| Kconfig-xlnxps | ||
| Make.defs | ||
| ptmx.c | ||
| pty.c | ||
| pty.h | ||
| serial.c | ||
| serial_cmsdk.c | ||
| serial_dma.c | ||
| serial_gdbstub.c | ||
| serial_io.c | ||
| uart_16550.c | ||
| uart_bth4.c | ||
| uart_bth5.c | ||
| uart_hostfs.c | ||
| uart_pci_16550.c | ||
| uart_pl011.c | ||
| uart_ram.c | ||
| uart_rpmsg.c | ||
| uart_rpmsg_raw.c | ||
| uart_xlnx_ps.c | ||