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>
impl<Dm: DriverMode> CanFdTx<'_, Dm>
Sourcepub fn tx_buffer_count(&self) -> u8
pub fn tx_buffer_count(&self) -> u8
Returns the number of TX buffers the hardware provides.
Sourcepub fn transmit(&mut self, frame: &Frame) -> Result<u8, Error>
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.
Sourcepub fn tx_buffer_state(&self, index: u8) -> TxBufferState
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.
Sourcepub fn abort_transmit(&mut self, index: u8)
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.
Sourcepub fn release_tx_buffer(&mut self, index: u8)
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.
Sourcepub fn set_tx_priority(&mut self, index: u8, priority: u8)
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.
Sourcepub fn error_state(&self) -> ErrorState
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.
Sourcepub fn receive_error_count(&self) -> u16
pub fn receive_error_count(&self) -> u16
Returns the receive error counter.
Sourcepub fn transmit_error_count(&self) -> u16
pub fn transmit_error_count(&self) -> u16
Returns the transmit error counter.
Sourcepub fn request_bus_off_recovery(&mut self)
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>
impl CanFdTx<'_, Async>
Sourcepub async fn transmit_async(&mut self, frame: &Frame) -> Result<(), Error>
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.