CANopenLinux
CANopenNode on Linux devices
Loading...
Searching...
No Matches
Epoll interface

Linux epoll interface to CANopenNode. More...

+ Collaboration diagram for Epoll interface:

Files

file  CO_epoll_interface.h
 Helper functions for Linux epoll interface to CANopenNode.
 

Data Structures

struct  CO_epoll_t
 Object for epoll, timer and event API. More...
 
struct  CO_epoll_gtw_t
 Object for gateway. More...
 

Enumerations

enum  CO_commandInterface_t
 Command interface type for gateway-ascii.
 

Functions

CO_ReturnError_t CO_epoll_create (CO_epoll_t *ep, uint32_t timerInterval_us)
 Create Linux epoll, timerfd and eventfd.
 
void CO_epoll_close (CO_epoll_t *ep)
 Close epoll, timerfd and eventfd.
 
void CO_epoll_wait (CO_epoll_t *ep)
 Wait for an epoll event.
 
void CO_epoll_processLast (CO_epoll_t *ep)
 Closing function for an epoll event.
 
void CO_epoll_initCANopenMain (CO_epoll_t *ep, CO_t *co)
 Initialization of functions in CANopen reset-communication section.
 
void CO_epoll_processMain (CO_epoll_t *ep, CO_t *co, bool_t enableGateway, CO_NMT_reset_cmd_t *reset)
 Process CANopen mainline functions.
 
void CO_epoll_processRT (CO_epoll_t *ep, CO_t *co, bool_t realtime)
 Process CAN receive and realtime functions.
 
CO_ReturnError_t CO_epoll_createGtw (CO_epoll_gtw_t *epGtw, int epoll_fd, int32_t commandInterface, uint32_t socketTimeout_ms, char *localSocketPath)
 Create socket for gateway-ascii command interface and add it to epoll.
 
void CO_epoll_closeGtw (CO_epoll_gtw_t *epGtw)
 Close gateway-ascii sockets.
 
void CO_epoll_initCANopenGtw (CO_epoll_gtw_t *epGtw, CO_t *co)
 Initialization of gateway functions in CANopen reset-communication section.
 
void CO_epoll_processGtw (CO_epoll_gtw_t *epGtw, CO_t *co, CO_epoll_t *ep)
 Process CANopen gateway functions.
 

Detailed Description

Linux epoll interface to CANopenNode.

The Linux epoll API performs a monitoring multiple file descriptors to see if I/O is possible on any of them.

CANopenNode uses epoll interface to provide an event based mechanism. Epoll waits for multiple different events, such as: interval timer event, notification event, CAN receive event or socket based event for gateway. CANopenNode non-blocking functions are processed after each event.

CANopenNode itself offers functionality for calculation of time, when next interval timer event should trigger the processing. It can also trigger notification events in case of multi-thread operation.

Function Documentation

◆ CO_epoll_create()

CO_ReturnError_t CO_epoll_create ( CO_epoll_t * ep,
uint32_t timerInterval_us )

Create Linux epoll, timerfd and eventfd.

Create and configure multiple Linux notification facilities, which trigger execution of the task. Epoll blocks and monitors multiple file descriptors, timerfd triggers in constant timer intervals and eventfd triggers on external signal.

Parameters
epThis object
timerInterval_usTimer interval in microseconds
Returns
CO_ReturnError_t CO_ERROR_NO, CO_ERROR_ILLEGAL_ARGUMENT or CO_ERROR_SYSCALL.

◆ CO_epoll_close()

void CO_epoll_close ( CO_epoll_t * ep)

Close epoll, timerfd and eventfd.

Parameters
epThis object

◆ CO_epoll_wait()

void CO_epoll_wait ( CO_epoll_t * ep)

Wait for an epoll event.

This function blocks until event registered on epoll: timerfd, eventfd, or application specified event. Function also calculates timeDifference_us since last call and prepares timerNext_us.

Parameters
epThis object

◆ CO_epoll_processLast()

void CO_epoll_processLast ( CO_epoll_t * ep)

Closing function for an epoll event.

This function must be called after CO_epoll_wait(). Between them should be application specified processing functions, which can check for own events and do own processing. Application may also lower timerNext_us variable. If lowered, then interval timer will be reconfigured and CO_epoll_wait() will be triggered earlier.

Parameters
epThis object

◆ CO_epoll_initCANopenMain()

void CO_epoll_initCANopenMain ( CO_epoll_t * ep,
CO_t * co )

Initialization of functions in CANopen reset-communication section.

Configure callbacks for CANopen objects.

Parameters
epThis object
coCANopen object

◆ CO_epoll_processMain()

void CO_epoll_processMain ( CO_epoll_t * ep,
CO_t * co,
bool_t enableGateway,
CO_NMT_reset_cmd_t * reset )

Process CANopen mainline functions.

This function calls CO_process(). It is non-blocking and should execute cyclically. It should be between CO_epoll_wait() and CO_epoll_processLast() functions.

Parameters
epThis object
coCANopen object
enableGatewayIf true, gateway to external world will be enabled.
[out]resetReturn from CO_process().

◆ CO_epoll_processRT()

void CO_epoll_processRT ( CO_epoll_t * ep,
CO_t * co,
bool_t realtime )

Process CAN receive and realtime functions.

This function checks epoll for CAN receive event and processes CANopen realtime functions: CO_process_SYNC(), CO_process_RPDO() and CO_process_TPDO(). It is non-blocking and should execute cyclically. It should be between CO_epoll_wait() and CO_epoll_processLast() functions.

Function can be used in the mainline thread or in own realtime thread.

Processing of CANopen realtime functions is protected with CO_LOCK_OD. Also Node-Id must be configured and CANmodule must be in CANnormal for processing.

Parameters
epPointer to CO_epoll_t object.
coCANopen object
realtimeSet to true, if function is called from the own realtime thread, and is executed at short constant interval.

◆ CO_epoll_createGtw()

CO_ReturnError_t CO_epoll_createGtw ( CO_epoll_gtw_t * epGtw,
int epoll_fd,
int32_t commandInterface,
uint32_t socketTimeout_ms,
char * localSocketPath )

Create socket for gateway-ascii command interface and add it to epoll.

Depending on arguments function configures stdio interface or local socket or IP socket.

Parameters
epGtwThis object
epoll_fdAlready configured epoll file descriptor
commandInterfaceCommand interface type from CO_commandInterface_t
socketTimeout_msTimeout for established socket connection in [ms]
localSocketPathFile path, if commandInterface is local socket
Returns
CO_ReturnError_t CO_ERROR_NO, CO_ERROR_ILLEGAL_ARGUMENT or CO_ERROR_SYSCALL.

◆ CO_epoll_closeGtw()

void CO_epoll_closeGtw ( CO_epoll_gtw_t * epGtw)

Close gateway-ascii sockets.

Parameters
epGtwThis object

◆ CO_epoll_initCANopenGtw()

void CO_epoll_initCANopenGtw ( CO_epoll_gtw_t * epGtw,
CO_t * co )

Initialization of gateway functions in CANopen reset-communication section.

Parameters
epGtwThis object
coCANopen object

◆ CO_epoll_processGtw()

void CO_epoll_processGtw ( CO_epoll_gtw_t * epGtw,
CO_t * co,
CO_epoll_t * ep )

Process CANopen gateway functions.

This function checks for epoll events and verifies socket connection timeout. It is non-blocking and should execute cyclically. It should be between CO_epoll_wait() and CO_epoll_processLast() functions.

Parameters
epGtwThis object
coCANopen object
epPointer to CO_epoll_t object.