Module capsules_extra::can

source ·
Expand description

Syscall driver capsule for CAN communication.

This module has a CAN syscall driver capsule implementation.

This capsule sends commands from the userspace to a driver that implements the Can trait.

The capsule shares 2 buffers with the userspace: one RO that is used for transmitting messages and one RW that is used for receiving messages.

The RO buffer uses the first 4 bytes as a counter of how many messages the userspace must read, at the time the upcall was sent. If the userspace is slower and in the meantime there were other messages that were received, the userspace reads them all and sends to the capsule a new buffer that has the counter on the first 4 bytes 0. Because of that, when receiving a callback from the driver regarding a received message, the capsule checks the counter:

  • if it’s 0, the message will be copied to the RW buffer, the counter will be incremented and an upcall will be sent
  • if it’s greater the 0, the message will be copied to the RW buffer but no upcall will be done

§Usage

You need a driver that implements the Can trait.

let grant_cap = create_capability!(capabilities::MemoryAllocationCapability);
let grant_can = self.board_kernel.create_grant(
    capsules::can::CanCapsule::DRIVER_NUM, &grant_cap);
let can = capsules::can::CanCapsule::new(
   can_peripheral,
   grant_can,
   tx_buffer,
   rx_buffer,
);

kernel::hil::can::Controller::set_client(can_peripheral, Some(can));
kernel::hil::can::Transmit::set_client(can_peripheral, Some(can));
kernel::hil::can::Receive::set_client(can_peripheral, Some(can));

Structs§

Constants§