Page 1 of 1

UART TX Ring Buffer Fill Level

Posted: Tue Dec 21, 2021 5:53 pm
by gfvalvo
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.

Re: UART TX Ring Buffer Fill Level

Posted: Tue Dec 21, 2021 8:38 pm
by Victoria Nope
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

Posted: Tue Dec 21, 2021 8:54 pm
by gfvalvo
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,

Re: UART TX Ring Buffer Fill Level

Posted: Tue Dec 21, 2021 11:52 pm
by gfvalvo
gfvalvo wrote:
Tue Dec 21, 2021 8:54 pm
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.
From the docs:
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.
Google has failed me on what the size of the "hardware Tx FIFO" is. But, I doubt it's very large.