master/device.c
branchstable-1.0
changeset 1619 0d4119024f55
parent 1618 5cff10efb927
equal deleted inserted replaced
1618:5cff10efb927 1619:0d4119024f55
     6  *
     6  *
     7  *  This file is part of the IgH EtherCAT Master.
     7  *  This file is part of the IgH EtherCAT Master.
     8  *
     8  *
     9  *  The IgH EtherCAT Master is free software; you can redistribute it
     9  *  The IgH EtherCAT Master is free software; you can redistribute it
    10  *  and/or modify it under the terms of the GNU General Public License
    10  *  and/or modify it under the terms of the GNU General Public License
    11  *  as published by the Free Software Foundation; version 2 of the License.
    11  *  as published by the Free Software Foundation; either version 2 of the
       
    12  *  License, or (at your option) any later version.
    12  *
    13  *
    13  *  The IgH EtherCAT Master is distributed in the hope that it will be
    14  *  The IgH EtherCAT Master is distributed in the hope that it will be
    14  *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  *  GNU General Public License for more details.
    17  *  GNU General Public License for more details.
    17  *
    18  *
    18  *  You should have received a copy of the GNU General Public License
    19  *  You should have received a copy of the GNU General Public License
    19  *  along with the IgH EtherCAT Master; if not, write to the Free Software
    20  *  along 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  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    22  *
       
    23  *  The right to use EtherCAT Technology is granted and comes free of
       
    24  *  charge under condition of compatibility of product made by
       
    25  *  Licensee. People intending to distribute/sell products based on the
       
    26  *  code, have to sign an agreement to guarantee that products using
       
    27  *  software based on IgH EtherCAT master stay compatible with the actual
       
    28  *  EtherCAT specification (which are released themselves as an open
       
    29  *  standard) as the (only) precondition to have the right to use EtherCAT
       
    30  *  Technology, IP and trade marks.
    21  *
    31  *
    22  *****************************************************************************/
    32  *****************************************************************************/
    23 
    33 
    24 /**
    34 /**
    25    \file
    35    \file
    59     device->module = module;
    69     device->module = module;
    60 
    70 
    61     device->open = 0;
    71     device->open = 0;
    62     device->link_state = 0; // down
    72     device->link_state = 0; // down
    63 
    73 
    64     if (!(device->tx_skb = dev_alloc_skb(ETH_HLEN + EC_MAX_FRAME_SIZE))) {
    74     if (ec_debug_init(&device->dbg)) {
       
    75         EC_ERR("Failed to init debug device!\n");
       
    76         goto out_return;
       
    77     }
       
    78 
       
    79     if (!(device->tx_skb = dev_alloc_skb(ETH_FRAME_LEN))) {
    65         EC_ERR("Error allocating device socket buffer!\n");
    80         EC_ERR("Error allocating device socket buffer!\n");
    66         return -1;
    81         goto out_debug;
    67     }
    82     }
    68 
    83 
    69     device->tx_skb->dev = net_dev;
    84     device->tx_skb->dev = net_dev;
    70 
    85 
    71     // add Ethernet-II-header
    86     // add Ethernet-II-header
    74     eth->h_proto = htons(0x88A4);
    89     eth->h_proto = htons(0x88A4);
    75     memcpy(eth->h_source, net_dev->dev_addr, net_dev->addr_len);
    90     memcpy(eth->h_source, net_dev->dev_addr, net_dev->addr_len);
    76     memset(eth->h_dest, 0xFF, net_dev->addr_len);
    91     memset(eth->h_dest, 0xFF, net_dev->addr_len);
    77 
    92 
    78     return 0;
    93     return 0;
       
    94 
       
    95  out_debug:
       
    96     ec_debug_clear(&device->dbg);
       
    97  out_return:
       
    98     return -1;
    79 }
    99 }
    80 
   100 
    81 /*****************************************************************************/
   101 /*****************************************************************************/
    82 
   102 
    83 /**
   103 /**
    86 
   106 
    87 void ec_device_clear(ec_device_t *device /**< EtherCAT device */)
   107 void ec_device_clear(ec_device_t *device /**< EtherCAT device */)
    88 {
   108 {
    89     if (device->open) ec_device_close(device);
   109     if (device->open) ec_device_close(device);
    90     if (device->tx_skb) dev_kfree_skb(device->tx_skb);
   110     if (device->tx_skb) dev_kfree_skb(device->tx_skb);
       
   111     ec_debug_clear(&device->dbg);
    91 }
   112 }
    92 
   113 
    93 /*****************************************************************************/
   114 /*****************************************************************************/
    94 
   115 
    95 /**
   116 /**
   177 
   198 
   178     if (unlikely(device->master->debug_level > 1)) {
   199     if (unlikely(device->master->debug_level > 1)) {
   179         EC_DBG("sending frame:\n");
   200         EC_DBG("sending frame:\n");
   180         ec_print_data(device->tx_skb->data + ETH_HLEN, size);
   201         ec_print_data(device->tx_skb->data + ETH_HLEN, size);
   181     }
   202     }
       
   203 
       
   204     ec_debug_send(&device->dbg, device->tx_skb->data, ETH_HLEN + size);
   182 
   205 
   183     // start sending
   206     // start sending
   184     device->dev->hard_start_xmit(device->tx_skb, device->dev);
   207     device->dev->hard_start_xmit(device->tx_skb, device->dev);
   185 }
   208 }
   186 
   209 
   208    and dispatch the received commands to the sending instances.
   231    and dispatch the received commands to the sending instances.
   209    \ingroup DeviceInterface
   232    \ingroup DeviceInterface
   210 */
   233 */
   211 
   234 
   212 void ecdev_receive(ec_device_t *device, /**< EtherCAT device */
   235 void ecdev_receive(ec_device_t *device, /**< EtherCAT device */
   213                    const void *data, /**< pointer to receibed data */
   236                    const void *data, /**< pointer to received data */
   214                    size_t size /**< number of bytes received */
   237                    size_t size /**< number of bytes received */
   215                    )
   238                    )
   216 {
   239 {
   217     if (unlikely(device->master->debug_level > 1)) {
   240     if (unlikely(device->master->debug_level > 1)) {
   218         EC_DBG("Received frame:\n");
   241         EC_DBG("Received frame:\n");
   219         ec_print_data_diff(device->tx_skb->data + ETH_HLEN, data, size);
   242         ec_print_data_diff(device->tx_skb->data + ETH_HLEN,
   220     }
   243                            data + ETH_HLEN, size - ETH_HLEN);
   221 
   244     }
   222     ec_master_receive(device->master, data, size);
   245 
       
   246     ec_debug_send(&device->dbg, data, size);
       
   247 
       
   248     ec_master_receive(device->master, data + ETH_HLEN, size - ETH_HLEN);
   223 }
   249 }
   224 
   250 
   225 /*****************************************************************************/
   251 /*****************************************************************************/
   226 
   252 
   227 /**
   253 /**