1CANopenNode
2===========
3
4CANopenNode is free and open source CANopen Stack.
5
6CANopen is the internationally standardized (EN 50325-4)
7([CiA301](http://can-cia.org/standardization/technical-documents))
8CAN-based higher-layer protocol for embedded control system. For more
9information on CANopen see http://www.can-cia.org/
10
11CANopenNode is written in ANSI C in object-oriented way. It runs on
12different microcontrollers, as standalone application or with RTOS.
13Stack includes master functionalities. For Linux implementation with
14CANopen master functionalities see
15https://github.com/CANopenNode/CANopenSocket.
16
17Variables (communication, device, custom) are ordered in CANopen Object
18Dictionary and are accessible from both: C code and from CAN network.
19
20CANopenNode homepage is https://github.com/CANopenNode/CANopenNode
21
22
23CANopen Features
24----------------
25 - NMT slave to start, stop, reset device. Simple NMT master.
26 - Heartbeat producer/consumer error control.
27 - PDO linking and dynamic mapping for fast exchange of process variables.
28 - SDO expedited, segmented and block transfer for service access to all parameters.
29 - SDO master.
30 - Emergency message.
31 - Sync producer/consumer.
32 - Time protocol (producer/consumer).
33 - Non-volatile storage.
34 - LSS master and slave, LSS fastscan
35
36### RTR
37RTR (remote transmission request) is a feature of CAN bus. Usage of RTR
38is not recommended for CANopen and it is not implemented in CANopenNode.
39
40### Self start
41Object **0x1F80** from Object Dictionary enables the NMT slaves to start
42automatically or allows it to start the whole network. It is specified in
43DSP302-2 standard. Standard allows two values for slaves for object 0x1F80:
44- Object 0x1F80, value = **0x8** - "NMT slave shall enter the NMT state
45  Operational after the NMT state Initialization autonomously (self starting)"
46- Object 0x1F80, value = **0x2** - "NMT slave shall execute the NMT service
47  start remote node with node-ID set to 0"
48
49Note: When node is stated (in NMT operational state), it is allowed to send or
50receive Process Data Objects (PDO). If Error Register (object 0x1001) is set,
51then NMT operational state is not allowed.
52
53
54Usage of the CANopenNode
55------------------------
56CANopenNode itself doesn't have complete working code for any microcontroller.
57It is only the library with the stack It has example, which should compile
58on any system with template driver (drvTemplate), which actually doesn't
59access CAN hardware. CANopenNode should be used as a git submodule included
60in a project with specific hardware and specific application.
61
62
63Documentation, support and contributions
64----------------------------------------
65Code is documented in header files. Running [doxygen](http://www.doxygen.nl/)
66or `make doc` in project base folder will produce complete html documentation.
67Just open CANopenNode/doc/html/index.html in browser.
68
69Report issues on https://github.com/CANopenNode/CANopenNode/issues
70
71Older and still active discussion group is on Sourceforge
72http://sourceforge.net/p/canopennode/discussion/387151/
73
74For some implementations of CANopenNode on real hardware see
75[Device support](#device-support) section.
76[CANopenSocket](https://github.com/CANopenNode/CANopenSocket) is nice
77implementation for Linux devices. It includes command line interface for
78master access of the CANopen network. There is also some Getting started.
79
80Contributions are welcome. Best way to contribute your code is to fork
81a project, modify it and then send a pull request. Some basic formatting
82rules should be followed: Linux style with indentation of 4 spaces. There
83is also a configuration file for `clang-format` tool.
84
85
86Flowchart of a typical CANopenNode implementation
87-------------------------------------------------
88~~~
89                            -----------------------
90                           |     Program start     |
91                            -----------------------
92                                       |
93                            -----------------------
94                           |     CANopen init      |
95                            -----------------------
96                                       |
97                            -----------------------
98                           |     Start threads     |
99                            -----------------------
100                                 |     |     |
101             --------------------      |      --------------------
102            |                          |                          |
103 -----------------------    -----------------------    -----------------------
104| CAN receive thread    |  | Timer interval thread |  | Mainline thread       |
105|                       |  |                       |  |                       |
106| - Fast response.      |  | - Realtime thread with|  | - Processing of time  |
107| - Detect CAN ID.      |  |   constant interval,  |  |   consuming tasks     |
108| - Partially process   |  |   typically 1ms.      |  |   in CANopen objects: |
109|   messages and copy   |  | - Network synchronized|  |    - SDO server,      |
110|   data to target      |  | - Copy inputs (RPDOs, |  |    - Emergency,       |
111|   CANopen objects.    |  |   HW) to Object Dict. |  |    - Network state,   |
112|                       |  | - May call application|  |    - Heartbeat.       |
113|                       |  |   for some processing.|  | - May cyclically call |
114|                       |  | - Copy variables from |  |   application code.   |
115|                       |  |   Object Dictionary to|  |                       |
116|                       |  |   outputs (TPDOs, HW).|  |                       |
117 -----------------------    -----------------------    -----------------------
118
119              -----------------------
120             | SDO client (optional) |
121             |                       |
122             | - Can be called by    |
123             |   external application|
124             | - Can read or write   |
125             |   any variable from   |
126             |   Object Dictionary   |
127             |   from any node in the|
128             |   CANopen network.    |
129              -----------------------
130
131              -----------------------
132             | LSS client (optional) |
133             |                       |
134             | - Can be called by    |
135             |   external application|
136             | - Can do LSS requests |
137             | - Can request node    |
138             |   enumeration         |
139              -----------------------
140
141
142~~~
143
144
145File structure
146--------------
147 - **CANopen.h/.c** - Initialization and processing of CANopen objects. Most
148   usual implementation of CANopen device.
149 - **stack** - Directory with all CANopen objects in separate files.
150   - **CO_Emergency.h/.c** - CANopen Emergency object.
151   - **CO_NMT_Heartbeat.h/.c** - CANopen Network slave and Heartbeat producer object.
152   - **CO_HBconsumer.h/.c** - CANopen Heartbeat consumer object.
153   - **CO_LSS.h** - CANopen LSS common. This is common to LSS master and slave.
154   - **CO_LSSmaster.h/.c** - CANopen LSS master functionality.
155   - **CO_LSSslave.h/.c** - CANopen LSS slave functionality.
156   - **CO_SYNC.h/.c** - CANopen SYNC producer and consumer object.
157   - **CO_TIME.h/.c** - CANopen TIME protocol object.
158   - **CO_SDO.h/.c** - CANopen SDO server object. It serves data from Object dictionary.
159   - **CO_PDO.h/.c** - CANopen PDO object. It configures, receives and transmits CANopen process data.
160   - **CO_SDOmaster.h/.c** - CANopen SDO client object (master functionality).
161   - **CO_trace.h/.c** - Trace object with timestamp for monitoring variables from Object Dictionary (optional).
162   - **crc16-ccitt.h/.c** - CRC calculation object.
163   - **drvTemplate** - Directory with microcontroller specific files. In this
164     case it is template for new implementations. It is also documented, other
165     directories are not.
166     - **CO_driver.h/.c** - Microcontroller specific objects for CAN module.
167     - **eeprom.h/.c** - Functions for storage of Object dictionary, optional.
168     - **helpers.h/.c** - Some optional files with specific helper functions.
169   - **socketCAN** - Directory for Linux socketCAN interface.
170   - **PIC32** - Directory for PIC32 devices from Microchip.
171   - **PIC24_dsPIC33** - Directory for PIC24 and dsPIC33 devices from Microchip.
172   - **dsPIC30F** - Directory for dsPIC30F devices from Microchip.
173   - **eCos** - Directory for all devices supported by eCos RTOS.
174   - **SAM3X** - Directory for SAM3X ARM Cortex M3 devices with ASF library from Atmel.
175   - **STM32** - Directory for STM32 ARM devices from ST.
176   - **LPC177x_8x** - Directory for LPC177x (Cortex M3) devices with FreeRTOS from NXP.
177   - **MCF5282** - Directory for MCF5282 (ColdFire V2) device from Freescale.
178 - **codingStyle** - Description of the coding style.
179 - **Doxyfile** - Configuration file for the documentation generator *doxygen*.
180 - **Makefile** - Basic makefile.
181 - **LICENSE** - License.
182 - **README.md** - This file.
183 - **example** - Directory with basic example.
184   - **main.c** - Mainline and other threads - example template.
185   - **application.h/.c** - Separate file with some functions, which are
186     called from main.c. May be used for application specific code.
187   - **CO_OD.h/.c** - CANopen Object dictionary. Automatically generated files.
188   - **IO.eds** - Standard CANopen EDS file, which may be used from CANopen
189     configuration tool. Automatically generated file.
190   - _ **project.xml** - XML file contains all data for CANopen Object dictionary.
191     It is used by *Object dictionary editor* application, which generates other
192     files.
193   - _ **project.html** - *Object dictionary editor* launcher.
194
195
196### Object dictionary editor
197Object Dictionary is one of the most important parts of CANopen. Its
198implementation in CANopenNode is quite outdated and there are efforts to
199rewrite it. Anyway, currently it is fully operational and works well.
200
201To customize the Object Dictionary it is necessary to use the
202external application. There are two:
203 - [libedssharp](https://github.com/robincornelius/libedssharp) -
204   recommended, can be used with mono.
205 - [Object_Dictionary_Editor](http://sourceforge.net/p/canopennode/code_complete/) -
206   originally part of CANopenNode. It is still operational, but requiers
207   very old version of Firefox to run.
208
209
210Device support
211--------------
212CANopenNode can be implemented on many different devices. It is
213necessary to implement interface to specific hardware, so called 'driver'.
214Currently driver files are part of CANopenNode, but they will be split from
215it in the future.
216
217Most up to date information on device support can be found on
218[CANopenNode/wiki](https://github.com/CANopenNode/CANopenNode/wiki).
219
220
221### Note for contributors
222For the driver developers, who wish to share and cooperate, I recommend the following approach:
2231. Make own git repo for the Device specific demo project on the Github or somewhere.
2242. Add https://github.com/CANopenNode/CANopenNode into your project (or at side of your project).
225   For example, include it in your project as a git submodule:
226   `git submodule add https://github.com/CANopenNode/CANopenNode`
2273. Add specific driver and other files.
2284. **Add a note** about your specific implementation here on
229   [CANopenNode/wiki](https://github.com/CANopenNode/CANopenNode/wiki) with some
230   basic description and status. Write a note, even it has an Alpha status.
2315. Make a demo folder, which contains project files, etc., necessary to run the demo.
2326. Write a good README.md file, where you describe your project, specify demo board, tools used, etc.
233
234
235History of the project
236----------------------
237Project was initially hosted on http://sourceforge.net/projects/canopennode/
238It started in 2004 with PIC18F microcontrollers from Microchip.
239Fresh, cleaned repository of CANopenNode stack started on 25.7.2015.
240For older history see http://sourceforge.net/p/canopennode/code_complete/
241
242
243License
244-------
245Licensed under the Apache License, Version 2.0 (the "License");
246you may not use this file except in compliance with the License.
247You may obtain a copy of the License at
248
249http://www.apache.org/licenses/LICENSE-2.0
250
251Unless required by applicable law or agreed to in writing, software
252distributed under the License is distributed on an "AS IS" BASIS,
253WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
254See the License for the specific language governing permissions and
255limitations under the License.
256