IgH EtherCAT Master  1.6.2
device.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
4  *
5  * This file is part of the IgH EtherCAT Master.
6  *
7  * The IgH EtherCAT Master is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License version 2, as
9  * published by the Free Software Foundation.
10  *
11  * The IgH EtherCAT Master is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with the IgH EtherCAT Master; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  ****************************************************************************/
21 
27 /****************************************************************************/
28 
29 #ifndef __EC_DEVICE_H__
30 #define __EC_DEVICE_H__
31 
32 #include <linux/interrupt.h>
33 
34 #include "../devices/ecdev.h"
35 #include "globals.h"
36 
43 #define EC_TX_RING_SIZE 2
44 
45 #ifdef EC_DEBUG_IF
46 #include "debug.h"
47 #endif
48 
49 #ifdef EC_DEBUG_RING
50 #define EC_DEBUG_RING_SIZE 10
51 
52 typedef enum {
53  TX, RX
54 } ec_debug_frame_dir_t;
55 
56 typedef struct {
57  ec_debug_frame_dir_t dir;
58  struct timeval t;
59  uint8_t data[EC_MAX_DATA_SIZE];
60  unsigned int data_size;
61 } ec_debug_frame_t;
62 
63 #endif
64 
65 /****************************************************************************/
66 
73 struct ec_device
74 {
76  struct net_device *dev;
78  struct module *module;
79  uint8_t open;
80  uint8_t link_state;
81  struct sk_buff *tx_skb[EC_TX_RING_SIZE];
82  unsigned int tx_ring_index;
83 #ifdef EC_HAVE_CYCLES
84  cycles_t cycles_poll;
85 #endif
86 #ifdef EC_DEBUG_RING
87  struct timeval timeval_poll;
88 #endif
89  unsigned long jiffies_poll;
91  // Frame statistics
92  u64 tx_count;
94  u64 rx_count;
97  u64 tx_bytes;
99  u64 rx_bytes;
102  u64 tx_errors;
114 #ifdef EC_DEBUG_IF
115  ec_debug_t dbg;
116 #endif
117 #ifdef EC_DEBUG_RING
118  ec_debug_frame_t debug_frames[EC_DEBUG_RING_SIZE];
119  unsigned int debug_frame_index;
120  unsigned int debug_frame_count;
121 #endif
122 };
123 
124 /****************************************************************************/
125 
128 
129 void ec_device_attach(ec_device_t *, struct net_device *, ec_pollfunc_t,
130  struct module *);
132 
135 
137 uint8_t *ec_device_tx_data(ec_device_t *);
138 void ec_device_send(ec_device_t *, size_t);
141 
142 #ifdef EC_DEBUG_RING
143 void ec_device_debug_ring_append(ec_device_t *, ec_debug_frame_dir_t,
144  const void *, size_t);
145 void ec_device_debug_ring_print(const ec_device_t *);
146 #endif
147 
148 /****************************************************************************/
149 
150 #endif
struct sk_buff * tx_skb[EC_TX_RING_SIZE]
transmit skb ring
Definition: device.h:81
void ec_device_attach(ec_device_t *, struct net_device *, ec_pollfunc_t, struct module *)
Associate with net_device.
Definition: device.c:179
ec_pollfunc_t poll
pointer to the device&#39;s poll function
Definition: device.h:77
unsigned long jiffies_poll
jiffies of last poll
Definition: device.h:89
Network interface for debugging purposes.
u64 last_tx_count
Number of frames sent of last statistics cycle.
Definition: device.h:93
#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:301
struct module * module
pointer to the device&#39;s owning module
Definition: device.h:78
s32 tx_frame_rates[EC_RATE_COUNT]
Transmit rates in frames/s for different statistics cycle periods.
Definition: device.h:103
Debugging network interface.
Definition: debug.h:38
uint8_t link_state
device link state
Definition: device.h:80
u64 rx_count
Number of frames received.
Definition: device.h:94
u64 last_tx_bytes
Number of bytes sent of last statistics cycle.
Definition: device.h:98
Global definitions and macros.
s32 rx_frame_rates[EC_RATE_COUNT]
Receive rates in frames/s for different statistics cycle periods.
Definition: device.h:106
void ec_device_detach(ec_device_t *)
Disconnect from net_device.
Definition: device.c:210
#define EC_TX_RING_SIZE
Size of the transmit ring.
Definition: device.h:43
u64 last_rx_count
Number of frames received of last statistics cycle.
Definition: device.h:95
void(* ec_pollfunc_t)(struct net_device *)
Device poll function type.
Definition: ecdev.h:49
s32 rx_byte_rates[EC_RATE_COUNT]
Receive rates in byte/s for different statistics cycle periods.
Definition: device.h:111
EtherCAT device.
Definition: device.h:73
unsigned int tx_ring_index
last ring entry used to transmit
Definition: device.h:82
void ec_device_poll(ec_device_t *)
Calls the poll function of the assigned net_device.
Definition: device.c:463
s32 tx_byte_rates[EC_RATE_COUNT]
Transmit rates in byte/s for different statistics cycle periods.
Definition: device.h:109
void ec_device_clear_stats(ec_device_t *)
Clears the frame statistics.
Definition: device.c:359
ec_master_t * master
EtherCAT master.
Definition: device.h:75
u64 rx_bytes
Number of bytes received.
Definition: device.h:99
u64 tx_count
Number of frames sent.
Definition: device.h:92
int ec_device_init(ec_device_t *, ec_master_t *)
Constructor.
Definition: device.c:60
uint8_t open
true, if the net_device has been opened
Definition: device.h:79
u64 tx_errors
Number of transmit errors.
Definition: device.h:102
u64 last_rx_bytes
Number of bytes received of last statistics cycle.
Definition: device.h:100
void ec_device_update_stats(ec_device_t *)
Update device statistics.
Definition: device.c:481
void ec_device_clear(ec_device_t *)
Destructor.
Definition: device.c:159
void ec_device_send(ec_device_t *, size_t)
Sends the content of the transmit socket buffer.
Definition: device.c:320
int ec_device_open(ec_device_t *)
Opens the EtherCAT device.
Definition: device.c:239
int ec_device_close(ec_device_t *)
Stops the EtherCAT device.
Definition: device.c:272
struct net_device * dev
pointer to the assigned net_device
Definition: device.h:76
EtherCAT master.
Definition: master.h:187
u64 tx_bytes
Number of bytes sent.
Definition: device.h:97
#define EC_MAX_DATA_SIZE
Resulting maximum data size of a single datagram in a frame.
Definition: globals.h:79