23#ifndef CO_DRIVER_TARGET_H
24#define CO_DRIVER_TARGET_H
34#ifndef CO_SINGLE_THREAD
41#ifdef CO_DRIVER_CUSTOM
42#include "CO_driver_custom.h"
51#ifdef CO_SINGLE_THREAD
52#define CO_CONFIG_GLOBAL_FLAG_CALLBACK_PRE 0
54#define CO_CONFIG_GLOBAL_FLAG_CALLBACK_PRE CO_CONFIG_FLAG_CALLBACK_PRE
56#define CO_CONFIG_GLOBAL_FLAG_TIMERNEXT CO_CONFIG_FLAG_TIMERNEXT
59#define CO_CONFIG_NMT \
60 (CO_CONFIG_NMT_CALLBACK_CHANGE | CO_CONFIG_NMT_MASTER | CO_CONFIG_GLOBAL_FLAG_CALLBACK_PRE \
61 | CO_CONFIG_GLOBAL_FLAG_TIMERNEXT)
64#ifndef CO_CONFIG_HB_CONS
65#define CO_CONFIG_HB_CONS \
66 (CO_CONFIG_HB_CONS_ENABLE | CO_CONFIG_HB_CONS_CALLBACK_CHANGE | CO_CONFIG_GLOBAL_FLAG_CALLBACK_PRE \
67 | CO_CONFIG_GLOBAL_FLAG_TIMERNEXT | CO_CONFIG_GLOBAL_FLAG_OD_DYNAMIC)
72 (CO_CONFIG_EM_PRODUCER | CO_CONFIG_EM_PROD_CONFIGURABLE | CO_CONFIG_EM_PROD_INHIBIT | CO_CONFIG_EM_HISTORY \
73 | CO_CONFIG_EM_STATUS_BITS | CO_CONFIG_EM_CONSUMER | CO_CONFIG_GLOBAL_FLAG_CALLBACK_PRE \
74 | CO_CONFIG_GLOBAL_FLAG_TIMERNEXT)
77#ifndef CO_CONFIG_SDO_SRV
78#define CO_CONFIG_SDO_SRV \
79 (CO_CONFIG_SDO_SRV_SEGMENTED | CO_CONFIG_SDO_SRV_BLOCK | CO_CONFIG_GLOBAL_FLAG_CALLBACK_PRE \
80 | CO_CONFIG_GLOBAL_FLAG_TIMERNEXT | CO_CONFIG_GLOBAL_FLAG_OD_DYNAMIC)
83#ifndef CO_CONFIG_SDO_SRV_BUFFER_SIZE
84#define CO_CONFIG_SDO_SRV_BUFFER_SIZE 900
87#ifndef CO_CONFIG_SDO_CLI
88#define CO_CONFIG_SDO_CLI \
89 (CO_CONFIG_SDO_CLI_ENABLE | CO_CONFIG_SDO_CLI_SEGMENTED | CO_CONFIG_SDO_CLI_BLOCK | CO_CONFIG_SDO_CLI_LOCAL \
90 | CO_CONFIG_GLOBAL_FLAG_CALLBACK_PRE | CO_CONFIG_GLOBAL_FLAG_TIMERNEXT | CO_CONFIG_GLOBAL_FLAG_OD_DYNAMIC)
94#define CO_CONFIG_TIME \
95 (CO_CONFIG_TIME_ENABLE | CO_CONFIG_TIME_PRODUCER | CO_CONFIG_GLOBAL_FLAG_CALLBACK_PRE \
96 | CO_CONFIG_GLOBAL_FLAG_OD_DYNAMIC)
100#define CO_CONFIG_LSS \
101 (CO_CONFIG_LSS_SLAVE | CO_CONFIG_LSS_SLAVE_FASTSCAN_DIRECT_RESPOND | CO_CONFIG_LSS_MASTER \
102 | CO_CONFIG_GLOBAL_FLAG_CALLBACK_PRE)
105#define CO_CONFIG_GFC (CO_CONFIG_GFC_ENABLE | CO_CONFIG_GFC_CONSUMER | CO_CONFIG_GFC_PRODUCER)
107#define CO_CONFIG_SRDO \
108 (CO_CONFIG_SRDO_ENABLE | CO_CONFIG_SRDO_CHECK_TX | CO_CONFIG_GLOBAL_FLAG_CALLBACK_PRE \
109 | CO_CONFIG_GLOBAL_FLAG_TIMERNEXT)
112#define CO_CONFIG_GTW \
113 (CO_CONFIG_GTW_ASCII | CO_CONFIG_GTW_ASCII_SDO | CO_CONFIG_GTW_ASCII_NMT | CO_CONFIG_GTW_ASCII_LSS \
114 | CO_CONFIG_GTW_ASCII_LOG | CO_CONFIG_GTW_ASCII_ERROR_DESC | CO_CONFIG_GTW_ASCII_PRINT_HELP \
115 | CO_CONFIG_GTW_ASCII_PRINT_LEDS)
116#define CO_CONFIG_GTW_BLOCK_DL_LOOP 3
117#define CO_CONFIG_GTWA_COMM_BUF_SIZE 2000
118#define CO_CONFIG_GTWA_LOG_BUF_SIZE 10000
121#ifndef CO_CONFIG_CRC16
122#define CO_CONFIG_CRC16 (CO_CONFIG_CRC16_ENABLE)
125#ifndef CO_CONFIG_FIFO
126#define CO_CONFIG_FIFO \
127 (CO_CONFIG_FIFO_ENABLE | CO_CONFIG_FIFO_ALT_READ | CO_CONFIG_FIFO_CRC16_CCITT | CO_CONFIG_FIFO_ASCII_COMMANDS \
128 | CO_CONFIG_FIFO_ASCII_DATATYPES)
132#if (CO_CONFIG_DEBUG) & CO_CONFIG_DEBUG_COMMON
135#define CO_DEBUG_COMMON(msg) log_printf(LOG_DEBUG, DBG_CO_DEBUG, msg);
162#ifndef CO_DRIVER_MULTI_INTERFACE
163#define CO_DRIVER_MULTI_INTERFACE 0
182#ifndef CO_DRIVER_ERROR_REPORTING
183#define CO_DRIVER_ERROR_REPORTING 1
191#if __BYTE_ORDER == __LITTLE_ENDIAN
192#define CO_LITTLE_ENDIAN
193#define CO_SWAP_16(x) x
194#define CO_SWAP_32(x) x
195#define CO_SWAP_64(x) x
199#define CO_SWAP_16(x) bswap_16(x)
200#define CO_SWAP_32(x) bswap_32(x)
201#define CO_SWAP_64(x) bswap_64(x)
207typedef uint_fast8_t
bool_t;
221CO_CANrxMsg_readIdent(
void* rxMsg) {
222 CO_CANrxMsg_t* rxMsgCasted = (CO_CANrxMsg_t*)rxMsg;
223 return (
uint16_t)(rxMsgCasted->ident & CAN_SFF_MASK);
227CO_CANrxMsg_readDLC(
void* rxMsg) {
228 CO_CANrxMsg_t* rxMsgCasted = (CO_CANrxMsg_t*)rxMsg;
229 return (
uint8_t)(rxMsgCasted->DLC);
233CO_CANrxMsg_readData(
void* rxMsg) {
234 CO_CANrxMsg_t* rxMsgCasted = (CO_CANrxMsg_t*)rxMsg;
235 return (
uint8_t*)(rxMsgCasted->data);
243 void (*CANrx_callback)(
void* object,
void* message);
245 struct timespec timestamp;
254 volatile bool_t bufferFull;
260#define CO_CAN_MSG_SFF_MAX_COB_ID (1 << CAN_SFF_ID_BITS)
266} CO_CANptrSocketCan_t;
271 char ifName[IFNAMSIZ];
273#if CO_DRIVER_ERROR_REPORTING > 0 || defined CO_DOXYGEN
281 CO_CANinterface_t* CANinterfaces;
285 struct can_filter* rxFilter;
290 volatile bool_t CANnormal;
293#if CO_DRIVER_MULTI_INTERFACE > 0 || defined CO_DOXYGEN
295 uint32_t rxIdentToIndex[CO_CAN_MSG_SFF_MAX_COB_ID];
296 uint32_t txIdentToIndex[CO_CAN_MSG_SFF_MAX_COB_ID];
301#ifndef CO_STORAGE_PATH_MAX
302#define CO_STORAGE_PATH_MAX 255
311 char filename[CO_STORAGE_PATH_MAX];
316#ifdef CO_SINGLE_THREAD
317#define CO_LOCK_CAN_SEND(CAN_MODULE) \
318 { (void)CAN_MODULE; }
319#define CO_UNLOCK_CAN_SEND(CAN_MODULE) \
320 { (void)CAN_MODULE; }
321#define CO_LOCK_EMCY(CAN_MODULE) \
322 { (void)CAN_MODULE; }
323#define CO_UNLOCK_EMCY(CAN_MODULE) \
324 { (void)CAN_MODULE; }
325#define CO_LOCK_OD(CAN_MODULE) \
326 { (void)CAN_MODULE; }
327#define CO_UNLOCK_OD(CAN_MODULE) \
328 { (void)CAN_MODULE; }
329#define CO_MemoryBarrier()
333#define CO_LOCK_CAN_SEND(CAN_MODULE)
334#define CO_UNLOCK_CAN_SEND(CAN_MODULE)
337extern pthread_mutex_t CO_EMCY_mutex;
342 return pthread_mutex_lock(&CO_EMCY_mutex);
348 (void)pthread_mutex_unlock(&CO_EMCY_mutex);
352extern pthread_mutex_t CO_OD_mutex;
357 return pthread_mutex_lock(&CO_OD_mutex);
363 (void)pthread_mutex_unlock(&CO_OD_mutex);
367#define CO_MemoryBarrier() \
368 { __sync_synchronize(); }
371#define CO_FLAG_READ(rxNew) ((rxNew) != NULL)
372#define CO_FLAG_SET(rxNew) \
374 CO_MemoryBarrier(); \
377#define CO_FLAG_CLEAR(rxNew) \
379 CO_MemoryBarrier(); \
385#if CO_DRIVER_MULTI_INTERFACE > 0 || defined CO_DOXYGEN
412 struct timespec* timestamp);
CANopenNode Linux socketCAN Error handling.
#define CO_LOCK_EMCY(CAN_MODULE)
#define CO_UNLOCK_EMCY(CAN_MODULE)
#define CO_UNLOCK_OD(CAN_MODULE)
#define CO_LOCK_OD(CAN_MODULE)
unsigned long int uint32_t
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:823
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.
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.
socketCAN interface error handling
Definition CO_error.h:98