Trait kernel::hil::uart::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>;
}

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. On completion, transmitted_buffer in the TransmitClient will be called. If the Result<(), ErrorCode> returned by transmit is an Ok(()), the struct will issue a transmitted_buffer callback in the future. If the value of the Result<(), ErrorCode> is Err(), then the tx_bufferargument is returned in theErr(), along with the ErrorCode. Valid ErrorCode` values are:

  • 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.
  • BUSY: the UART is already transmitting and has not made a transmission callback yet.
  • SIZE : tx_len is larger than the passed slice.
  • FAIL: some other error.

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_word.

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

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 the Result<(), ErrorCode> is Ok(()), on completion, transmitted_word will be called on the TransmitClient. Other valid Result<(), ErrorCode> values are:

  • 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.
  • BUSY: the UART is already transmitting and has not made a transmission callback yet.
  • FAIL: not supported, or some other error. If the Result<(), ErrorCode> is not Ok(()), no callback will be made. Calling transmit_word while there is an outstanding transmit_buffer or transmit_word operation will return BUSY.
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_buffer MUST always make a callback, to return the passed buffer back to the caller.

If abort_transmit returns Ok(()), there will be no future callback and the client may retransmit immediately. If abort_transmit returns any other Result<(), ErrorCode> there will be a callback. This means that if there is no outstanding call to transmit_word or transmit_buffer then a call to abort_transmit returns Ok(()). If there was a transmit outstanding and is cancelled successfully then BUSY will be returned and there will be a callback with a Result<(), ErrorCode> of CANCEL. If there was a reception outstanding, which is not cancelled successfully, then FAIL will be returned and there will be a later callback.

Returns Ok(()) or

  • 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§