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/types.h>
44#include <libosal/mutex.h>
45
46#include <libethercat/pool.h>
48
49#if LIBETHERCAT_BUILD_DEVICE_PIKEOS == 1
50#include <vm_file_types.h>
51#include <drv/sbuf_hdr.h>
52#endif
53
54#define container_of(ptr, type, member) ({ \
55 __typeof__( ((type *)0)->member ) *__mptr = (void *)(ptr); \
56 (type *)( (char *)__mptr - offsetof(type,member) );})
57
65#define ETH_P_ECAT ((osal_uint16_t)0x88A4u)
66
67// forward decl
68struct ec;
69struct hw_common;
70
72typedef enum pooltype {
73 POOL_HIGH,
74 POOL_LOW,
76 //
78
83typedef int (*hw_device_recv_t)(struct hw_common *phw);
84
86
93typedef int (*hw_device_send_t)(struct hw_common *phw, ec_frame_t *pframe, pooltype_t pool_type);
94
96
99typedef void (*hw_device_send_finished_t)(struct hw_common *phw);
100
102
108typedef int (*hw_device_get_tx_buffer_t)(struct hw_common *phw, ec_frame_t **ppframe);
109
111
116typedef int (*hw_device_close_t)(struct hw_common *phw);
117
118#define ETH_FRAME_LEN 0x1518
119
121typedef struct hw_common {
122 struct ec *pec;
123
124 osal_uint32_t mtu_size;
125 osal_mutex_t hw_lock;
126
129
131
132 osal_uint64_t frame_idx;
133 osal_size_t bytes_sent;
134 osal_size_t bytes_last_sent;
135 osal_timer_t next_cylce_start;
136
142
143 osal_uint64_t last_tx_duration_ns;
144 osal_uint64_t last_rx_duration_ns;
146
147#ifdef __cplusplus
148extern "C" {
149#endif
150
152
158int hw_open(struct hw_common *phw, struct ec *pec);
159
161
165int hw_close(struct hw_common *phw);
166
168
173
175
180
182
186int hw_tx(struct hw_common *phw);
187
189
195osal_bool_t hw_process_rx_frame(struct hw_common *phw, ec_frame_t *pframe);
196
198
203void hw_enqueue(struct hw_common *phw, pool_entry_t *p_entry, pooltype_t pool_type);
204
205#ifdef __cplusplus
206}
207#endif
208
211#endif // LIBETHERCAT_HW_H
212
ethercat datagram
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:108
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
osal_bool_t hw_process_rx_frame(struct hw_common *phw, ec_frame_t *pframe)
Process a received EtherCAT frame.
void hw_enqueue(struct hw_common *phw, pool_entry_t *p_entry, pooltype_t pool_type)
Enqueue frame to send queue.
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:93
pooltype
Flag to distinguish the pool types during processing.
Definition hw.h:72
int(* hw_device_close_t)(struct hw_common *phw)
Close hardware layer.
Definition hw.h:116
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:99
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:83
Data pool implementation.
Definition datagram.h:60
ethercat master structure
Definition ec.h:192
struct hw_common * phw
pointer to hardware interface
Definition ec.h:193
hardware structure
Definition hw.h:121
pool_entry_t * tx_send[256]
sent datagrams
Definition hw.h:130
pool_t tx_low
low priority datagrams
Definition hw.h:128
osal_mutex_t hw_lock
transmit lock
Definition hw.h:125
osal_uint64_t frame_idx
frame index number.
Definition hw.h:132
hw_device_send_t send
Function to send frames via device.
Definition hw.h:138
osal_uint32_t mtu_size
mtu size
Definition hw.h:124
osal_size_t bytes_last_sent
Bytes last sent.
Definition hw.h:134
osal_timer_t next_cylce_start
Next cycle start time.
Definition hw.h:135
hw_device_close_t close
Function to close hw layer.
Definition hw.h:141
pool_t tx_high
high priority datagrams
Definition hw.h:127
struct ec * pec
Pointer to EtherCAT master structure.
Definition hw.h:122
osal_size_t bytes_sent
Bytes currently sent.
Definition hw.h:133
hw_device_get_tx_buffer_t get_tx_buffer
Function to retreave next TX buffer.
Definition hw.h:140
hw_device_recv_t recv
\biref Function to receive frame from device.
Definition hw.h:137
hw_device_send_finished_t send_finished
Function to be called after frames were sent.
Definition hw.h:139
Pool queue entry.
Definition pool.h:67
the datagram pool itself
Definition pool.h:84