Skip to main content

CanFdTx

Struct CanFdTx 

Source
pub struct CanFdTx<'a, Dm: DriverMode> { /* private fields */ }
Expand description

Transmitting half of a split controller.

See CanFd::split.

Implementations§

Source§

impl<Dm: DriverMode> CanFdTx<'_, Dm>

Source

pub fn tx_buffer_count(&self) -> u8

Returns the number of TX buffers the hardware provides.

Source

pub fn transmit(&mut self, frame: &Frame) -> Result<u8, Error>

Queues a frame in the first free TX buffer and arms it.

Returns the index of the buffer used. Up to CanFdTx::tx_buffer_count frames can be queued at once.

The hardware picks the next frame to send among the armed buffers by priority, and among equal priorities by the lower buffer index; see CanFdTx::set_tx_priority. The order in which frames were queued plays no part in that choice. With equal priorities a frame queued into a buffer that a finished frame freed up is sent before frames still waiting in higher-numbered buffers. To keep frames in the order they were queued, wait for each buffer to leave TxBufferState::Ready before queueing the next frame, or give later frames lower priorities.

§Errors

Error::ControllerStopped when the controller is not on the bus. A stopped controller ignores the command that arms a buffer, so the frame would be lost.

Error::NoFreeTxBuffer when every TX buffer is occupied.

Source

pub fn tx_buffer_state(&self, index: u8) -> TxBufferState

Returns the state of one TX buffer.

Returns TxBufferState::NotExist for an index the hardware does not have.

Source

pub fn abort_transmit(&mut self, index: u8)

Requests that a queued transmission be aborted.

Does nothing for an index the hardware does not have.

Source

pub fn release_tx_buffer(&mut self, index: u8)

Returns a TX buffer to the empty state, releasing it for reuse.

Does nothing for an index the hardware does not have.

Source

pub fn set_tx_priority(&mut self, index: u8, priority: u8)

Sets a TX buffer’s arbitration priority.

Higher values win. Equal priorities are resolved in favor of the lower buffer index (TRM 38.3.8.1). A value above MAX_TX_PRIORITY counts as that maximum. Does nothing for an index the hardware does not have.

The priority belongs to the buffer, not to the frame in it, and all buffers start out equal. Set it before arming the buffer with CanFdTx::transmit, or right after, while the frame is still TxBufferState::Ready.

Source

pub fn error_state(&self) -> ErrorState

Returns the current fault confinement state; see CanFd::error_state.

On bus-off every armed TX buffer fails, so a transmission that ends in Error::TransmitFailed can be told apart from an exhausted retransmission limit here.

Source

pub fn receive_error_count(&self) -> u16

Returns the receive error counter.

Source

pub fn transmit_error_count(&self) -> u16

Returns the transmit error counter.

Source

pub fn request_bus_off_recovery(&mut self)

Requests that a bus-off controller rejoin the bus.

Does nothing unless the controller is bus-off. Rejoining takes 128 occurrences of 11 recessive bits, as ISO 11898-1 requires. Leaving the bus with CanFd::stop and joining it again with CanFd::start also clears the bus-off state, after ordinary integration.

The state is checked here because the hardware remembers a request made while error-active and then rejoins on its own the next time it goes bus-off (measured on an ESP32-C5; TRM register 38.3 says otherwise).

Source§

impl CanFdTx<'_, Async>

Source

pub async fn transmit_async(&mut self, frame: &Frame) -> Result<(), Error>

Queues a frame and waits until the hardware finishes with it.

§Errors

Error::ControllerStopped when the controller is not on the bus, and Error::NoFreeTxBuffer when every TX buffer is occupied; see CanFdTx::transmit.

Error::TransmitFailed when the controller gave up on the frame.

Error::TransmitAborted when the transmission was aborted.

§Cancellation Safety

This future is not cancel-safe. Dropping it leaves the frame queued, and the hardware may still transmit it.

Trait Implementations§

Source§

impl<Dm: DriverMode> Debug for CanFdTx<'_, Dm>

Available on crate feature unstable only.
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, Dm> !RefUnwindSafe for CanFdTx<'a, Dm>

§

impl<'a, Dm> !UnwindSafe for CanFdTx<'a, Dm>

§

impl<'a, Dm> Freeze for CanFdTx<'a, Dm>
where PhantomData<Dm>: Freeze,

§

impl<'a, Dm> Send for CanFdTx<'a, Dm>
where PhantomData<Dm>: Send,

§

impl<'a, Dm> Sync for CanFdTx<'a, Dm>
where PhantomData<Dm>: Sync,

§

impl<'a, Dm> Unpin for CanFdTx<'a, Dm>
where PhantomData<Dm>: Unpin,

§

impl<'a, Dm> UnsafeUnpin for CanFdTx<'a, Dm>
where PhantomData<Dm>: UnsafeUnpin,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> Same for T

Source§

type Output = T

Should always be Self
§

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

§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.