Sample can-mcp2515 driver

The can-mcp2515 is a driver for the Microchip MCP2515 CAN Controller. It's available with full source code, which makes it a good example of the libcan driver.



You can find the source code at: https://gitlab.com/qnx/projects/drivers/can-mcp2515. The code is organized into the following directories:

lib

Contains code that interacts with the MCP2515 hardware using io-spi. Since this directory is hardware-specific, it's beyond the scope of this document.

driver

Contains code that uses the code in the lib directory to integrate with the libcan library.

This directory is organized into several source and header files:

command_line.h, command_line.c

  • Functions to parse the command line.

debug.h, debug.c

  • Functions to generate debug information in the logging sinks.

drv_state.h, drv_state.c

  • State information required by the driver to function.
  • Functions to initialize and clean up the state information.

rpi4.h, rpi4.c

  • RPI4 platform support.
  • Functions used to interact with GPIOs and associated IRQs.

version.h, version.c

  • Functions related to the version of the driver.

main.c

  • Entry point into the driver program; initializes the driver state and calls the execute() function from core.c.

core.h, core.c

  • Main logic of the driver (execute()), called from main().
  • Contains required callback functions, which include libcan_transmit_cb(), libcan_devctl_cb(), and libcan_event_handler_cb().
  • Hardware-specific initialization functions.
  • Contains libcan and CAN device configuration (configure_libcan(), configure_mcp2515()), initialization (go(), connect()), and cleanup (destroy_libcan(), disconnect()) functions.
  • Contains utility functions.
Page updated: