Skip to content

Commit 9c04d69

Browse files
authored
Merge branch 'master' into add-nmt-callback
2 parents 260cbc5 + 895e2f6 commit 9c04d69

14 files changed

+119
-6
lines changed

CANopen.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
be generated with calloc(). */
5353
/* #define CO_USE_GLOBALS */
5454

55+
/* If defined, the user provides an own implemetation for calculating the
56+
* CRC16 CCITT checksum. */
57+
/* #define CO_USE_OWN_CRC16 */
5558

5659
#ifndef CO_USE_GLOBALS
5760
#include <stdlib.h> /* for malloc, free */
@@ -349,7 +352,11 @@ CO_ReturnError_t CO_init(
349352
CO_CANsetConfigurationMode(CANbaseAddress);
350353

351354
/* Verify CANopen Node-ID */
352-
if(nodeId<1 || nodeId>127) nodeId = 0x10;
355+
if(nodeId<1 || nodeId>127)
356+
{
357+
CO_delete(CANbaseAddress);
358+
return CO_ERROR_PARAMETERS;
359+
}
353360

354361

355362
err = CO_CANmodule_init(

CANopen.h

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
#ifndef CANopen_H
5555
#define CANopen_H
5656

57+
#ifdef __cplusplus
58+
extern "C" {
59+
#endif
5760

5861
/**
5962
* @defgroup CO_CANopen CANopen stack
@@ -239,6 +242,9 @@ void CO_process_TPDO(
239242
bool_t syncWas,
240243
uint32_t timeDifference_us);
241244

245+
#ifdef __cplusplus
246+
}
247+
#endif /*__cplusplus*/
242248

243249
/** @} */
244250
#endif

stack/CO_Emergency.h

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#ifndef CO_EMERGENCY_H
4848
#define CO_EMERGENCY_H
4949

50+
#ifdef __cplusplus
51+
extern "C" {
52+
#endif
5053

5154
/**
5255
* @defgroup CO_Emergency Emergency
@@ -421,5 +424,9 @@ void CO_EM_process(
421424

422425
#endif
423426

427+
#ifdef __cplusplus
428+
}
429+
#endif /*__cplusplus*/
430+
424431
/** @} */
425432
#endif

stack/CO_HBconsumer.h

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#ifndef CO_HB_CONS_H
4848
#define CO_HB_CONS_H
4949

50+
#ifdef __cplusplus
51+
extern "C" {
52+
#endif
5053

5154
/**
5255
* @defgroup CO_HBconsumer Heartbeat consumer
@@ -140,6 +143,9 @@ void CO_HBconsumer_process(
140143
bool_t NMTisPreOrOperational,
141144
uint16_t timeDifference_ms);
142145

146+
#ifdef __cplusplus
147+
}
148+
#endif /*__cplusplus*/
143149

144150
/** @} */
145151
#endif

stack/CO_NMT_Heartbeat.h

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#ifndef CO_NMT_HEARTBEAT_H
4848
#define CO_NMT_HEARTBEAT_H
4949

50+
#ifdef __cplusplus
51+
extern "C" {
52+
#endif
5053

5154
/**
5255
* @defgroup CO_NMT_Heartbeat NMT and Heartbeat
@@ -254,6 +257,7 @@ CO_NMT_reset_cmd_t CO_NMT_process(
254257
const uint8_t errorBehavior[],
255258
uint16_t *timerNext_ms);
256259

260+
257261
/**
258262
* Query current NMT state
259263
*
@@ -265,5 +269,9 @@ CO_NMT_internalState_t CO_NMT_getInternalState(
265269
CO_NMT_t *NMT);
266270

267271

272+
#ifdef __cplusplus
273+
}
274+
#endif /*__cplusplus*/
275+
268276
/** @} */
269277
#endif

stack/CO_PDO.h

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#ifndef CO_PDO_H
4848
#define CO_PDO_H
4949

50+
#ifdef __cplusplus
51+
extern "C" {
52+
#endif
5053

5154
/**
5255
* @defgroup CO_PDO PDO
@@ -395,6 +398,9 @@ void CO_TPDO_process(
395398
bool_t syncWas,
396399
uint32_t timeDifference_us);
397400

401+
#ifdef __cplusplus
402+
}
403+
#endif /*__cplusplus*/
398404

399405
/** @} */
400406
#endif

stack/CO_SDO.h

+36-5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#ifndef CO_SDO_H
4848
#define CO_SDO_H
4949

50+
#ifdef __cplusplus
51+
extern "C" {
52+
#endif
5053

5154
/**
5255
* @defgroup CO_SDO SDO server
@@ -256,17 +259,42 @@ typedef enum{
256259
*
257260
*
258261
* Function CO_SDO_init() initializes object CO_SDO_t, which includes SDO
259-
* server and Object dictionary. Interface to Object dictionary is provided by
260-
* following functions: CO_OD_find() finds OD entry by index, CO_OD_getLength()
261-
* returns length of variable, CO_OD_getAttribute returns attribute and
262-
* CO_OD_getDataPointer() returns pointer to data. These functions are used by
263-
* SDO server and by PDO configuration.
262+
* server and Object dictionary.
264263
*
265264
* Application doesn't need to know anything about the Object dictionary. It can
266265
* use variables specified in CO_OD.h file directly. If it needs more control
267266
* over the CANopen communication with the variables, it can configure additional
268267
* functionality with function CO_OD_configure(). Additional functionality
269268
* include: @ref CO_SDO_OD_function and #CO_SDO_OD_flags_t.
269+
*
270+
* Interface to Object dictionary is provided by following functions: CO_OD_find()
271+
* finds OD entry by index, CO_OD_getLength() returns length of variable,
272+
* CO_OD_getAttribute returns attribute and CO_OD_getDataPointer() returns pointer
273+
* to data. These functions are used by SDO server and by PDO configuration. They
274+
* can also be used to access the OD by index like this.
275+
*
276+
* \code{.c}
277+
* index = CO_OD_find(CO->SDO[0], OD_H1001_ERR_REG);
278+
* if (index == 0xffff) {
279+
* return;
280+
* }
281+
* length = CO_OD_getLength(CO->SDO[0], index, 1);
282+
* if (length != sizeof(new_data)) {
283+
* return;
284+
* }
285+
*
286+
* p = CO_OD_getDataPointer(CO->SDO[0], index, 1);
287+
* if (p == NULL) {
288+
* return;
289+
* }
290+
* CO_LOCK_OD();
291+
* *p = new_data;
292+
* CO_UNLOCK_OD();
293+
* \endcode
294+
*
295+
* Be aware that accessing the OD directly using CO_OD.h files is more CPU
296+
* efficient as CO_OD_find() has to do a search everytime it is called.
297+
*
270298
*/
271299

272300

@@ -930,6 +958,9 @@ uint32_t CO_SDO_readOD(CO_SDO_t *SDO, uint16_t SDOBufferSize);
930958
*/
931959
uint32_t CO_SDO_writeOD(CO_SDO_t *SDO, uint16_t length);
932960

961+
#ifdef __cplusplus
962+
}
963+
#endif /*__cplusplus*/
933964

934965
/** @} */
935966
#endif

stack/CO_SDOmaster.h

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
#ifndef CO_SDO_CLIENT_H
4949
#define CO_SDO_CLIENT_H
5050

51+
#ifdef __cplusplus
52+
extern "C" {
53+
#endif
5154

5255
/**
5356
* @defgroup CO_SDOmaster SDO client
@@ -356,6 +359,9 @@ CO_SDOclient_return_t CO_SDOclientUpload(
356359
*/
357360
void CO_SDOclientClose(CO_SDOclient_t *SDO_C);
358361

362+
#ifdef __cplusplus
363+
}
364+
#endif /*__cplusplus*/
359365

360366
/** @} */
361367
#endif

stack/CO_SYNC.h

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#ifndef CO_SYNC_H
4848
#define CO_SYNC_H
4949

50+
#ifdef __cplusplus
51+
extern "C" {
52+
#endif
5053

5154
/**
5255
* @defgroup CO_SYNC SYNC
@@ -173,6 +176,9 @@ uint8_t CO_SYNC_process(
173176
uint32_t timeDifference_us,
174177
uint32_t ObjDict_synchronousWindowLength);
175178

179+
#ifdef __cplusplus
180+
}
181+
#endif /*__cplusplus*/
176182

177183
/** @} */
178184
#endif

stack/CO_trace.h

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#ifndef CO_TRACE_H
4848
#define CO_TRACE_H
4949

50+
#ifdef __cplusplus
51+
extern "C" {
52+
#endif
5053

5154
#include "CO_driver.h"
5255
#include "CO_SDO.h"
@@ -180,6 +183,9 @@ void CO_trace_init(
180183
*/
181184
void CO_trace_process(CO_trace_t *trace, uint32_t timestamp);
182185

186+
#ifdef __cplusplus
187+
}
188+
#endif /*__cplusplus*/
183189

184190
/** @} */
185191
#endif

stack/crc16-ccitt.c

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* to do so, delete this exception statement from your version.
4444
*/
4545

46+
#ifndef CO_USE_OWN_CRC16
4647

4748
#include "crc16-ccitt.h"
4849

@@ -114,3 +115,5 @@ unsigned short crc16_ccitt(
114115
}
115116
return crc;
116117
}
118+
119+
#endif /* CO_USE_OWN_CRC16 */

stack/crc16-ccitt.h

+9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
#ifndef CRC16_CCITT_H
4949
#define CRC16_CCITT_H
5050

51+
#ifdef __cplusplus
52+
extern "C" {
53+
#endif
5154

5255
/**
5356
* @defgroup CO_crc16_ccitt CRC 16 CCITT
@@ -72,11 +75,17 @@
7275
*
7376
* @return Calculated CRC.
7477
*/
78+
#ifdef CO_USE_OWN_CRC16
79+
extern
80+
#endif
7581
unsigned short crc16_ccitt(
7682
const unsigned char block[],
7783
unsigned int blockLength,
7884
unsigned short crc);
7985

86+
#ifdef __cplusplus
87+
}
88+
#endif /*__cplusplus*/
8089

8190
/** @} */
8291
#endif

stack/drvTemplate/CO_driver.h

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
#ifndef CO_DRIVER_H
5050
#define CO_DRIVER_H
5151

52+
#ifdef __cplusplus
53+
extern "C" {
54+
#endif
5255

5356
/* Include processor header file */
5457
#include <stddef.h> /* for 'NULL' */
@@ -460,6 +463,9 @@ void CO_CANverifyErrors(CO_CANmodule_t *CANmodule);
460463
*/
461464
void CO_CANinterrupt(CO_CANmodule_t *CANmodule);
462465

466+
#ifdef __cplusplus
467+
}
468+
#endif /*__cplusplus*/
463469

464470
/** @} */
465471
#endif

stack/drvTemplate/eeprom.h

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
#ifndef EEPROM_H
5050
#define EEPROM_H
5151

52+
#ifdef __cplusplus
53+
extern "C" {
54+
#endif
5255

5356
/**
5457
* @defgroup CO_eeprom Nonvolatile storage
@@ -117,6 +120,9 @@ void CO_EE_init_2(
117120
*/
118121
void CO_EE_process(CO_EE_t *ee);
119122

123+
#ifdef __cplusplus
124+
}
125+
#endif /*__cplusplus*/
120126

121127
/** @} */
122128
#endif

0 commit comments

Comments
 (0)