master/device.c
author Florian Pose <fp@igh-essen.com>
Wed, 19 Nov 2008 17:10:04 +0000
changeset 1316 d01d9cce8b59
parent 1313 ed15eef57d5c
child 1326 ef907b0b5125
permissions -rw-r--r--
Fixed unprocessed interrupts in e100 driver.
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 33
diff changeset
     1
/******************************************************************************
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 33
diff changeset
     3
 *  $Id$
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     6
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     8
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    12
 *  License, or (at your option) any later version.
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    13
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    17
 *  GNU General Public License for more details.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    18
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    22
 *
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    24
 *  charge under condition of compatibility of product made by
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    30
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    31
 *
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 33
diff changeset
    32
 *****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    34
/**
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    35
   \file
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    36
   EtherCAT device methods.
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    37
*/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    38
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    39
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    40
24
d417dd9bdc2f Wilhelms ?nderungen ?bernommen.
Florian Pose <fp@igh-essen.com>
parents: 23
diff changeset
    41
#include <linux/module.h>
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include <linux/skbuff.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include <linux/if_ether.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include <linux/netdevice.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    46
#include "device.h"
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
    47
#include "master.h"
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    49
#ifdef EC_DEBUG_RING
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    50
#define timersub(a, b, result) \
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    51
    do { \
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    52
        (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    53
        (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    54
        if ((result)->tv_usec < 0) { \
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    55
            --(result)->tv_sec; \
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    56
            (result)->tv_usec += 1000000; \
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    57
        } \
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    58
    } while (0)
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    59
#endif
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    60
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 33
diff changeset
    61
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    63
/** Constructor.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    64
 * 
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    65
 * \return 0 in case of success, else < 0
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    66
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    67
int ec_device_init(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    68
        ec_device_t *device, /**< EtherCAT device */
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
    69
        ec_master_t *master /**< master owning the device */
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
    70
        )
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
    71
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
    72
    int ret;
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
    73
    unsigned int i;
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
    74
    struct ethhdr *eth;
687
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    75
#ifdef EC_DEBUG_IF
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    76
    char ifname[10];
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    77
    char mb = 'x';
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    78
#endif
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    79
#ifdef EC_DEBUG_RING
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    80
    device->debug_frame_index = 0;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    81
    device->debug_frame_count = 0;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    82
#endif
687
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    83
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
    84
    device->master = master;
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
    85
    device->tx_ring_index = 0;
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
    86
679
62fc387ec928 Added --enable-dummy; renamed EC_DBG_IF to EC_DEBUG_IF, ENABLE_DEBUG_IF
Florian Pose <fp@igh-essen.com>
parents: 670
diff changeset
    87
#ifdef EC_DEBUG_IF
687
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    88
    if (device == &master->main_device)
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    89
        mb = 'm';
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    90
    else if (device == &master->backup_device)
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    91
        mb = 'b';
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    92
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    93
    sprintf(ifname, "ecdbg%c%u", mb, master->index);
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    94
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
    95
    ret = ec_debug_init(&device->dbg, ifname);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
    96
    if (ret < 0) {
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
    97
        EC_ERR("Failed to init debug device!\n");
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
    98
        goto out_return;
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
    99
    }
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   100
#endif
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   101
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   102
    for (i = 0; i < EC_TX_RING_SIZE; i++)
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   103
        device->tx_skb[i] = NULL;
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   104
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   105
    for (i = 0; i < EC_TX_RING_SIZE; i++) {
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   106
        if (!(device->tx_skb[i] = dev_alloc_skb(ETH_FRAME_LEN))) {
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   107
            EC_ERR("Error allocating device socket buffer!\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   108
            ret = -ENOMEM;
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   109
            goto out_tx_ring;
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   110
        }
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   111
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   112
        // add Ethernet-II-header
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   113
        skb_reserve(device->tx_skb[i], ETH_HLEN);
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   114
        eth = (struct ethhdr *) skb_push(device->tx_skb[i], ETH_HLEN);
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   115
        eth->h_proto = htons(0x88A4);
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   116
        memset(eth->h_dest, 0xFF, ETH_ALEN);
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   117
    }
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   118
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   119
    ec_device_detach(device); // resets remaining fields
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   120
    return 0;
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   121
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   122
out_tx_ring:
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   123
    for (i = 0; i < EC_TX_RING_SIZE; i++)
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   124
        if (device->tx_skb[i])
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   125
            dev_kfree_skb(device->tx_skb[i]);
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   126
#ifdef EC_DEBUG_IF
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   127
    ec_debug_clear(&device->dbg);
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   128
out_return:
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   129
#endif
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   130
    return ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   131
}
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   132
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   133
/*****************************************************************************/
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   134
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   135
/** Destructor.
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   136
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   137
void ec_device_clear(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   138
        ec_device_t *device /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   139
        )
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   140
{
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   141
    unsigned int i;
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   142
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   143
    if (device->open) ec_device_close(device);
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   144
    for (i = 0; i < EC_TX_RING_SIZE; i++)
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   145
        dev_kfree_skb(device->tx_skb[i]);
679
62fc387ec928 Added --enable-dummy; renamed EC_DBG_IF to EC_DEBUG_IF, ENABLE_DEBUG_IF
Florian Pose <fp@igh-essen.com>
parents: 670
diff changeset
   146
#ifdef EC_DEBUG_IF
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   147
    ec_debug_clear(&device->dbg);
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   148
#endif
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   149
}
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   150
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   151
/*****************************************************************************/
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   152
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   153
/** Associate with net_device.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   154
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   155
void ec_device_attach(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   156
        ec_device_t *device, /**< EtherCAT device */
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   157
        struct net_device *net_dev, /**< net_device structure */
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   158
        ec_pollfunc_t poll, /**< pointer to device's poll function */
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   159
        struct module *module /**< the device's module */
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   160
        )
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   161
{
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   162
    unsigned int i;
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   163
    struct ethhdr *eth;
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   164
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   165
    ec_device_detach(device); // resets fields
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   166
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 97
diff changeset
   167
    device->dev = net_dev;
533
acdd1f9ef7ab Replaced ec_isr_t by ec_pollfunc_t; added poll function s in network drivers.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
   168
    device->poll = poll;
539
7bb92fca28ef Fixed invalid module pointer in device structure.
Florian Pose <fp@igh-essen.com>
parents: 533
diff changeset
   169
    device->module = module;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 97
diff changeset
   170
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   171
    for (i = 0; i < EC_TX_RING_SIZE; i++) {
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   172
        device->tx_skb[i]->dev = net_dev;
759
fe32d4cdc9c3 Fixed source MAC address setting bug.
Florian Pose <fp@igh-essen.com>
parents: 725
diff changeset
   173
        eth = (struct ethhdr *) (device->tx_skb[i]->data);
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   174
        memcpy(eth->h_source, net_dev->dev_addr, ETH_ALEN);
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   175
    }
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   176
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   177
#ifdef EC_DEBUG_IF
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   178
    ec_debug_register(&device->dbg, net_dev);
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   179
#endif
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   180
}
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   181
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   182
/*****************************************************************************/
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   183
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   184
/** Disconnect from net_device.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   185
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   186
void ec_device_detach(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   187
        ec_device_t *device /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   188
        )
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   189
{
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   190
    unsigned int i;
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   191
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   192
#ifdef EC_DEBUG_IF
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   193
    ec_debug_unregister(&device->dbg);
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   194
#endif
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   195
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   196
    device->dev = NULL;
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   197
    device->poll = NULL;
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   198
    device->module = NULL;
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   199
    device->open = 0;
96
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   200
    device->link_state = 0; // down
493
b17c95eac6b2 Added frame counter.
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
   201
    device->tx_count = 0;
b17c95eac6b2 Added frame counter.
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
   202
    device->rx_count = 0;
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   203
    for (i = 0; i < EC_TX_RING_SIZE; i++)
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   204
        device->tx_skb[i]->dev = NULL;
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
}
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 33
diff changeset
   207
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   209
/** Opens the EtherCAT device.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   210
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   211
 * \return 0 in case of success, else < 0
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   212
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   213
int ec_device_open(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   214
        ec_device_t *device /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   215
        )
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   217
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   218
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   219
    if (!device->dev) {
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 78
diff changeset
   220
        EC_ERR("No net_device to open!\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   221
        return -ENODEV;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   222
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   223
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   224
    if (device->open) {
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 78
diff changeset
   225
        EC_WARN("Device already opened!\n");
91
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
   226
        return 0;
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
   227
    }
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
   228
96
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   229
    device->link_state = 0;
493
b17c95eac6b2 Added frame counter.
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
   230
    device->tx_count = 0;
b17c95eac6b2 Added frame counter.
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
   231
    device->rx_count = 0;
91
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
   232
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   233
    ret = device->dev->open(device->dev);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   234
    if (!ret)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   235
        device->open = 1;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   236
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   237
    return ret;
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
}
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 33
diff changeset
   240
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   242
/** Stops the EtherCAT device.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   243
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   244
 * \return 0 in case of success, else < 0
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   245
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   246
int ec_device_close(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   247
        ec_device_t *device /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   248
        )
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   249
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   250
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   251
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   252
    if (!device->dev) {
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 78
diff changeset
   253
        EC_ERR("No device to close!\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   254
        return -ENODEV;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   255
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   256
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   257
    if (!device->open) {
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 78
diff changeset
   258
        EC_WARN("Device already closed!\n");
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 97
diff changeset
   259
        return 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 97
diff changeset
   260
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 97
diff changeset
   261
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   262
    ret = device->dev->stop(device->dev);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   263
    if (!ret)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   264
        device->open = 0;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   265
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   266
    return ret;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   267
}
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   268
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   269
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   270
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   271
/** Returns a pointer to the device's transmit memory.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   272
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   273
 * \return pointer to the TX socket buffer
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   274
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   275
uint8_t *ec_device_tx_data(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   276
        ec_device_t *device /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   277
        )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 97
diff changeset
   278
{
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   279
    /* cycle through socket buffers, because otherwise there is a race
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   280
     * condition, if multiple frames are sent and the DMA is not scheduled in
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   281
     * between. */
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   282
    device->tx_ring_index++;
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   283
    device->tx_ring_index %= EC_TX_RING_SIZE;
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   284
    return device->tx_skb[device->tx_ring_index]->data + ETH_HLEN;
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
}
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   286
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 33
diff changeset
   287
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   289
/** Sends the content of the transmit socket buffer.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   290
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   291
 * Cuts the socket buffer content to the (now known) size, and calls the
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   292
 * start_xmit() function of the assigned net_device.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   293
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   294
void ec_device_send(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   295
        ec_device_t *device, /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   296
        size_t size /**< number of bytes to send */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   297
        )
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   298
{
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   299
    struct sk_buff *skb = device->tx_skb[device->tx_ring_index];
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   300
97
e6264685dd7b Link-Down-Verhalten verbessert.
Florian Pose <fp@igh-essen.com>
parents: 96
diff changeset
   301
    if (unlikely(!device->link_state)) // Link down
96
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   302
        return;
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   303
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   304
    // set the right length for the data
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   305
    skb->len = ETH_HLEN + size;
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   306
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   307
    if (unlikely(device->master->debug_level > 1)) {
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 97
diff changeset
   308
        EC_DBG("sending frame:\n");
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   309
        ec_print_data(skb->data + ETH_HLEN, size);
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   310
    }
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   311
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   312
    // start sending
725
8bacb27f3aa2 Send frame to debug-if and debug-ring only when transmitted
Florian Pose <fp@igh-essen.com>
parents: 693
diff changeset
   313
    if (device->dev->hard_start_xmit(skb, device->dev) == NETDEV_TX_OK) {
8bacb27f3aa2 Send frame to debug-if and debug-ring only when transmitted
Florian Pose <fp@igh-essen.com>
parents: 693
diff changeset
   314
		device->tx_count++;
8bacb27f3aa2 Send frame to debug-if and debug-ring only when transmitted
Florian Pose <fp@igh-essen.com>
parents: 693
diff changeset
   315
#ifdef EC_DEBUG_IF
8bacb27f3aa2 Send frame to debug-if and debug-ring only when transmitted
Florian Pose <fp@igh-essen.com>
parents: 693
diff changeset
   316
		ec_debug_send(&device->dbg, skb->data, ETH_HLEN + size);
8bacb27f3aa2 Send frame to debug-if and debug-ring only when transmitted
Florian Pose <fp@igh-essen.com>
parents: 693
diff changeset
   317
#endif
8bacb27f3aa2 Send frame to debug-if and debug-ring only when transmitted
Florian Pose <fp@igh-essen.com>
parents: 693
diff changeset
   318
#ifdef EC_DEBUG_RING
8bacb27f3aa2 Send frame to debug-if and debug-ring only when transmitted
Florian Pose <fp@igh-essen.com>
parents: 693
diff changeset
   319
		ec_device_debug_ring_append(
8bacb27f3aa2 Send frame to debug-if and debug-ring only when transmitted
Florian Pose <fp@igh-essen.com>
parents: 693
diff changeset
   320
				device, TX, skb->data + ETH_HLEN, size);
8bacb27f3aa2 Send frame to debug-if and debug-ring only when transmitted
Florian Pose <fp@igh-essen.com>
parents: 693
diff changeset
   321
#endif
8bacb27f3aa2 Send frame to debug-if and debug-ring only when transmitted
Florian Pose <fp@igh-essen.com>
parents: 693
diff changeset
   322
	}
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   323
}
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   324
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   325
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   326
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   327
#ifdef EC_DEBUG_RING
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   328
/** Appends frame data to the debug ring.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   329
 */
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   330
void ec_device_debug_ring_append(
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   331
        ec_device_t *device, /**< EtherCAT device */
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   332
        ec_debug_frame_dir_t dir, /**< direction */
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   333
        const void *data, /**< frame data */
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   334
        size_t size /**< data size */
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   335
        )
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   336
{
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   337
    ec_debug_frame_t *df = &device->debug_frames[device->debug_frame_index];
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   338
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   339
    df->dir = dir;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   340
    if (dir == TX)
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   341
        do_gettimeofday(&df->t);
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   342
    else
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   343
        df->t = device->timeval_poll;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   344
    memcpy(df->data, data, size);
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   345
    df->data_size = size;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   346
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   347
    device->debug_frame_index++;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   348
    device->debug_frame_index %= EC_DEBUG_RING_SIZE;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   349
    if (unlikely(device->debug_frame_count < EC_DEBUG_RING_SIZE))
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   350
        device->debug_frame_count++;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   351
}
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   352
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   353
/*****************************************************************************/
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   354
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   355
/** Outputs the debug ring.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   356
 */
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   357
void ec_device_debug_ring_print(
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   358
        const ec_device_t *device /**< EtherCAT device */
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   359
        )
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   360
{
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   361
    int i;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   362
    unsigned int ring_index;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   363
    const ec_debug_frame_t *df;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   364
    struct timeval t0, diff;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   365
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   366
    // calculate index of the newest frame in the ring to get its time
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   367
    ring_index = (device->debug_frame_index + EC_DEBUG_RING_SIZE - 1)
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   368
        % EC_DEBUG_RING_SIZE;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   369
    t0 = device->debug_frames[ring_index].t;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   370
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 759
diff changeset
   371
    EC_DBG("Debug ring %u:\n", ring_index);
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   372
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   373
    // calculate index of the oldest frame in the ring
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   374
    ring_index = (device->debug_frame_index + EC_DEBUG_RING_SIZE
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   375
            - device->debug_frame_count) % EC_DEBUG_RING_SIZE;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   376
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   377
    for (i = 0; i < device->debug_frame_count; i++) {
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   378
        df = &device->debug_frames[ring_index];
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   379
        timersub(&t0, &df->t, &diff);
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   380
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 759
diff changeset
   381
        EC_DBG("Frame %u, dt=%u.%06u s, %s:\n",
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   382
                i + 1 - device->debug_frame_count,
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   383
                (unsigned int) diff.tv_sec,
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   384
                (unsigned int) diff.tv_usec,
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   385
                (df->dir == TX) ? "TX" : "RX");
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   386
        ec_print_data(df->data, df->data_size);
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   387
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   388
        ring_index++;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   389
        ring_index %= EC_DEBUG_RING_SIZE;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   390
    }
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   391
}
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   392
#endif
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   393
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   394
/*****************************************************************************/
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   395
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   396
/** Calls the poll function of the assigned net_device.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   397
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   398
 * The master itself works without using interrupts. Therefore the processing
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   399
 * of received data and status changes of the network device has to be
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   400
 * done by the master calling the ISR "manually".
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   401
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   402
void ec_device_poll(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   403
        ec_device_t *device /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   404
        )
533
acdd1f9ef7ab Replaced ec_isr_t by ec_pollfunc_t; added poll function s in network drivers.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
   405
{
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   406
#ifdef EC_HAVE_CYCLES
533
acdd1f9ef7ab Replaced ec_isr_t by ec_pollfunc_t; added poll function s in network drivers.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
   407
    device->cycles_poll = get_cycles();
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   408
#endif
533
acdd1f9ef7ab Replaced ec_isr_t by ec_pollfunc_t; added poll function s in network drivers.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
   409
    device->jiffies_poll = jiffies;
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   410
#ifdef EC_DEBUG_RING
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   411
    do_gettimeofday(&device->timeval_poll);
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   412
#endif
533
acdd1f9ef7ab Replaced ec_isr_t by ec_pollfunc_t; added poll function s in network drivers.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
   413
    device->poll(device->dev);
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 33
diff changeset
   414
}
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 33
diff changeset
   415
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   416
/******************************************************************************
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   417
 *  Device interface
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   418
 *****************************************************************************/
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   419
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   420
/** Withdraws an EtherCAT device from the master.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   421
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   422
 * The device is disconnected from the master and all device ressources
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   423
 * are freed.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   424
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   425
 * \attention Before calling this function, the ecdev_stop() function has
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   426
 *            to be called, to be sure that the master does not use the device
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   427
 *            any more.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   428
 * \ingroup DeviceInterface
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   429
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   430
void ecdev_withdraw(ec_device_t *device /**< EtherCAT device */)
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   431
{
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   432
    ec_master_t *master = device->master;
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   433
    char str[20];
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   434
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   435
    ec_mac_print(device->dev->dev_addr, str);
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   436
    EC_INFO("Master %u releasing main device %s.\n", master->index, str);
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   437
    
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   438
    down(&master->device_sem);
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   439
    ec_device_detach(device);
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   440
    up(&master->device_sem);
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   441
}
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   442
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   443
/*****************************************************************************/
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   444
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1011
diff changeset
   445
/** Opens the network device and makes the master enter IDLE phase.
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   446
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   447
 * \return 0 on success, else < 0
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   448
 * \ingroup DeviceInterface
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   449
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   450
int ecdev_open(ec_device_t *device /**< EtherCAT device */)
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   451
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   452
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   453
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   454
    ret = ec_device_open(device);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   455
    if (ret) {
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   456
        EC_ERR("Failed to open device!\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   457
        return ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   458
    }
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   459
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   460
    ret = ec_master_enter_idle_phase(device->master);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   461
    if (ret) {
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1011
diff changeset
   462
        EC_ERR("Failed to enter IDLE phase!\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   463
        return ret;
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   464
    }
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   465
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   466
    return 0;
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   467
}
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   468
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   469
/*****************************************************************************/
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   470
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1011
diff changeset
   471
/** Makes the master leave IDLE phase and closes the network device.
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   472
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   473
 * \return 0 on success, else < 0
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   474
 * \ingroup DeviceInterface
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   475
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   476
void ecdev_close(ec_device_t *device /**< EtherCAT device */)
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   477
{
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1011
diff changeset
   478
    ec_master_leave_idle_phase(device->master);
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   479
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   480
    if (ec_device_close(device))
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   481
        EC_WARN("Failed to close device!\n");
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   482
}
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   483
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   484
/*****************************************************************************/
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   485
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   486
/** Accepts a received frame.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   487
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   488
 * Forwards the received data to the master. The master will analyze the frame
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   489
 * and dispatch the received commands to the sending instances.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   490
 * 
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   491
 * \ingroup DeviceInterface
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   492
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   493
void ecdev_receive(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   494
        ec_device_t *device, /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   495
        const void *data, /**< pointer to received data */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   496
        size_t size /**< number of bytes received */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   497
        )
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   498
{
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   499
    const void *ec_data = data + ETH_HLEN;
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   500
    size_t ec_size = size - ETH_HLEN;
493
b17c95eac6b2 Added frame counter.
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
   501
    device->rx_count++;
b17c95eac6b2 Added frame counter.
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
   502
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   503
    if (unlikely(device->master->debug_level > 1)) {
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 78
diff changeset
   504
        EC_DBG("Received frame:\n");
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   505
        ec_print_data(ec_data, ec_size);
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents: 211
diff changeset
   506
    }
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents: 211
diff changeset
   507
679
62fc387ec928 Added --enable-dummy; renamed EC_DBG_IF to EC_DEBUG_IF, ENABLE_DEBUG_IF
Florian Pose <fp@igh-essen.com>
parents: 670
diff changeset
   508
#ifdef EC_DEBUG_IF
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents: 211
diff changeset
   509
    ec_debug_send(&device->dbg, data, size);
392
eaee3c8d6ae0 Debug interfaces not compiled by default.
Florian Pose <fp@igh-essen.com>
parents: 331
diff changeset
   510
#endif
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   511
#ifdef EC_DEBUG_RING
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   512
    ec_device_debug_ring_append(device, RX, ec_data, ec_size);
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   513
#endif
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   514
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   515
    ec_master_receive_datagrams(device->master, ec_data, ec_size);
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   516
}
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   517
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   518
/*****************************************************************************/
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   519
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   520
/** Sets a new link state.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   521
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   522
 * If the device notifies the master about the link being down, the master
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   523
 * will not try to send frames using this device.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   524
 * 
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   525
 * \ingroup DeviceInterface
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   526
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   527
void ecdev_set_link(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   528
        ec_device_t *device, /**< EtherCAT device */
670
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   529
        uint8_t state /**< new link state */
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   530
        )
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   531
{
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 152
diff changeset
   532
    if (unlikely(!device)) {
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   533
        EC_WARN("ecdev_set_link(): No device!\n");
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 152
diff changeset
   534
        return;
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 152
diff changeset
   535
    }
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 152
diff changeset
   536
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   537
    if (likely(state != device->link_state)) {
96
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   538
        device->link_state = state;
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   539
        EC_INFO("Link state changed to %s.\n", (state ? "UP" : "DOWN"));
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   540
    }
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   541
}
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   542
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   543
/*****************************************************************************/
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   544
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   545
/** Reads the link state.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   546
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   547
 * \ingroup DeviceInterface
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   548
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   549
uint8_t ecdev_get_link(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   550
        const ec_device_t *device /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   551
        )
670
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   552
{
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   553
    if (unlikely(!device)) {
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   554
        EC_WARN("ecdev_get_link(): No device!\n");
670
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   555
        return 0;
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   556
    }
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   557
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   558
    return device->link_state;
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   559
}
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   560
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   561
/*****************************************************************************/
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   562
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   563
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   564
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   565
EXPORT_SYMBOL(ecdev_withdraw);
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   566
EXPORT_SYMBOL(ecdev_open);
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   567
EXPORT_SYMBOL(ecdev_close);
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   568
EXPORT_SYMBOL(ecdev_receive);
670
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   569
EXPORT_SYMBOL(ecdev_get_link);
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   570
EXPORT_SYMBOL(ecdev_set_link);
27
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents: 26
diff changeset
   571
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   572
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   573
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   574
/*****************************************************************************/