Go to the documentation of this file.
29 #ifndef CO_DRIVER_TARGET_H
30 #define CO_DRIVER_TARGET_H
40 #ifndef CO_SINGLE_THREAD
43 #include <linux/can.h>
45 #include <sys/epoll.h>
47 #ifdef CO_DRIVER_CUSTOM
48 #include "CO_driver_custom.h"
57 #define CO_CONFIG_HB_CONS (0)
58 #define CO_CONFIG_TIME (0)
59 #define CO_CONFIG_SYNC (0)
60 #define CO_CONFIG_PDO (0)
61 #define CO_CONFIG_TRACE (0)
66 #ifdef CO_SINGLE_THREAD
67 #define CO_CONFIG_FLAG_CALLBACK_PRE_USED 0
69 #define CO_CONFIG_FLAG_CALLBACK_PRE_USED CO_CONFIG_FLAG_CALLBACK_PRE
73 #define CO_CONFIG_NMT (CO_CONFIG_NMT_CALLBACK_CHANGE | \
74 CO_CONFIG_NMT_MASTER | \
75 CO_CONFIG_FLAG_CALLBACK_PRE_USED | \
76 CO_CONFIG_FLAG_TIMERNEXT)
79 #ifndef CO_CONFIG_HB_CONS
80 #define CO_CONFIG_HB_CONS (CO_CONFIG_HB_CONS_ENABLE | \
81 CO_CONFIG_HB_CONS_CALLBACK_CHANGE | \
82 CO_CONFIG_FLAG_CALLBACK_PRE_USED | \
83 CO_CONFIG_FLAG_TIMERNEXT)
87 #define CO_CONFIG_EM (CO_CONFIG_EM_PRODUCER | \
88 CO_CONFIG_EM_PROD_CONFIGURABLE | \
89 CO_CONFIG_EM_PROD_INHIBIT | \
90 CO_CONFIG_EM_HISTORY | \
91 CO_CONFIG_EM_STATUS_BITS | \
92 CO_CONFIG_EM_CONSUMER | \
93 CO_CONFIG_FLAG_CALLBACK_PRE_USED | \
94 CO_CONFIG_FLAG_TIMERNEXT)
97 #ifndef CO_CONFIG_SDO_SRV
98 #define CO_CONFIG_SDO_SRV (CO_CONFIG_SDO_SRV_SEGMENTED | \
99 CO_CONFIG_SDO_SRV_BLOCK | \
100 CO_CONFIG_FLAG_CALLBACK_PRE_USED | \
101 CO_CONFIG_FLAG_TIMERNEXT | \
102 CO_CONFIG_FLAG_OD_DYNAMIC)
105 #ifndef CO_CONFIG_SDO_SRV_BUFFER_SIZE
106 #define CO_CONFIG_SDO_SRV_BUFFER_SIZE 900
109 #ifndef CO_CONFIG_SDO_CLI
110 #define CO_CONFIG_SDO_CLI (CO_CONFIG_SDO_CLI_ENABLE | \
111 CO_CONFIG_SDO_CLI_SEGMENTED | \
112 CO_CONFIG_SDO_CLI_BLOCK | \
113 CO_CONFIG_SDO_CLI_LOCAL | \
114 CO_CONFIG_FLAG_CALLBACK_PRE_USED | \
115 CO_CONFIG_FLAG_TIMERNEXT | \
116 CO_CONFIG_FLAG_OD_DYNAMIC)
119 #ifndef CO_CONFIG_TIME
120 #define CO_CONFIG_TIME (CO_CONFIG_TIME_ENABLE | \
121 CO_CONFIG_TIME_PRODUCER | \
122 CO_CONFIG_FLAG_CALLBACK_PRE_USED)
125 #ifndef CO_CONFIG_SYNC
126 #define CO_CONFIG_SYNC (CO_CONFIG_SYNC_ENABLE | \
127 CO_CONFIG_SYNC_PRODUCER | \
128 CO_CONFIG_FLAG_CALLBACK_PRE_USED | \
129 CO_CONFIG_FLAG_TIMERNEXT)
132 #ifndef CO_CONFIG_PDO
133 #define CO_CONFIG_PDO (CO_CONFIG_RPDO_ENABLE | \
134 CO_CONFIG_TPDO_ENABLE | \
135 CO_CONFIG_PDO_SYNC_ENABLE | \
136 CO_CONFIG_RPDO_CALLS_EXTENSION | \
137 CO_CONFIG_TPDO_CALLS_EXTENSION | \
138 CO_CONFIG_FLAG_CALLBACK_PRE_USED | \
139 CO_CONFIG_FLAG_TIMERNEXT)
142 #ifndef CO_CONFIG_LEDS
143 #define CO_CONFIG_LEDS (CO_CONFIG_LEDS_ENABLE | \
144 CO_CONFIG_FLAG_TIMERNEXT)
147 #ifndef CO_CONFIG_LSS
148 #define CO_CONFIG_LSS (CO_CONFIG_LSS_SLAVE | \
149 CO_CONFIG_LSS_SLAVE_FASTSCAN_DIRECT_RESPOND | \
150 CO_CONFIG_LSS_MASTER | \
151 CO_CONFIG_FLAG_CALLBACK_PRE_USED)
154 #ifndef CO_CONFIG_GTW
155 #define CO_CONFIG_GTW (CO_CONFIG_GTW_ASCII | \
156 CO_CONFIG_GTW_ASCII_SDO | \
157 CO_CONFIG_GTW_ASCII_NMT | \
158 CO_CONFIG_GTW_ASCII_LSS | \
159 CO_CONFIG_GTW_ASCII_LOG | \
160 CO_CONFIG_GTW_ASCII_ERROR_DESC | \
161 CO_CONFIG_GTW_ASCII_PRINT_HELP | \
162 CO_CONFIG_GTW_ASCII_PRINT_LEDS)
163 #define CO_CONFIG_GTW_BLOCK_DL_LOOP 3
164 #define CO_CONFIG_GTWA_COMM_BUF_SIZE 2000
165 #define CO_CONFIG_GTWA_LOG_BUF_SIZE 10000
168 #ifndef CO_CONFIG_CRC16
169 #define CO_CONFIG_CRC16 (CO_CONFIG_CRC16_ENABLE)
172 #ifndef CO_CONFIG_FIFO
173 #define CO_CONFIG_FIFO (CO_CONFIG_FIFO_ENABLE | \
174 CO_CONFIG_FIFO_ALT_READ | \
175 CO_CONFIG_FIFO_CRC16_CCITT | \
176 CO_CONFIG_FIFO_ASCII_COMMANDS | \
177 CO_CONFIG_FIFO_ASCII_DATATYPES)
180 #ifndef CO_CONFIG_TRACE
181 #define CO_CONFIG_TRACE (CO_CONFIG_TRACE_ENABLE)
186 #if (CO_CONFIG_DEBUG) & CO_CONFIG_DEBUG_COMMON
189 #define CO_DEBUG_COMMON(msg) log_printf(LOG_DEBUG, DBG_CO_DEBUG, msg);
202 #define CO_errinfo(CANmodule, err) CANmodule->errinfo = err
224 #ifndef CO_DRIVER_MULTI_INTERFACE
225 #define CO_DRIVER_MULTI_INTERFACE 0
245 #ifndef CO_DRIVER_ERROR_REPORTING
246 #define CO_DRIVER_ERROR_REPORTING 1
254 #if __BYTE_ORDER == __LITTLE_ENDIAN
255 #define CO_LITTLE_ENDIAN
256 #define CO_SWAP_16(x) x
257 #define CO_SWAP_32(x) x
258 #define CO_SWAP_64(x) x
260 #define CO_BIG_ENDIAN
261 #include <byteswap.h>
262 #define CO_SWAP_16(x) bswap_16(x)
263 #define CO_SWAP_32(x) bswap_32(x)
264 #define CO_SWAP_64(x) bswap_64(x)
271 typedef unsigned char bool_t;
289 CO_CANrxMsg_t *rxMsgCasted = (CO_CANrxMsg_t *)rxMsg;
290 return (
uint16_t) (rxMsgCasted->ident & CAN_SFF_MASK);
293 CO_CANrxMsg_t *rxMsgCasted = (CO_CANrxMsg_t *)rxMsg;
294 return (
uint8_t) (rxMsgCasted->DLC);
297 CO_CANrxMsg_t *rxMsgCasted = (CO_CANrxMsg_t *)rxMsg;
298 return (
uint8_t *) (rxMsgCasted->data);
309 struct timespec timestamp;
318 volatile bool_t bufferFull;
325 #define CO_CAN_MSG_SFF_MAX_COB_ID (1 << CAN_SFF_ID_BITS)
332 } CO_CANptrSocketCan_t;
337 char ifName[IFNAMSIZ];
339 #if CO_DRIVER_ERROR_REPORTING > 0 || defined CO_DOXYGEN
348 CO_CANinterface_t *CANinterfaces;
352 struct can_filter *rxFilter;
358 volatile bool_t CANnormal;
361 #if CO_DRIVER_MULTI_INTERFACE > 0 || defined CO_DOXYGEN
364 uint32_t rxIdentToIndex[CO_CAN_MSG_SFF_MAX_COB_ID];
365 uint32_t txIdentToIndex[CO_CAN_MSG_SFF_MAX_COB_ID];
369 #ifdef CO_SINGLE_THREAD
370 #define CO_LOCK_CAN_SEND()
371 #define CO_UNLOCK_CAN_SEND()
372 #define CO_LOCK_EMCY()
373 #define CO_UNLOCK_EMCY()
375 #define CO_UNLOCK_OD()
376 #define CO_MemoryBarrier()
380 #define CO_LOCK_CAN_SEND()
381 #define CO_UNLOCK_CAN_SEND()
384 extern pthread_mutex_t CO_EMCY_mutex;
386 return pthread_mutex_lock(&CO_EMCY_mutex);
389 (void)pthread_mutex_unlock(&CO_EMCY_mutex);
393 extern pthread_mutex_t CO_OD_mutex;
395 return pthread_mutex_lock(&CO_OD_mutex);
398 (void)pthread_mutex_unlock(&CO_OD_mutex);
402 #define CO_MemoryBarrier() {__sync_synchronize();}
405 #define CO_FLAG_READ(rxNew) ((rxNew) != NULL)
406 #define CO_FLAG_SET(rxNew) {CO_MemoryBarrier(); rxNew = (void*)1L;}
407 #define CO_FLAG_CLEAR(rxNew) {CO_MemoryBarrier(); rxNew = NULL;}
412 #if CO_DRIVER_MULTI_INTERFACE > 0 || defined CO_DOXYGEN
443 const void **
const CANptrRx,
444 struct timespec *timestamp);
463 const void *CANptrTx);
492 struct epoll_event *ev,
493 CO_CANrxMsg_t *buffer,
unsigned long int uint32_t
UNSIGNED32 in CANopen (0007h), 32-bit unsigned integer.
Definition: CO_driver.h:155
CO_ReturnError_t CO_CANtxBuffer_setInterface(CO_CANmodule_t *CANmodule, uint16_t ident, const void *CANptrTx)
Set which interface should be used for message buffer transmission.
CO_ReturnError_t CO_CANmodule_addInterface(CO_CANmodule_t *CANmodule, int can_ifindex)
Add socketCAN interface to can driver.
CANopenNode Linux socketCAN Error handling.
char char_t
VISIBLE_STRING in CANopen (0009h), string of signed 8-bit values.
Definition: CO_driver.h:163
#define CO_UNLOCK_EMCY()
Unlock critical section in CO_errorReport() or CO_errorReset()
Definition: CO_driver.h:394
unsigned int uint16_t
UNSIGNED16 in CANopen (0006h), 16-bit unsigned integer.
Definition: CO_driver.h:153
#define CO_LOCK_EMCY()
Lock critical section in CO_errorReport() or CO_errorReset()
Definition: CO_driver.h:392
CO_ReturnError_t
Return values of some CANopen functions.
Definition: CO_driver.h:488
static uint8_t CO_CANrxMsg_readDLC(void *rxMsg)
CANrx_callback() can read Data Length Code from received CAN message.
Definition: CO_driver.h:230
unsigned char bool_t
Boolean data type for general use.
Definition: CO_driver.h:141
void CANrx_callback(void *object, void *rxMsg)
CAN receive callback function which pre-processes received CAN message.
static uint8_t * CO_CANrxMsg_readData(void *rxMsg)
CANrx_callback() can read pointer to data from received CAN message.
Definition: CO_driver.h:242
signed long int int32_t
INTEGER32 in CANopen (0004h), 32-bit signed integer.
Definition: CO_driver.h:147
#define CO_LOCK_OD()
Lock critical section when accessing Object Dictionary.
Definition: CO_driver.h:396
static uint16_t CO_CANrxMsg_readIdent(void *rxMsg)
CANrx_callback() can read CAN identifier from received CAN message.
Definition: CO_driver.h:218
bool_t CO_CANrxFromEpoll(CO_CANmodule_t *CANmodule, struct epoll_event *ev, CO_CANrxMsg_t *buffer, int32_t *msgIndex)
Receives CAN messages from matching epoll event.
Definition: CO_driver.c:842
double float64_t
REAL64 in CANopen (0011h), double precision floating point value, 64-bit.
Definition: CO_driver.h:161
float float32_t
REAL32 in CANopen (0008h), single precision floating point value, 32-bit.
Definition: CO_driver.h:159
unsigned char oChar_t
OCTET_STRING in CANopen (000Ah), string of unsigned 8-bit values.
Definition: CO_driver.h:165
bool_t CO_CANrxBuffer_getInterface(CO_CANmodule_t *CANmodule, uint16_t ident, const void **const CANptrRx, struct timespec *timestamp)
Check on which interface the last message for one message buffer was received.
#define CO_UNLOCK_OD()
Unock critical section when accessing Object Dictionary.
Definition: CO_driver.h:398
Configuration object for CAN received message for specific CANopenNode Object.
Definition: CO_driver.h:257
Complete CAN module object.
Definition: CO_driver.h:319
unsigned char domain_t
DOMAIN in CANopen (000Fh), used to transfer a large block of data.
Definition: CO_driver.h:167
Configuration object for CAN transmit message for specific CANopenNode Object.
Definition: CO_driver.h:299
socketCAN interface error handling
Definition: CO_error.h:113
unsigned char uint8_t
UNSIGNED8 in CANopen (0005h), 8-bit unsigned integer.
Definition: CO_driver.h:151