master/device.c
author Philipp Weyer <pw@igh-essen.com>
Fri, 18 Aug 2017 12:30:16 +0200
changeset 2679 33b922ec1871
parent 2589 2b9c78543663
permissions -rw-r--r--
Fixed lib include paths
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
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
197
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
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    11
 *  published by the Free Software Foundation.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    12
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    16
 *  Public License for more details.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    17
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    20
 *  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
    21
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    27
 *
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 33
diff changeset
    28
 *****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    30
/**
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    31
   \file
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    32
   EtherCAT device methods.
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    33
*/
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
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    36
24
d417dd9bdc2f Wilhelms ?nderungen ?bernommen.
Florian Pose <fp@igh-essen.com>
parents: 23
diff changeset
    37
#include <linux/module.h>
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include <linux/skbuff.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include <linux/if_ether.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include <linux/netdevice.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    42
#include "device.h"
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
    43
#include "master.h"
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    45
#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
    46
#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
    47
    do { \
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    48
        (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
    49
        (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
    50
        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
    51
            --(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
    52
            (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
    53
        } \
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    54
    } 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
    55
#endif
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    56
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 33
diff changeset
    57
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    59
/** Constructor.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    60
 *
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    61
 * \return 0 in case of success, else < 0
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    62
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    63
int ec_device_init(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    64
        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
    65
        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
    66
        )
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
    67
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
    68
    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
    69
    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
    70
    struct ethhdr *eth;
687
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    71
#ifdef EC_DEBUG_IF
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    72
    char ifname[10];
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    73
    char mb = 'x';
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
    74
#endif
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    75
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    76
    device->master = master;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    77
    device->dev = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    78
    device->poll = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    79
    device->module = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    80
    device->open = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    81
    device->link_state = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    82
    for (i = 0; i < EC_TX_RING_SIZE; i++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    83
        device->tx_skb[i] = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    84
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    85
    device->tx_ring_index = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    86
#ifdef EC_HAVE_CYCLES
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    87
    device->cycles_poll = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    88
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    89
#ifdef EC_DEBUG_RING
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    90
    device->timeval_poll.tv_sec = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    91
    device->timeval_poll.tv_usec = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    92
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    93
    device->jiffies_poll = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    94
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    95
    ec_device_clear_stats(device);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    96
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    97
#ifdef EC_DEBUG_RING
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    98
    for (i = 0; i < EC_DEBUG_RING_SIZE; i++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
    99
        ec_debug_frame_t *df = &device->debug_frames[i];
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   100
        df->dir = TX;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   101
        df->t.tv_sec = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   102
        df->t.tv_usec = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   103
        memset(df->data, 0, EC_MAX_DATA_SIZE);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   104
        df->data_size = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   105
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   106
#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
   107
#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
   108
    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
   109
    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
   110
#endif
687
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
   111
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
   112
#ifdef EC_DEBUG_IF
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   113
    if (device == &master->devices[EC_DEVICE_MAIN]) {
687
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
   114
        mb = 'm';
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   115
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   116
    else {
687
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
   117
        mb = 'b';
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   118
    }
687
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
   119
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
   120
    sprintf(ifname, "ecdbg%c%u", mb, master->index);
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 679
diff changeset
   121
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   122
    ret = ec_debug_init(&device->dbg, device, ifname);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   123
    if (ret < 0) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   124
        EC_MASTER_ERR(master, "Failed to init debug device!\n");
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   125
        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
   126
    }
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   127
#endif
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   128
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   129
    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
   130
        if (!(device->tx_skb[i] = dev_alloc_skb(ETH_FRAME_LEN))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   131
            EC_MASTER_ERR(master, "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
   132
            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
   133
            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
   134
        }
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   135
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   136
        // 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
   137
        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
   138
        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
   139
        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
   140
        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
   141
    }
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   142
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   143
    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
   144
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   145
out_tx_ring:
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   146
    for (i = 0; i < EC_TX_RING_SIZE; i++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   147
        if (device->tx_skb[i]) {
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   148
            dev_kfree_skb(device->tx_skb[i]);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   149
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   150
    }
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   151
#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
   152
    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
   153
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
   154
#endif
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   155
    return ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   156
}
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   157
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   158
/*****************************************************************************/
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   159
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   160
/** Destructor.
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   161
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   162
void ec_device_clear(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   163
        ec_device_t *device /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
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
{
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   166
    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
   167
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   168
    if (device->open) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   169
        ec_device_close(device);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
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
        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
   173
#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
   174
    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
   175
#endif
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   176
}
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   177
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   178
/*****************************************************************************/
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   179
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   180
/** Associate with net_device.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   181
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   182
void ec_device_attach(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   183
        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
   184
        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
   185
        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
   186
        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
   187
        )
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   188
{
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   189
    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
   190
    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
   191
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   192
    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
   193
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 97
diff changeset
   194
    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
   195
    device->poll = poll;
539
7bb92fca28ef Fixed invalid module pointer in device structure.
Florian Pose <fp@igh-essen.com>
parents: 533
diff changeset
   196
    device->module = module;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 97
diff changeset
   197
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   198
    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
   199
        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
   200
        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
   201
        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
   202
    }
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   203
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   204
#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
   205
    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
   206
#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
   207
}
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   208
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   209
/*****************************************************************************/
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   210
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   211
/** Disconnect from net_device.
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
void ec_device_detach(
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
        )
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   216
{
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   217
    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
   218
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   219
#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
   220
    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
   221
#endif
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   222
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 574
diff changeset
   223
    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
   224
    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
   225
    device->module = NULL;
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   226
    device->open = 0;
96
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   227
    device->link_state = 0; // down
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1856
diff changeset
   228
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1856
diff changeset
   229
    ec_device_clear_stats(device);
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1856
diff changeset
   230
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   231
    for (i = 0; i < EC_TX_RING_SIZE; i++) {
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   232
        device->tx_skb[i]->dev = NULL;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   233
    }
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
}
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 33
diff changeset
   236
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   238
/** Opens the EtherCAT device.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   239
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   240
 * \return 0 in case of success, else < 0
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   241
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   242
int ec_device_open(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   243
        ec_device_t *device /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   244
        )
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   246
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   247
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   248
    if (!device->dev) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   249
        EC_MASTER_ERR(device->master, "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
   250
        return -ENODEV;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   251
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   252
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   253
    if (device->open) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   254
        EC_MASTER_WARN(device->master, "Device already opened!\n");
91
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
   255
        return 0;
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
   256
    }
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
   257
96
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   258
    device->link_state = 0;
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1856
diff changeset
   259
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1856
diff changeset
   260
    ec_device_clear_stats(device);
91
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
   261
1476
1da1c72fd495 Implemented new network device operations for kernel 2.6.29, thanks to M. Goetze.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   262
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
1da1c72fd495 Implemented new network device operations for kernel 2.6.29, thanks to M. Goetze.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   263
    ret = device->dev->netdev_ops->ndo_open(device->dev);
1da1c72fd495 Implemented new network device operations for kernel 2.6.29, thanks to M. Goetze.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   264
#else
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   265
    ret = device->dev->open(device->dev);
1476
1da1c72fd495 Implemented new network device operations for kernel 2.6.29, thanks to M. Goetze.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   266
#endif
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   267
    if (!ret)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   268
        device->open = 1;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   269
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   270
    return ret;
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
}
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 33
diff changeset
   273
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   275
/** Stops the EtherCAT device.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   276
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   277
 * \return 0 in case of success, else < 0
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   278
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   279
int ec_device_close(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   280
        ec_device_t *device /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   281
        )
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   282
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   283
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   284
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   285
    if (!device->dev) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   286
        EC_MASTER_ERR(device->master, "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
   287
        return -ENODEV;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   288
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   289
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   290
    if (!device->open) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   291
        EC_MASTER_WARN(device->master, "Device already closed!\n");
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 97
diff changeset
   292
        return 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 97
diff changeset
   293
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 97
diff changeset
   294
1476
1da1c72fd495 Implemented new network device operations for kernel 2.6.29, thanks to M. Goetze.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   295
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
1da1c72fd495 Implemented new network device operations for kernel 2.6.29, thanks to M. Goetze.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   296
    ret = device->dev->netdev_ops->ndo_stop(device->dev);
1da1c72fd495 Implemented new network device operations for kernel 2.6.29, thanks to M. Goetze.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   297
#else
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   298
    ret = device->dev->stop(device->dev);
1476
1da1c72fd495 Implemented new network device operations for kernel 2.6.29, thanks to M. Goetze.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   299
#endif
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   300
    if (!ret)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   301
        device->open = 0;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   302
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   303
    return ret;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   304
}
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   305
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   306
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   307
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   308
/** Returns a pointer to the device's transmit memory.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   309
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   310
 * \return pointer to the TX socket buffer
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   311
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   312
uint8_t *ec_device_tx_data(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   313
        ec_device_t *device /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   314
        )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 97
diff changeset
   315
{
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   316
    /* 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
   317
     * 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
   318
     * between. */
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   319
    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
   320
    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
   321
    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
   322
}
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   323
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 33
diff changeset
   324
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   326
/** Sends the content of the transmit socket buffer.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   327
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   328
 * 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
   329
 * start_xmit() function of the assigned net_device.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   330
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   331
void ec_device_send(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   332
        ec_device_t *device, /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   333
        size_t size /**< number of bytes to send */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   334
        )
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   335
{
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   336
    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
   337
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   338
    // 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
   339
    skb->len = ETH_HLEN + size;
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   340
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   341
    if (unlikely(device->master->debug_level > 1)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   342
        EC_MASTER_DBG(device->master, 2, "Sending frame:\n");
1554
e07a0f8de03d Print complete Ethernet frame during debug.
Florian Pose <fp@igh-essen.com>
parents: 1521
diff changeset
   343
        ec_print_data(skb->data, ETH_HLEN + size);
693
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   344
    }
e341f1788608 Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
   345
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   346
    // start sending
1476
1da1c72fd495 Implemented new network device operations for kernel 2.6.29, thanks to M. Goetze.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   347
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
1554
e07a0f8de03d Print complete Ethernet frame during debug.
Florian Pose <fp@igh-essen.com>
parents: 1521
diff changeset
   348
    if (device->dev->netdev_ops->ndo_start_xmit(skb, device->dev) ==
e07a0f8de03d Print complete Ethernet frame during debug.
Florian Pose <fp@igh-essen.com>
parents: 1521
diff changeset
   349
            NETDEV_TX_OK)
1476
1da1c72fd495 Implemented new network device operations for kernel 2.6.29, thanks to M. Goetze.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   350
#else
1554
e07a0f8de03d Print complete Ethernet frame during debug.
Florian Pose <fp@igh-essen.com>
parents: 1521
diff changeset
   351
    if (device->dev->hard_start_xmit(skb, device->dev) == NETDEV_TX_OK)
e07a0f8de03d Print complete Ethernet frame during debug.
Florian Pose <fp@igh-essen.com>
parents: 1521
diff changeset
   352
#endif
e07a0f8de03d Print complete Ethernet frame during debug.
Florian Pose <fp@igh-essen.com>
parents: 1521
diff changeset
   353
    {
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1476
diff changeset
   354
        device->tx_count++;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   355
        device->master->device_stats.tx_count++;
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1856
diff changeset
   356
        device->tx_bytes += ETH_HLEN + size;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   357
        device->master->device_stats.tx_bytes += ETH_HLEN + size;
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1476
diff changeset
   358
#ifdef EC_DEBUG_IF
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1476
diff changeset
   359
        ec_debug_send(&device->dbg, skb->data, ETH_HLEN + size);
725
8bacb27f3aa2 Send frame to debug-if and debug-ring only when transmitted
Florian Pose <fp@igh-essen.com>
parents: 693
diff changeset
   360
#endif
8bacb27f3aa2 Send frame to debug-if and debug-ring only when transmitted
Florian Pose <fp@igh-essen.com>
parents: 693
diff changeset
   361
#ifdef EC_DEBUG_RING
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1476
diff changeset
   362
        ec_device_debug_ring_append(
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1476
diff changeset
   363
                device, TX, skb->data + ETH_HLEN, size);
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1476
diff changeset
   364
#endif
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1856
diff changeset
   365
    } else {
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1856
diff changeset
   366
        device->tx_errors++;
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1476
diff changeset
   367
    }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   368
}
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   369
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   370
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   371
1856
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   372
/** Clears the frame statistics.
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   373
 */
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   374
void ec_device_clear_stats(
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   375
        ec_device_t *device /**< EtherCAT device */
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   376
        )
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   377
{
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   378
    unsigned int i;
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   379
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   380
    // zero frame statistics
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   381
    device->tx_count = 0;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   382
    device->last_tx_count = 0;
1856
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   383
    device->rx_count = 0;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   384
    device->last_rx_count = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   385
    device->tx_bytes = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   386
    device->last_tx_bytes = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   387
    device->rx_bytes = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   388
    device->last_rx_bytes = 0;
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1856
diff changeset
   389
    device->tx_errors = 0;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   390
1856
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   391
    for (i = 0; i < EC_RATE_COUNT; i++) {
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1856
diff changeset
   392
        device->tx_frame_rates[i] = 0;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   393
        device->rx_frame_rates[i] = 0;
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1856
diff changeset
   394
        device->tx_byte_rates[i] = 0;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   395
        device->rx_byte_rates[i] = 0;
1856
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   396
    }
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   397
}
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   398
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   399
/*****************************************************************************/
10175d5f35ea Fixed clearing frame statistics on link down.
Florian Pose <fp@igh-essen.com>
parents: 1854
diff changeset
   400
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   401
#ifdef EC_DEBUG_RING
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   402
/** Appends frame data to the debug ring.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   403
 */
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   404
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
   405
        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
   406
        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
   407
        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
   408
        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
   409
        )
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   410
{
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   411
    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
   412
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   413
    df->dir = dir;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   414
    if (dir == TX) {
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   415
        do_gettimeofday(&df->t);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   416
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   417
    else {
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   418
        df->t = device->timeval_poll;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   419
    }
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   420
    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
   421
    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
   422
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   423
    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
   424
    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
   425
    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
   426
        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
   427
}
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   428
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   429
/*****************************************************************************/
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   430
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   431
/** Outputs the debug ring.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   432
 */
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   433
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
   434
        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
   435
        )
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   436
{
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   437
    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
   438
    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
   439
    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
   440
    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
   441
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   442
    // 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
   443
    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
   444
        % 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
   445
    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
   446
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   447
    EC_MASTER_DBG(device->master, 1, "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
   448
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   449
    // 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
   450
    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
   451
            - 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
   452
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   453
    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
   454
        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
   455
        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
   456
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   457
        EC_MASTER_DBG(device->master, 1, "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
   458
                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
   459
                (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
   460
                (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
   461
                (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
   462
        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
   463
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   464
        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
   465
        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
   466
    }
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   467
}
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   468
#endif
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   469
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   470
/*****************************************************************************/
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   471
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   472
/** Calls the poll function of the assigned net_device.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   473
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   474
 * The master itself works without using interrupts. Therefore the processing
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   475
 * 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
   476
 * done by the master calling the ISR "manually".
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   477
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   478
void ec_device_poll(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   479
        ec_device_t *device /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   480
        )
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
   481
{
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   482
#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
   483
    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
   484
#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
   485
    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
   486
#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
   487
    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
   488
#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
   489
    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
   490
}
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 33
diff changeset
   491
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   492
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   493
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   494
/** Update device statistics.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   495
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   496
void ec_device_update_stats(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   497
        ec_device_t *device /**< EtherCAT device */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   498
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   499
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   500
    unsigned int i;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   501
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   502
    s32 tx_frame_rate = (device->tx_count - device->last_tx_count) * 1000;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   503
    s32 rx_frame_rate = (device->rx_count - device->last_rx_count) * 1000;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   504
    s32 tx_byte_rate = (device->tx_bytes - device->last_tx_bytes);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   505
    s32 rx_byte_rate = (device->rx_bytes - device->last_rx_bytes);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   506
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   507
    /* Low-pass filter:
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   508
     *      Y_n = y_(n - 1) + T / tau * (x - y_(n - 1))   | T = 1
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   509
     *   -> Y_n += (x - y_(n - 1)) / tau
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   510
     */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   511
    for (i = 0; i < EC_RATE_COUNT; i++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   512
        s32 n = rate_intervals[i];
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   513
        device->tx_frame_rates[i] +=
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   514
            (tx_frame_rate - device->tx_frame_rates[i]) / n;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   515
        device->rx_frame_rates[i] +=
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   516
            (rx_frame_rate - device->rx_frame_rates[i]) / n;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   517
        device->tx_byte_rates[i] +=
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   518
            (tx_byte_rate - device->tx_byte_rates[i]) / n;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   519
        device->rx_byte_rates[i] +=
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   520
            (rx_byte_rate - device->rx_byte_rates[i]) / n;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   521
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   522
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   523
    device->last_tx_count = device->tx_count;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   524
    device->last_rx_count = device->rx_count;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   525
    device->last_tx_bytes = device->tx_bytes;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   526
    device->last_rx_bytes = device->rx_bytes;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   527
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   528
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   529
/******************************************************************************
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   530
 *  Device interface
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   531
 *****************************************************************************/
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   532
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   533
/** Withdraws an EtherCAT device from the master.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   534
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   535
 * 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
   536
 * are freed.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   537
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   538
 * \attention Before calling this function, the ecdev_stop() function has
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   539
 *            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
   540
 *            any more.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   541
 * \ingroup DeviceInterface
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   542
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   543
void ecdev_withdraw(ec_device_t *device /**< EtherCAT device */)
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   544
{
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   545
    ec_master_t *master = device->master;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   546
    char dev_str[20], mac_str[20];
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   547
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   548
    ec_mac_print(device->dev->dev_addr, mac_str);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   549
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   550
    if (device == &master->devices[EC_DEVICE_MAIN]) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   551
        sprintf(dev_str, "main");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   552
    } else if (device == &master->devices[EC_DEVICE_BACKUP]) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   553
        sprintf(dev_str, "backup");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   554
    } else {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   555
        EC_MASTER_WARN(master, "%s() called with unknown device %s!\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   556
                __func__, mac_str);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   557
        sprintf(dev_str, "UNKNOWN");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   558
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   559
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   560
    EC_MASTER_INFO(master, "Releasing %s device %s.\n", dev_str, mac_str);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   561
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   562
    down(&master->device_sem);
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   563
    ec_device_detach(device);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   564
    up(&master->device_sem);
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   565
}
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   566
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   567
/*****************************************************************************/
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   568
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1011
diff changeset
   569
/** 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
   570
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   571
 * \return 0 on success, else < 0
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   572
 * \ingroup DeviceInterface
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   573
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   574
int ecdev_open(ec_device_t *device /**< EtherCAT device */)
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   575
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   576
    int ret;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   577
    ec_master_t *master = device->master;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   578
    unsigned int all_open = 1, dev_idx;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   579
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   580
    ret = ec_device_open(device);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   581
    if (ret) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   582
        EC_MASTER_ERR(master, "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
   583
        return ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   584
    }
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
   585
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   586
    for (dev_idx = EC_DEVICE_MAIN;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   587
            dev_idx < ec_master_num_devices(device->master); dev_idx++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   588
        if (!master->devices[dev_idx].open) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   589
            all_open = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   590
            break;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   591
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   592
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   593
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   594
    if (all_open) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   595
        ret = ec_master_enter_idle_phase(device->master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   596
        if (ret) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   597
            EC_MASTER_ERR(device->master, "Failed to enter IDLE phase!\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   598
            return ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   599
        }
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   600
    }
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   601
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   602
    return 0;
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   603
}
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   604
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   605
/*****************************************************************************/
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   606
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1011
diff changeset
   607
/** 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
   608
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   609
 * \return 0 on success, else < 0
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   610
 * \ingroup DeviceInterface
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   611
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   612
void ecdev_close(ec_device_t *device /**< EtherCAT device */)
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   613
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   614
    ec_master_t *master = device->master;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   615
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   616
    if (master->phase == EC_IDLE) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   617
        ec_master_leave_idle_phase(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   618
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   619
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   620
    if (ec_device_close(device)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   621
        EC_MASTER_WARN(master, "Failed to close device!\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   622
    }
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   623
}
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   624
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   625
/*****************************************************************************/
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   626
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   627
/** Accepts a received frame.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   628
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   629
 * 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
   630
 * and dispatch the received commands to the sending instances.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   631
 *
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   632
 * \ingroup DeviceInterface
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   633
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   634
void ecdev_receive(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   635
        ec_device_t *device, /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   636
        const void *data, /**< pointer to received data */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   637
        size_t size /**< number of bytes received */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   638
        )
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 70
diff changeset
   639
{
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   640
    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
   641
    size_t ec_size = size - ETH_HLEN;
1521
2180c608e250 Check for NULL pointer in ecdev_receive().
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   642
2180c608e250 Check for NULL pointer in ecdev_receive().
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   643
    if (unlikely(!data)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   644
        EC_MASTER_WARN(device->master, "%s() called with NULL data.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   645
                __func__);
1521
2180c608e250 Check for NULL pointer in ecdev_receive().
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   646
        return;
2180c608e250 Check for NULL pointer in ecdev_receive().
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   647
    }
2180c608e250 Check for NULL pointer in ecdev_receive().
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   648
493
b17c95eac6b2 Added frame counter.
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
   649
    device->rx_count++;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   650
    device->master->device_stats.rx_count++;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   651
    device->rx_bytes += size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   652
    device->master->device_stats.rx_bytes += size;
493
b17c95eac6b2 Added frame counter.
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
   653
78
3d74183d6c6b Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   654
    if (unlikely(device->master->debug_level > 1)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   655
        EC_MASTER_DBG(device->master, 2, "Received frame:\n");
1554
e07a0f8de03d Print complete Ethernet frame during debug.
Florian Pose <fp@igh-essen.com>
parents: 1521
diff changeset
   656
        ec_print_data(data, size);
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents: 211
diff changeset
   657
    }
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents: 211
diff changeset
   658
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
   659
#ifdef EC_DEBUG_IF
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents: 211
diff changeset
   660
    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
   661
#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
   662
#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
   663
    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
   664
#endif
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   665
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   666
    ec_master_receive_datagrams(device->master, device, ec_data, ec_size);
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   667
}
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   668
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   669
/*****************************************************************************/
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   670
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   671
/** Sets a new link state.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   672
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   673
 * 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
   674
 * will not try to send frames using this device.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   675
 *
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   676
 * \ingroup DeviceInterface
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   677
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   678
void ecdev_set_link(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   679
        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
   680
        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
   681
        )
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   682
{
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 152
diff changeset
   683
    if (unlikely(!device)) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   684
        EC_WARN("ecdev_set_link() called with null device!\n");
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 152
diff changeset
   685
        return;
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 152
diff changeset
   686
    }
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 152
diff changeset
   687
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   688
    if (likely(state != device->link_state)) {
96
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   689
        device->link_state = state;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   690
        EC_MASTER_INFO(device->master,
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   691
                "Link state of %s changed to %s.\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   692
                device->dev->name, (state ? "UP" : "DOWN"));
96
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   693
    }
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   694
}
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   695
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   696
/*****************************************************************************/
080b46eb6e2d Link-State im Device.
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   697
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   698
/** Reads the link state.
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   699
 *
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   700
 * \ingroup DeviceInterface
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   701
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   702
 * \return Link state.
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   703
 */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   704
uint8_t ecdev_get_link(
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   705
        const ec_device_t *device /**< EtherCAT device */
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   706
        )
670
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   707
{
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   708
    if (unlikely(!device)) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2028
diff changeset
   709
        EC_WARN("ecdev_get_link() called with null device!\n");
670
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   710
        return 0;
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   711
    }
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   712
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   713
    return device->link_state;
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   714
}
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   715
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   716
/*****************************************************************************/
f57de4585a5f Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents: 590
diff changeset
   717
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   718
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   719
1011
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   720
EXPORT_SYMBOL(ecdev_withdraw);
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   721
EXPORT_SYMBOL(ecdev_open);
a0759d0dded4 Improved ecdev_offer().
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   722
EXPORT_SYMBOL(ecdev_close);
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   723
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
   724
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
   725
EXPORT_SYMBOL(ecdev_set_link);
27
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents: 26
diff changeset
   726
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   727
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   728
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   729
/*****************************************************************************/