CANopenLinux
CANopenNode on Linux devices
|
Linux epoll interface to CANopenNode. More...
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. | |
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.
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.
ep | This object |
timerInterval_us | Timer interval in microseconds |
void CO_epoll_close | ( | CO_epoll_t * | ep | ) |
Close epoll, timerfd and eventfd.
ep | This object |
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.
ep | This object |
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.
ep | This object |
void CO_epoll_initCANopenMain | ( | CO_epoll_t * | ep, |
CO_t * | co ) |
Initialization of functions in CANopen reset-communication section.
Configure callbacks for CANopen objects.
ep | This object |
co | CANopen object |
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.
ep | This object | |
co | CANopen object | |
enableGateway | If true, gateway to external world will be enabled. | |
[out] | reset | Return from CO_process(). |
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.
ep | Pointer to CO_epoll_t object. |
co | CANopen object |
realtime | Set to true, if function is called from the own realtime thread, and is executed at short constant interval. |
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.
epGtw | This object |
epoll_fd | Already configured epoll file descriptor |
commandInterface | Command interface type from CO_commandInterface_t |
socketTimeout_ms | Timeout for established socket connection in [ms] |
localSocketPath | File path, if commandInterface is local socket |
void CO_epoll_closeGtw | ( | CO_epoll_gtw_t * | epGtw | ) |
Close gateway-ascii sockets.
epGtw | This object |
void CO_epoll_initCANopenGtw | ( | CO_epoll_gtw_t * | epGtw, |
CO_t * | co ) |
Initialization of gateway functions in CANopen reset-communication section.
epGtw | This object |
co | CANopen object |
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.
epGtw | This object |
co | CANopen object |
ep | Pointer to CO_epoll_t object. |