CANopenNode
CO_driver_target.h

Files

file  CO_driver_target.h
 Linux socketCAN specific definitions for CANopenNode.
 

Macros

#define CO_DRIVER_MULTI_INTERFACE   0
 Multi interface support. More...
 
#define CO_DRIVER_ERROR_REPORTING   1
 CAN bus error reporting. More...
 

Functions

CO_ReturnError_t CO_CANmodule_addInterface (CO_CANmodule_t *CANmodule, int can_ifindex)
 Add socketCAN interface to can driver. More...
 
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. More...
 
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. More...
 
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. More...
 

Detailed Description

Linux socketCAN specific Driver definitions for CANopenNode.

Macro Definition Documentation

◆ CO_DRIVER_MULTI_INTERFACE

#define CO_DRIVER_MULTI_INTERFACE   0

Multi interface support.

Enable this to use interface combining at driver level. This adds functions to broadcast/selective transmit messages on the given interfaces as well as combining all received message into one queue.

If CO_DRIVER_MULTI_INTERFACE is set to 0, then CO_CANmodule_init() adds single socketCAN interface specified by CANptr argument. In case of failure, CO_CANmodule_init() returns CO_ERROR_SYSCALL.

If CO_DRIVER_MULTI_INTERFACE is set to 1, then CO_CANmodule_init() ignores CANptr argument. Interfaces must be added by CO_CANmodule_addInterface() function after CO_CANmodule_init().

Macro is set to 0 (disabled) by default. It can be overridden.

This is not intended to realize interface redundancy!!!

◆ CO_DRIVER_ERROR_REPORTING

#define CO_DRIVER_ERROR_REPORTING   1

CAN bus error reporting.

CO_DRIVER_ERROR_REPORTING enabled adds support for socketCAN error detection and handling functions inside the driver. This is needed when you have CANopen with "0" connected nodes as a use case, as this is normally forbidden in CAN.

Macro is set to 1 (enabled) by default. It can be overridden.

you need to enable error reporting in your kernel driver using:

ip link set canX type can berr-reporting on

Of course, the kernel driver for your hardware needs this functionality to be implemented...

Function Documentation

◆ CO_CANmodule_addInterface()

CO_ReturnError_t CO_CANmodule_addInterface ( CO_CANmodule_t CANmodule,
int  can_ifindex 
)

Add socketCAN interface to can driver.

Function must be called after CO_CANmodule_init.

Parameters
CANmoduleThis object will be initialized.
can_ifindexCAN Interface index
Returns
CO_ReturnError_t: CO_ERROR_NO, CO_ERROR_ILLEGAL_ARGUMENT, CO_ERROR_SYSCALL or CO_ERROR_INVALID_STATE.

◆ CO_CANrxBuffer_getInterface()

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.

It is in the responsibility of the user to check that this information is useful as some messages can be received at any time on any bus.

Parameters
CANmoduleThis object.
ident11-bit standard CAN Identifier.
[out]CANptrRxmessage was received on this interface
[out]timestampmessage was received at this time (system clock)
Return values
falsemessage has never been received, therefore no base address and timestamp are available
truebase address and timestamp are valid

◆ CO_CANtxBuffer_setInterface()

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.

It is in the responsibility of the user to ensure that the correct interface is used. Some messages need to be transmitted on all interfaces.

If given interface is unknown or NULL is used, a message is transmitted on all available interfaces.

Parameters
CANmoduleThis object.
ident11-bit standard CAN Identifier.
CANptrTxuse this interface. NULL = not specified
Returns
CO_ReturnError_t: CO_ERROR_NO or CO_ERROR_ILLEGAL_ARGUMENT.

◆ CO_CANrxFromEpoll()

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.

This function verifies, if epoll event matches event from any CANinterface. In case of match, message is read from CAN and pre-processed for CANopenNode objects. CAN error frames are also processed.

In case of CAN message function searches rxArray from CO_CANmodule_t and if matched it calls the corresponding CANrx_callback, optionally copies received CAN message to buffer and returns index of matched rxArray.

This function can be used in two ways, which can be combined:

  • automatic mode: If CANrx_callback is specified for matched rxArray, then calls its callback.
  • manual mode: evaluate message filters, return received message
Parameters
CANmoduleThis object.
evEpoll event, which vill be verified for matches.
[out]bufferStorage for received message or NULL if not used.
[out]msgIndexIndex of received message in array from CO_CANmodule_t rxArray, copy of CAN message is available in buffer.
Returns
True, if epoll event matches any CAN interface.