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.
- libcan_devctl_cb()
- Provides support for the following commands:
- For RX nodes, provides support for the following commands using default libcan functionality:
- For TX nodes, provides support for the following commands using default libcan functionality:
- Allows libcan to handle all other commands, either by using default functionality or reporting them as not supported.
- 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:
Parses the command line and sets the driver options and connects to the hardware.
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.
Configures the hardware board and each hardware device using hardware-specific functions.
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.
Starts the resource manager by calling can_resmgr_start() and blocks until the function exits when the driver is terminated by the SIGTERM signal.
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().
Uses hardware-specific functions to clean up and disconnect from the hardware.
