Trait kernel::hil::uart::Receive

source ·
pub trait Receive<'a> {
    // Required methods
    fn set_receive_client(&self, client: &'a dyn ReceiveClient);
    fn receive_buffer(
        &self,
        rx_buffer: &'static mut [u8],
        rx_len: usize,
    ) -> Result<(), (ErrorCode, &'static mut [u8])>;
    fn receive_word(&self) -> Result<(), ErrorCode>;
    fn receive_abort(&self) -> Result<(), ErrorCode>;
}
Expand description

Trait for receiving data via a UART bus.

Required Methods§

source

fn set_receive_client(&self, client: &'a dyn ReceiveClient)

Set the receive client, which will be called when reads complete.

source

fn receive_buffer( &self, rx_buffer: &'static mut [u8], rx_len: usize, ) -> Result<(), (ErrorCode, &'static mut [u8])>

Receive rx_len bytes into rx_buffer.

If this function returns Ok(()), there will be a callback to the ReceiveClient::received_buffer when the receive is complete.

Each byte in rx_buffer will be a UART transfer word of 8 or fewer bits. The width is determined by the UART configuration. Clients that need to transfer 9-bit words should use Receive::receive_word.

§Return values
  • Ok(()): The receive started successfully and a ReceiveClient::received_buffer callback will be generated when the read completes.
  • Err(OFF): The underlying hardware is not available, perhaps because it has not been initialized or in the case of a shared hardware USART controller because it is set up for SPI.
  • Err(BUSY): the UART is already receiving and has not made a reception complete callback yet.
  • Err(SIZE): rx_len is larger than the passed slice.
source

fn receive_word(&self) -> Result<(), ErrorCode>

Receive a single word of data.

The word length is determined by the UART configuration: it can be 6, 7, 8, or 9 bits long.

§Return values
  • Ok(()): The receive started successfully and ReceiveClient::received_word will be called.
  • Err(OFF): The underlying hardware is not available, perhaps because it has not been initialized or in the case of a shared hardware USART controller because it is set up for SPI.
  • Err(BUSY): the UART is already receiving and has not made a reception callback yet.
  • Err(FAIL): not supported or some other error.
source

fn receive_abort(&self) -> Result<(), ErrorCode>

Abort any ongoing receive transfers and return what has been received.

If there was an ongoing receive, the received data and the receive buffer will be provided in the correct callback, either ReceiveClient::received_word or ReceiveClient::received_buffer.

If there is no outstanding receive operation, Ok(()) is returned and there will be no callback.

§Return values
  • Ok(()): The abort was successful because there was nothing to abort. There will be no callback.
  • Err(BUSY): There is a receive in progress and it canceling it has started successfully. A callback will be generated later with a result of Err(CANCEL).
  • Err(FAIL): Cancelling an ongoing receive did not occur correctly. A future callback will be generated when the receive finishes.

Implementors§