Is it possible to determine the UART TX Ring Buffer Fill Level or equivalently the space available?
I'd like to call uart_write_bytes() and specify the number of bytes to be written to a value no higher than space available in the ring buffer. That way I can be assured that the function will return immediately after copying the bytes and not wait for more space to become available. That could easily be accomplished if the API had a call that returns either the space available or the fill level.
UART TX Ring Buffer Fill Level
-
- Posts: 75
- Joined: Fri Dec 04, 2020 9:56 pm
Re: UART TX Ring Buffer Fill Level
Would not uart_tx_chars function fit for your needs? According to docs (have not checked the source), it should return immediately when the TX FIFO is full, returning number of bytes enqueued.
Re: UART TX Ring Buffer Fill Level
I believe uart_tx_chars() bypasses the (potentially large) ring buffer in memory and writes as many characters as it can directly into the UART's hardware FIFO. That's not what I want as the hardware FIFO is likely pretty small.
Anyway, that's my impression from reading the docs. But, they do play kind of fast and loose with the terms "FIFO" and "BUFFER". So, I may be wrong,
Anyway, that's my impression from reading the docs. But, they do play kind of fast and loose with the terms "FIFO" and "BUFFER". So, I may be wrong,
Re: UART TX Ring Buffer Fill Level
From the docs:
Google has failed me on what the size of the "hardware Tx FIFO" is. But, I doubt it's very large.Another function for writing data to the Tx FIFO buffer is uart_tx_chars(). Unlike uart_write_bytes(), this function will not block until space is available. Instead, it will write all data which can immediately fit into the hardware Tx FIFO, and then return the number of bytes that were written.