libcan integration

The sample driver implements the following required callbacks, as discussed in the "Implementing the required callbacks" section:

libcan_transmit_cb()
  • Removes a message element from the device's msg_queue.
  • Calls the hardware-specific mcp2515_cmd_tx_can_message() function to send the message.
  • Adds the message element to the device's free_queue.
libcan_devctl_cb()
libcan_event_handler_cb()
  • Verifies that an interrupt was triggered by a device.
  • Checks the status of each receive mailbox. If the message finds the interrupt, it:
    • Removes the free message element from the device's free_queue, or if not available, drops a message from the active queue by removing the oldest message element from the device's msg_queue.
    • Calls the hardware-specific mcp2515_cmd_rx_can_message() function to populate the message element data.
    • Adds the message element to the device's msg_queue.
  • Checks the status of each transmit mailbox to verify that message transmission is complete and clears the in-use flag.
  • Clears the GPIO interrupts and unmasks the interrupt.

Once implemented, the driver must use the can_resmgr_*() functions to integrate with libcan. The driver uses execute() to perform driver integration. It:

  1. Parses the command line and sets the driver options and connects to the hardware.

  2. Configures libcan by specifying the callback functions, calling can_resmgr_init() once, and calling can_resmgr_init_device() for each hardware RX and TX device.

  3. Configures the hardware board and each hardware device using hardware-specific functions.

  4. Initializes libcan by calling can_resmgr_create_device() once for every RX and TX hardware device, and can_resmgr_attach_intr() to set up the hardware interrupt handler.

  5. Starts the resource manager by calling can_resmgr_start() and blocks until the function exits when the driver is terminated by the SIGTERM signal.

  6. Cleans up libcan by calling can_resmgr_detach_intr(), can_resmgr_destroy_device() for each RX and TX hardware device, and finally can_resmgr_fini().

  7. Uses hardware-specific functions to clean up and disconnect from the hardware.

Page updated: