netif.h
Go to the documentation of this file.
00001 // $Id: netif.h,v 1.13 2006/02/20 15:57:33 kgad Exp $
00002 //===========================================================================
00003 //      This file is part of "EtherCAT Master Library".
00004 //      Copyright (C) 2005 FMTC vzw, Diamant Building, A. Reyerslaan 80,
00005 //      B-1030 Brussels, Belgium.
00006 //
00007 //      EtherCAT Master Library is free software; you can redistribute it
00008 //      and/or modify it under the terms of the GNU General Public License
00009 //      as published by the Free Software Foundation; either version 2 or
00010 //      (at your option) any later version.
00011 //
00012 //      EtherCAT Master Code is distributed in the hope that it will be
00013 //      useful, but WITHOUT ANY WARRANTY; without even the implied
00014 //      warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00015 //      PURPOSE. See the GNU General Public License for more details.
00016 //
00017 //      You should have received a copy of the GNU General Public License
00018 //      along with the EtherCAT Master Library; if not, write to the Free
00019 //      Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00020 //      02111-1307 USA.
00021 //
00022 //      EtherCAT, the EtherCAT trade name and logo are the intellectual
00023 //      property of, and protected by Beckhoff. You can use "EtherCAT
00024 //      Master Library" for creating and/or selling or otherwise
00025 //      distributing an EtherCAT network master under the terms of the
00026 //      EtherCAT Master License.
00027 //
00028 //      You should have received a copy of the EtherCAT Master License
00029 //      along with the EtherCAT Master Library; if not, write to Beckhoff
00030 //      Automation GmbH, Eiserstrasse 5, D-33415 Verl, Germany.
00031 //===========================================================================
00032 
00033 // $Id: netif.h,v 1.13 2006/02/20 15:57:33 kgad Exp $
00034 #ifndef __posix_netif_h__
00035 #define __posix_netif_h__
00036 
00037 // Forward declarations
00038 struct EtherCAT_Frame;
00039 struct netif;
00040 
00041 #include <stdint.h>
00042 #include <stdlib.h>
00043 
00044 #define ETHERCAT_DEVICE_NAME_MAX_LENGTH 256
00045 // Size of MAC addresses expressed as a number of bytes
00046 #define MAC_ADDRESS_SIZE 6
00047 
00048 void if_attach(struct netif * netif);
00049 int framedump(const struct EtherCAT_Frame * frame, unsigned char * buffer, size_t bufferlength);
00050 int framebuild(struct EtherCAT_Frame * frame, const unsigned char * buffer);
00051 
00052 // Number of outstanding packets to keep track of
00053 #define PKT_LIST_SIZE 128
00054 
00055 // Number of buffers to hold received packets
00056 #define BUF_LIST_SIZE 16
00057 
00058 // Should be < number of RX buffers
00059 #define MAX_UNCLAIMED_PACKETS (BUF_LIST_SIZE-1)
00060 
00061 // buffer to hold received packets
00062 
00063 struct pkt_buf
00064 {
00065   // True if the buffer is being used
00066   bool is_free;
00067   // buffer for to store ethernet message
00068   // more than enough to hold any type of message
00069   unsigned char data[2000];
00070 };
00071 
00072 // record of packet that has been sent but.
00073 //  1. has not received reply
00074 //      .... OR ....
00075 //  2. has not been claimed by higher level software
00076 
00077 struct outstanding_pkt
00078 {
00079   // whether this record is holding an outstanding packet or not
00080   bool is_free;
00081 
00082   // pointer to received packet buffer
00083   // If this is NULL if the packet has not been received
00084   struct pkt_buf *buf;
00085 
00086   // The source MAC address is used to keep track of
00087   // which packet belongs where
00088   uint8_t ether_shost[MAC_ADDRESS_SIZE];
00089 
00090   // EtherCAT_Frame that was use to generate the sent packet...
00091   // The exact same frame must be used to pickup the packet
00092   struct EtherCAT_Frame * frame;
00093 
00094   // To allow synchronization between input thread and rx function
00095   //pthread_mutex_t rx_mut;
00096   //pthread_mutexattr_t rx_attr;
00097   pthread_cond_t rx_cond;
00098 
00099   // Temember when packet was sent
00100   struct timespec tx_time;
00101 };
00102 
00103 struct netif_counters
00104 {
00105   uint64_t sent;
00106   uint64_t received;
00107   uint64_t collected;
00108   uint64_t dropped;
00109   uint64_t tx_error;
00110   uint64_t tx_net_down;
00111   uint64_t tx_would_block;
00112   uint64_t tx_no_bufs;
00113   uint64_t tx_full;
00114   uint64_t rx_runt_pkt;
00115   uint64_t rx_not_ecat;
00116   uint64_t rx_other_eml;
00117   uint64_t rx_bad_index;
00118   uint64_t rx_bad_seqnum;
00119   uint64_t rx_dup_seqnum;
00120   uint64_t rx_dup_pkt;
00121   uint64_t rx_bad_order;
00122   uint64_t rx_late_pkt; // Count of all late packets
00123   uint64_t sw_dropped; // packets that were dropped by software (for testing purposes)
00124   uint64_t rx_late_pkt_rtt_us; // Round trip time (in microseconds) of last late packet arrival
00125   uint64_t rx_late_pkt_rtt_us_sum; // Sum of rtt's of all late packets (for calculating average)
00126 };
00127 
00129 
00134 struct netif
00135 {
00137 
00141   bool (*txandrx)(struct EtherCAT_Frame * frame, struct netif * netif);
00142 
00145   bool (*txandrx_once)(struct EtherCAT_Frame * frame, struct netif * netif);
00146 
00148 
00151   int (*tx)(struct EtherCAT_Frame * frame, struct netif * netif);
00152 
00154 
00156   bool (*rx)(struct EtherCAT_Frame * frame, struct netif * netif, int handle);
00157 
00159 
00161   bool (*drop)(struct EtherCAT_Frame * frame, struct netif * netif, int handle);
00162 
00164 
00166   bool (*rx_nowait)(struct EtherCAT_Frame * frame, struct netif * netif, int handle);
00167 
00169   unsigned char hwaddr[MAC_ADDRESS_SIZE];
00171   int socket_private;
00172 
00174   struct netif_counters counters;
00175 
00177   unsigned tx_seqnum;
00178 
00180   unsigned rx_seqnum;
00181 
00183   unsigned next_pkt_index;
00184 
00187   struct outstanding_pkt pkt_list[PKT_LIST_SIZE];
00188 
00189   // Number of tx'd packets that have not been rx'd yet
00190   unsigned unclaimed_packets;
00191 
00193   struct pkt_buf buf_list[BUF_LIST_SIZE];
00194 
00195   // For thread safety: txandrx() can be called from multiple threads...
00196   pthread_mutex_t txandrx_mut;
00197   pthread_mutexattr_t txandrx_attr;
00198 
00199   // For input thread -- if it is used
00200   pthread_t input_thread;
00201   volatile bool stop;
00202   volatile bool is_stopped;
00203 
00204   // Timeout for receive in microseconds.
00205   int timeout_us;
00206 
00207   // private variable
00208   void* private_data;
00209 };
00210 
00211 #endif // __netif_h__


ros_ethercat_eml
Author(s): Tom Panis, Klaas Gadeyne, Bob Koninckx, Austin Hendrix, Manos Nikolaidis
autogenerated on Thu Jul 4 2019 20:01:49