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