Pigweed
 
Loading...
Searching...
No Matches
pw::uart::Uart Class Referenceabstract

#include <uart.h>

Inheritance diagram for pw::uart::Uart:
pw::uart::UartBase pw::uart::UartBlockingAdapter

Public Member Functions

StatusWithSize ReadAtLeast (ByteSpan rx_buffer, size_t min_bytes)
 
StatusWithSize ReadExactly (ByteSpan rx_buffer)
 
Status Read (ByteSpan rx_buffer)
 
StatusWithSize TryReadAtLeastFor (ByteSpan rx_buffer, size_t min_bytes, chrono::SystemClock::duration timeout)
 
StatusWithSize TryReadExactlyFor (ByteSpan rx_buffer, chrono::SystemClock::duration timeout)
 
StatusWithSize TryReadFor (ByteSpan rx_buffer, chrono::SystemClock::duration timeout)
 
Status Write (ConstByteSpan tx_buffer)
 
StatusWithSize TryWriteFor (ConstByteSpan tx_buffer, chrono::SystemClock::duration timeout)
 
Status FlushOutput ()
 
- Public Member Functions inherited from pw::uart::UartBase
Status Enable ()
 
Status Disable ()
 
Status SetBaudRate (uint32_t baud_rate)
 
Status SetFlowControl (bool enable)
 
size_t ConservativeReadAvailable ()
 
Status ClearPendingReceiveBytes ()
 

Private Member Functions

virtual StatusWithSize DoTryReadFor (ByteSpan rx_buffer, std::optional< chrono::SystemClock::duration > timeout)
 
virtual StatusWithSize DoTryReadFor (ByteSpan, size_t, std::optional< chrono::SystemClock::duration >)
 
virtual StatusWithSize DoTryWriteFor (ConstByteSpan tx_buffer, std::optional< chrono::SystemClock::duration > timeout)=0
 Writes data from a provided buffer to the UART with an optional timeout.
 

Detailed Description

Represents an abstract UART interface.

The Uart interface provides a basic set of methods for performing blocking UART communication.

Member Function Documentation

◆ DoTryReadFor() [1/2]

virtual StatusWithSize pw::uart::Uart::DoTryReadFor ( ByteSpan  rx_buffer,
std::optional< chrono::SystemClock::duration timeout 
)
inlineprivatevirtual

Reads data from the UART into a provided buffer with an optional timeout provided.

This virtual function attempts to read data into the provided byte buffer (rx_buffer). The operation will continue until either the buffer is full, an error occurs, or the optional timeout duration expires.

Parameters
rx_bufferThe buffer to read data into.
timeoutAn optional timeout duration. If specified, the function will block for no longer than this duration. If zero, the function will immediately return with at least one hardware read operation attempt. If not specified, the function blocks until the buffer is full.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successful and the entire buffer has been
*     filled with data.
* 
*     DEADLINE_EXCEEDED: The operation timed out before the entire buffer
*     could be filled.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ DoTryReadFor() [2/2]

virtual StatusWithSize pw::uart::Uart::DoTryReadFor ( ByteSpan  ,
size_t  ,
std::optional< chrono::SystemClock::duration  
)
inlineprivatevirtual

Reads data from the UART into a provided buffer with an optional timeout provided.

This virtual function attempts to read data into the provided byte buffer (rx_buffer). The operation will continue until either min_bytes have been read into the buffer, an error occurs, or the optional timeout duration expires.

Parameters
rx_bufferThe buffer to read data into.
min_bytesThe minimum number of bytes to read before returning.
timeoutAn optional timeout duration. If specified, the function will block for no longer than this duration. If zero, the function will immediately return with at least one hardware read operation attempt. If not specified, the function blocks until the buffer is full.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successful and the entire buffer has been
*     filled with data.
* 
*     DEADLINE_EXCEEDED: The operation timed out before the entire buffer
*     could be filled.
* 
*  May return other implementation-specific status codes.
* 
*  

Reimplemented in pw::uart::UartBlockingAdapter.

◆ DoTryWriteFor()

virtual StatusWithSize pw::uart::Uart::DoTryWriteFor ( ConstByteSpan  tx_buffer,
std::optional< chrono::SystemClock::duration timeout 
)
privatepure virtual

Writes data from a provided buffer to the UART with an optional timeout.

This virtual function attempts to write data from the provided byte buffer (tx_buffer) to the UART. The operation will continue until either the buffer is empty, an error occurs, or the optional timeout duration expires.

Parameters
tx_bufferThe buffer containing data to be written.
timeoutAn optional timeout duration. If specified, the function will block for no longer than this duration. If zero, the function will immediately return after at least one hardware write operation attempt. If not specified, the function blocks until the buffer is empty.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successful and the entire buffer has been
*     written.
* 
*     DEADLINE_EXCEEDED: The operation timed out before the entire buffer
*     could be written.
* 
*  May return other implementation-specific status codes.
* 
*  

Implemented in pw::uart::UartBlockingAdapter.

◆ FlushOutput()

Status pw::uart::Uart::FlushOutput ( )
inline

Blocks until all queued data in the UART has been transmitted and the FIFO is empty.

This function ensures that all data enqueued before calling this function has been transmitted. Any data enqueued after calling this function will be transmitted immediately.

Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successful.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ Read()

Status pw::uart::Uart::Read ( ByteSpan  rx_buffer)
inline

Deprecated: Prefer ReadExactly in new code.

Reads data from the UART into a provided buffer.

This function blocks until the entire buffer has been filled.

Parameters
rx_bufferThe buffer to read data into.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successful.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ ReadAtLeast()

StatusWithSize pw::uart::Uart::ReadAtLeast ( ByteSpan  rx_buffer,
size_t  min_bytes 
)
inline

Reads data from the UART into a provided buffer.

This function blocks until min_bytes have been read into rx_buffer.

Parameters
rx_bufferThe buffer to read data into.
min_bytesThe minimum number of bytes to read before returning.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successful.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ ReadExactly()

StatusWithSize pw::uart::Uart::ReadExactly ( ByteSpan  rx_buffer)
inline

Reads data from the UART into a provided buffer.

This function blocks until the entire buffer has been filled.

Parameters
rx_bufferThe buffer to read data into.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successful.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ TryReadAtLeastFor()

StatusWithSize pw::uart::Uart::TryReadAtLeastFor ( ByteSpan  rx_buffer,
size_t  min_bytes,
chrono::SystemClock::duration  timeout 
)
inline

Reads data from the UART into a provided buffer.

This function blocks until either min_bytes have been read into buffer or the specified timeout has elapsed, whichever occurs first.

Parameters
rx_bufferThe buffer to read data into.
min_bytesThe minimum number of bytes to read before returning.
timeoutThe maximum time to wait for data to be read. If zero, the function will immediately return with at least one hardware read operation attempt.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successful and the entire buffer has been filled
*     with data.
* 
*     DEADLINE_EXCEEDED: The operation timed out before the entire buffer
*     could be filled.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ TryReadExactlyFor()

StatusWithSize pw::uart::Uart::TryReadExactlyFor ( ByteSpan  rx_buffer,
chrono::SystemClock::duration  timeout 
)
inline

Reads data from the UART into a provided buffer.

This function blocks until either rx_buffer.size() bytes have been read into buffer or the specified timeout has elapsed, whichever occurs first.

Parameters
rx_bufferThe buffer to read data into.
timeoutThe maximum time to wait for data to be read. If zero, the function will immediately return with at least one hardware read operation attempt.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successful and the entire buffer has been filled
*     with data.
* 
*     DEADLINE_EXCEEDED: The operation timed out before the entire buffer
*     could be filled.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ TryReadFor()

StatusWithSize pw::uart::Uart::TryReadFor ( ByteSpan  rx_buffer,
chrono::SystemClock::duration  timeout 
)
inline

Deprecated: Prefer TryReadExactlyFor in new code. Reads data from the UART into a provided buffer.

This function blocks until either rx_buffer.size() bytes have been read into buffer or the specified timeout has elapsed, whichever occurs first.

Parameters
rx_bufferThe buffer to read data into.
timeoutThe maximum time to wait for data to be read. If zero, the function will immediately return with at least one hardware read operation attempt.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successful and the entire buffer has been filled
*     with data.
* 
*     DEADLINE_EXCEEDED: The operation timed out before the entire buffer
*     could be filled.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ TryWriteFor()

StatusWithSize pw::uart::Uart::TryWriteFor ( ConstByteSpan  tx_buffer,
chrono::SystemClock::duration  timeout 
)
inline

Writes data from the provided buffer to the UART. The function blocks until either the entire buffer has been written or the specified timeout has elapsed, whichever occurs first.

Parameters
tx_bufferThe buffer to write data from.
timeoutThe maximum time to wait for data to be written. If zero, the function will immediately return with at least one hardware write operation attempt.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successful and the entire buffer has been
*     written.
* 
*     DEADLINE_EXCEEDED: The operation timed out before the entire buffer
*     could be written.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ Write()

Status pw::uart::Uart::Write ( ConstByteSpan  tx_buffer)
inline

Writes data from the provided buffer to the UART. The function blocks until the entire buffer has been written.

Parameters
tx_buffer- The buffer to write data from.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successful.
* 
*  May return other implementation-specific status codes.
* 
*  

The documentation for this class was generated from the following file: