Trait kernel::hil::can::Controller

source ·
pub trait Controller {
    // Required methods
    fn set_client(&self, client: Option<&'static dyn ControllerClient>);
    fn enable(&self) -> Result<(), ErrorCode>;
    fn disable(&self) -> Result<(), ErrorCode>;
    fn get_state(&self) -> Result<State, ErrorCode>;
}
Expand description

The Controller trait is used to enable and disable the CAN peripheral. The enable process applies the settings that were previously provided to the driver using the Configure trait.

Required Methods§

source

fn set_client(&self, client: Option<&'static dyn ControllerClient>)

Set the client to be used for callbacks of the Controller implementation.

source

fn enable(&self) -> Result<(), ErrorCode>

This function enables the CAN peripheral with the Timing, Operation and Mode arguments that are provided to the driver before calling the enable function.

§Return values:
  • Ok() - The parameters were provided and the process can begin. The driver will call the state_changed and enabled callbacks after the process ends. Both of the callbacks must be called and the capsule should wait for the enable callback before transmitting or receiving frames, as enabling might fail with an error. While state_changed will report the device as being in State::Disabled, it does not report the error. A client cannot otherwise differentiate between a callback issued due to failed enable or a peripheral’s decision to enter a disabled state.
  • Err(ErrorCode) - Indicates the error because of which the request cannot be completed.
    • ErrorCode::BUSY - the peripheral was already enabled
    • ErrorCode::INVAL - no arguments were previously provided
source

fn disable(&self) -> Result<(), ErrorCode>

This function disables the CAN peripheral and puts it in Sleep Mode. The peripheral must be previously enabled.

§Return values:
  • Ok() - The peripheral was already enabled and the process can begin. The driver will call the state_changed and disabled callbacks after the process ends. Both of the callbacks must be called and the capsule should wait for the disabled callback before considering the peripheral disabled, as disabling might fail with an erro . While state_changed will report the device as being in State::Enabled, it does not report the error. A client cannot otherwise differentiate between a callback issued due to failed disable or a peripheral’s decision to enter the enable state.
  • Err(ErrorCode) - Indicates the error because of which the request cannot be completed.
    • ErrorCode::OFF - the peripheral was not previously enabled
source

fn get_state(&self) -> Result<State, ErrorCode>

This function returns the current state of the CAN peripheral.

§Return values:
  • Ok(State) - The state of the CAN peripheral if it is functional
  • Err(ErrorCode) - The driver cannot report the state of the peripheral if it is not functional.

Implementors§