RxWithInterrupt

Struct RxWithInterrupt 

Source
pub struct RxWithInterrupt(/* private fields */);
Expand description

Serial receiver, using interrupts to offload reading to the hardware.

You can use Rx::into_rx_with_irq to convert a normal Rx structure into this structure. This structure provides two distinct ways to read the UART RX using interrupts. It should be noted that the interrupt service routine (ISR) still has to be provided by the user. However, this structure provides API calls which can be used inside the ISRs to simplify the reading of the UART.

  1. The first way simply empties the FIFO on an interrupt into a user provided buffer. You can simply use Self::start to prepare the peripheral and then call the Self::on_interrupt in the interrupt service routine.
  2. The second way reads packets bounded by a maximum size or a baudtick based timeout. You can use Self::read_fixed_len_or_timeout_based_using_irq to prepare the peripheral and then call the Self::on_interrupt_max_size_or_timeout_based in the interrupt service routine. You have to call Self::read_fixed_len_or_timeout_based_using_irq in the ISR to start reading the next packet.

Implementations§

Source§

impl RxWithInterrupt

Source

pub fn new(rx: Rx) -> Self

Source

pub fn start(&mut self)

This function should be called once at initialization time if the regular Self::on_interrupt is used to read the UART receiver to enable and start the receiver.

Source

pub fn rx(&self) -> &Rx

Source

pub fn read_fixed_len_or_timeout_based_using_irq( &mut self, context: &mut InterruptContextTimeoutOrMaxSize, ) -> Result<(), TransferPendingError>

This function is used together with the Self::on_interrupt_max_size_or_timeout_based function to read packets with a maximum size or variable sized packets by using the receive timeout of the hardware.

This function should be called once at initialization to initiate the context state and to Self::start the receiver. After that, it should be called after each completed Self::on_interrupt_max_size_or_timeout_based call to restart the reception of a packet.

Source

pub fn cancel_transfer(&mut self)

Source

pub fn on_interrupt(&mut self, buf: &mut [u8; 16]) -> InterruptResult

This function should be called in the user provided UART interrupt handler.

It simply empties any bytes in the FIFO into the user provided buffer and returns the result of the operation.

This function will not disable the RX interrupts, so you don’t need to call any other API after calling this function to continue emptying the FIFO. RX errors are handled as partial errors and are returned as part of the InterruptResult.

Source

pub fn on_interrupt_max_size_or_timeout_based( &mut self, context: &mut InterruptContextTimeoutOrMaxSize, buf: &mut [u8], ) -> Result<InterruptResultMaxSizeOrTimeout, BufferTooShortError>

This function should be called in the user provided UART interrupt handler.

This function is used to read packets which either have a maximum size or variable sized packet which are bounded by sufficient delays between them, triggering a hardware timeout.

If either the maximum number of packets have been read or a timeout occured, the transfer will be deemed completed. The state information of the transfer is tracked in the InterruptContextTimeoutOrMaxSize structure.

If passed buffer is equal to or larger than the specified maximum length, an BufferTooShortError will be returned. Other RX errors are treated as partial errors and returned inside the InterruptResultMaxSizeOrTimeout structure.

Source

pub unsafe fn release(self) -> Rx

§Safety

This API allows creating multiple UART instances when releasing the TX structure as well. The user must ensure that these instances are not used to create multiple overlapping UART drivers.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.