CANopenNode is free and open source CANopen protocol stack.
CANopen is the internationally standardized (EN 50325-4) (CiA301) higher-layer protocol for embedded control system built on top of CAN. For more information on CANopen see http://www.can-cia.org/
CANopenNode is written in ANSI C in object-oriented way. It runs on different microcontrollers, as standalone application or with RTOS.
Variables (communication, device, custom) are collected in CANopen Object Dictionary and are accessible from both: C code and from CANopen network.
CANopenNode homepage is https://github.com/CANopenNode/CANopenNode
This is version 4 of CANopenNode with new Object Dictionary implementation. For older versions git checkout branches v1.3-master or v2.0-master.
All code is documented in the source header files. Some additional documents are in doc directory.
To generate complete html documentation, run doxygen in the project base directory: sudo apt install doxygen graphviz pdf2svg; doxygen > /dev/null
Complete generated documentation is also available online: https://canopennode.github.io
Tutorial, demo device and tests are available in CANopenDemo repository.
Report issues on https://github.com/CANopenNode/CANopenNode/issues
Contributions are welcome. Best way to contribute your code is to fork a project, modify it and then send a pull request. Please follow the Recommended C style and coding rules, use .clang-format file for automatic code formatting.
The CANopenNode files conform to the MISRA C:2012 guidelines, with some noted exceptions, as indicated in MISRA.md.
Flowchart of a typical CANopenNode implementation:
-----------------------
| Program start |
-----------------------
|
-----------------------
| CANopen init |
-----------------------
|
-----------------------
| Start threads |
-----------------------
| | |
-------------------- | --------------------
| | |
---------------------- ------------------------ -----------------------
| CAN receive thread | | Timer interval thread | | Mainline thread |
| | | | | |
| - Fast response. | | - Realtime thread with | | - Processing of time |
| - Detect CAN ID. | | constant interval, | | consuming tasks |
| - Partially process | | typically 1ms. | | in CANopen objects: |
| messages and copy | | - Network synchronized | | - SDO server, |
| data to target | | - Copy inputs (RPDOs, | | - Emergency, |
| CANopen objects. | | HW) to Object Dict. | | - Network state, |
| | | - May call application | | - Heartbeat. |
| | | for some processing. | | - LSS slave |
| | | - Copy variables from | | - Gateway (optional): |
| | | Object Dictionary to | | - NMT master |
| | | outputs (TPDOs, HW). | | - SDO client |
| | | | | - LSS master |
| | | | | - May cyclically call |
| | | | | application code. |
---------------------- ------------------------ -----------------------
All code of the CANopenNode is non-blocking. Code in source files is collected into objects. Parts of the code can be enabled/disabled, so only files and parts of code can be used, which are required for the project. See stack configuration in 301/CO_config.h file.
For most efficiency code can run in different thread as seen in above flowchart. This is suitable for microcontrollers. It is also possible to run everything from single thread, as available on Linux devices. Code includes mechanisms, which triggers processing of OD objects when necessary.
In CANopen initialization section all CANopen objects are initialized. In run time CANopen objects are processed cyclically.
Files CANopen.h and CANopen.c is a joint of all CANopen objects. It may seems complex, but offers some flexibility and is suitable for most common configurations of the CANopen objects. CANopen objects can be defined in global space or can be dynamically allocated. Object dictionary can be used default (OD.h/.c files), but configuration with multiple object dictionaries is also possible by using the #CO_config_t structure. CANopen.h and CANopen.c files can also be only a reference for more customized implementation of CANopenNode based device.
Object Dictionary is a collection of all network accessible variables and offers most flexible usage. OD variables can be initialized by object dictionary or application can specify own read/write access functions for specific OD variables. Groups of OD variables are also able to be stored to non-volatile memory, either on command or automatically.
$ claude mcp add CANopenNode \
-- python -m otcore.mcp_server <graph>