libethercat - an embeddable realtime EtherCAT-master library
Communicate with EtherCAT slaves attached to a Network interface.
Loading...
Searching...
No Matches
hw.h
Go to the documentation of this file.
1
12/*
13 * This file is part of libethercat.
14 *
15 * libethercat is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 3 of the License, or (at your option) any later version.
19 *
20 * libethercat is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with libethercat (LICENSE.LGPL-V3); if not, write
27 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
28 * Floor, Boston, MA 02110-1301, USA.
29 *
30 * Please note that the use of the EtherCAT technology, the EtherCAT
31 * brand name and the EtherCAT logo is only permitted if the property
32 * rights of Beckhoff Automation GmbH are observed. For further
33 * information please contact Beckhoff Automation GmbH & Co. KG,
34 * Hülshorstweg 20, D-33415 Verl, Germany (www.beckhoff.com) or the
35 * EtherCAT Technology Group, Ostendstraße 196, D-90482 Nuremberg,
36 * Germany (ETG, www.ethercat.org).
37 *
38 */
39
40#ifndef LIBETHERCAT_HW_H
41#define LIBETHERCAT_HW_H
42
43#include <libosal/task.h>
44#include <libosal/types.h>
45#include <libosal/mutex.h>
46
47#ifdef HAVE_CONFIG_H
48#include <libethercat/config.h>
49#endif
50
51#include <libethercat/pool.h>
53
54#if LIBETHERCAT_BUILD_DEVICE_PIKEOS == 1
55#include <vm_file_types.h>
56#include <drv/sbuf_hdr.h>
57#endif
58
59#define container_of(ptr, type, member) ({ \
60 __typeof__( ((type *)0)->member ) *__mptr = (void *)(ptr); \
61 (type *)( (char *)__mptr - offsetof(type,member) );})
62
70#define ETH_P_ECAT ((osal_uint16_t)0x88A4u)
71
72// forward decl
73struct ec;
74struct hw_common;
75
77typedef enum pooltype {
78 POOL_HIGH,
79 POOL_LOW,
81 //
83
88typedef int (*hw_device_recv_t)(struct hw_common *phw);
89
91
98typedef int (*hw_device_send_t)(struct hw_common *phw, ec_frame_t *pframe, pooltype_t pool_type);
99
101
104typedef void (*hw_device_send_finished_t)(struct hw_common *phw);
105
107
113typedef int (*hw_device_get_tx_buffer_t)(struct hw_common *phw, ec_frame_t **ppframe);
114
116
121typedef int (*hw_device_close_t)(struct hw_common *phw);
122
123#define ETH_FRAME_LEN 0x1518
124
126typedef struct hw_common {
127 struct ec *pec;
128
129 osal_uint32_t mtu_size;
130 osal_mutex_t hw_lock;
131
134
136
137 osal_size_t bytes_sent;
138 osal_size_t bytes_last_sent;
139 osal_timer_t next_cylce_start;
140
146
147 osal_uint64_t last_tx_duration_ns;
148 osal_uint64_t last_rx_duration_ns;
150
151#ifdef __cplusplus
152extern "C" {
153#endif
154
156
162int hw_open(struct hw_common *phw, struct ec *pec);
163
165
169int hw_close(struct hw_common *phw);
170
172
177
179
184
186
190int hw_tx(struct hw_common *phw);
191
193
198
199#ifdef __cplusplus
200}
201#endif
202
205#endif // LIBETHERCAT_HW_H
206
ethercat datagram
void hw_process_rx_frame(struct hw_common *phw, ec_frame_t *pframe)
Process a received EtherCAT frame.
int hw_tx_high(struct hw_common *phw)
start sending queued ethercat datagrams
int(* hw_device_get_tx_buffer_t)(struct hw_common *phw, ec_frame_t **ppframe)
Get a free tx buffer from underlying hw device.
Definition hw.h:113
int hw_tx(struct hw_common *phw)
start sending queued ethercat datagrams
int hw_tx_low(struct hw_common *phw)
start sending queued ethercat datagrams
int hw_close(struct hw_common *phw)
destroys a hw
int(* hw_device_send_t)(struct hw_common *phw, ec_frame_t *pframe, pooltype_t pool_type)
Send a frame from an EtherCAT hw device.
Definition hw.h:98
pooltype
Flag to distinguish the pool types during processing.
Definition hw.h:77
int(* hw_device_close_t)(struct hw_common *phw)
Close hardware layer.
Definition hw.h:121
enum pooltype pooltype_t
Flag to distinguish the pool types during processing.
void(* hw_device_send_finished_t)(struct hw_common *phw)
Doing internal stuff when finished sending frames.
Definition hw.h:104
int hw_open(struct hw_common *phw, struct ec *pec)
open a new hw
struct hw_common hw_common_t
hardware structure
int(* hw_device_recv_t)(struct hw_common *phw)
Receive a frame from an EtherCAT hw device.
Definition hw.h:88
Data pool implementation.
Definition datagram.h:60
ethercat master structure
Definition ec.h:188
struct hw_common * phw
pointer to hardware interface
Definition ec.h:189
hardware structure
Definition hw.h:126
pool_entry_t * tx_send[256]
sent datagrams
Definition hw.h:135
pool_t tx_low
low priority datagrams
Definition hw.h:133
osal_mutex_t hw_lock
transmit lock
Definition hw.h:130
hw_device_send_t send
Function to send frames via device.
Definition hw.h:142
osal_uint32_t mtu_size
mtu size
Definition hw.h:129
osal_size_t bytes_last_sent
Bytes last sent.
Definition hw.h:138
osal_timer_t next_cylce_start
Next cycle start time.
Definition hw.h:139
hw_device_close_t close
Function to close hw layer.
Definition hw.h:145
pool_t tx_high
high priority datagrams
Definition hw.h:132
struct ec * pec
Pointer to EtherCAT master structure.
Definition hw.h:127
osal_size_t bytes_sent
Bytes currently sent.
Definition hw.h:137
hw_device_get_tx_buffer_t get_tx_buffer
Function to retreave next TX buffer.
Definition hw.h:144
hw_device_recv_t recv
\biref Function to receive frame from device.
Definition hw.h:141
hw_device_send_finished_t send_finished
Function to be called after frames were sent.
Definition hw.h:143
Pool queue entry.
Definition pool.h:67
the datagram pool itself
Definition pool.h:81