00001 /****************************************************************************** 00002 * 00003 * $Id$ 00004 * 00005 * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH 00006 * 00007 * This file is part of the IgH EtherCAT Master. 00008 * 00009 * The IgH EtherCAT Master is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU General Public License version 2, as 00011 * published by the Free Software Foundation. 00012 * 00013 * The IgH EtherCAT Master is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 00016 * Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License along 00019 * with the IgH EtherCAT Master; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00021 * 00022 * --- 00023 * 00024 * The license mentioned above concerns the source code only. Using the 00025 * EtherCAT technology and brand is only permitted in compliance with the 00026 * industrial property and similar rights of Beckhoff Automation GmbH. 00027 * 00028 *****************************************************************************/ 00029 00035 /*****************************************************************************/ 00036 00037 #ifndef __EC_DEVICE_H__ 00038 #define __EC_DEVICE_H__ 00039 00040 #include <linux/interrupt.h> 00041 00042 #include "../devices/ecdev.h" 00043 #include "globals.h" 00044 00051 #define EC_TX_RING_SIZE 2 00052 00053 #ifdef EC_DEBUG_IF 00054 #include "debug.h" 00055 #endif 00056 00057 #ifdef EC_DEBUG_RING 00058 #define EC_DEBUG_RING_SIZE 10 00059 00060 typedef enum { 00061 TX, RX 00062 } ec_debug_frame_dir_t; 00063 00064 typedef struct { 00065 ec_debug_frame_dir_t dir; 00066 struct timeval t; 00067 uint8_t data[EC_MAX_DATA_SIZE]; 00068 unsigned int data_size; 00069 } ec_debug_frame_t; 00070 00071 #endif 00072 00073 /*****************************************************************************/ 00074 00081 struct ec_device 00082 { 00083 ec_master_t *master; 00084 struct net_device *dev; 00085 ec_pollfunc_t poll; 00086 struct module *module; 00087 uint8_t open; 00088 uint8_t link_state; 00089 struct sk_buff *tx_skb[EC_TX_RING_SIZE]; 00090 unsigned int tx_ring_index; 00091 #ifdef EC_HAVE_CYCLES 00092 cycles_t cycles_poll; 00093 #endif 00094 #ifdef EC_DEBUG_RING 00095 struct timeval timeval_poll; 00096 #endif 00097 unsigned long jiffies_poll; 00099 // Frame statistics 00100 u64 tx_count; 00101 u64 last_tx_count; 00102 u64 rx_count; 00103 u64 last_rx_count; 00105 u64 tx_bytes; 00106 u64 last_tx_bytes; 00107 u64 rx_bytes; 00108 u64 last_rx_bytes; 00110 u64 tx_errors; 00111 s32 tx_frame_rates[EC_RATE_COUNT]; 00114 s32 rx_frame_rates[EC_RATE_COUNT]; 00117 s32 tx_byte_rates[EC_RATE_COUNT]; 00119 s32 rx_byte_rates[EC_RATE_COUNT]; 00122 #ifdef EC_DEBUG_IF 00123 ec_debug_t dbg; 00124 #endif 00125 #ifdef EC_DEBUG_RING 00126 ec_debug_frame_t debug_frames[EC_DEBUG_RING_SIZE]; 00127 unsigned int debug_frame_index; 00128 unsigned int debug_frame_count; 00129 #endif 00130 }; 00131 00132 /*****************************************************************************/ 00133 00134 int ec_device_init(ec_device_t *, ec_master_t *); 00135 void ec_device_clear(ec_device_t *); 00136 00137 void ec_device_attach(ec_device_t *, struct net_device *, ec_pollfunc_t, 00138 struct module *); 00139 void ec_device_detach(ec_device_t *); 00140 00141 int ec_device_open(ec_device_t *); 00142 int ec_device_close(ec_device_t *); 00143 00144 void ec_device_poll(ec_device_t *); 00145 uint8_t *ec_device_tx_data(ec_device_t *); 00146 void ec_device_send(ec_device_t *, size_t); 00147 void ec_device_clear_stats(ec_device_t *); 00148 void ec_device_update_stats(ec_device_t *); 00149 00150 #ifdef EC_DEBUG_RING 00151 void ec_device_debug_ring_append(ec_device_t *, ec_debug_frame_dir_t, 00152 const void *, size_t); 00153 void ec_device_debug_ring_print(const ec_device_t *); 00154 #endif 00155 00156 /*****************************************************************************/ 00157 00158 #endif
1.5.6