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

#include <uart_non_blocking.h>

Inheritance diagram for pw::uart::UartNonBlocking:
pw::uart::UartBase

Public Member Functions

Status ReadExactly (ByteSpan rx_buffer, Function< void(Status status, ConstByteSpan buffer)> &&callback)
 
Status ReadAtLeast (ByteSpan rx_buffer, size_t min_bytes, Function< void(Status status, ConstByteSpan buffer)> &&callback)
 
bool CancelRead ()
 
Status Write (ConstByteSpan tx_buffer, Function< void(StatusWithSize status)> &&callback)
 
bool CancelWrite ()
 
Status FlushOutput (Function< void(Status status)> &&callback)
 
bool CancelFlushOutput ()
 
- 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 Status DoRead (ByteSpan rx_buffer, size_t min_bytes, Function< void(Status status, ConstByteSpan buffer)> &&callback)=0
 
virtual bool DoCancelRead ()=0
 
virtual Status DoWrite (ConstByteSpan tx_buffer, Function< void(StatusWithSize status)> &&callback)=0
 
virtual bool DoCancelWrite ()=0
 
virtual Status DoFlushOutput (Function< void(Status status)> &&)
 
virtual bool DoCancelFlushOutput ()
 

Detailed Description

Represents an abstract UART interface.

The UartNonBlocking interface provides a basic set of methods for performing Non-Blocking UART communication.

Member Function Documentation

◆ CancelFlushOutput()

bool pw::uart::UartNonBlocking::CancelFlushOutput ( )
inline

Cancels a pending FlushOutput() operation.

This function will cancel an output flush in progress. The FlushOutput callback will be called with status=CANCELLED.

Returns
embed:rst:leading-asterisk
 
* 
*     true: The operation was successfully canceled a transaction in progress
*           and the callback will be invoked with status=CANCELLED.
*     false: There were no transactions in progress and nothing was
*            cancelled. No callback will be invoked.
* 
*  

◆ CancelRead()

bool pw::uart::UartNonBlocking::CancelRead ( )
inline

Cancel a current read in progress.

This function will cancel a read in progress. The read's callback will be invoked with status=CANCELLED.

Returns
embed:rst:leading-asterisk
 
* 
*     true: The operation was successfully canceled a transaction in progress
*           and the callback will be invoked with status=CANCELLED.
*     false: There were no transactions in progress and nothing was
*            cancelled. No callback will be invoked.
* 
*  

◆ CancelWrite()

bool pw::uart::UartNonBlocking::CancelWrite ( )
inline

Cancel a current write in progress.

This function will cancel a write in progress. The write's callback will be called with status=CANCELLED.

Returns
embed:rst:leading-asterisk
 
* 
*     true: The operation was successfully canceled a transaction in progress
*           and the callback will be invoked with status=CANCELLED.
*     false: There were no transactions in progress and nothing was
*            cancelled. No callback will be invoked.
* 
*  

◆ DoCancelFlushOutput()

virtual bool pw::uart::UartNonBlocking::DoCancelFlushOutput ( )
inlineprivatevirtual

Cancels a pending FlushOutput() operation.

This function will cancel an output flush in progress. The DoFlushOutput callback will be called with status=CANCELLED.

Returns
embed:rst:leading-asterisk
 
* 
*     true: The operation was successfully canceled a transaction in progress
*           and the callback will be invoked with status=CANCELLED.
*     false: There were no transactions in progress and nothing was
*            cancelled. No callback will be invoked.
* 
*  

◆ DoCancelRead()

virtual bool pw::uart::UartNonBlocking::DoCancelRead ( )
privatepure virtual

Cancels a current read in progress.

This virtual function will cancel a read in progress. The read's callback will be called with status=CANCELLED.

Returns
embed:rst:leading-asterisk
 
* 
*     true: The operation was successfully canceled a transaction in progress
*           and the callback will be invoked with status=CANCELLED.
*     false: There were no transactions in progress and nothing was
*            cancelled. No callback will be invoked.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ DoCancelWrite()

virtual bool pw::uart::UartNonBlocking::DoCancelWrite ( )
privatepure virtual

Cancel a current write in progress.

This virtual function will cancel a write in progress. The write's callback will be invoked with status=CANCELLED.

Returns
embed:rst:leading-asterisk
 
* 
*     true: The operation was successfully canceled a transaction in progress
*           and the callback will be invoked with status=CANCELLED.
*     false: There were no transactions in progress and nothing was
*            cancelled. No callback will be invoked.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ DoFlushOutput()

virtual Status pw::uart::UartNonBlocking::DoFlushOutput ( Function< void(Status status)> &&  )
inlineprivatevirtual

Ensures all queued data in the UART has been transmitted and the hardware FIFO is empty.

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

Parameters
callbackA callback to invoke when the flush is completed.
statusOK: The operation was successful and the transmit FIFO is empty. CANCELLED: The operation was cancelled via CancelFlushOutput(). May return other implementation-specific status codes.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successfully started.
*     UNAVAILABLE: Another Write() or FlushOutput() operation is currently
*     in progress.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ DoRead()

virtual Status pw::uart::UartNonBlocking::DoRead ( ByteSpan  rx_buffer,
size_t  min_bytes,
Function< void(Status status, ConstByteSpan buffer)> &&  callback 
)
privatepure virtual

Reads at least min_bytes and at most rx_buffer.size() bytes from the UART into the provided buffer.

This virtual function attempts to read data into the provided byte buffer (rx_buffer). This virtual function will return immediately. callback will be invoked when the buffer has been filled with at least min_bytes, or an error occurs. Implementation Notes:

  • The callback may be called in ISR context.
  • The callback must be moved and stored prior to its invocation.
  • Do not hold a lock when invoking the callback.
Parameters
rx_bufferThe buffer to read data into.
min_bytesMinimum bytes to read.
callbackA callback to invoke when the transaction is completed.
statusOK: The operation was successful and the buffer has been filled with at least min_bytes with data. CANCELLED: The operation was cancelled via CancelRead(). May return other implementation-specific status codes.
bufferbuffer.size() returns the number of bytes successfully read into the buffer.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successful started.
*     UNAVAILABLE: Another Read() transaction is currently in progress.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ DoWrite()

virtual Status pw::uart::UartNonBlocking::DoWrite ( ConstByteSpan  tx_buffer,
Function< void(StatusWithSize status)> &&  callback 
)
privatepure virtual

Writes data from a provided buffer to the UART.

This virtual function attempts to write data from the provided byte buffer (tx_buffer). This virtual function will return immediately. callback will be invoked when either the buffer fully written, or an error occurs. Implementation Notes:

  • The callback may be called in ISR context.
  • The callback must be moved and stored prior to its invocation.
  • Do not hold a lock when invoking the callback.
Parameters
tx_bufferThe buffer to write to the UART.
callbackA callback to invoke when the transaction is completed.
statusstatus.size() returns the number of bytes successfully written from tx_buffer.
statusOK: The operation was successful and the entire buffer has been written. CANCELLED: The operation was cancelled via CancelWrite(). May return other implementation-specific status codes.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successful started.
*     UNAVAILABLE: Another Write() transaction is currently in progress.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ FlushOutput()

Status pw::uart::UartNonBlocking::FlushOutput ( Function< void(Status status)> &&  callback)
inline

Ensures all queued data in the UART has been transmitted and the hardware FIFO is empty.

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

Parameters
callbackA callback to invoke when the flush is completed.
statusOK: The operation was successful and the transmit FIFO is empty. CANCELLED: The operation was cancelled via CancelFlushOutput(). May return other implementation-specific status codes.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successfully started.
*     UNAVAILABLE: Another Write() or FlushOutput() operation is currently
*     in progress.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ ReadAtLeast()

Status pw::uart::UartNonBlocking::ReadAtLeast ( ByteSpan  rx_buffer,
size_t  min_bytes,
Function< void(Status status, ConstByteSpan buffer)> &&  callback 
)
inline

Reads at least min_bytes and at most rx_buffer.size() bytes from the UART into the provided buffer.

This function calls callback after rx_buffer is filled with at least min_bytes of data. This may be called from interrupt context. The callback may be called in ISR context. It is not safe to call any Uart methods from the callback context.

Parameters
rx_bufferThe buffer to read data into.
min_bytesMinimum bytes to read.
callbackA callback to invoke when the transaction is completed.
statusOK: The operation was successful and the buffer has been filled with at least min_bytes with data. CANCELLED: The operation was cancelled via CancelRead(). May return other implementation-specific status codes.
bufferbuffer.size() returns the number of bytes successfully read into the buffer.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successfully started.
*     UNAVAILABLE: Another Read() transaction is currently in progress.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ ReadExactly()

Status pw::uart::UartNonBlocking::ReadExactly ( ByteSpan  rx_buffer,
Function< void(Status status, ConstByteSpan buffer)> &&  callback 
)
inline

Reads exactly rx_buffer.size() bytes from the UART into the provided buffer.

This function calls callback after the entirety of rx_buffer is filled with data. This may be called from interrupt context. The callback may be called in ISR context. It is not safe to call any Uart methods from the callback context.

Parameters
rx_bufferThe buffer to read data into.
callbackA callback to invoke when the transaction is completed.
statusOK: The operation was successful and the entire buffer has been filled with data. CANCELLED: The operation was cancelled via CancelRead(). May return other implementation-specific status codes.
bufferbuffer.size() returns the number of bytes successfully read into the buffer. If status=OK, the buffer is identical to rx_buffer
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successfully started.
*     UNAVAILABLE: Another Read() transaction is currently in progress.
* 
*  May return other implementation-specific status codes.
* 
*  

◆ Write()

Status pw::uart::UartNonBlocking::Write ( ConstByteSpan  tx_buffer,
Function< void(StatusWithSize status)> &&  callback 
)
inline

Writes data from a provided buffer to the UART.

This function calls callback after the entirety of tx_buffer is written to the UART. This may be called from interrupt context. The callback may be called in ISR context. It is not safe to call any Uart methods from the callback context.

Parameters
tx_bufferThe buffer to write to the UART.
callbackA callback to invoke when the transaction is completed.
statusstatus.size() returns the number of bytes successfully written from tx_buffer. OK: The operation was successful and the entire buffer has been written. CANCELLED: The operation was cancelled via CancelWrite(). May return other implementation-specific status codes.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The operation was successfully started.
*     UNAVAILABLE: Another Write() transaction is currently in progress.
* 
*  May return other implementation-specific status codes.
* 
*  

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