CO_epoll_interface.h
Go to the documentation of this file.
#ifndef CO_EPOLL_INTERFACE_H
#define CO_EPOLL_INTERFACE_H
#include "CANopen.h"
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <sys/timerfd.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int epoll_fd;
int event_fd;
int timer_fd;
uint32_t timerInterval_us;
uint32_t timeDifference_us;
uint32_t timerNext_us;
bool_t timerEvent;
uint64_t previousTime_us;
struct itimerspec tm;
struct epoll_event ev;
bool_t epoll_new;
} CO_epoll_t;
CO_ReturnError_t CO_epoll_create(CO_epoll_t *ep, uint32_t timerInterval_us);
void CO_epoll_close(CO_epoll_t *ep);
void CO_epoll_wait(CO_epoll_t *ep);
void CO_epoll_processLast(CO_epoll_t *ep);
void CO_epoll_initCANopenMain(CO_epoll_t *ep, CO_t *co);
void CO_epoll_processMain(CO_epoll_t *ep,
CO_t *co,
bool_t enableGateway,
CO_NMT_reset_cmd_t *reset);
void CO_epoll_processRT(CO_epoll_t *ep,
CO_t *co,
bool_t realtime);
#if ((CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII) || defined CO_DOXYGEN
typedef enum {
CO_COMMAND_IF_DISABLED = -100,
CO_COMMAND_IF_STDIO = -2,
CO_COMMAND_IF_LOCAL_SOCKET = -1,
CO_COMMAND_IF_TCP_SOCKET_MIN = 0,
CO_COMMAND_IF_TCP_SOCKET_MAX = 0xFFFF
} CO_commandInterface_t;
typedef struct {
int epoll_fd;
int32_t commandInterface;
uint32_t socketTimeout_us;
uint32_t socketTimeoutTmr_us;
char *localSocketPath;
int gtwa_fdSocket;
int gtwa_fd;
bool_t freshCommand;
} CO_epoll_gtw_t;
CO_ReturnError_t CO_epoll_createGtw(CO_epoll_gtw_t *epGtw,
int epoll_fd,
int32_t commandInterface,
uint32_t socketTimeout_ms,
char *localSocketPath);
void CO_epoll_closeGtw(CO_epoll_gtw_t *epGtw);
void CO_epoll_initCANopenGtw(CO_epoll_gtw_t *epGtw, CO_t *co);
void CO_epoll_processGtw(CO_epoll_gtw_t *epGtw,
CO_t *co,
CO_epoll_t *ep);
#endif /* (CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII */
#ifdef __cplusplus
}
#endif /*__cplusplus*/
#endif /* CO_EPOLL_INTERFACE_H */
uint32_t
unsigned long int uint32_t
UNSIGNED32 in CANopen (0007h), 32-bit unsigned integer.
Definition: CO_driver.h:155
CO_epoll_gtw_t::epoll_fd
int epoll_fd
Epoll file descriptor, from CO_epoll_createGtw()
Definition: CO_epoll_interface.h:233
CO_epoll_processRT
void CO_epoll_processRT(CO_epoll_t *ep, CO_t *co, bool_t realtime)
Process CAN receive and realtime functions.
Definition: CO_epoll_interface.c:304
CO_commandInterface_t
CO_commandInterface_t
Command interface type for gateway-ascii.
Definition: CO_epoll_interface.h:220
CO_epoll_gtw_t
Object for gateway.
Definition: CO_epoll_interface.h:231
CO_ReturnError_t
CO_ReturnError_t
Return values of some CANopen functions.
Definition: CO_driver.h:488
CO_epoll_gtw_t::localSocketPath
char * localSocketPath
Path in case of local socket.
Definition: CO_epoll_interface.h:242
CO_epoll_gtw_t::gtwa_fd
int gtwa_fd
Gateway io stream file descriptor.
Definition: CO_epoll_interface.h:246
bool_t
unsigned char bool_t
Boolean data type for general use.
Definition: CO_driver.h:141
CO_epoll_processGtw
void CO_epoll_processGtw(CO_epoll_gtw_t *epGtw, CO_t *co, CO_epoll_t *ep)
Process CANopen gateway functions.
int32_t
signed long int int32_t
INTEGER32 in CANopen (0004h), 32-bit signed integer.
Definition: CO_driver.h:147
CO_NMT_reset_cmd_t
CO_NMT_reset_cmd_t
Return code from CO_NMT_process() that tells application code what to reset.
Definition: CO_NMT_Heartbeat.h:112
uint64_t
unsigned long long int uint64_t
UNSIGNED64 in CANopen (001Bh), 64-bit unsigned integer.
Definition: CO_driver.h:157
CO_epoll_wait
void CO_epoll_wait(CO_epoll_t *ep)
Wait for an epoll event.
Definition: CO_epoll_interface.c:138
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.
Definition: CO_epoll_interface.c:286
CO_epoll_t::timer_fd
int timer_fd
Interval timer file descriptor.
Definition: CO_epoll_interface.h:95
CO_epoll_gtw_t::commandInterface
int32_t commandInterface
Command interface type or tcp port number, see CO_commandInterface_t.
Definition: CO_epoll_interface.h:236
CO_epoll_initCANopenMain
void CO_epoll_initCANopenMain(CO_epoll_t *ep, CO_t *co)
Initialization of functions in CANopen reset-communication section.
Definition: CO_epoll_interface.c:232
CO_epoll_t::timerNext_us
uint32_t timerNext_us
Timer value in microseconds, which can be changed by application and can shorten time of next CO_epol...
Definition: CO_epoll_interface.h:103
CO_epoll_gtw_t::socketTimeoutTmr_us
uint32_t socketTimeoutTmr_us
Socket timeout timer in microseconds.
Definition: CO_epoll_interface.h:240
CO_epoll_t::timerEvent
bool_t timerEvent
True,if timer event is inside CO_epoll_wait()
Definition: CO_epoll_interface.h:105
CO_epoll_t
Object for epoll, timer and event API.
Definition: CO_epoll_interface.h:89
CO_epoll_t::epoll_new
bool_t epoll_new
true, if new epoll event is necessary to process
Definition: CO_epoll_interface.h:113
CO_epoll_create
CO_ReturnError_t CO_epoll_create(CO_epoll_t *ep, uint32_t timerInterval_us)
Create Linux epoll, timerfd and eventfd.
Definition: CO_epoll_interface.c:63
CANopen.h
Main CANopenNode file.
CO_epoll_t::timeDifference_us
uint32_t timeDifference_us
Time difference since last CO_epoll_wait() execution in microseconds.
Definition: CO_epoll_interface.h:100
CO_epoll_gtw_t::socketTimeout_us
uint32_t socketTimeout_us
Socket timeout in microseconds.
Definition: CO_epoll_interface.h:238
CO_epoll_close
void CO_epoll_close(CO_epoll_t *ep)
Close epoll, timerfd and eventfd.
Definition: CO_epoll_interface.c:122
CO_epoll_processLast
void CO_epoll_processLast(CO_epoll_t *ep)
Closing function for an epoll event.
Definition: CO_epoll_interface.c:187
CO_epoll_initCANopenGtw
void CO_epoll_initCANopenGtw(CO_epoll_gtw_t *epGtw, CO_t *co)
Initialization of gateway functions in CANopen reset-communication section.
CO_epoll_closeGtw
void CO_epoll_closeGtw(CO_epoll_gtw_t *epGtw)
Close gateway-ascii sockets.
CO_epoll_t::event_fd
int event_fd
Notification event file descriptor.
Definition: CO_epoll_interface.h:93
CO_t
CANopen object - collection of all CANopenNode objects.
Definition: CANopen.h:301
CO_epoll_t::epoll_fd
int epoll_fd
Epoll file descriptor.
Definition: CO_epoll_interface.h:91
CO_epoll_t::timerInterval_us
uint32_t timerInterval_us
Interval of the timer in microseconds, from CO_epoll_create()
Definition: CO_epoll_interface.h:97
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.
CO_epoll_t::previousTime_us
uint64_t previousTime_us
time value from the last process call in microseconds
Definition: CO_epoll_interface.h:107
CO_epoll_gtw_t::freshCommand
bool_t freshCommand
Indication of fresh command.
Definition: CO_epoll_interface.h:248
CO_epoll_gtw_t::gtwa_fdSocket
int gtwa_fdSocket
Gateway socket file descriptor.
Definition: CO_epoll_interface.h:244