IgH EtherCAT Master  1.5.3
device.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * $Id$
4  *
5  * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
6  *
7  * This file is part of the IgH EtherCAT Master.
8  *
9  * The IgH EtherCAT Master is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License version 2, as
11  * published by the Free Software Foundation.
12  *
13  * The IgH EtherCAT Master is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with the IgH EtherCAT Master; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * ---
23  *
24  * The license mentioned above concerns the source code only. Using the
25  * EtherCAT technology and brand is only permitted in compliance with the
26  * industrial property and similar rights of Beckhoff Automation GmbH.
27  *
28  *****************************************************************************/
29 
35 /*****************************************************************************/
36 
37 #ifndef __EC_DEVICE_H__
38 #define __EC_DEVICE_H__
39 
40 #include <linux/interrupt.h>
41 
42 #include "../devices/ecdev.h"
43 #include "globals.h"
44 
51 #define EC_TX_RING_SIZE 2
52 
53 #ifdef EC_DEBUG_IF
54 #include "debug.h"
55 #endif
56 
57 #ifdef EC_DEBUG_RING
58 #define EC_DEBUG_RING_SIZE 10
59 
60 typedef enum {
61  TX, RX
62 } ec_debug_frame_dir_t;
63 
64 typedef struct {
65  ec_debug_frame_dir_t dir;
66  struct timeval t;
67  uint8_t data[EC_MAX_DATA_SIZE];
68  unsigned int data_size;
69 } ec_debug_frame_t;
70 
71 #endif
72 
73 /*****************************************************************************/
74 
81 struct ec_device
82 {
84  struct net_device *dev;
86  struct module *module;
87  uint8_t open;
88  uint8_t link_state;
89  struct sk_buff *tx_skb[EC_TX_RING_SIZE];
90  unsigned int tx_ring_index;
91 #ifdef EC_HAVE_CYCLES
92  cycles_t cycles_poll;
93 #endif
94 #ifdef EC_DEBUG_RING
95  struct timeval timeval_poll;
96 #endif
97  unsigned long jiffies_poll;
99  // Frame statistics
100  u64 tx_count;
102  u64 rx_count;
105  u64 tx_bytes;
107  u64 rx_bytes;
110  u64 tx_errors;
122 #ifdef EC_DEBUG_IF
123  ec_debug_t dbg;
124 #endif
125 #ifdef EC_DEBUG_RING
126  ec_debug_frame_t debug_frames[EC_DEBUG_RING_SIZE];
127  unsigned int debug_frame_index;
128  unsigned int debug_frame_count;
129 #endif
130 };
131 
132 /*****************************************************************************/
133 
136 
137 void ec_device_attach(ec_device_t *, struct net_device *, ec_pollfunc_t,
138  struct module *);
140 
143 
145 uint8_t *ec_device_tx_data(ec_device_t *);
146 void ec_device_send(ec_device_t *, size_t);
149 
150 #ifdef EC_DEBUG_RING
151 void ec_device_debug_ring_append(ec_device_t *, ec_debug_frame_dir_t,
152  const void *, size_t);
153 void ec_device_debug_ring_print(const ec_device_t *);
154 #endif
155 
156 /*****************************************************************************/
157 
158 #endif
struct sk_buff * tx_skb[EC_TX_RING_SIZE]
transmit skb ring
Definition: device.h:89
void ec_device_attach(ec_device_t *, struct net_device *, ec_pollfunc_t, struct module *)
Associate with net_device.
Definition: device.c:187
ec_pollfunc_t poll
pointer to the device&#39;s poll function
Definition: device.h:85
unsigned long jiffies_poll
jiffies of last poll
Definition: device.h:97
Network interface for debugging purposes.
u64 last_tx_count
Number of frames sent of last statistics cycle.
Definition: device.h:101
#define EC_RATE_COUNT
Number of statistic rate intervals to maintain.
Definition: globals.h:60
uint8_t * ec_device_tx_data(ec_device_t *)
Returns a pointer to the device&#39;s transmit memory.
Definition: device.c:317
struct module * module
pointer to the device&#39;s owning module
Definition: device.h:86
s32 tx_frame_rates[EC_RATE_COUNT]
Transmit rates in frames/s for different statistics cycle periods.
Definition: device.h:111
Debugging network interface.
Definition: debug.h:46
uint8_t link_state
device link state
Definition: device.h:88
u64 rx_count
Number of frames received.
Definition: device.h:102
u64 last_tx_bytes
Number of bytes sent of last statistics cycle.
Definition: device.h:106
Global definitions and macros.
s32 rx_frame_rates[EC_RATE_COUNT]
Receive rates in frames/s for different statistics cycle periods.
Definition: device.h:114
void ec_device_detach(ec_device_t *)
Disconnect from net_device.
Definition: device.c:218
#define EC_TX_RING_SIZE
Size of the transmit ring.
Definition: device.h:51
u64 last_rx_count
Number of frames received of last statistics cycle.
Definition: device.h:103
void(* ec_pollfunc_t)(struct net_device *)
Device poll function type.
Definition: ecdev.h:57
s32 rx_byte_rates[EC_RATE_COUNT]
Receive rates in byte/s for different statistics cycle periods.
Definition: device.h:119
EtherCAT device.
Definition: device.h:81
unsigned int tx_ring_index
last ring entry used to transmit
Definition: device.h:90
void ec_device_poll(ec_device_t *)
Calls the poll function of the assigned net_device.
Definition: device.c:483
s32 tx_byte_rates[EC_RATE_COUNT]
Transmit rates in byte/s for different statistics cycle periods.
Definition: device.h:117
void ec_device_clear_stats(ec_device_t *)
Clears the frame statistics.
Definition: device.c:379
ec_master_t * master
EtherCAT master.
Definition: device.h:83
u64 rx_bytes
Number of bytes received.
Definition: device.h:107
u64 tx_count
Number of frames sent.
Definition: device.h:100
int ec_device_init(ec_device_t *, ec_master_t *)
Constructor.
Definition: device.c:68
uint8_t open
true, if the net_device has been opened
Definition: device.h:87
u64 tx_errors
Number of transmit errors.
Definition: device.h:110
u64 last_rx_bytes
Number of bytes received of last statistics cycle.
Definition: device.h:108
void ec_device_update_stats(ec_device_t *)
Update device statistics.
Definition: device.c:501
void ec_device_clear(ec_device_t *)
Destructor.
Definition: device.c:167
void ec_device_send(ec_device_t *, size_t)
Sends the content of the transmit socket buffer.
Definition: device.c:336
int ec_device_open(ec_device_t *)
Opens the EtherCAT device.
Definition: device.c:247
int ec_device_close(ec_device_t *)
Stops the EtherCAT device.
Definition: device.c:284
struct net_device * dev
pointer to the assigned net_device
Definition: device.h:84
EtherCAT master.
Definition: master.h:194
u64 tx_bytes
Number of bytes sent.
Definition: device.h:105
#define EC_MAX_DATA_SIZE
Resulting maximum data size of a single datagram in a frame.
Definition: globals.h:79