author | Florian Pose <fp@igh-essen.com> |
Mon, 15 Feb 2010 18:31:23 +0100 | |
changeset 1805 | 44dde06c0685 |
parent 1554 | e07a0f8de03d |
child 1851 | a56bd34e20a1 |
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 |
* |
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 | 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 | 38 |
#include <linux/skbuff.h> |
39 |
#include <linux/if_ether.h> |
|
40 |
#include <linux/netdevice.h> |
|
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 | 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 | 58 |
|
1011 | 59 |
/** Constructor. |
60 |
* |
|
61 |
* \return 0 in case of success, else < 0 |
|
62 |
*/ |
|
63 |
int ec_device_init( |
|
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 |
692
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
75 |
#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
|
76 |
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
|
77 |
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
|
78 |
#endif |
687
6de97f276423
Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents:
679
diff
changeset
|
79 |
|
78
3d74183d6c6b
Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
80 |
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
|
81 |
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
|
82 |
|
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
|
83 |
#ifdef EC_DEBUG_IF |
687
6de97f276423
Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents:
679
diff
changeset
|
84 |
if (device == &master->main_device) |
6de97f276423
Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents:
679
diff
changeset
|
85 |
mb = 'm'; |
6de97f276423
Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents:
679
diff
changeset
|
86 |
else if (device == &master->backup_device) |
6de97f276423
Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents:
679
diff
changeset
|
87 |
mb = 'b'; |
6de97f276423
Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents:
679
diff
changeset
|
88 |
|
6de97f276423
Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents:
679
diff
changeset
|
89 |
sprintf(ifname, "ecdbg%c%u", mb, master->index); |
6de97f276423
Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents:
679
diff
changeset
|
90 |
|
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
91 |
ret = ec_debug_init(&device->dbg, ifname); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
92 |
if (ret < 0) { |
579
17c6fd3b076e
Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents:
574
diff
changeset
|
93 |
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
|
94 |
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
|
95 |
} |
17c6fd3b076e
Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents:
574
diff
changeset
|
96 |
#endif |
17c6fd3b076e
Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents:
574
diff
changeset
|
97 |
|
693
e341f1788608
Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents:
692
diff
changeset
|
98 |
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
|
99 |
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
|
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 |
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
|
102 |
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
|
103 |
EC_ERR("Error allocating device socket buffer!\n"); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
104 |
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
|
105 |
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
|
106 |
} |
e341f1788608
Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents:
692
diff
changeset
|
107 |
|
e341f1788608
Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents:
692
diff
changeset
|
108 |
// 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
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
} |
579
17c6fd3b076e
Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents:
574
diff
changeset
|
114 |
|
17c6fd3b076e
Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents:
574
diff
changeset
|
115 |
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
|
116 |
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
|
117 |
|
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_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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
#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
|
123 |
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
|
124 |
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
|
125 |
#endif |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
126 |
return ret; |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
127 |
} |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
128 |
|
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
129 |
/*****************************************************************************/ |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
130 |
|
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
131 |
/** Destructor. |
1011 | 132 |
*/ |
133 |
void ec_device_clear( |
|
134 |
ec_device_t *device /**< EtherCAT device */ |
|
135 |
) |
|
579
17c6fd3b076e
Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents:
574
diff
changeset
|
136 |
{ |
693
e341f1788608
Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents:
692
diff
changeset
|
137 |
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
|
138 |
|
579
17c6fd3b076e
Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents:
574
diff
changeset
|
139 |
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
|
140 |
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
|
141 |
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
|
142 |
#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
|
143 |
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
|
144 |
#endif |
17c6fd3b076e
Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents:
574
diff
changeset
|
145 |
} |
17c6fd3b076e
Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents:
574
diff
changeset
|
146 |
|
17c6fd3b076e
Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents:
574
diff
changeset
|
147 |
/*****************************************************************************/ |
17c6fd3b076e
Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents:
574
diff
changeset
|
148 |
|
1011 | 149 |
/** Associate with net_device. |
150 |
*/ |
|
151 |
void ec_device_attach( |
|
152 |
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
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
) |
17c6fd3b076e
Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents:
574
diff
changeset
|
157 |
{ |
693
e341f1788608
Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents:
692
diff
changeset
|
158 |
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
|
159 |
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
|
160 |
|
579
17c6fd3b076e
Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents:
574
diff
changeset
|
161 |
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
|
162 |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
97
diff
changeset
|
163 |
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
|
164 |
device->poll = poll; |
539
7bb92fca28ef
Fixed invalid module pointer in device structure.
Florian Pose <fp@igh-essen.com>
parents:
533
diff
changeset
|
165 |
device->module = module; |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
97
diff
changeset
|
166 |
|
693
e341f1788608
Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents:
692
diff
changeset
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
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
|
171 |
} |
1305
de3fcbb6773e
Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents:
1040
diff
changeset
|
172 |
|
de3fcbb6773e
Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents:
1040
diff
changeset
|
173 |
#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
|
174 |
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
|
175 |
#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
|
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 | 180 |
/** Disconnect from net_device. |
181 |
*/ |
|
182 |
void ec_device_detach( |
|
183 |
ec_device_t *device /**< EtherCAT device */ |
|
184 |
) |
|
579
17c6fd3b076e
Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents:
574
diff
changeset
|
185 |
{ |
693
e341f1788608
Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents:
692
diff
changeset
|
186 |
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
|
187 |
|
1305
de3fcbb6773e
Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents:
1040
diff
changeset
|
188 |
#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
|
189 |
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
|
190 |
#endif |
de3fcbb6773e
Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents:
1040
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 |
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
|
193 |
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
|
194 |
device->module = NULL; |
78
3d74183d6c6b
Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
195 |
device->open = 0; |
96 | 196 |
device->link_state = 0; // down |
493 | 197 |
device->tx_count = 0; |
198 |
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
|
199 |
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
|
200 |
device->tx_skb[i]->dev = NULL; |
0 | 201 |
} |
202 |
||
39
6965c23a6826
likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents:
33
diff
changeset
|
203 |
/*****************************************************************************/ |
0 | 204 |
|
1011 | 205 |
/** Opens the EtherCAT device. |
206 |
* |
|
207 |
* \return 0 in case of success, else < 0 |
|
208 |
*/ |
|
209 |
int ec_device_open( |
|
210 |
ec_device_t *device /**< EtherCAT device */ |
|
211 |
) |
|
0 | 212 |
{ |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
213 |
int ret; |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
214 |
|
78
3d74183d6c6b
Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
215 |
if (!device->dev) { |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
78
diff
changeset
|
216 |
EC_ERR("No net_device to open!\n"); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
217 |
return -ENODEV; |
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
70
diff
changeset
|
218 |
} |
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
70
diff
changeset
|
219 |
|
78
3d74183d6c6b
Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
220 |
if (device->open) { |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
78
diff
changeset
|
221 |
EC_WARN("Device already opened!\n"); |
91
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
222 |
return 0; |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
223 |
} |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
224 |
|
96 | 225 |
device->link_state = 0; |
493 | 226 |
device->tx_count = 0; |
227 |
device->rx_count = 0; |
|
91
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
228 |
|
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
|
229 |
#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
|
230 |
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
|
231 |
#else |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
232 |
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
|
233 |
#endif |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
234 |
if (!ret) |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
235 |
device->open = 1; |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
236 |
|
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
237 |
return ret; |
0 | 238 |
} |
239 |
||
39
6965c23a6826
likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents:
33
diff
changeset
|
240 |
/*****************************************************************************/ |
0 | 241 |
|
1011 | 242 |
/** Stops the EtherCAT device. |
243 |
* |
|
244 |
* \return 0 in case of success, else < 0 |
|
245 |
*/ |
|
246 |
int ec_device_close( |
|
247 |
ec_device_t *device /**< EtherCAT device */ |
|
248 |
) |
|
78
3d74183d6c6b
Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
249 |
{ |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
250 |
int ret; |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
251 |
|
78
3d74183d6c6b
Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
252 |
if (!device->dev) { |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
78
diff
changeset
|
253 |
EC_ERR("No device to close!\n"); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
254 |
return -ENODEV; |
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
70
diff
changeset
|
255 |
} |
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
70
diff
changeset
|
256 |
|
78
3d74183d6c6b
Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
257 |
if (!device->open) { |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
78
diff
changeset
|
258 |
EC_WARN("Device already closed!\n"); |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
97
diff
changeset
|
259 |
return 0; |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
97
diff
changeset
|
260 |
} |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
97
diff
changeset
|
261 |
|
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_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
|
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->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
|
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 = 0; |
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; |
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
70
diff
changeset
|
271 |
} |
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
70
diff
changeset
|
272 |
|
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
70
diff
changeset
|
273 |
/*****************************************************************************/ |
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
70
diff
changeset
|
274 |
|
1011 | 275 |
/** Returns a pointer to the device's transmit memory. |
276 |
* |
|
277 |
* \return pointer to the TX socket buffer |
|
278 |
*/ |
|
279 |
uint8_t *ec_device_tx_data( |
|
280 |
ec_device_t *device /**< EtherCAT device */ |
|
281 |
) |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
97
diff
changeset
|
282 |
{ |
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 |
/* 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
|
284 |
* 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
|
285 |
* between. */ |
e341f1788608
Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents:
692
diff
changeset
|
286 |
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
|
287 |
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
|
288 |
return device->tx_skb[device->tx_ring_index]->data + ETH_HLEN; |
0 | 289 |
} |
290 |
||
39
6965c23a6826
likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents:
33
diff
changeset
|
291 |
/*****************************************************************************/ |
0 | 292 |
|
1011 | 293 |
/** Sends the content of the transmit socket buffer. |
294 |
* |
|
295 |
* Cuts the socket buffer content to the (now known) size, and calls the |
|
296 |
* start_xmit() function of the assigned net_device. |
|
297 |
*/ |
|
298 |
void ec_device_send( |
|
299 |
ec_device_t *device, /**< EtherCAT device */ |
|
300 |
size_t size /**< number of bytes to send */ |
|
301 |
) |
|
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
70
diff
changeset
|
302 |
{ |
693
e341f1788608
Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents:
692
diff
changeset
|
303 |
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
|
304 |
|
97
e6264685dd7b
Link-Down-Verhalten verbessert.
Florian Pose <fp@igh-essen.com>
parents:
96
diff
changeset
|
305 |
if (unlikely(!device->link_state)) // Link down |
96 | 306 |
return; |
307 |
||
195
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
191
diff
changeset
|
308 |
// 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
|
309 |
skb->len = ETH_HLEN + size; |
78
3d74183d6c6b
Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
310 |
|
3d74183d6c6b
Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
311 |
if (unlikely(device->master->debug_level > 1)) { |
1554
e07a0f8de03d
Print complete Ethernet frame during debug.
Florian Pose <fp@igh-essen.com>
parents:
1521
diff
changeset
|
312 |
EC_DBG("Sending frame:\n"); |
e07a0f8de03d
Print complete Ethernet frame during debug.
Florian Pose <fp@igh-essen.com>
parents:
1521
diff
changeset
|
313 |
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
|
314 |
} |
e341f1788608
Switched to tx socket buffer ring to avoid race conditions when multiple
Florian Pose <fp@igh-essen.com>
parents:
692
diff
changeset
|
315 |
|
195
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
191
diff
changeset
|
316 |
// 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
|
317 |
#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
|
318 |
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
|
319 |
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
|
320 |
#else |
1554
e07a0f8de03d
Print complete Ethernet frame during debug.
Florian Pose <fp@igh-essen.com>
parents:
1521
diff
changeset
|
321 |
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
|
322 |
#endif |
e07a0f8de03d
Print complete Ethernet frame during debug.
Florian Pose <fp@igh-essen.com>
parents:
1521
diff
changeset
|
323 |
{ |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1476
diff
changeset
|
324 |
device->tx_count++; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1476
diff
changeset
|
325 |
#ifdef EC_DEBUG_IF |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1476
diff
changeset
|
326 |
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
|
327 |
#endif |
8bacb27f3aa2
Send frame to debug-if and debug-ring only when transmitted
Florian Pose <fp@igh-essen.com>
parents:
693
diff
changeset
|
328 |
#ifdef EC_DEBUG_RING |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1476
diff
changeset
|
329 |
ec_device_debug_ring_append( |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1476
diff
changeset
|
330 |
device, TX, skb->data + ETH_HLEN, size); |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1476
diff
changeset
|
331 |
#endif |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1476
diff
changeset
|
332 |
} |
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
70
diff
changeset
|
333 |
} |
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
70
diff
changeset
|
334 |
|
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
70
diff
changeset
|
335 |
/*****************************************************************************/ |
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
70
diff
changeset
|
336 |
|
692
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
337 |
#ifdef EC_DEBUG_RING |
1011 | 338 |
/** Appends frame data to the debug ring. |
339 |
*/ |
|
692
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
340 |
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
|
341 |
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
|
342 |
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
|
343 |
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
|
344 |
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
|
345 |
) |
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 |
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
|
348 |
|
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
349 |
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
|
350 |
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
|
351 |
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
|
352 |
else |
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
353 |
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
|
354 |
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
|
355 |
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
|
356 |
|
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
357 |
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
|
358 |
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
|
359 |
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
|
360 |
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
|
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 |
|
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
363 |
/*****************************************************************************/ |
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
364 |
|
1011 | 365 |
/** Outputs the debug ring. |
366 |
*/ |
|
692
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
367 |
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
|
368 |
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
|
369 |
) |
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
370 |
{ |
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
371 |
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
|
372 |
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
|
373 |
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
|
374 |
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
|
375 |
|
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
376 |
// 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
|
377 |
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
|
378 |
% 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
|
379 |
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
|
380 |
|
986
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
759
diff
changeset
|
381 |
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
|
382 |
|
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
383 |
// 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
|
384 |
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
|
385 |
- 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
|
386 |
|
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
387 |
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
|
388 |
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
|
389 |
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
|
390 |
|
986
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
759
diff
changeset
|
391 |
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
|
392 |
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
|
393 |
(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
|
394 |
(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
|
395 |
(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
|
396 |
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
|
397 |
|
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
398 |
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
|
399 |
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
|
400 |
} |
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
401 |
} |
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
402 |
#endif |
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
403 |
|
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
404 |
/*****************************************************************************/ |
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
405 |
|
1011 | 406 |
/** Calls the poll function of the assigned net_device. |
407 |
* |
|
408 |
* The master itself works without using interrupts. Therefore the processing |
|
409 |
* of received data and status changes of the network device has to be |
|
410 |
* done by the master calling the ISR "manually". |
|
411 |
*/ |
|
412 |
void ec_device_poll( |
|
413 |
ec_device_t *device /**< EtherCAT device */ |
|
414 |
) |
|
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
|
415 |
{ |
1040
d2527675cdd5
Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
416 |
#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
|
417 |
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
|
418 |
#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
|
419 |
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
|
420 |
#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
|
421 |
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
|
422 |
#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
|
423 |
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
|
424 |
} |
6965c23a6826
likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents:
33
diff
changeset
|
425 |
|
54
7506e67dd122
Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents:
42
diff
changeset
|
426 |
/****************************************************************************** |
195
674071846ee3
Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents:
191
diff
changeset
|
427 |
* Device interface |
54
7506e67dd122
Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents:
42
diff
changeset
|
428 |
*****************************************************************************/ |
7506e67dd122
Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents:
42
diff
changeset
|
429 |
|
1011 | 430 |
/** Withdraws an EtherCAT device from the master. |
431 |
* |
|
432 |
* The device is disconnected from the master and all device ressources |
|
433 |
* are freed. |
|
434 |
* |
|
435 |
* \attention Before calling this function, the ecdev_stop() function has |
|
436 |
* to be called, to be sure that the master does not use the device |
|
437 |
* any more. |
|
438 |
* \ingroup DeviceInterface |
|
439 |
*/ |
|
440 |
void ecdev_withdraw(ec_device_t *device /**< EtherCAT device */) |
|
441 |
{ |
|
442 |
ec_master_t *master = device->master; |
|
443 |
char str[20]; |
|
444 |
||
445 |
ec_mac_print(device->dev->dev_addr, str); |
|
446 |
EC_INFO("Master %u releasing main device %s.\n", master->index, str); |
|
447 |
||
448 |
down(&master->device_sem); |
|
449 |
ec_device_detach(device); |
|
450 |
up(&master->device_sem); |
|
451 |
} |
|
452 |
||
453 |
/*****************************************************************************/ |
|
454 |
||
1029
61ffe5f22306
Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents:
1011
diff
changeset
|
455 |
/** Opens the network device and makes the master enter IDLE phase. |
1011 | 456 |
* |
457 |
* \return 0 on success, else < 0 |
|
458 |
* \ingroup DeviceInterface |
|
459 |
*/ |
|
460 |
int ecdev_open(ec_device_t *device /**< EtherCAT device */) |
|
461 |
{ |
|
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
462 |
int ret; |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
463 |
|
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
464 |
ret = ec_device_open(device); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
465 |
if (ret) { |
1011 | 466 |
EC_ERR("Failed to open device!\n"); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
467 |
return ret; |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
468 |
} |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
469 |
|
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
470 |
ret = ec_master_enter_idle_phase(device->master); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
471 |
if (ret) { |
1029
61ffe5f22306
Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents:
1011
diff
changeset
|
472 |
EC_ERR("Failed to enter IDLE phase!\n"); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1305
diff
changeset
|
473 |
return ret; |
1011 | 474 |
} |
475 |
||
476 |
return 0; |
|
477 |
} |
|
478 |
||
479 |
/*****************************************************************************/ |
|
480 |
||
1029
61ffe5f22306
Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents:
1011
diff
changeset
|
481 |
/** Makes the master leave IDLE phase and closes the network device. |
1011 | 482 |
* |
483 |
* \return 0 on success, else < 0 |
|
484 |
* \ingroup DeviceInterface |
|
485 |
*/ |
|
486 |
void ecdev_close(ec_device_t *device /**< EtherCAT device */) |
|
487 |
{ |
|
1029
61ffe5f22306
Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents:
1011
diff
changeset
|
488 |
ec_master_leave_idle_phase(device->master); |
1011 | 489 |
|
490 |
if (ec_device_close(device)) |
|
491 |
EC_WARN("Failed to close device!\n"); |
|
492 |
} |
|
493 |
||
494 |
/*****************************************************************************/ |
|
495 |
||
496 |
/** Accepts a received frame. |
|
497 |
* |
|
498 |
* Forwards the received data to the master. The master will analyze the frame |
|
499 |
* and dispatch the received commands to the sending instances. |
|
500 |
* |
|
501 |
* \ingroup DeviceInterface |
|
502 |
*/ |
|
503 |
void ecdev_receive( |
|
504 |
ec_device_t *device, /**< EtherCAT device */ |
|
505 |
const void *data, /**< pointer to received data */ |
|
506 |
size_t size /**< number of bytes received */ |
|
507 |
) |
|
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
70
diff
changeset
|
508 |
{ |
692
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
509 |
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
|
510 |
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
|
511 |
|
2180c608e250
Check for NULL pointer in ecdev_receive().
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
512 |
if (unlikely(!data)) { |
2180c608e250
Check for NULL pointer in ecdev_receive().
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
513 |
EC_WARN("%s() called with NULL data.\n", __func__); |
2180c608e250
Check for NULL pointer in ecdev_receive().
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
514 |
return; |
2180c608e250
Check for NULL pointer in ecdev_receive().
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
515 |
} |
2180c608e250
Check for NULL pointer in ecdev_receive().
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
516 |
|
493 | 517 |
device->rx_count++; |
518 |
||
78
3d74183d6c6b
Frame-Debugging ins Device ausgelagert und verbessert.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
519 |
if (unlikely(device->master->debug_level > 1)) { |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
78
diff
changeset
|
520 |
EC_DBG("Received frame:\n"); |
1554
e07a0f8de03d
Print complete Ethernet frame during debug.
Florian Pose <fp@igh-essen.com>
parents:
1521
diff
changeset
|
521 |
ec_print_data(data, size); |
231
767548c75bf3
Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
211
diff
changeset
|
522 |
} |
767548c75bf3
Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
211
diff
changeset
|
523 |
|
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
|
524 |
#ifdef EC_DEBUG_IF |
231
767548c75bf3
Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
211
diff
changeset
|
525 |
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
|
526 |
#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
|
527 |
#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
|
528 |
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
|
529 |
#endif |
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
530 |
|
fe7cf37c33f1
Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents:
687
diff
changeset
|
531 |
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
|
532 |
} |
7506e67dd122
Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents:
42
diff
changeset
|
533 |
|
7506e67dd122
Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents:
42
diff
changeset
|
534 |
/*****************************************************************************/ |
7506e67dd122
Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents:
42
diff
changeset
|
535 |
|
1011 | 536 |
/** Sets a new link state. |
537 |
* |
|
538 |
* If the device notifies the master about the link being down, the master |
|
539 |
* will not try to send frames using this device. |
|
540 |
* |
|
541 |
* \ingroup DeviceInterface |
|
542 |
*/ |
|
543 |
void ecdev_set_link( |
|
544 |
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
|
545 |
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
|
546 |
) |
104
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
547 |
{ |
191 | 548 |
if (unlikely(!device)) { |
1011 | 549 |
EC_WARN("ecdev_set_link(): No device!\n"); |
191 | 550 |
return; |
551 |
} |
|
552 |
||
104
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
553 |
if (likely(state != device->link_state)) { |
96 | 554 |
device->link_state = state; |
555 |
EC_INFO("Link state changed to %s.\n", (state ? "UP" : "DOWN")); |
|
556 |
} |
|
557 |
} |
|
558 |
||
559 |
/*****************************************************************************/ |
|
560 |
||
1011 | 561 |
/** Reads the link state. |
562 |
* |
|
563 |
* \ingroup DeviceInterface |
|
564 |
*/ |
|
565 |
uint8_t ecdev_get_link( |
|
566 |
const ec_device_t *device /**< EtherCAT device */ |
|
567 |
) |
|
670
f57de4585a5f
Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents:
590
diff
changeset
|
568 |
{ |
f57de4585a5f
Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents:
590
diff
changeset
|
569 |
if (unlikely(!device)) { |
1011 | 570 |
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
|
571 |
return 0; |
f57de4585a5f
Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents:
590
diff
changeset
|
572 |
} |
f57de4585a5f
Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents:
590
diff
changeset
|
573 |
|
f57de4585a5f
Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents:
590
diff
changeset
|
574 |
return device->link_state; |
f57de4585a5f
Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents:
590
diff
changeset
|
575 |
} |
f57de4585a5f
Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents:
590
diff
changeset
|
576 |
|
f57de4585a5f
Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents:
590
diff
changeset
|
577 |
/*****************************************************************************/ |
f57de4585a5f
Replaced ecdev_link_state() with ecdev_set_link(); added
Florian Pose <fp@igh-essen.com>
parents:
590
diff
changeset
|
578 |
|
199
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
579 |
/** \cond */ |
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
580 |
|
1011 | 581 |
EXPORT_SYMBOL(ecdev_withdraw); |
582 |
EXPORT_SYMBOL(ecdev_open); |
|
583 |
EXPORT_SYMBOL(ecdev_close); |
|
104
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
584 |
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
|
585 |
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
|
586 |
EXPORT_SYMBOL(ecdev_set_link); |
27
d75ef6b46e33
EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
26
diff
changeset
|
587 |
|
199
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
588 |
/** \endcond */ |
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
589 |
|
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
590 |
/*****************************************************************************/ |