author | Florian Pose <fp@igh-essen.com> |
Tue, 30 Sep 2008 12:33:28 +0000 | |
changeset 1232 | 65700377b947 |
parent 1225 | 4d5b739edcb5 |
child 1312 | 74853e018898 |
permissions | -rw-r--r-- |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/****************************************************************************** |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
197
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
5 |
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
6 |
* |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
8 |
* |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
10 |
* and/or modify it under the terms of the GNU General Public License |
246
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
237
diff
changeset
|
11 |
* as published by the Free Software Foundation; either version 2 of the |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
237
diff
changeset
|
12 |
* License, or (at your option) any later version. |
197
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
13 |
* |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
14 |
* The IgH EtherCAT Master is distributed in the hope that it will be |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
15 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
17 |
* GNU General Public License for more details. |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
18 |
* |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
19 |
* You should have received a copy of the GNU General Public License |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
20 |
* along with the IgH EtherCAT Master; if not, write to the Free Software |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
21 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
b9a6e2c22745
GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents:
195
diff
changeset
|
22 |
* |
246
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
237
diff
changeset
|
23 |
* The right to use EtherCAT Technology is granted and comes free of |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
237
diff
changeset
|
24 |
* charge under condition of compatibility of product made by |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
237
diff
changeset
|
25 |
* Licensee. People intending to distribute/sell products based on the |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
237
diff
changeset
|
26 |
* code, have to sign an agreement to guarantee that products using |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
237
diff
changeset
|
27 |
* software based on IgH EtherCAT master stay compatible with the actual |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
237
diff
changeset
|
28 |
* EtherCAT specification (which are released themselves as an open |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
237
diff
changeset
|
29 |
* standard) as the (only) precondition to have the right to use EtherCAT |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
237
diff
changeset
|
30 |
* Technology, IP and trade marks. |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
237
diff
changeset
|
31 |
* |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
*****************************************************************************/ |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
|
199
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
34 |
/** |
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
35 |
\file |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
36 |
Methods of an EtherCAT datagram. |
199
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
37 |
*/ |
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
38 |
|
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
39 |
/*****************************************************************************/ |
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
40 |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
#include <linux/slab.h> |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
|
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
43 |
#include "datagram.h" |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
#include "master.h" |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
45 |
|
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
/*****************************************************************************/ |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
|
199
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
48 |
/** \cond */ |
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
49 |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
50 |
#define EC_FUNC_HEADER \ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
51 |
if (unlikely(ec_datagram_prealloc(datagram, data_size))) \ |
144
fdc24bf62f80
Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents:
104
diff
changeset
|
52 |
return -1; \ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
53 |
datagram->index = 0; \ |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
54 |
datagram->working_counter = 0; \ |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
293
diff
changeset
|
55 |
datagram->state = EC_DATAGRAM_INIT; |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
56 |
|
144
fdc24bf62f80
Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents:
104
diff
changeset
|
57 |
#define EC_FUNC_FOOTER \ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
58 |
datagram->data_size = data_size; \ |
144
fdc24bf62f80
Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents:
104
diff
changeset
|
59 |
return 0; |
fdc24bf62f80
Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents:
104
diff
changeset
|
60 |
|
199
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
61 |
/** \endcond */ |
04ecf40fc2e9
Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents:
197
diff
changeset
|
62 |
|
144
fdc24bf62f80
Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents:
104
diff
changeset
|
63 |
/*****************************************************************************/ |
fdc24bf62f80
Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents:
104
diff
changeset
|
64 |
|
816
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
65 |
/** Array of datagram type strings used in ec_datagram_type_string(). |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
66 |
* |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
67 |
* \attention This is indexed by ec_datagram_type_t. |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
68 |
*/ |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
69 |
static const char *type_strings[] = { |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
70 |
"?", |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
71 |
"APRD", |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
72 |
"APWR", |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
73 |
"APRW", |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
74 |
"FPRD", |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
75 |
"FPWR", |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
76 |
"FPRW", |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
77 |
"BRD", |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
78 |
"BWR", |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
79 |
"BRW", |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
80 |
"LRD", |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
81 |
"LWR", |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
82 |
"LRW", |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
83 |
"ARMW", |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
84 |
"FRMW" |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
85 |
}; |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
86 |
|
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
87 |
/*****************************************************************************/ |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
88 |
|
809 | 89 |
/** Constructor. |
90 |
*/ |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
91 |
void ec_datagram_init(ec_datagram_t *datagram /**< EtherCAT datagram. */) |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
92 |
{ |
446 | 93 |
INIT_LIST_HEAD(&datagram->queue); // mark as unqueued |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
293
diff
changeset
|
94 |
datagram->type = EC_DATAGRAM_NONE; |
708
90bdb315f560
Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents:
514
diff
changeset
|
95 |
memset(datagram->address, 0x00, EC_ADDR_LEN); |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
96 |
datagram->data = NULL; |
809 | 97 |
datagram->data_origin = EC_ORIG_INTERNAL; |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
98 |
datagram->mem_size = 0; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
99 |
datagram->data_size = 0; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
100 |
datagram->index = 0x00; |
809 | 101 |
datagram->working_counter = 0x0000; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
293
diff
changeset
|
102 |
datagram->state = EC_DATAGRAM_INIT; |
1040
d2527675cdd5
Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
103 |
#ifdef EC_HAVE_CYCLES |
344
5d8281f1aa2a
Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
104 |
datagram->cycles_sent = 0; |
1040
d2527675cdd5
Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
105 |
#endif |
398
ff37601361a8
Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents:
397
diff
changeset
|
106 |
datagram->jiffies_sent = 0; |
1040
d2527675cdd5
Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
107 |
#ifdef EC_HAVE_CYCLES |
398
ff37601361a8
Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents:
397
diff
changeset
|
108 |
datagram->cycles_received = 0; |
1040
d2527675cdd5
Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
109 |
#endif |
398
ff37601361a8
Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents:
397
diff
changeset
|
110 |
datagram->jiffies_received = 0; |
719
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
111 |
datagram->skip_count = 0; |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
112 |
datagram->stats_output_jiffies = 0; |
809 | 113 |
memset(datagram->name, 0x00, EC_DATAGRAM_NAME_SIZE); |
114 |
} |
|
115 |
||
116 |
/*****************************************************************************/ |
|
117 |
||
118 |
/** Destructor. |
|
119 |
*/ |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
120 |
void ec_datagram_clear(ec_datagram_t *datagram /**< EtherCAT datagram. */) |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
121 |
{ |
809 | 122 |
if (datagram->data_origin == EC_ORIG_INTERNAL && datagram->data) |
123 |
kfree(datagram->data); |
|
124 |
} |
|
125 |
||
126 |
/*****************************************************************************/ |
|
127 |
||
128 |
/** Allocates internal payload memory. |
|
129 |
* |
|
130 |
* If the allocated memory is already larger than requested, nothing ist done. |
|
131 |
* |
|
132 |
* \attention If external payload memory has been provided, no range checking |
|
133 |
* is done! |
|
134 |
* |
|
135 |
* \return 0 in case of success, else < 0 |
|
136 |
*/ |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
137 |
int ec_datagram_prealloc( |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
138 |
ec_datagram_t *datagram, /**< EtherCAT datagram. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
139 |
size_t size /**< New payload size in bytes. */ |
809 | 140 |
) |
141 |
{ |
|
142 |
if (datagram->data_origin == EC_ORIG_EXTERNAL |
|
143 |
|| size <= datagram->mem_size) |
|
144 |
return 0; |
|
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
145 |
|
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
146 |
if (datagram->data) { |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
147 |
kfree(datagram->data); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
148 |
datagram->data = NULL; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
149 |
datagram->mem_size = 0; |
144
fdc24bf62f80
Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents:
104
diff
changeset
|
150 |
} |
fdc24bf62f80
Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents:
104
diff
changeset
|
151 |
|
998
05a24788f3b2
Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
152 |
if (!(datagram->data = kmalloc(size, GFP_KERNEL))) { |
986
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
816
diff
changeset
|
153 |
EC_ERR("Failed to allocate %u bytes of datagram memory!\n", size); |
144
fdc24bf62f80
Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents:
104
diff
changeset
|
154 |
return -1; |
fdc24bf62f80
Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents:
104
diff
changeset
|
155 |
} |
fdc24bf62f80
Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents:
104
diff
changeset
|
156 |
|
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
157 |
datagram->mem_size = size; |
144
fdc24bf62f80
Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents:
104
diff
changeset
|
158 |
return 0; |
fdc24bf62f80
Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents:
104
diff
changeset
|
159 |
} |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
160 |
|
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
161 |
/*****************************************************************************/ |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
162 |
|
1225
4d5b739edcb5
Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents:
1040
diff
changeset
|
163 |
/** Fills the datagram payload memory with zeros. |
4d5b739edcb5
Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents:
1040
diff
changeset
|
164 |
*/ |
4d5b739edcb5
Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents:
1040
diff
changeset
|
165 |
void ec_datagram_zero(ec_datagram_t *datagram /**< EtherCAT datagram. */) |
4d5b739edcb5
Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents:
1040
diff
changeset
|
166 |
{ |
4d5b739edcb5
Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents:
1040
diff
changeset
|
167 |
memset(datagram->data, 0x00, datagram->data_size); |
4d5b739edcb5
Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents:
1040
diff
changeset
|
168 |
} |
4d5b739edcb5
Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents:
1040
diff
changeset
|
169 |
|
4d5b739edcb5
Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents:
1040
diff
changeset
|
170 |
/*****************************************************************************/ |
4d5b739edcb5
Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents:
1040
diff
changeset
|
171 |
|
809 | 172 |
/** Initializes an EtherCAT APRD datagram. |
173 |
* |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
174 |
* \return 0 in case of success, else < 0 |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
175 |
*/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
176 |
int ec_datagram_aprd( |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
177 |
ec_datagram_t *datagram, /**< EtherCAT datagram. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
178 |
uint16_t ring_position, /**< Auto-increment address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
179 |
uint16_t mem_address, /**< Physical memory address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
180 |
size_t data_size /**< Number of bytes to read. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
181 |
) |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
182 |
{ |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
183 |
EC_FUNC_HEADER; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
293
diff
changeset
|
184 |
datagram->type = EC_DATAGRAM_APRD; |
708
90bdb315f560
Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents:
514
diff
changeset
|
185 |
EC_WRITE_S16(datagram->address, (int16_t) ring_position * (-1)); |
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
186 |
EC_WRITE_U16(datagram->address + 2, mem_address); |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
187 |
EC_FUNC_FOOTER; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
188 |
} |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
189 |
|
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
190 |
/*****************************************************************************/ |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
191 |
|
809 | 192 |
/** Initializes an EtherCAT APWR datagram. |
193 |
* |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
194 |
* \return 0 in case of success, else < 0 |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
195 |
*/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
196 |
int ec_datagram_apwr( |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
197 |
ec_datagram_t *datagram, /**< EtherCAT datagram. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
198 |
uint16_t ring_position, /**< Auto-increment address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
199 |
uint16_t mem_address, /**< Physical memory address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
200 |
size_t data_size /**< Number of bytes to write. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
201 |
) |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
202 |
{ |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
203 |
EC_FUNC_HEADER; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
293
diff
changeset
|
204 |
datagram->type = EC_DATAGRAM_APWR; |
708
90bdb315f560
Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents:
514
diff
changeset
|
205 |
EC_WRITE_S16(datagram->address, (int16_t) ring_position * (-1)); |
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
206 |
EC_WRITE_U16(datagram->address + 2, mem_address); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
207 |
EC_FUNC_FOOTER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
208 |
} |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
209 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
210 |
/*****************************************************************************/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
211 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
212 |
/** Initializes an EtherCAT APRW datagram. |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
213 |
* |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
214 |
* \return 0 in case of success, else < 0 |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
215 |
*/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
216 |
int ec_datagram_aprw( |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
217 |
ec_datagram_t *datagram, /**< EtherCAT datagram. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
218 |
uint16_t ring_position, /**< Auto-increment address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
219 |
uint16_t mem_address, /**< Physical memory address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
220 |
size_t data_size /**< Number of bytes to write. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
221 |
) |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
222 |
{ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
223 |
EC_FUNC_HEADER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
224 |
datagram->type = EC_DATAGRAM_APRW; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
225 |
EC_WRITE_S16(datagram->address, (int16_t) ring_position * (-1)); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
226 |
EC_WRITE_U16(datagram->address + 2, mem_address); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
227 |
EC_FUNC_FOOTER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
228 |
} |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
229 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
230 |
/*****************************************************************************/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
231 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
232 |
/** Initializes an EtherCAT ARMW datagram. |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
233 |
* |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
234 |
* \return 0 in case of success, else < 0 |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
235 |
*/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
236 |
int ec_datagram_armw( |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
237 |
ec_datagram_t *datagram, /**< EtherCAT datagram. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
238 |
uint16_t ring_position, /**< Auto-increment address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
239 |
uint16_t mem_address, /**< Physical memory address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
240 |
size_t data_size /**< Number of bytes to read. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
241 |
) |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
242 |
{ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
243 |
EC_FUNC_HEADER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
244 |
datagram->type = EC_DATAGRAM_ARMW; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
245 |
EC_WRITE_S16(datagram->address, (int16_t) ring_position * (-1)); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
246 |
EC_WRITE_U16(datagram->address + 2, mem_address); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
247 |
EC_FUNC_FOOTER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
248 |
} |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
249 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
250 |
/*****************************************************************************/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
251 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
252 |
/** Initializes an EtherCAT FPRD datagram. |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
253 |
* |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
254 |
* \return 0 in case of success, else < 0 |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
255 |
*/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
256 |
int ec_datagram_fprd( |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
257 |
ec_datagram_t *datagram, /**< EtherCAT datagram. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
258 |
uint16_t configured_address, /**< Configured station address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
259 |
uint16_t mem_address, /**< Physical memory address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
260 |
size_t data_size /**< Number of bytes to read. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
261 |
) |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
262 |
{ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
263 |
if (unlikely(configured_address == 0x0000)) |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
264 |
EC_WARN("Using configured station address 0x0000!\n"); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
265 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
266 |
EC_FUNC_HEADER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
267 |
datagram->type = EC_DATAGRAM_FPRD; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
268 |
EC_WRITE_U16(datagram->address, configured_address); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
269 |
EC_WRITE_U16(datagram->address + 2, mem_address); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
270 |
EC_FUNC_FOOTER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
271 |
} |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
272 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
273 |
/*****************************************************************************/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
274 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
275 |
/** Initializes an EtherCAT FPWR datagram. |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
276 |
* |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
277 |
* \return 0 in case of success, else < 0 |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
278 |
*/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
279 |
int ec_datagram_fpwr( |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
280 |
ec_datagram_t *datagram, /**< EtherCAT datagram. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
281 |
uint16_t configured_address, /**< Configured station address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
282 |
uint16_t mem_address, /**< Physical memory address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
283 |
size_t data_size /**< Number of bytes to write. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
284 |
) |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
285 |
{ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
286 |
if (unlikely(configured_address == 0x0000)) |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
287 |
EC_WARN("Using configured station address 0x0000!\n"); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
288 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
289 |
EC_FUNC_HEADER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
290 |
datagram->type = EC_DATAGRAM_FPWR; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
291 |
EC_WRITE_U16(datagram->address, configured_address); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
292 |
EC_WRITE_U16(datagram->address + 2, mem_address); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
293 |
EC_FUNC_FOOTER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
294 |
} |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
295 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
296 |
/*****************************************************************************/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
297 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
298 |
/** Initializes an EtherCAT FPRW datagram. |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
299 |
* |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
300 |
* \return 0 in case of success, else < 0 |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
301 |
*/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
302 |
int ec_datagram_fprw( |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
303 |
ec_datagram_t *datagram, /**< EtherCAT datagram. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
304 |
uint16_t configured_address, /**< Configured station address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
305 |
uint16_t mem_address, /**< Physical memory address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
306 |
size_t data_size /**< Number of bytes to write. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
307 |
) |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
308 |
{ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
309 |
if (unlikely(configured_address == 0x0000)) |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
310 |
EC_WARN("Using configured station address 0x0000!\n"); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
311 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
312 |
EC_FUNC_HEADER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
313 |
datagram->type = EC_DATAGRAM_FPRW; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
314 |
EC_WRITE_U16(datagram->address, configured_address); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
315 |
EC_WRITE_U16(datagram->address + 2, mem_address); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
316 |
EC_FUNC_FOOTER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
317 |
} |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
318 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
319 |
/*****************************************************************************/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
320 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
321 |
/** Initializes an EtherCAT FRMW datagram. |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
322 |
* |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
323 |
* \return 0 in case of success, else < 0 |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
324 |
*/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
325 |
int ec_datagram_frmw( |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
326 |
ec_datagram_t *datagram, /**< EtherCAT datagram. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
327 |
uint16_t configured_address, /**< Configured station address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
328 |
uint16_t mem_address, /**< Physical memory address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
329 |
size_t data_size /**< Number of bytes to write. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
330 |
) |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
331 |
{ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
332 |
if (unlikely(configured_address == 0x0000)) |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
333 |
EC_WARN("Using configured station address 0x0000!\n"); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
334 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
335 |
EC_FUNC_HEADER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
336 |
datagram->type = EC_DATAGRAM_FRMW; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
337 |
EC_WRITE_U16(datagram->address, configured_address); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
338 |
EC_WRITE_U16(datagram->address + 2, mem_address); |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
339 |
EC_FUNC_FOOTER; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
340 |
} |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
341 |
|
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
342 |
/*****************************************************************************/ |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
343 |
|
809 | 344 |
/** Initializes an EtherCAT BRD datagram. |
345 |
* |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
346 |
* \return 0 in case of success, else < 0 |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
347 |
*/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
348 |
int ec_datagram_brd( |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
349 |
ec_datagram_t *datagram, /**< EtherCAT datagram. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
350 |
uint16_t mem_address, /**< Physical memory address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
351 |
size_t data_size /**< Number of bytes to read. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
352 |
) |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
353 |
{ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
354 |
EC_FUNC_HEADER; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
293
diff
changeset
|
355 |
datagram->type = EC_DATAGRAM_BRD; |
708
90bdb315f560
Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents:
514
diff
changeset
|
356 |
EC_WRITE_U16(datagram->address, 0x0000); |
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
357 |
EC_WRITE_U16(datagram->address + 2, mem_address); |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
358 |
EC_FUNC_FOOTER; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
359 |
} |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
360 |
|
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
361 |
/*****************************************************************************/ |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
362 |
|
809 | 363 |
/** Initializes an EtherCAT BWR datagram. |
364 |
* |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
365 |
* \return 0 in case of success, else < 0 |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
366 |
*/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
367 |
int ec_datagram_bwr( |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
368 |
ec_datagram_t *datagram, /**< EtherCAT datagram. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
369 |
uint16_t mem_address, /**< Physical memory address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
370 |
size_t data_size /**< Number of bytes to write. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
371 |
) |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
372 |
{ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
373 |
EC_FUNC_HEADER; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
293
diff
changeset
|
374 |
datagram->type = EC_DATAGRAM_BWR; |
708
90bdb315f560
Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents:
514
diff
changeset
|
375 |
EC_WRITE_U16(datagram->address, 0x0000); |
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
376 |
EC_WRITE_U16(datagram->address + 2, mem_address); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
377 |
EC_FUNC_FOOTER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
378 |
} |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
379 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
380 |
/*****************************************************************************/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
381 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
382 |
/** Initializes an EtherCAT BRW datagram. |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
383 |
* |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
384 |
* \return 0 in case of success, else < 0 |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
385 |
*/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
386 |
int ec_datagram_brw( |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
387 |
ec_datagram_t *datagram, /**< EtherCAT datagram. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
388 |
uint16_t mem_address, /**< Physical memory address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
389 |
size_t data_size /**< Number of bytes to write. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
390 |
) |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
391 |
{ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
392 |
EC_FUNC_HEADER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
393 |
datagram->type = EC_DATAGRAM_BRW; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
394 |
EC_WRITE_U16(datagram->address, 0x0000); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
395 |
EC_WRITE_U16(datagram->address + 2, mem_address); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
396 |
EC_FUNC_FOOTER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
397 |
} |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
398 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
399 |
/*****************************************************************************/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
400 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
401 |
/** Initializes an EtherCAT LRD datagram. |
809 | 402 |
* |
403 |
* \attention It is assumed, that the external memory is at least \a data_size |
|
404 |
* bytes large. |
|
405 |
* |
|
406 |
* \return 0 in case of success, else < 0 |
|
407 |
*/ |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
408 |
int ec_datagram_lrd( |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
409 |
ec_datagram_t *datagram, /**< EtherCAT datagram. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
410 |
uint32_t offset, /**< Logical address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
411 |
size_t data_size, /**< Number of bytes to read/write. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
412 |
uint8_t *external_memory /**< Pointer to the memory to use. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
413 |
) |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
414 |
{ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
415 |
datagram->data = external_memory; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
416 |
datagram->data_origin = EC_ORIG_EXTERNAL; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
417 |
EC_FUNC_HEADER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
418 |
datagram->type = EC_DATAGRAM_LRD; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
419 |
EC_WRITE_U32(datagram->address, offset); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
420 |
EC_FUNC_FOOTER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
421 |
} |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
422 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
423 |
/*****************************************************************************/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
424 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
425 |
/** Initializes an EtherCAT LWR datagram. |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
426 |
* |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
427 |
* \attention It is assumed, that the external memory is at least \a data_size |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
428 |
* bytes large. |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
429 |
* |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
430 |
* \return 0 in case of success, else < 0 |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
431 |
*/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
432 |
int ec_datagram_lwr( |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
433 |
ec_datagram_t *datagram, /**< EtherCAT datagram. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
434 |
uint32_t offset, /**< Logical address. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
435 |
size_t data_size, /**< Number of bytes to read/write. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
436 |
uint8_t *external_memory /**< Pointer to the memory to use. */ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
437 |
) |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
438 |
{ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
439 |
datagram->data = external_memory; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
440 |
datagram->data_origin = EC_ORIG_EXTERNAL; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
441 |
EC_FUNC_HEADER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
442 |
datagram->type = EC_DATAGRAM_LWR; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
443 |
EC_WRITE_U32(datagram->address, offset); |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
444 |
EC_FUNC_FOOTER; |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
445 |
} |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
446 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
447 |
/*****************************************************************************/ |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
448 |
|
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
449 |
/** Initializes an EtherCAT LRW datagram. |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
450 |
* |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
451 |
* \attention It is assumed, that the external memory is at least \a data_size |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
452 |
* bytes large. |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
453 |
* |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
454 |
* \return 0 in case of success, else < 0 |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
455 |
*/ |
809 | 456 |
int ec_datagram_lrw( |
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
809
diff
changeset
|
457 |
ec_datagram_t *datagram, /**< EtherCAT datagram. */ |
809 | 458 |
uint32_t offset, /**< Logical address. */ |
459 |
size_t data_size, /**< Number of bytes to read/write. */ |
|
460 |
uint8_t *external_memory /**< Pointer to the memory to use. */ |
|
461 |
) |
|
462 |
{ |
|
463 |
datagram->data = external_memory; |
|
464 |
datagram->data_origin = EC_ORIG_EXTERNAL; |
|
144
fdc24bf62f80
Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents:
104
diff
changeset
|
465 |
EC_FUNC_HEADER; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
293
diff
changeset
|
466 |
datagram->type = EC_DATAGRAM_LRW; |
708
90bdb315f560
Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents:
514
diff
changeset
|
467 |
EC_WRITE_U32(datagram->address, offset); |
90bdb315f560
Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents:
514
diff
changeset
|
468 |
EC_FUNC_FOOTER; |
90bdb315f560
Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents:
514
diff
changeset
|
469 |
} |
90bdb315f560
Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents:
514
diff
changeset
|
470 |
|
90bdb315f560
Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents:
514
diff
changeset
|
471 |
/*****************************************************************************/ |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
472 |
|
809 | 473 |
/** Evaluates the working counter of a single-cast datagram. |
474 |
* |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
475 |
* Outputs an error message. |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
476 |
*/ |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
477 |
void ec_datagram_print_wc_error( |
758
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
719
diff
changeset
|
478 |
const ec_datagram_t *datagram /**< EtherCAT datagram */ |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
479 |
) |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
480 |
{ |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
481 |
if (datagram->working_counter == 0) |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
482 |
printk("No response."); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
483 |
else if (datagram->working_counter > 1) |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
484 |
printk("%u slaves responded!", datagram->working_counter); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
485 |
else |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
486 |
printk("Success."); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
487 |
printk("\n"); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
488 |
} |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
489 |
|
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
708
diff
changeset
|
490 |
/*****************************************************************************/ |
719
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
491 |
|
809 | 492 |
/** Outputs datagram statistics at most every second. |
493 |
*/ |
|
719
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
494 |
void ec_datagram_output_stats( |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
495 |
ec_datagram_t *datagram |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
496 |
) |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
497 |
{ |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
498 |
if (jiffies - datagram->stats_output_jiffies < HZ) { |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
499 |
datagram->stats_output_jiffies = jiffies; |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
500 |
|
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
501 |
if (unlikely(datagram->skip_count)) { |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
502 |
EC_WARN("Datagram %x (%s) was SKIPPED %u time%s.\n", |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
503 |
(unsigned int) datagram, datagram->name, |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
504 |
datagram->skip_count, |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
505 |
datagram->skip_count == 1 ? "" : "s"); |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
506 |
datagram->skip_count = 0; |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
507 |
} |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
508 |
} |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
509 |
} |
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
510 |
|
03d5b96632fb
Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
511 |
/*****************************************************************************/ |
816
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
512 |
|
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
513 |
/** Returns a string describing the datagram type. |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
514 |
*/ |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
515 |
const char *ec_datagram_type_string( |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
516 |
const ec_datagram_t *datagram /**< EtherCAT datagram. */ |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
517 |
) |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
518 |
{ |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
519 |
return type_strings[datagram->type]; |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
520 |
} |
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
521 |
|
d02761e14eb0
Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
522 |
/*****************************************************************************/ |