kernel::hil::uart

Trait Transmit

Source
pub trait Transmit<'a> {
    // Required methods
    fn set_transmit_client(&self, client: &'a dyn TransmitClient);
    fn transmit_buffer(
        &self,
        tx_buffer: &'static mut [u8],
        tx_len: usize,
    ) -> Result<(), (ErrorCode, &'static mut [u8])>;
    fn transmit_word(&self, word: u32) -> Result<(), ErrorCode>;
    fn transmit_abort(&self) -> Result<(), ErrorCode>;
}
Expand description

Trait for sending data via a UART bus.

Required Methods§

Source

fn set_transmit_client(&self, client: &'a dyn TransmitClient)

Set the transmit client, which will be called when transmissions complete.

Source

fn transmit_buffer( &self, tx_buffer: &'static mut [u8], tx_len: usize, ) -> Result<(), (ErrorCode, &'static mut [u8])>

Transmit a buffer of data.

If the transmission is not started successfully, this function will return Err() and no callback will be called.

Each byte in tx_buffer is a UART transfer word of 8 or fewer bits. The word width is determined by the UART configuration, truncating any more significant bits. E.g., 0x18f transmitted in 8N1 will be sent as 0x8f and in 7N1 will be sent as 0x0f. Clients that need to transfer 9-bit words should use Transmit::transmit_word.

Calling Transmit::transmit_buffer while there is an outstanding Transmit::transmit_buffer or Transmit::transmit_word operation will return ErrorCode::BUSY.

§Return values
  • Ok(()): The transmission started successfully. TransmitClient::transmitted_buffer 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 transmitting and has not made a transmission callback yet.
  • Err(SIZE) : tx_len is larger than the passed slice.
  • Err(FAIL): some other error.
Source

fn transmit_word(&self, word: u32) -> Result<(), ErrorCode>

Transmit a single word of data asynchronously.

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

If initiating the transmission failed, this function will return Err() and no callback will be made.

§Return values
  • Ok(()): The transmission started successfully. TransmitClient::transmitted_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 transmitting and has not made a transmission callback yet.
  • Err(FAIL): not supported, or some other error.
Source

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

Abort an outstanding call to transmit_word or transmit_buffer.

The return code indicates whether the call has fully terminated or there will be a callback. Cancelled calls to Transmit::transmit_buffer MUST always make a callback, to return the passed buffer back to the caller.

If this function returns Ok(()), there will be no future callback and the client may retransmit immediately. If this function returns any Err() there will be a callback. This means that if there is no outstanding call to Transmit::transmit_word or Transmit::transmit_buffer then a call to this function returns Ok(()).

§Return values
  • Ok(()): The cancel happened immediate and no callback will be generated.
  • Err(BUSY): There was a transmit operation outstanding and it was cancelled successfully. There will be an appropriate callback (based on the type of transmission) with a result of Err(CANCEL).
  • Err(FAIL): if the outstanding call to either transmit operation could not be synchronously cancelled. A callback will be made on the client indicating whether the call was successfully cancelled.

Implementors§