Struct MctpI2cHandler

Source
pub struct MctpI2cHandler { /* private fields */ }
Expand description

A handler for I2C MCTP

One instance should exist for each I2C bus with a MCTP transport.

Implementations§

Source§

impl MctpI2cHandler

Source

pub fn new( own_addr: u8, send_message: &'static mut Vec<u8, MAX_PAYLOAD>, ) -> Self

Constructs a new MctpI2cHandler.

Note that the heapless::Vec for fill_msg is the version specified by mctp-estack crate. The re-export mctp_estack::Vec can be used for API compatibility.

Source

pub fn receive<'f>( &mut self, packet: &[u8], mctp: &'f mut Stack, ) -> Result<Option<(MctpMessage<'f>, u8, ReceiveHandle)>>

Handles receiving an I2C target write

Expects to be passed a packet starting from the MCTP I2C header (first byte is destination address). buf should have the PEC byte removed, already checked by callers.

TODO: provide separate software PEC check function?

Source

pub fn is_send_ready(&self) -> bool

Indicates whether data is pending to send

Source

pub fn is_send_idle(&self) -> bool

Indicates whether the send queue is idle, ready for an application to enqueue a new message

Source

pub fn send_fill<'f>(&mut self, buf: &'f mut [u8]) -> SendOutput<'f>

Fill a buffer with a packet to send over the i2c bus.

The send_complete closure is called when an entire message completes sending. It is called with Some(Tag) on success (with the tag that was sent) or None on failure. The cookie is the one provided to send_enqueue.

Source

pub fn cancel_send(&mut self) -> Option<AppCookie>

Source

pub fn send_enqueue<F>( &mut self, eid: Eid, typ: MsgType, tag: Option<Tag>, ic: MsgIC, i2c_dest: u8, cookie: Option<AppCookie>, mctp: &mut Stack, fill_msg: F, ) -> Result<()>
where F: FnOnce(&mut Vec<u8, MAX_PAYLOAD>) -> Option<()>,

Provides a MCTP message to send.

The provided closure will fill out the message buffer, returning Some(()) on success. If the closure fails it returns None, and send_enqueue() will return mctp::Error::InvalidInput.

send_enqueue() must only be called when is_send_idle() is true. TODO fill_msg will take something that isn’t a Vec.

Note that the heapless::Vec for fill_msg is the version specified by mctp-estack crate. The re-export mctp_estack::Vec can be used for API compatibility.

Trait Implementations§

Source§

impl Debug for MctpI2cHandler

Source§

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

Formats the value using the given formatter. Read more

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.