author | Florian Pose <fp@igh-essen.com> |
Wed, 05 Dec 2012 12:15:49 +0100 | |
branch | stable-1.5 |
changeset 2473 | f62b64fdbc23 |
parent 2438 | 9c3e629a220c |
child 2498 | 9cdd7669dc0b |
permissions | -rw-r--r-- |
436 | 1 |
/****************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
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 |
436 | 6 |
* |
7 |
* This file is part of the IgH EtherCAT Master. |
|
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. |
436 | 12 |
* |
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
|
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. |
436 | 17 |
* |
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
|
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 |
436 | 20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
21 |
* |
|
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1339
diff
changeset
|
22 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1339
diff
changeset
|
23 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1339
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:
1339
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:
1339
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
436 | 27 |
* |
28 |
*****************************************************************************/ |
|
29 |
||
30 |
/** |
|
31 |
\file |
|
32 |
EtherCAT CoE state machines. |
|
33 |
*/ |
|
34 |
||
35 |
/*****************************************************************************/ |
|
36 |
||
37 |
#include "globals.h" |
|
38 |
#include "master.h" |
|
39 |
#include "mailbox.h" |
|
40 |
#include "fsm_coe.h" |
|
2438
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
41 |
#include "slave_config.h" |
436 | 42 |
|
43 |
/*****************************************************************************/ |
|
44 |
||
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
45 |
/** Maximum time in ms to wait for responses when reading out the dictionary. |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
46 |
*/ |
1794
94e0e1756dec
Reduced CoE timeouts to 1000 ms.
Florian Pose <fp@igh-essen.com>
parents:
1793
diff
changeset
|
47 |
#define EC_FSM_COE_DICT_TIMEOUT 1000 |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
48 |
|
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
49 |
/** CoE download request header size. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
50 |
*/ |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
51 |
#define EC_COE_DOWN_REQ_HEADER_SIZE 10 |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
52 |
|
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
53 |
/** CoE download segment request header size. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
54 |
*/ |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
55 |
#define EC_COE_DOWN_SEG_REQ_HEADER_SIZE 3 |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
56 |
|
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
57 |
/** Minimum size of download segment. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
58 |
*/ |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
59 |
#define EC_COE_DOWN_SEG_MIN_DATA_SIZE 7 |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
60 |
|
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
61 |
/** Enable debug output for CoE retries. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
62 |
*/ |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
63 |
#define DEBUG_RETRIES 0 |
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
64 |
|
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
65 |
/** Enable warning output if transfers take too long. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
66 |
*/ |
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
67 |
#define DEBUG_LONG 0 |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
68 |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
69 |
/*****************************************************************************/ |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
70 |
|
436 | 71 |
void ec_fsm_coe_dict_start(ec_fsm_coe_t *); |
72 |
void ec_fsm_coe_dict_request(ec_fsm_coe_t *); |
|
73 |
void ec_fsm_coe_dict_check(ec_fsm_coe_t *); |
|
74 |
void ec_fsm_coe_dict_response(ec_fsm_coe_t *); |
|
75 |
void ec_fsm_coe_dict_desc_request(ec_fsm_coe_t *); |
|
76 |
void ec_fsm_coe_dict_desc_check(ec_fsm_coe_t *); |
|
77 |
void ec_fsm_coe_dict_desc_response(ec_fsm_coe_t *); |
|
78 |
void ec_fsm_coe_dict_entry_request(ec_fsm_coe_t *); |
|
79 |
void ec_fsm_coe_dict_entry_check(ec_fsm_coe_t *); |
|
80 |
void ec_fsm_coe_dict_entry_response(ec_fsm_coe_t *); |
|
81 |
||
82 |
void ec_fsm_coe_down_start(ec_fsm_coe_t *); |
|
83 |
void ec_fsm_coe_down_request(ec_fsm_coe_t *); |
|
84 |
void ec_fsm_coe_down_check(ec_fsm_coe_t *); |
|
85 |
void ec_fsm_coe_down_response(ec_fsm_coe_t *); |
|
1562 | 86 |
void ec_fsm_coe_down_seg_check(ec_fsm_coe_t *); |
87 |
void ec_fsm_coe_down_seg_response(ec_fsm_coe_t *); |
|
436 | 88 |
|
89 |
void ec_fsm_coe_up_start(ec_fsm_coe_t *); |
|
90 |
void ec_fsm_coe_up_request(ec_fsm_coe_t *); |
|
91 |
void ec_fsm_coe_up_check(ec_fsm_coe_t *); |
|
92 |
void ec_fsm_coe_up_response(ec_fsm_coe_t *); |
|
93 |
void ec_fsm_coe_up_seg_request(ec_fsm_coe_t *); |
|
94 |
void ec_fsm_coe_up_seg_check(ec_fsm_coe_t *); |
|
95 |
void ec_fsm_coe_up_seg_response(ec_fsm_coe_t *); |
|
96 |
||
97 |
void ec_fsm_coe_end(ec_fsm_coe_t *); |
|
98 |
void ec_fsm_coe_error(ec_fsm_coe_t *); |
|
99 |
||
100 |
/*****************************************************************************/ |
|
101 |
||
102 |
/** |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
103 |
SDO abort messages. |
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
104 |
The "abort SDO transfer request" supplies an abort code, |
436 | 105 |
which can be translated to clear text. This table does |
106 |
the mapping of the codes and messages. |
|
107 |
*/ |
|
108 |
||
109 |
const ec_code_msg_t sdo_abort_messages[] = { |
|
110 |
{0x05030000, "Toggle bit not changed"}, |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
111 |
{0x05040000, "SDO protocol timeout"}, |
436 | 112 |
{0x05040001, "Client/Server command specifier not valid or unknown"}, |
113 |
{0x05040005, "Out of memory"}, |
|
114 |
{0x06010000, "Unsupported access to an object"}, |
|
115 |
{0x06010001, "Attempt to read a write-only object"}, |
|
116 |
{0x06010002, "Attempt to write a read-only object"}, |
|
117 |
{0x06020000, "This object does not exist in the object directory"}, |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
118 |
{0x06040041, "The object cannot be mapped into the PDO"}, |
436 | 119 |
{0x06040042, "The number and length of the objects to be mapped would" |
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
120 |
" exceed the PDO length"}, |
436 | 121 |
{0x06040043, "General parameter incompatibility reason"}, |
122 |
{0x06040047, "Gerneral internal incompatibility in device"}, |
|
123 |
{0x06060000, "Access failure due to a hardware error"}, |
|
124 |
{0x06070010, "Data type does not match, length of service parameter does" |
|
125 |
" not match"}, |
|
126 |
{0x06070012, "Data type does not match, length of service parameter too" |
|
127 |
" high"}, |
|
128 |
{0x06070013, "Data type does not match, length of service parameter too" |
|
129 |
" low"}, |
|
130 |
{0x06090011, "Subindex does not exist"}, |
|
131 |
{0x06090030, "Value range of parameter exceeded"}, |
|
132 |
{0x06090031, "Value of parameter written too high"}, |
|
133 |
{0x06090032, "Value of parameter written too low"}, |
|
134 |
{0x06090036, "Maximum value is less than minimum value"}, |
|
135 |
{0x08000000, "General error"}, |
|
136 |
{0x08000020, "Data cannot be transferred or stored to the application"}, |
|
137 |
{0x08000021, "Data cannot be transferred or stored to the application" |
|
138 |
" because of local control"}, |
|
139 |
{0x08000022, "Data cannot be transferred or stored to the application" |
|
140 |
" because of the present device state"}, |
|
141 |
{0x08000023, "Object dictionary dynamic generation fails or no object" |
|
142 |
" dictionary is present"}, |
|
143 |
{} |
|
144 |
}; |
|
145 |
||
146 |
/*****************************************************************************/ |
|
147 |
||
1921 | 148 |
/** Outputs an SDO abort message. |
149 |
*/ |
|
150 |
void ec_canopen_abort_msg(const ec_slave_t *slave, uint32_t abort_code) |
|
436 | 151 |
{ |
152 |
const ec_code_msg_t *abort_msg; |
|
153 |
||
154 |
for (abort_msg = sdo_abort_messages; abort_msg->code; abort_msg++) { |
|
155 |
if (abort_msg->code == abort_code) { |
|
1921 | 156 |
EC_SLAVE_ERR(slave, "SDO abort message 0x%08X: \"%s\".\n", |
436 | 157 |
abort_msg->code, abort_msg->message); |
158 |
return; |
|
159 |
} |
|
160 |
} |
|
161 |
||
1921 | 162 |
EC_SLAVE_ERR(slave, "Unknown SDO abort code 0x%08X.\n", abort_code); |
436 | 163 |
} |
164 |
||
165 |
/*****************************************************************************/ |
|
166 |
||
167 |
/** |
|
168 |
Constructor. |
|
169 |
*/ |
|
170 |
||
171 |
void ec_fsm_coe_init(ec_fsm_coe_t *fsm, /**< finite state machine */ |
|
172 |
ec_datagram_t *datagram /**< datagram */ |
|
173 |
) |
|
174 |
{ |
|
175 |
fsm->state = NULL; |
|
176 |
fsm->datagram = datagram; |
|
177 |
} |
|
178 |
||
179 |
/*****************************************************************************/ |
|
180 |
||
181 |
/** |
|
182 |
Destructor. |
|
183 |
*/ |
|
184 |
||
185 |
void ec_fsm_coe_clear(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
186 |
{ |
|
187 |
} |
|
188 |
||
189 |
/*****************************************************************************/ |
|
190 |
||
191 |
/** |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
192 |
Starts reading a slaves' SDO dictionary. |
436 | 193 |
*/ |
194 |
||
195 |
void ec_fsm_coe_dictionary(ec_fsm_coe_t *fsm, /**< finite state machine */ |
|
196 |
ec_slave_t *slave /**< EtherCAT slave */ |
|
197 |
) |
|
198 |
{ |
|
199 |
fsm->slave = slave; |
|
200 |
fsm->state = ec_fsm_coe_dict_start; |
|
201 |
} |
|
202 |
||
203 |
/*****************************************************************************/ |
|
204 |
||
205 |
/** |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
206 |
Starts to transfer an SDO to/from a slave. |
859
233e32f428e1
Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents:
854
diff
changeset
|
207 |
*/ |
233e32f428e1
Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents:
854
diff
changeset
|
208 |
|
233e32f428e1
Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents:
854
diff
changeset
|
209 |
void ec_fsm_coe_transfer( |
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
210 |
ec_fsm_coe_t *fsm, /**< State machine. */ |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
211 |
ec_slave_t *slave, /**< EtherCAT slave. */ |
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
212 |
ec_sdo_request_t *request /**< SDO request. */ |
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
213 |
) |
436 | 214 |
{ |
215 |
fsm->slave = slave; |
|
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
216 |
fsm->request = request; |
859
233e32f428e1
Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents:
854
diff
changeset
|
217 |
if (request->dir == EC_DIR_OUTPUT) |
233e32f428e1
Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents:
854
diff
changeset
|
218 |
fsm->state = ec_fsm_coe_down_start; |
233e32f428e1
Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents:
854
diff
changeset
|
219 |
else |
233e32f428e1
Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents:
854
diff
changeset
|
220 |
fsm->state = ec_fsm_coe_up_start; |
436 | 221 |
} |
222 |
||
223 |
/*****************************************************************************/ |
|
224 |
||
225 |
/** |
|
226 |
Executes the current state of the state machine. |
|
227 |
\return false, if state machine has terminated |
|
228 |
*/ |
|
229 |
||
230 |
int ec_fsm_coe_exec(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
231 |
{ |
|
232 |
fsm->state(fsm); |
|
233 |
||
234 |
return fsm->state != ec_fsm_coe_end && fsm->state != ec_fsm_coe_error; |
|
235 |
} |
|
236 |
||
237 |
/*****************************************************************************/ |
|
238 |
||
239 |
/** |
|
240 |
Returns, if the state machine terminated with success. |
|
241 |
\return non-zero if successful. |
|
242 |
*/ |
|
243 |
||
244 |
int ec_fsm_coe_success(ec_fsm_coe_t *fsm /**< Finite state machine */) |
|
245 |
{ |
|
246 |
return fsm->state == ec_fsm_coe_end; |
|
247 |
} |
|
248 |
||
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
249 |
/*****************************************************************************/ |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
250 |
|
1092 | 251 |
/** Check if the received data are a CoE emergency request. |
252 |
* |
|
253 |
* If the check is positive, the emergency request is output. |
|
254 |
* |
|
255 |
* \return The data were an emergency request. |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
256 |
*/ |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
257 |
int ec_fsm_coe_check_emergency( |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
258 |
ec_fsm_coe_t *fsm, /**< Finite state machine */ |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
259 |
const uint8_t *data, /**< CoE mailbox data. */ |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
260 |
size_t size /**< CoE mailbox data size. */ |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
261 |
) |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
262 |
{ |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
263 |
if (size < 2 || ((EC_READ_U16(data) >> 12) & 0x0F) != 0x01) |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
264 |
return 0; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
265 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
266 |
if (size < 10) { |
1921 | 267 |
EC_SLAVE_WARN(fsm->slave, "Received incomplete CoE Emergency" |
268 |
" request:\n"); |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
269 |
ec_print_data(data, size); |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
270 |
return 1; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
271 |
} |
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
272 |
|
2438
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
273 |
{ |
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
274 |
ec_slave_config_t *sc = fsm->slave->config; |
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
275 |
if (sc) { |
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
276 |
ec_coe_emerg_ring_push(&sc->emerg_ring, data + 2); |
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
277 |
} |
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
278 |
} |
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
279 |
|
1921 | 280 |
EC_SLAVE_WARN(fsm->slave, "CoE Emergency Request received:\n" |
281 |
"Error code 0x%04X, Error register 0x%02X, data:\n", |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
282 |
EC_READ_U16(data + 2), EC_READ_U8(data + 4)); |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
283 |
ec_print_data(data + 5, 5); |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
284 |
return 1; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
285 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
286 |
|
436 | 287 |
/****************************************************************************** |
288 |
* CoE dictionary state machine |
|
289 |
*****************************************************************************/ |
|
290 |
||
291 |
/** |
|
292 |
CoE state: DICT START. |
|
293 |
*/ |
|
294 |
||
295 |
void ec_fsm_coe_dict_start(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
296 |
{ |
|
297 |
ec_datagram_t *datagram = fsm->datagram; |
|
298 |
ec_slave_t *slave = fsm->slave; |
|
299 |
uint8_t *data; |
|
300 |
||
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
301 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
1921 | 302 |
EC_SLAVE_ERR(slave, "Slave does not support CoE!\n"); |
825
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
303 |
fsm->state = ec_fsm_coe_error; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
304 |
return; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
305 |
} |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
306 |
|
1219
aa030fb1e980
Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents:
1169
diff
changeset
|
307 |
if (slave->sii.has_general && !slave->sii.coe_details.enable_sdo_info) { |
1921 | 308 |
EC_SLAVE_ERR(slave, "Slave does not support" |
309 |
" SDO information service!\n"); |
|
1219
aa030fb1e980
Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents:
1169
diff
changeset
|
310 |
fsm->state = ec_fsm_coe_error; |
aa030fb1e980
Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents:
1169
diff
changeset
|
311 |
return; |
aa030fb1e980
Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents:
1169
diff
changeset
|
312 |
} |
aa030fb1e980
Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents:
1169
diff
changeset
|
313 |
|
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
314 |
data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
315 |
if (IS_ERR(data)) { |
436 | 316 |
fsm->state = ec_fsm_coe_error; |
317 |
return; |
|
318 |
} |
|
319 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
320 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 321 |
EC_WRITE_U8 (data + 2, 0x01); // Get OD List Request |
322 |
EC_WRITE_U8 (data + 3, 0x00); |
|
323 |
EC_WRITE_U16(data + 4, 0x0000); |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
324 |
EC_WRITE_U16(data + 6, 0x0001); // deliver all SDOs! |
436 | 325 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
326 |
fsm->retries = EC_FSM_RETRIES; |
436 | 327 |
fsm->state = ec_fsm_coe_dict_request; |
328 |
} |
|
329 |
||
330 |
/*****************************************************************************/ |
|
331 |
||
332 |
/** |
|
333 |
CoE state: DICT REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
334 |
\todo Timeout behavior |
436 | 335 |
*/ |
336 |
||
337 |
void ec_fsm_coe_dict_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
338 |
{ |
|
339 |
ec_datagram_t *datagram = fsm->datagram; |
|
340 |
ec_slave_t *slave = fsm->slave; |
|
341 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
342 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
343 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
344 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
345 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
346 |
fsm->state = ec_fsm_coe_error; |
1921 | 347 |
EC_SLAVE_ERR(slave, "Failed to receive CoE dictionary" |
348 |
" request datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
349 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
350 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
351 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
352 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
353 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
354 |
fsm->state = ec_fsm_coe_error; |
1921 | 355 |
EC_SLAVE_ERR(slave, "Reception of CoE dictionary request failed: "); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
356 |
ec_datagram_print_wc_error(datagram); |
436 | 357 |
return; |
358 |
} |
|
359 |
||
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
360 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 361 |
|
362 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
363 |
fsm->retries = EC_FSM_RETRIES; |
436 | 364 |
fsm->state = ec_fsm_coe_dict_check; |
365 |
} |
|
366 |
||
367 |
/*****************************************************************************/ |
|
368 |
||
369 |
/** |
|
370 |
CoE state: DICT CHECK. |
|
371 |
*/ |
|
372 |
||
373 |
void ec_fsm_coe_dict_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
374 |
{ |
|
375 |
ec_datagram_t *datagram = fsm->datagram; |
|
376 |
ec_slave_t *slave = fsm->slave; |
|
377 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
378 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
379 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
380 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
381 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
382 |
fsm->state = ec_fsm_coe_error; |
1921 | 383 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: "); |
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
384 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
385 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
386 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
387 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
388 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
389 |
fsm->state = ec_fsm_coe_error; |
1921 | 390 |
EC_SLAVE_ERR(slave,"Reception of CoE mailbox check" |
391 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
392 |
ec_datagram_print_wc_error(datagram); |
436 | 393 |
return; |
394 |
} |
|
395 |
||
396 |
if (!ec_slave_mbox_check(datagram)) { |
|
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
397 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
398 |
(datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ; |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
399 |
if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) { |
436 | 400 |
fsm->state = ec_fsm_coe_error; |
1921 | 401 |
EC_SLAVE_ERR(slave, "Timeout while waiting for" |
402 |
" SDO dictionary list response.\n"); |
|
436 | 403 |
return; |
404 |
} |
|
405 |
||
406 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
407 |
fsm->retries = EC_FSM_RETRIES; |
436 | 408 |
return; |
409 |
} |
|
410 |
||
411 |
// Fetch response |
|
412 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
413 |
fsm->retries = EC_FSM_RETRIES; |
436 | 414 |
fsm->state = ec_fsm_coe_dict_response; |
415 |
} |
|
416 |
||
417 |
/*****************************************************************************/ |
|
418 |
||
419 |
/** |
|
420 |
CoE state: DICT RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
421 |
\todo Timeout behavior |
436 | 422 |
*/ |
423 |
||
424 |
void ec_fsm_coe_dict_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
425 |
{ |
|
426 |
ec_datagram_t *datagram = fsm->datagram; |
|
427 |
ec_slave_t *slave = fsm->slave; |
|
428 |
uint8_t *data, mbox_prot; |
|
429 |
size_t rec_size; |
|
430 |
unsigned int sdo_count, i; |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
431 |
uint16_t sdo_index, fragments_left; |
436 | 432 |
ec_sdo_t *sdo; |
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
433 |
bool first_segment; |
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
434 |
size_t index_list_offset; |
436 | 435 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
436 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
437 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
438 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
439 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
440 |
fsm->state = ec_fsm_coe_error; |
1921 | 441 |
EC_SLAVE_ERR(slave, "Failed to receive CoE dictionary" |
442 |
" response datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
443 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
444 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
445 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
446 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
447 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
448 |
fsm->state = ec_fsm_coe_error; |
1921 | 449 |
EC_SLAVE_ERR(slave, "Reception of CoE dictionary response failed: "); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
450 |
ec_datagram_print_wc_error(datagram); |
436 | 451 |
return; |
452 |
} |
|
453 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
454 |
data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
455 |
if (IS_ERR(data)) { |
436 | 456 |
fsm->state = ec_fsm_coe_error; |
457 |
return; |
|
458 |
} |
|
459 |
||
460 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 461 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
462 |
mbox_prot); |
|
436 | 463 |
fsm->state = ec_fsm_coe_error; |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
464 |
return; |
436 | 465 |
} |
466 |
||
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
467 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
468 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
469 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
470 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
471 |
fsm->state = ec_fsm_coe_dict_check; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
472 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
473 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
474 |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
475 |
if (rec_size < 3) { |
1921 | 476 |
EC_SLAVE_ERR(slave, "Received corrupted SDO dictionary response" |
477 |
" (size %zu).\n", rec_size); |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
478 |
fsm->state = ec_fsm_coe_error; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
479 |
return; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
480 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
481 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
482 |
if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information |
436 | 483 |
(EC_READ_U8(data + 2) & 0x7F) == 0x07) { // error response |
1921 | 484 |
EC_SLAVE_ERR(slave, "SDO information error response!\n"); |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
485 |
if (rec_size < 10) { |
1921 | 486 |
EC_SLAVE_ERR(slave, "Incomplete SDO information" |
487 |
" error response:\n"); |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
488 |
ec_print_data(data, rec_size); |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
489 |
} else { |
1921 | 490 |
ec_canopen_abort_msg(slave, EC_READ_U32(data + 6)); |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
491 |
} |
436 | 492 |
fsm->state = ec_fsm_coe_error; |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
493 |
return; |
436 | 494 |
} |
495 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
496 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
436 | 497 |
(EC_READ_U8 (data + 2) & 0x7F) != 0x02) { // Get OD List response |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
498 |
if (fsm->slave->master->debug_level) { |
1921 | 499 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO list response!" |
500 |
" Retrying...\n"); |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
501 |
ec_print_data(data, rec_size); |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
502 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
503 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
504 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
505 |
fsm->state = ec_fsm_coe_dict_check; |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
506 |
return; |
436 | 507 |
} |
508 |
||
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
509 |
first_segment = list_empty(&slave->sdo_dictionary) ? true : false; |
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
510 |
index_list_offset = first_segment ? 8 : 6; |
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
511 |
|
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
512 |
if (rec_size < index_list_offset || rec_size % 2) { |
1921 | 513 |
EC_SLAVE_ERR(slave, "Invalid data size %zu!\n", rec_size); |
436 | 514 |
ec_print_data(data, rec_size); |
515 |
fsm->state = ec_fsm_coe_error; |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
516 |
return; |
436 | 517 |
} |
518 |
||
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
519 |
sdo_count = (rec_size - index_list_offset) / 2; |
436 | 520 |
|
521 |
for (i = 0; i < sdo_count; i++) { |
|
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
522 |
sdo_index = EC_READ_U16(data + index_list_offset + i * 2); |
436 | 523 |
if (!sdo_index) { |
1921 | 524 |
EC_SLAVE_DBG(slave, 1, "SDO dictionary contains index 0x0000.\n"); |
436 | 525 |
continue; |
526 |
} |
|
527 |
||
998
05a24788f3b2
Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents:
992
diff
changeset
|
528 |
if (!(sdo = (ec_sdo_t *) kmalloc(sizeof(ec_sdo_t), GFP_KERNEL))) { |
1921 | 529 |
EC_SLAVE_ERR(slave, "Failed to allocate memory for SDO!\n"); |
436 | 530 |
fsm->state = ec_fsm_coe_error; |
531 |
return; |
|
532 |
} |
|
533 |
||
992
50a44cbd30af
Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents:
991
diff
changeset
|
534 |
ec_sdo_init(sdo, slave, sdo_index); |
436 | 535 |
list_add_tail(&sdo->list, &slave->sdo_dictionary); |
536 |
} |
|
537 |
||
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
538 |
fragments_left = EC_READ_U16(data + 4); |
1923 | 539 |
if (fragments_left) { |
1921 | 540 |
EC_SLAVE_DBG(slave, 1, "SDO list fragments left: %u\n", |
541 |
fragments_left); |
|
542 |
} |
|
543 |
||
544 |
if (EC_READ_U8(data + 2) & 0x80 || fragments_left) { |
|
545 |
// more messages waiting. check again. |
|
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
546 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 547 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
548 |
fsm->retries = EC_FSM_RETRIES; |
436 | 549 |
fsm->state = ec_fsm_coe_dict_check; |
550 |
return; |
|
551 |
} |
|
552 |
||
553 |
if (list_empty(&slave->sdo_dictionary)) { |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
554 |
// no SDOs in dictionary. finished. |
436 | 555 |
fsm->state = ec_fsm_coe_end; // success |
556 |
return; |
|
557 |
} |
|
558 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
559 |
// fetch SDO descriptions |
436 | 560 |
fsm->sdo = list_entry(slave->sdo_dictionary.next, ec_sdo_t, list); |
561 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
562 |
data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
563 |
if (IS_ERR(data)) { |
436 | 564 |
fsm->state = ec_fsm_coe_error; |
565 |
return; |
|
566 |
} |
|
567 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
568 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 569 |
EC_WRITE_U8 (data + 2, 0x03); // Get object description request |
570 |
EC_WRITE_U8 (data + 3, 0x00); |
|
571 |
EC_WRITE_U16(data + 4, 0x0000); |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
572 |
EC_WRITE_U16(data + 6, fsm->sdo->index); // SDO index |
436 | 573 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
574 |
fsm->retries = EC_FSM_RETRIES; |
436 | 575 |
fsm->state = ec_fsm_coe_dict_desc_request; |
576 |
} |
|
577 |
||
578 |
/*****************************************************************************/ |
|
579 |
||
580 |
/** |
|
581 |
CoE state: DICT DESC REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
582 |
\todo Timeout behavior |
436 | 583 |
*/ |
584 |
||
585 |
void ec_fsm_coe_dict_desc_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
586 |
{ |
|
587 |
ec_datagram_t *datagram = fsm->datagram; |
|
588 |
ec_slave_t *slave = fsm->slave; |
|
589 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
590 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
591 |
return; // FIXME: check for response first? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
592 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
593 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
594 |
fsm->state = ec_fsm_coe_error; |
1921 | 595 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO" |
596 |
" description request datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
597 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
598 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
599 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
600 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
601 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
602 |
fsm->state = ec_fsm_coe_error; |
1921 | 603 |
EC_SLAVE_ERR(slave, "Reception of CoE SDO description" |
604 |
" request failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
605 |
ec_datagram_print_wc_error(datagram); |
436 | 606 |
return; |
607 |
} |
|
608 |
||
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
609 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 610 |
|
611 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
612 |
fsm->retries = EC_FSM_RETRIES; |
436 | 613 |
fsm->state = ec_fsm_coe_dict_desc_check; |
614 |
} |
|
615 |
||
616 |
/*****************************************************************************/ |
|
617 |
||
618 |
/** |
|
619 |
CoE state: DICT DESC CHECK. |
|
620 |
*/ |
|
621 |
||
622 |
void ec_fsm_coe_dict_desc_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
623 |
{ |
|
624 |
ec_datagram_t *datagram = fsm->datagram; |
|
625 |
ec_slave_t *slave = fsm->slave; |
|
626 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
627 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
628 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
629 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
630 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
631 |
fsm->state = ec_fsm_coe_error; |
1921 | 632 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: "); |
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
633 |
ec_datagram_print_state(datagram); |
436 | 634 |
return; |
635 |
} |
|
636 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
637 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
638 |
fsm->state = ec_fsm_coe_error; |
1921 | 639 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
640 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
641 |
ec_datagram_print_wc_error(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
642 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
643 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
644 |
|
436 | 645 |
if (!ec_slave_mbox_check(datagram)) { |
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
646 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
647 |
(datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ; |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
648 |
if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) { |
436 | 649 |
fsm->state = ec_fsm_coe_error; |
1921 | 650 |
EC_SLAVE_ERR(slave, "Timeout while waiting for" |
651 |
" SDO 0x%04x object description response.\n", |
|
652 |
fsm->sdo->index); |
|
436 | 653 |
return; |
654 |
} |
|
655 |
||
656 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
657 |
fsm->retries = EC_FSM_RETRIES; |
436 | 658 |
return; |
659 |
} |
|
660 |
||
661 |
// Fetch response |
|
662 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
663 |
fsm->retries = EC_FSM_RETRIES; |
436 | 664 |
fsm->state = ec_fsm_coe_dict_desc_response; |
665 |
} |
|
666 |
||
667 |
/*****************************************************************************/ |
|
668 |
||
669 |
/** |
|
670 |
CoE state: DICT DESC RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
671 |
\todo Timeout behavior |
436 | 672 |
*/ |
673 |
||
674 |
void ec_fsm_coe_dict_desc_response(ec_fsm_coe_t *fsm |
|
675 |
/**< finite state machine */) |
|
676 |
{ |
|
677 |
ec_datagram_t *datagram = fsm->datagram; |
|
678 |
ec_slave_t *slave = fsm->slave; |
|
679 |
ec_sdo_t *sdo = fsm->sdo; |
|
680 |
uint8_t *data, mbox_prot; |
|
681 |
size_t rec_size, name_size; |
|
682 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
683 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
684 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
685 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
686 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
687 |
fsm->state = ec_fsm_coe_error; |
1921 | 688 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO description" |
689 |
" response datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
690 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
691 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
692 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
693 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
694 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
695 |
fsm->state = ec_fsm_coe_error; |
1921 | 696 |
EC_SLAVE_ERR(slave, "Reception of CoE SDO description" |
697 |
" response failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
698 |
ec_datagram_print_wc_error(datagram); |
436 | 699 |
return; |
700 |
} |
|
701 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
702 |
data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
703 |
if (IS_ERR(data)) { |
436 | 704 |
fsm->state = ec_fsm_coe_error; |
705 |
return; |
|
706 |
} |
|
707 |
||
708 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 709 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
710 |
mbox_prot); |
|
436 | 711 |
fsm->state = ec_fsm_coe_error; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
712 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
713 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
714 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
715 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
716 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
717 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
718 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
719 |
fsm->state = ec_fsm_coe_dict_desc_check; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
720 |
return; |
436 | 721 |
} |
722 |
||
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
723 |
if (rec_size < 3) { |
1921 | 724 |
EC_SLAVE_ERR(slave, "Received corrupted SDO description response" |
725 |
" (size %zu).\n", rec_size); |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
726 |
fsm->state = ec_fsm_coe_error; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
727 |
return; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
728 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
729 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
730 |
if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information |
436 | 731 |
(EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response |
1921 | 732 |
EC_SLAVE_ERR(slave, "SDO information error response while" |
733 |
" fetching SDO 0x%04X!\n", sdo->index); |
|
734 |
ec_canopen_abort_msg(slave, EC_READ_U32(data + 6)); |
|
436 | 735 |
fsm->state = ec_fsm_coe_error; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
736 |
return; |
436 | 737 |
} |
738 |
||
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
739 |
if (rec_size < 8) { |
1921 | 740 |
EC_SLAVE_ERR(slave, "Received corrupted SDO" |
741 |
" description response (size %zu).\n", rec_size); |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
742 |
fsm->state = ec_fsm_coe_error; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
743 |
return; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
744 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
745 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
746 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
436 | 747 |
(EC_READ_U8 (data + 2) & 0x7F) != 0x04 || // Object desc. response |
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
748 |
EC_READ_U16(data + 6) != sdo->index) { // SDO index |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
749 |
if (fsm->slave->master->debug_level) { |
1921 | 750 |
EC_SLAVE_DBG(slave, 1, "Invalid object description response while" |
751 |
" fetching SDO 0x%04X!\n", sdo->index); |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
752 |
ec_print_data(data, rec_size); |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
753 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
754 |
// check for CoE response again |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
755 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
756 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
757 |
fsm->state = ec_fsm_coe_dict_desc_check; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
758 |
return; |
436 | 759 |
} |
760 |
||
761 |
if (rec_size < 12) { |
|
1921 | 762 |
EC_SLAVE_ERR(slave, "Invalid data size!\n"); |
436 | 763 |
ec_print_data(data, rec_size); |
764 |
fsm->state = ec_fsm_coe_error; |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
765 |
return; |
436 | 766 |
} |
767 |
||
962
ea83a7aab57a
Renamed subindices to max_subindex.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
768 |
sdo->max_subindex = EC_READ_U8(data + 10); |
436 | 769 |
sdo->object_code = EC_READ_U8(data + 11); |
770 |
||
771 |
name_size = rec_size - 12; |
|
772 |
if (name_size) { |
|
998
05a24788f3b2
Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents:
992
diff
changeset
|
773 |
if (!(sdo->name = kmalloc(name_size + 1, GFP_KERNEL))) { |
1921 | 774 |
EC_SLAVE_ERR(slave, "Failed to allocate SDO name!\n"); |
436 | 775 |
fsm->state = ec_fsm_coe_error; |
776 |
return; |
|
777 |
} |
|
778 |
||
779 |
memcpy(sdo->name, data + 12, name_size); |
|
780 |
sdo->name[name_size] = 0; |
|
781 |
} |
|
782 |
||
783 |
if (EC_READ_U8(data + 2) & 0x80) { |
|
1921 | 784 |
EC_SLAVE_ERR(slave, "Fragment follows (not implemented)!\n"); |
436 | 785 |
fsm->state = ec_fsm_coe_error; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
786 |
return; |
436 | 787 |
} |
788 |
||
789 |
// start fetching entries |
|
790 |
||
791 |
fsm->subindex = 0; |
|
792 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
793 |
data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
794 |
if (IS_ERR(data)) { |
436 | 795 |
fsm->state = ec_fsm_coe_error; |
796 |
return; |
|
797 |
} |
|
798 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
799 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 800 |
EC_WRITE_U8 (data + 2, 0x05); // Get entry description request |
801 |
EC_WRITE_U8 (data + 3, 0x00); |
|
802 |
EC_WRITE_U16(data + 4, 0x0000); |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
803 |
EC_WRITE_U16(data + 6, sdo->index); // SDO index |
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
804 |
EC_WRITE_U8 (data + 8, fsm->subindex); // SDO subindex |
1382
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
805 |
EC_WRITE_U8 (data + 9, 0x01); // value info (access rights only) |
436 | 806 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
807 |
fsm->retries = EC_FSM_RETRIES; |
436 | 808 |
fsm->state = ec_fsm_coe_dict_entry_request; |
809 |
} |
|
810 |
||
811 |
/*****************************************************************************/ |
|
812 |
||
813 |
/** |
|
814 |
CoE state: DICT ENTRY REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
815 |
\todo Timeout behavior |
436 | 816 |
*/ |
817 |
||
818 |
void ec_fsm_coe_dict_entry_request(ec_fsm_coe_t *fsm |
|
819 |
/**< finite state machine */) |
|
820 |
{ |
|
821 |
ec_datagram_t *datagram = fsm->datagram; |
|
822 |
ec_slave_t *slave = fsm->slave; |
|
823 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
824 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
825 |
return; // FIXME: check for response first? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
826 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
827 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
828 |
fsm->state = ec_fsm_coe_error; |
1921 | 829 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO entry" |
830 |
" request datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
831 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
832 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
833 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
834 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
835 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
836 |
fsm->state = ec_fsm_coe_error; |
1921 | 837 |
EC_SLAVE_ERR(slave, "Reception of CoE SDO entry request failed: "); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
838 |
ec_datagram_print_wc_error(datagram); |
436 | 839 |
return; |
840 |
} |
|
841 |
||
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
842 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 843 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
844 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
845 |
fsm->retries = EC_FSM_RETRIES; |
436 | 846 |
fsm->state = ec_fsm_coe_dict_entry_check; |
847 |
} |
|
848 |
||
849 |
/*****************************************************************************/ |
|
850 |
||
851 |
/** |
|
852 |
CoE state: DICT ENTRY CHECK. |
|
853 |
*/ |
|
854 |
||
855 |
void ec_fsm_coe_dict_entry_check(ec_fsm_coe_t *fsm |
|
856 |
/**< finite state machine */) |
|
857 |
{ |
|
858 |
ec_datagram_t *datagram = fsm->datagram; |
|
859 |
ec_slave_t *slave = fsm->slave; |
|
860 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
861 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
862 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
863 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
864 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
865 |
fsm->state = ec_fsm_coe_error; |
1921 | 866 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: "); |
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
867 |
ec_datagram_print_state(datagram); |
436 | 868 |
return; |
869 |
} |
|
870 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
871 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
872 |
fsm->state = ec_fsm_coe_error; |
1921 | 873 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
874 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
875 |
ec_datagram_print_wc_error(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
876 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
877 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
878 |
|
436 | 879 |
if (!ec_slave_mbox_check(datagram)) { |
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
880 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
881 |
(datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ; |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
882 |
if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) { |
436 | 883 |
fsm->state = ec_fsm_coe_error; |
1921 | 884 |
EC_SLAVE_ERR(slave, "Timeout while waiting for" |
885 |
" SDO entry 0x%04x:%x description response.\n", |
|
886 |
fsm->sdo->index, fsm->subindex); |
|
436 | 887 |
return; |
888 |
} |
|
889 |
||
890 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
891 |
fsm->retries = EC_FSM_RETRIES; |
436 | 892 |
return; |
893 |
} |
|
894 |
||
895 |
// Fetch response |
|
896 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
897 |
fsm->retries = EC_FSM_RETRIES; |
436 | 898 |
fsm->state = ec_fsm_coe_dict_entry_response; |
899 |
} |
|
900 |
||
901 |
/*****************************************************************************/ |
|
902 |
||
903 |
/** |
|
904 |
CoE state: DICT ENTRY RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
905 |
\todo Timeout behavior |
436 | 906 |
*/ |
907 |
||
908 |
void ec_fsm_coe_dict_entry_response(ec_fsm_coe_t *fsm |
|
909 |
/**< finite state machine */) |
|
910 |
{ |
|
911 |
ec_datagram_t *datagram = fsm->datagram; |
|
912 |
ec_slave_t *slave = fsm->slave; |
|
913 |
ec_sdo_t *sdo = fsm->sdo; |
|
914 |
uint8_t *data, mbox_prot; |
|
915 |
size_t rec_size, data_size; |
|
916 |
ec_sdo_entry_t *entry; |
|
1382
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
917 |
u16 word; |
436 | 918 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
919 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
920 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
921 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
922 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
923 |
fsm->state = ec_fsm_coe_error; |
1921 | 924 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO" |
925 |
" description response datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
926 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
927 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
928 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
929 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
930 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
931 |
fsm->state = ec_fsm_coe_error; |
1921 | 932 |
EC_SLAVE_ERR(slave, "Reception of CoE SDO description" |
933 |
" response failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
934 |
ec_datagram_print_wc_error(datagram); |
436 | 935 |
return; |
936 |
} |
|
937 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
938 |
data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
939 |
if (IS_ERR(data)) { |
436 | 940 |
fsm->state = ec_fsm_coe_error; |
941 |
return; |
|
942 |
} |
|
943 |
||
944 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 945 |
EC_SLAVE_ERR(slave, "Received mailbox protocol" |
946 |
" 0x%02X as response.\n", mbox_prot); |
|
436 | 947 |
fsm->state = ec_fsm_coe_error; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
948 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
949 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
950 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
951 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
952 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
953 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
954 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
955 |
fsm->state = ec_fsm_coe_dict_entry_check; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
956 |
return; |
436 | 957 |
} |
958 |
||
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
959 |
if (rec_size < 3) { |
1921 | 960 |
EC_SLAVE_ERR(slave, "Received corrupted SDO entry" |
961 |
" description response (size %zu).\n", rec_size); |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
962 |
fsm->state = ec_fsm_coe_error; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
963 |
return; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
964 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
965 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
966 |
if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information |
436 | 967 |
(EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response |
2197
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
968 |
EC_SLAVE_WARN(slave, "SDO information error response while" |
1921 | 969 |
" fetching SDO entry 0x%04X:%02X!\n", |
436 | 970 |
sdo->index, fsm->subindex); |
1921 | 971 |
ec_canopen_abort_msg(slave, EC_READ_U32(data + 6)); |
2197
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
972 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
973 |
/* There may be gaps in the subindices, so try to continue with next |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
974 |
* subindex. */ |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
975 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
976 |
} else { |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
977 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
978 |
if (rec_size < 9) { |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
979 |
EC_SLAVE_ERR(slave, "Received corrupted SDO entry" |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
980 |
" description response (size %zu).\n", rec_size); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
981 |
fsm->state = ec_fsm_coe_error; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
982 |
return; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
983 |
} |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
984 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
985 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
986 |
(EC_READ_U8(data + 2) & 0x7F) != 0x06 || // Entry desc. response |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
987 |
EC_READ_U16(data + 6) != sdo->index || // SDO index |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
988 |
EC_READ_U8(data + 8) != fsm->subindex) { // SDO subindex |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
989 |
if (fsm->slave->master->debug_level) { |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
990 |
EC_SLAVE_DBG(slave, 1, "Invalid entry description response" |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
991 |
" while fetching SDO entry 0x%04X:%02X!\n", |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
992 |
sdo->index, fsm->subindex); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
993 |
ec_print_data(data, rec_size); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
994 |
} |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
995 |
// check for CoE response again |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
996 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
997 |
fsm->retries = EC_FSM_RETRIES; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
998 |
fsm->state = ec_fsm_coe_dict_entry_check; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
999 |
return; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1000 |
} |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1001 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1002 |
if (rec_size < 16) { |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1003 |
EC_SLAVE_ERR(slave, "Invalid data size %zu!\n", rec_size); |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1004 |
ec_print_data(data, rec_size); |
436 | 1005 |
fsm->state = ec_fsm_coe_error; |
1006 |
return; |
|
1007 |
} |
|
2197
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1008 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1009 |
data_size = rec_size - 16; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1010 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1011 |
if (!(entry = (ec_sdo_entry_t *) |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1012 |
kmalloc(sizeof(ec_sdo_entry_t), GFP_KERNEL))) { |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1013 |
EC_SLAVE_ERR(slave, "Failed to allocate entry!\n"); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1014 |
fsm->state = ec_fsm_coe_error; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1015 |
return; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1016 |
} |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1017 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1018 |
ec_sdo_entry_init(entry, sdo, fsm->subindex); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1019 |
entry->data_type = EC_READ_U16(data + 10); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1020 |
entry->bit_length = EC_READ_U16(data + 12); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1021 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1022 |
// read access rights |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1023 |
word = EC_READ_U16(data + 14); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1024 |
entry->read_access[EC_SDO_ENTRY_ACCESS_PREOP] = word & 0x0001; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1025 |
entry->read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1026 |
(word >> 1) & 0x0001; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1027 |
entry->read_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 2) & 0x0001; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1028 |
entry->write_access[EC_SDO_ENTRY_ACCESS_PREOP] = (word >> 3) & 0x0001; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1029 |
entry->write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1030 |
(word >> 4) & 0x0001; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1031 |
entry->write_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 5) & 0x0001; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1032 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1033 |
if (data_size) { |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1034 |
uint8_t *desc; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1035 |
if (!(desc = kmalloc(data_size + 1, GFP_KERNEL))) { |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1036 |
EC_SLAVE_ERR(slave, "Failed to allocate SDO entry name!\n"); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1037 |
fsm->state = ec_fsm_coe_error; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1038 |
return; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1039 |
} |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1040 |
memcpy(desc, data + 16, data_size); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1041 |
desc[data_size] = 0; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1042 |
entry->description = desc; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1043 |
} |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1044 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1045 |
list_add_tail(&entry->list, &sdo->entries); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1046 |
} |
436 | 1047 |
|
962
ea83a7aab57a
Renamed subindices to max_subindex.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
1048 |
if (fsm->subindex < sdo->max_subindex) { |
436 | 1049 |
fsm->subindex++; |
1050 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1051 |
data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1052 |
if (IS_ERR(data)) { |
436 | 1053 |
fsm->state = ec_fsm_coe_error; |
1054 |
return; |
|
1055 |
} |
|
1056 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1057 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 1058 |
EC_WRITE_U8 (data + 2, 0x05); // Get entry description request |
1059 |
EC_WRITE_U8 (data + 3, 0x00); |
|
1060 |
EC_WRITE_U16(data + 4, 0x0000); |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1061 |
EC_WRITE_U16(data + 6, sdo->index); // SDO index |
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1062 |
EC_WRITE_U8 (data + 8, fsm->subindex); // SDO subindex |
436 | 1063 |
EC_WRITE_U8 (data + 9, 0x00); // value info (no values) |
1064 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1065 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1066 |
fsm->state = ec_fsm_coe_dict_entry_request; |
1067 |
return; |
|
1068 |
} |
|
1069 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1070 |
// another SDO description to fetch? |
436 | 1071 |
if (fsm->sdo->list.next != &slave->sdo_dictionary) { |
1072 |
fsm->sdo = list_entry(fsm->sdo->list.next, ec_sdo_t, list); |
|
1073 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1074 |
data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1075 |
if (IS_ERR(data)) { |
436 | 1076 |
fsm->state = ec_fsm_coe_error; |
1077 |
return; |
|
1078 |
} |
|
1079 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1080 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 1081 |
EC_WRITE_U8 (data + 2, 0x03); // Get object description request |
1082 |
EC_WRITE_U8 (data + 3, 0x00); |
|
1083 |
EC_WRITE_U16(data + 4, 0x0000); |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1084 |
EC_WRITE_U16(data + 6, fsm->sdo->index); // SDO index |
436 | 1085 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1086 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1087 |
fsm->state = ec_fsm_coe_dict_desc_request; |
1088 |
return; |
|
1089 |
} |
|
1090 |
||
1091 |
fsm->state = ec_fsm_coe_end; |
|
1092 |
} |
|
1093 |
||
1094 |
/****************************************************************************** |
|
1095 |
* CoE state machine |
|
1096 |
*****************************************************************************/ |
|
1097 |
||
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1098 |
/** CoE state: DOWN START. |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1099 |
*/ |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1100 |
void ec_fsm_coe_down_start( |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1101 |
ec_fsm_coe_t *fsm /**< finite state machine */ |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1102 |
) |
436 | 1103 |
{ |
1104 |
ec_datagram_t *datagram = fsm->datagram; |
|
1105 |
ec_slave_t *slave = fsm->slave; |
|
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
1106 |
ec_sdo_request_t *request = fsm->request; |
436 | 1107 |
uint8_t *data; |
1562 | 1108 |
uint8_t data_set_size; |
436 | 1109 |
|
874 | 1110 |
if (fsm->slave->master->debug_level) { |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1111 |
char subidxstr[10]; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1112 |
if (request->complete_access) { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1113 |
subidxstr[0] = 0x00; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1114 |
} else { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1115 |
sprintf(subidxstr, ":%02X", request->subindex); |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1116 |
} |
1921 | 1117 |
EC_SLAVE_DBG(slave, 1, "Downloading SDO 0x%04X%s.\n", |
1118 |
request->index, subidxstr); |
|
874 | 1119 |
ec_print_data(request->data, request->data_size); |
1120 |
} |
|
436 | 1121 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
1122 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
1921 | 1123 |
EC_SLAVE_ERR(slave, "Slave does not support CoE!\n"); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1124 |
request->errno = EPROTONOSUPPORT; |
825
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1125 |
fsm->state = ec_fsm_coe_error; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1126 |
return; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1127 |
} |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1128 |
|
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
1129 |
if (slave->configured_rx_mailbox_size < |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1130 |
EC_MBOX_HEADER_SIZE + EC_COE_DOWN_REQ_HEADER_SIZE) { |
1921 | 1131 |
EC_SLAVE_ERR(slave, "Mailbox too small!\n"); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1132 |
request->errno = EOVERFLOW; |
1562 | 1133 |
fsm->state = ec_fsm_coe_error; |
1134 |
return; |
|
1135 |
} |
|
1136 |
||
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1137 |
if (request->data_size <= 4) { // use expedited transfer type |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1138 |
data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1139 |
EC_COE_DOWN_REQ_HEADER_SIZE); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1140 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1141 |
request->errno = PTR_ERR(data); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1142 |
fsm->state = ec_fsm_coe_error; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1143 |
return; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1144 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1145 |
|
1562 | 1146 |
fsm->remaining = 0; |
1147 |
||
1148 |
data_set_size = 4 - request->data_size; |
|
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1149 |
|
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1150 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1151 |
EC_WRITE_U8 (data + 2, (0x3 // size specified, expedited |
1562 | 1152 |
| data_set_size << 2 |
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
1153 |
| ((request->complete_access ? 1 : 0) << 4) |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1154 |
| 0x1 << 5)); // Download request |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1155 |
EC_WRITE_U16(data + 3, request->index); |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1156 |
EC_WRITE_U8 (data + 5, |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1157 |
request->complete_access ? 0x00 : request->subindex); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1158 |
memcpy(data + 6, request->data, request->data_size); |
1457
ec3ad6641d65
Slightly improved CoE download expedited request.
Florian Pose <fp@igh-essen.com>
parents:
1382
diff
changeset
|
1159 |
memset(data + 6 + request->data_size, 0x00, 4 - request->data_size); |
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1160 |
|
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1161 |
if (slave->master->debug_level) { |
1921 | 1162 |
EC_SLAVE_DBG(slave, 1, "Expedited download request:\n"); |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1163 |
ec_print_data(data, EC_COE_DOWN_REQ_HEADER_SIZE); |
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1164 |
} |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1165 |
} |
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1166 |
else { // request->data_size > 4, use normal transfer type |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1167 |
size_t data_size, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1168 |
max_data_size = |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1169 |
slave->configured_rx_mailbox_size - EC_MBOX_HEADER_SIZE, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1170 |
required_data_size = |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1171 |
EC_COE_DOWN_REQ_HEADER_SIZE + request->data_size; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1172 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1173 |
if (max_data_size < required_data_size) { |
1562 | 1174 |
// segmenting needed |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1175 |
data_size = max_data_size; |
1562 | 1176 |
} else { |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1177 |
data_size = required_data_size; |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1178 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1179 |
|
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1180 |
data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, |
1562 | 1181 |
data_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1182 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1183 |
request->errno = PTR_ERR(data); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1184 |
fsm->state = ec_fsm_coe_error; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1185 |
return; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1186 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1187 |
|
1562 | 1188 |
fsm->offset = 0; |
1189 |
fsm->remaining = request->data_size; |
|
1190 |
||
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1191 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1192 |
EC_WRITE_U8(data + 2, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1193 |
0x1 // size indicator, normal |
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
1194 |
| ((request->complete_access ? 1 : 0) << 4) |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1195 |
| 0x1 << 5); // Download request |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1196 |
EC_WRITE_U16(data + 3, request->index); |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1197 |
EC_WRITE_U8 (data + 5, |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1198 |
request->complete_access ? 0x00 : request->subindex); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1199 |
EC_WRITE_U32(data + 6, request->data_size); |
1562 | 1200 |
|
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1201 |
if (data_size > EC_COE_DOWN_REQ_HEADER_SIZE) { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1202 |
size_t segment_size = data_size - EC_COE_DOWN_REQ_HEADER_SIZE; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1203 |
memcpy(data + EC_COE_DOWN_REQ_HEADER_SIZE, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1204 |
request->data, segment_size); |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1205 |
fsm->offset += segment_size; |
1562 | 1206 |
fsm->remaining -= segment_size; |
1207 |
} |
|
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1208 |
|
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1209 |
if (slave->master->debug_level) { |
1921 | 1210 |
EC_SLAVE_DBG(slave, 1, "Normal download request:\n"); |
1562 | 1211 |
ec_print_data(data, data_size); |
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1212 |
} |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1213 |
} |
975
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1214 |
|
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1215 |
fsm->request->jiffies_sent = jiffies; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1216 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1217 |
fsm->state = ec_fsm_coe_down_request; |
1218 |
} |
|
1219 |
||
1220 |
/*****************************************************************************/ |
|
1221 |
||
1222 |
/** |
|
1223 |
CoE state: DOWN REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1224 |
\todo Timeout behavior |
436 | 1225 |
*/ |
1226 |
||
1227 |
void ec_fsm_coe_down_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1228 |
{ |
|
1229 |
ec_datagram_t *datagram = fsm->datagram; |
|
1230 |
ec_slave_t *slave = fsm->slave; |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1231 |
unsigned long diff_ms; |
436 | 1232 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1233 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1234 |
return; // FIXME: check for response first? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1235 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1236 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1237 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1238 |
fsm->state = ec_fsm_coe_error; |
1921 | 1239 |
EC_SLAVE_ERR(slave, "Failed to receive CoE download" |
1240 |
" request datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1241 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1242 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1243 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1244 |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1245 |
diff_ms = (jiffies - fsm->request->jiffies_sent) * 1000 / HZ; |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1246 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1247 |
if (datagram->working_counter != 1) { |
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1248 |
if (!datagram->working_counter) { |
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1249 |
if (diff_ms < fsm->request->response_timeout) { |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1250 |
#if DEBUG_RETRIES |
1931 | 1251 |
EC_SLAVE_DBG(slave, 1, "Slave did not respond to SDO" |
1252 |
" download request. Retrying after %lu ms...\n", |
|
1253 |
diff_ms); |
|
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1254 |
#endif |
1112
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1255 |
// no response; send request datagram again |
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1256 |
return; |
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1257 |
} |
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1258 |
} |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1259 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1260 |
fsm->state = ec_fsm_coe_error; |
1921 | 1261 |
EC_SLAVE_ERR(slave, "Reception of CoE download request" |
1931 | 1262 |
" for SDO 0x%04x:%x failed with timeout after %lu ms: ", |
1263 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1264 |
ec_datagram_print_wc_error(datagram); |
436 | 1265 |
return; |
1266 |
} |
|
1267 |
||
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1268 |
#if DEBUG_LONG |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1269 |
if (diff_ms > 200) { |
1931 | 1270 |
EC_SLAVE_WARN(slave, "SDO 0x%04x:%x download took %lu ms.\n", |
1271 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1272 |
} |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1273 |
#endif |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1274 |
|
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1275 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 1276 |
|
1277 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1278 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1279 |
fsm->state = ec_fsm_coe_down_check; |
1280 |
} |
|
1281 |
||
1282 |
/*****************************************************************************/ |
|
1283 |
||
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1284 |
/** CoE state: DOWN CHECK. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1285 |
*/ |
436 | 1286 |
void ec_fsm_coe_down_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
1287 |
{ |
|
1288 |
ec_datagram_t *datagram = fsm->datagram; |
|
1289 |
ec_slave_t *slave = fsm->slave; |
|
1290 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1291 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1292 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1293 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1294 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1295 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1296 |
fsm->state = ec_fsm_coe_error; |
1921 | 1297 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check" |
1298 |
" datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1299 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1300 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1301 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1302 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1303 |
if (datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1304 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1305 |
fsm->state = ec_fsm_coe_error; |
1921 | 1306 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
1307 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1308 |
ec_datagram_print_wc_error(datagram); |
436 | 1309 |
return; |
1310 |
} |
|
1311 |
||
1312 |
if (!ec_slave_mbox_check(datagram)) { |
|
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1313 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1314 |
(datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ; |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1315 |
if (diff_ms >= fsm->request->response_timeout) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1316 |
fsm->request->errno = EIO; |
436 | 1317 |
fsm->state = ec_fsm_coe_error; |
1931 | 1318 |
EC_SLAVE_ERR(slave, "Timeout after %lu ms while waiting" |
1319 |
" for SDO 0x%04x:%x download response.\n", diff_ms, |
|
1921 | 1320 |
fsm->request->index, fsm->request->subindex); |
436 | 1321 |
return; |
1322 |
} |
|
1323 |
||
1324 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1325 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1326 |
return; |
1327 |
} |
|
1328 |
||
1329 |
// Fetch response |
|
1330 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1331 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1332 |
fsm->state = ec_fsm_coe_down_response; |
1333 |
} |
|
1334 |
||
1335 |
/*****************************************************************************/ |
|
1336 |
||
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1337 |
/** Prepare a download segment request. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1338 |
*/ |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1339 |
void ec_fsm_coe_down_prepare_segment_request( |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1340 |
ec_fsm_coe_t *fsm /**< finite state machine */ |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1341 |
) |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1342 |
{ |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1343 |
ec_datagram_t *datagram = fsm->datagram; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1344 |
ec_slave_t *slave = fsm->slave; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1345 |
ec_sdo_request_t *request = fsm->request; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1346 |
size_t max_segment_size = |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1347 |
slave->configured_rx_mailbox_size |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1348 |
- EC_MBOX_HEADER_SIZE |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1349 |
- EC_COE_DOWN_SEG_REQ_HEADER_SIZE; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1350 |
size_t segment_size, data_size; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1351 |
uint8_t last_segment, seg_data_size, *data; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1352 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1353 |
if (fsm->remaining > max_segment_size) { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1354 |
segment_size = max_segment_size; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1355 |
last_segment = 0; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1356 |
} else { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1357 |
segment_size = fsm->remaining; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1358 |
last_segment = 1; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1359 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1360 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1361 |
if (segment_size > EC_COE_DOWN_SEG_MIN_DATA_SIZE) { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1362 |
seg_data_size = 0x00; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1363 |
data_size = EC_COE_DOWN_SEG_REQ_HEADER_SIZE + segment_size; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1364 |
} else { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1365 |
seg_data_size = EC_COE_DOWN_SEG_MIN_DATA_SIZE - segment_size; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1366 |
data_size = EC_COE_DOWN_SEG_REQ_HEADER_SIZE |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1367 |
+ EC_COE_DOWN_SEG_MIN_DATA_SIZE; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1368 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1369 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1370 |
data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1371 |
data_size); |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1372 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1373 |
request->errno = PTR_ERR(data); |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1374 |
fsm->state = ec_fsm_coe_error; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1375 |
return; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1376 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1377 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1378 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1379 |
EC_WRITE_U8(data + 2, (last_segment ? 1 : 0) |
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
1380 |
| (seg_data_size << 1) |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1381 |
| (fsm->toggle << 4) |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1382 |
| (0x00 << 5)); // Download segment request |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1383 |
memcpy(data + EC_COE_DOWN_SEG_REQ_HEADER_SIZE, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1384 |
request->data + fsm->offset, segment_size); |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1385 |
if (segment_size < EC_COE_DOWN_SEG_MIN_DATA_SIZE) { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1386 |
memset(data + EC_COE_DOWN_SEG_REQ_HEADER_SIZE + segment_size, 0x00, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1387 |
EC_COE_DOWN_SEG_MIN_DATA_SIZE - segment_size); |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1388 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1389 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1390 |
fsm->offset += segment_size; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1391 |
fsm->remaining -= segment_size; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1392 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1393 |
if (slave->master->debug_level) { |
1921 | 1394 |
EC_SLAVE_DBG(slave, 1, "Download segment request:\n"); |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1395 |
ec_print_data(data, data_size); |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1396 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1397 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1398 |
fsm->state = ec_fsm_coe_down_seg_check; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1399 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1400 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1401 |
/*****************************************************************************/ |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1402 |
|
436 | 1403 |
/** |
1404 |
CoE state: DOWN RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1405 |
\todo Timeout behavior |
436 | 1406 |
*/ |
1407 |
||
1408 |
void ec_fsm_coe_down_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1409 |
{ |
|
1410 |
ec_datagram_t *datagram = fsm->datagram; |
|
1411 |
ec_slave_t *slave = fsm->slave; |
|
1412 |
uint8_t *data, mbox_prot; |
|
1413 |
size_t rec_size; |
|
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
1414 |
ec_sdo_request_t *request = fsm->request; |
436 | 1415 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1416 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1417 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1418 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1419 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1420 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1421 |
fsm->state = ec_fsm_coe_error; |
1921 | 1422 |
EC_SLAVE_ERR(slave, "Failed to receive CoE download" |
1423 |
" response datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1424 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1425 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1426 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1427 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1428 |
if (datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1429 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1430 |
fsm->state = ec_fsm_coe_error; |
1921 | 1431 |
EC_SLAVE_ERR(slave, "Reception of CoE download response failed: "); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1432 |
ec_datagram_print_wc_error(datagram); |
436 | 1433 |
return; |
1434 |
} |
|
1435 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1436 |
data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1437 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1438 |
request->errno = PTR_ERR(data); |
436 | 1439 |
fsm->state = ec_fsm_coe_error; |
1440 |
return; |
|
1441 |
} |
|
1442 |
||
1443 |
if (mbox_prot != 0x03) { // CoE |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1444 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1445 |
fsm->state = ec_fsm_coe_error; |
1921 | 1446 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
1447 |
mbox_prot); |
|
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1448 |
return; |
436 | 1449 |
} |
1450 |
||
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1451 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1452 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1453 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1454 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1455 |
fsm->state = ec_fsm_coe_down_check; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1456 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1457 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1458 |
|
975
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1459 |
if (slave->master->debug_level) { |
1921 | 1460 |
EC_SLAVE_DBG(slave, 1, "Download response:\n"); |
975
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1461 |
ec_print_data(data, rec_size); |
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1462 |
} |
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1463 |
|
436 | 1464 |
if (rec_size < 6) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1465 |
request->errno = EIO; |
436 | 1466 |
fsm->state = ec_fsm_coe_error; |
1921 | 1467 |
EC_SLAVE_ERR(slave, "Received data are too small (%zu bytes):\n", |
1468 |
rec_size); |
|
436 | 1469 |
ec_print_data(data, rec_size); |
1470 |
return; |
|
1471 |
} |
|
1472 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1473 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1474 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1475 |
char subidxstr[10]; |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1476 |
request->errno = EIO; |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1477 |
fsm->state = ec_fsm_coe_error; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1478 |
if (request->complete_access) { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1479 |
subidxstr[0] = 0x00; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1480 |
} else { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1481 |
sprintf(subidxstr, ":%02X", request->subindex); |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1482 |
} |
1921 | 1483 |
EC_SLAVE_ERR(slave, "SDO download 0x%04X%s (%zu bytes) aborted.\n", |
1484 |
request->index, subidxstr, request->data_size); |
|
436 | 1485 |
if (rec_size < 10) { |
1921 | 1486 |
EC_SLAVE_ERR(slave, "Incomplete abort command:\n"); |
436 | 1487 |
ec_print_data(data, rec_size); |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1488 |
} else { |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1489 |
fsm->request->abort_code = EC_READ_U32(data + 6); |
1921 | 1490 |
ec_canopen_abort_msg(slave, fsm->request->abort_code); |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1491 |
} |
436 | 1492 |
return; |
1493 |
} |
|
1494 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1495 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
436 | 1496 |
EC_READ_U8 (data + 2) >> 5 != 0x3 || // Download response |
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
1497 |
EC_READ_U16(data + 3) != request->index || // index |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
1498 |
EC_READ_U8 (data + 5) != request->subindex) { // subindex |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1499 |
if (slave->master->debug_level) { |
1921 | 1500 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO download response!" |
1501 |
" Retrying...\n"); |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1502 |
ec_print_data(data, rec_size); |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1503 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1504 |
// check for CoE response again |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1505 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1506 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1507 |
fsm->state = ec_fsm_coe_down_check; |
436 | 1508 |
return; |
1509 |
} |
|
1510 |
||
1562 | 1511 |
if (fsm->remaining) { // more segments to download |
1512 |
fsm->toggle = 0; |
|
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1513 |
ec_fsm_coe_down_prepare_segment_request(fsm); |
1562 | 1514 |
} else { |
1515 |
fsm->state = ec_fsm_coe_end; // success |
|
1516 |
} |
|
1517 |
} |
|
1518 |
||
1519 |
/*****************************************************************************/ |
|
1520 |
||
1521 |
/** |
|
1522 |
CoE state: DOWN SEG CHECK. |
|
1523 |
*/ |
|
1524 |
||
1525 |
void ec_fsm_coe_down_seg_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1526 |
{ |
|
1527 |
ec_datagram_t *datagram = fsm->datagram; |
|
1528 |
ec_slave_t *slave = fsm->slave; |
|
1529 |
||
1530 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
|
1531 |
return; |
|
1532 |
||
1533 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1534 |
fsm->request->errno = EIO; |
1562 | 1535 |
fsm->state = ec_fsm_coe_error; |
1921 | 1536 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: "); |
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1537 |
ec_datagram_print_state(datagram); |
1562 | 1538 |
return; |
1539 |
} |
|
1540 |
||
1541 |
if (datagram->working_counter != 1) { |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1542 |
fsm->request->errno = EIO; |
1562 | 1543 |
fsm->state = ec_fsm_coe_error; |
1921 | 1544 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox segment check" |
1545 |
" datagram failed: "); |
|
1562 | 1546 |
ec_datagram_print_wc_error(datagram); |
1547 |
return; |
|
1548 |
} |
|
1549 |
||
1550 |
if (!ec_slave_mbox_check(datagram)) { |
|
1551 |
unsigned long diff_ms = |
|
1552 |
(datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ; |
|
1553 |
if (diff_ms >= fsm->request->response_timeout) { |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1554 |
fsm->request->errno = EIO; |
1562 | 1555 |
fsm->state = ec_fsm_coe_error; |
1921 | 1556 |
EC_SLAVE_ERR(slave, "Timeout while waiting for SDO download" |
1557 |
" segment response.\n"); |
|
1562 | 1558 |
return; |
1559 |
} |
|
1560 |
||
1561 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
1562 |
fsm->retries = EC_FSM_RETRIES; |
|
1563 |
return; |
|
1564 |
} |
|
1565 |
||
1566 |
// Fetch response |
|
1567 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
|
1568 |
fsm->retries = EC_FSM_RETRIES; |
|
1569 |
fsm->state = ec_fsm_coe_down_seg_response; |
|
1570 |
} |
|
1571 |
||
1572 |
/*****************************************************************************/ |
|
1573 |
||
1574 |
/** |
|
1575 |
CoE state: DOWN SEG RESPONSE. |
|
1576 |
\todo Timeout behavior |
|
1577 |
*/ |
|
1578 |
||
1579 |
void ec_fsm_coe_down_seg_response( |
|
1580 |
ec_fsm_coe_t *fsm /**< finite state machine */ |
|
1581 |
) |
|
1582 |
{ |
|
1583 |
ec_datagram_t *datagram = fsm->datagram; |
|
1584 |
ec_slave_t *slave = fsm->slave; |
|
1585 |
uint8_t *data, mbox_prot; |
|
1586 |
size_t rec_size; |
|
1587 |
ec_sdo_request_t *request = fsm->request; |
|
1588 |
||
1589 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
|
1590 |
return; // FIXME: request again? |
|
1591 |
||
1592 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1593 |
request->errno = EIO; |
1562 | 1594 |
fsm->state = ec_fsm_coe_error; |
1921 | 1595 |
EC_SLAVE_ERR(slave, "Failed to receive CoE download response" |
1596 |
" datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1597 |
ec_datagram_print_state(datagram); |
1562 | 1598 |
return; |
1599 |
} |
|
1600 |
||
1601 |
if (datagram->working_counter != 1) { |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1602 |
request->errno = EIO; |
1562 | 1603 |
fsm->state = ec_fsm_coe_error; |
1921 | 1604 |
EC_SLAVE_ERR(slave, "Reception of CoE download response failed: "); |
1562 | 1605 |
ec_datagram_print_wc_error(datagram); |
1606 |
return; |
|
1607 |
} |
|
1608 |
||
1609 |
data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size); |
|
1610 |
if (IS_ERR(data)) { |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1611 |
request->errno = PTR_ERR(data); |
1562 | 1612 |
fsm->state = ec_fsm_coe_error; |
1613 |
return; |
|
1614 |
} |
|
1615 |
||
1616 |
if (mbox_prot != 0x03) { // CoE |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1617 |
request->errno = EIO; |
1562 | 1618 |
fsm->state = ec_fsm_coe_error; |
1921 | 1619 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
1620 |
mbox_prot); |
|
1562 | 1621 |
return; |
1622 |
} |
|
1623 |
||
1624 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
|
1625 |
// check for CoE response again |
|
1626 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
1627 |
fsm->retries = EC_FSM_RETRIES; |
|
1628 |
fsm->state = ec_fsm_coe_down_check; |
|
1629 |
return; |
|
1630 |
} |
|
1631 |
||
1632 |
if (slave->master->debug_level) { |
|
1921 | 1633 |
EC_SLAVE_DBG(slave, 1, "Download response:\n"); |
1562 | 1634 |
ec_print_data(data, rec_size); |
1635 |
} |
|
1636 |
||
1637 |
if (rec_size < 6) { |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1638 |
request->errno = EIO; |
1562 | 1639 |
fsm->state = ec_fsm_coe_error; |
1921 | 1640 |
EC_SLAVE_ERR(slave, "Received data are too small (%zu bytes):\n", |
1641 |
rec_size); |
|
1562 | 1642 |
ec_print_data(data, rec_size); |
1643 |
return; |
|
1644 |
} |
|
1645 |
||
1646 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
|
1647 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
|
1648 |
char subidxstr[10]; |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1649 |
request->errno = EIO; |
1562 | 1650 |
fsm->state = ec_fsm_coe_error; |
1651 |
if (request->complete_access) { |
|
1652 |
subidxstr[0] = 0x00; |
|
1653 |
} else { |
|
1654 |
sprintf(subidxstr, ":%02X", request->subindex); |
|
1655 |
} |
|
1921 | 1656 |
EC_SLAVE_ERR(slave, "SDO download 0x%04X%s (%zu bytes) aborted.\n", |
1657 |
request->index, subidxstr, request->data_size); |
|
1562 | 1658 |
if (rec_size < 10) { |
1921 | 1659 |
EC_SLAVE_ERR(slave, "Incomplete abort command:\n"); |
1562 | 1660 |
ec_print_data(data, rec_size); |
1661 |
} else { |
|
1662 |
fsm->request->abort_code = EC_READ_U32(data + 6); |
|
1921 | 1663 |
ec_canopen_abort_msg(slave, fsm->request->abort_code); |
1562 | 1664 |
} |
1665 |
return; |
|
1666 |
} |
|
1667 |
||
1668 |
if (EC_READ_U16(data) >> 12 != 0x3 || |
|
1669 |
((EC_READ_U8(data + 2) >> 5) != 0x01)) { // segment response |
|
1670 |
if (slave->master->debug_level) { |
|
1921 | 1671 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO download response!" |
1672 |
" Retrying...\n"); |
|
1562 | 1673 |
ec_print_data(data, rec_size); |
1674 |
} |
|
1675 |
// check for CoE response again |
|
1676 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
1677 |
fsm->retries = EC_FSM_RETRIES; |
|
1678 |
fsm->state = ec_fsm_coe_down_seg_check; |
|
1679 |
return; |
|
1680 |
} |
|
1681 |
||
1682 |
if (((EC_READ_U8(data + 2) >> 4) & 0x01) != fsm->toggle) { |
|
1921 | 1683 |
EC_SLAVE_ERR(slave, "Invalid toggle received during" |
1684 |
" segmented download:\n"); |
|
1562 | 1685 |
ec_print_data(data, rec_size); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1686 |
request->errno = EIO; |
1562 | 1687 |
fsm->state = ec_fsm_coe_error; |
1688 |
return; |
|
1689 |
} |
|
1690 |
||
1691 |
if (fsm->remaining) { // more segments to download |
|
1692 |
fsm->toggle = !fsm->toggle; |
|
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1693 |
ec_fsm_coe_down_prepare_segment_request(fsm); |
1562 | 1694 |
} else { |
1695 |
fsm->state = ec_fsm_coe_end; // success |
|
1696 |
} |
|
436 | 1697 |
} |
1698 |
||
1699 |
/*****************************************************************************/ |
|
1700 |
||
1701 |
/** |
|
1702 |
CoE state: UP START. |
|
1703 |
*/ |
|
1704 |
||
1705 |
void ec_fsm_coe_up_start(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1706 |
{ |
|
1707 |
ec_datagram_t *datagram = fsm->datagram; |
|
1708 |
ec_slave_t *slave = fsm->slave; |
|
1709 |
ec_master_t *master = slave->master; |
|
1710 |
ec_sdo_request_t *request = fsm->request; |
|
1711 |
uint8_t *data; |
|
1712 |
||
1921 | 1713 |
EC_SLAVE_DBG(slave, 1, "Uploading SDO 0x%04X:%02X.\n", |
1714 |
request->index, request->subindex); |
|
436 | 1715 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
1716 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
1921 | 1717 |
EC_SLAVE_ERR(slave, "Slave does not support CoE!\n"); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1718 |
request->errno = EPROTONOSUPPORT; |
825
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1719 |
fsm->state = ec_fsm_coe_error; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1720 |
return; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1721 |
} |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1722 |
|
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1723 |
data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1724 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1725 |
request->errno = PTR_ERR(data); |
436 | 1726 |
fsm->state = ec_fsm_coe_error; |
1727 |
return; |
|
1728 |
} |
|
1729 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1730 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
436 | 1731 |
EC_WRITE_U8 (data + 2, 0x2 << 5); // initiate upload request |
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1732 |
EC_WRITE_U16(data + 3, request->index); |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1733 |
EC_WRITE_U8 (data + 5, request->subindex); |
476
fd7c0ee645f8
Fixed CoE Upload Request, now 10 bytes of Mailbox Service Data.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1734 |
memset(data + 6, 0x00, 4); |
436 | 1735 |
|
1736 |
if (master->debug_level) { |
|
1921 | 1737 |
EC_SLAVE_DBG(slave, 1, "Upload request:\n"); |
476
fd7c0ee645f8
Fixed CoE Upload Request, now 10 bytes of Mailbox Service Data.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1738 |
ec_print_data(data, 10); |
436 | 1739 |
} |
1740 |
||
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1741 |
fsm->request->jiffies_sent = jiffies; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1742 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1743 |
fsm->state = ec_fsm_coe_up_request; |
1744 |
} |
|
1745 |
||
1746 |
/*****************************************************************************/ |
|
1747 |
||
1748 |
/** |
|
1749 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1750 |
\todo Timeout behavior |
436 | 1751 |
*/ |
1752 |
||
1753 |
void ec_fsm_coe_up_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1754 |
{ |
|
1755 |
ec_datagram_t *datagram = fsm->datagram; |
|
1756 |
ec_slave_t *slave = fsm->slave; |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1757 |
unsigned long diff_ms; |
436 | 1758 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1759 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1760 |
return; // FIXME: check for response first? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1761 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1762 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1763 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1764 |
fsm->state = ec_fsm_coe_error; |
1921 | 1765 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload request: "); |
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1766 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1767 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1768 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1769 |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1770 |
diff_ms = (jiffies - fsm->request->jiffies_sent) * 1000 / HZ; |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1771 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1772 |
if (datagram->working_counter != 1) { |
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1773 |
if (!datagram->working_counter) { |
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1774 |
if (diff_ms < fsm->request->response_timeout) { |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1775 |
#if DEBUG_RETRIES |
1921 | 1776 |
EC_SLAVE_DBG(slave, 1, "Slave did not respond to" |
1931 | 1777 |
" SDO upload request. Retrying after %lu ms...\n", |
1778 |
diff_ms); |
|
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1779 |
#endif |
1112
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1780 |
// no response; send request datagram again |
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1781 |
return; |
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1782 |
} |
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1783 |
} |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1784 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1785 |
fsm->state = ec_fsm_coe_error; |
1921 | 1786 |
EC_SLAVE_ERR(slave, "Reception of CoE upload request for" |
1931 | 1787 |
" SDO 0x%04x:%x failed with timeout after %lu ms: ", |
1788 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1789 |
ec_datagram_print_wc_error(datagram); |
436 | 1790 |
return; |
1791 |
} |
|
1792 |
||
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1793 |
#if DEBUG_LONG |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1794 |
if (diff_ms > 200) { |
1931 | 1795 |
EC_SLAVE_WARN(slave, "SDO 0x%04x:%x upload took %lu ms.\n", |
1796 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1797 |
} |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1798 |
#endif |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1799 |
|
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1800 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 1801 |
|
1802 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1803 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1804 |
fsm->state = ec_fsm_coe_up_check; |
1805 |
} |
|
1806 |
||
1807 |
/*****************************************************************************/ |
|
1808 |
||
1809 |
/** |
|
1810 |
CoE state: UP CHECK. |
|
1811 |
*/ |
|
1812 |
||
1813 |
void ec_fsm_coe_up_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1814 |
{ |
|
1815 |
ec_datagram_t *datagram = fsm->datagram; |
|
1816 |
ec_slave_t *slave = fsm->slave; |
|
1817 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1818 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1819 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1820 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1821 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1822 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1823 |
fsm->state = ec_fsm_coe_error; |
1921 | 1824 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: "); |
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1825 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1826 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1827 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1828 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1829 |
if (datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1830 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1831 |
fsm->state = ec_fsm_coe_error; |
1921 | 1832 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
1833 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1834 |
ec_datagram_print_wc_error(datagram); |
436 | 1835 |
return; |
1836 |
} |
|
1837 |
||
1838 |
if (!ec_slave_mbox_check(datagram)) { |
|
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1839 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1840 |
(datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ; |
1043
2abea4233a6d
Response timeout for checking Sdo upload.
Florian Pose <fp@igh-essen.com>
parents:
1038
diff
changeset
|
1841 |
if (diff_ms >= fsm->request->response_timeout) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1842 |
fsm->request->errno = EIO; |
436 | 1843 |
fsm->state = ec_fsm_coe_error; |
1931 | 1844 |
EC_SLAVE_ERR(slave, "Timeout after %lu ms while waiting for" |
1845 |
" SDO 0x%04x:%x upload response.\n", diff_ms, |
|
1921 | 1846 |
fsm->request->index, fsm->request->subindex); |
436 | 1847 |
return; |
1848 |
} |
|
1849 |
||
1850 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1851 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1852 |
return; |
1853 |
} |
|
1854 |
||
1855 |
// Fetch response |
|
1856 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1857 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1858 |
fsm->state = ec_fsm_coe_up_response; |
1859 |
} |
|
1860 |
||
1861 |
/*****************************************************************************/ |
|
1862 |
||
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1863 |
/** Prepare an SDO upload segment request. |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1864 |
*/ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1865 |
void ec_fsm_coe_up_prepare_segment_request( |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1866 |
ec_fsm_coe_t *fsm /**< Finite state machine */ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1867 |
) |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1868 |
{ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1869 |
uint8_t *data = |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1870 |
ec_slave_mbox_prepare_send(fsm->slave, fsm->datagram, 0x03, 10); |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1871 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1872 |
fsm->request->errno = PTR_ERR(data); |
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1873 |
fsm->state = ec_fsm_coe_error; |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1874 |
return; |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1875 |
} |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1876 |
|
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1877 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1878 |
EC_WRITE_U8 (data + 2, (fsm->toggle << 4 // toggle |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1879 |
| 0x3 << 5)); // upload segment request |
1550
81a16ba13ae6
Avoid zeroing mailbox datagram because of VoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
1544
diff
changeset
|
1880 |
memset(data + 3, 0x00, 7); |
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1881 |
|
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1882 |
if (fsm->slave->master->debug_level) { |
1921 | 1883 |
EC_SLAVE_DBG(fsm->slave, 1, "Upload segment request:\n"); |
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1884 |
ec_print_data(data, 10); |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1885 |
} |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1886 |
} |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1887 |
|
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1888 |
/*****************************************************************************/ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1889 |
|
436 | 1890 |
/** |
1891 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1892 |
\todo Timeout behavior |
436 | 1893 |
*/ |
1894 |
||
1895 |
void ec_fsm_coe_up_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1896 |
{ |
|
1897 |
ec_datagram_t *datagram = fsm->datagram; |
|
1898 |
ec_slave_t *slave = fsm->slave; |
|
1899 |
ec_master_t *master = slave->master; |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1900 |
uint16_t rec_index; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1901 |
uint8_t *data, mbox_prot, rec_subindex; |
436 | 1902 |
size_t rec_size, data_size; |
1903 |
ec_sdo_request_t *request = fsm->request; |
|
1904 |
unsigned int expedited, size_specified; |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1905 |
int ret; |
436 | 1906 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1907 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1908 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1909 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1910 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1911 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1912 |
fsm->state = ec_fsm_coe_error; |
1921 | 1913 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload response" |
1914 |
" datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1915 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1916 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1917 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1918 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1919 |
if (datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1920 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1921 |
fsm->state = ec_fsm_coe_error; |
1921 | 1922 |
EC_SLAVE_ERR(slave, "Reception of CoE upload response failed: "); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1923 |
ec_datagram_print_wc_error(datagram); |
436 | 1924 |
return; |
1925 |
} |
|
1926 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1927 |
data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1928 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1929 |
request->errno = PTR_ERR(data); |
436 | 1930 |
fsm->state = ec_fsm_coe_error; |
1931 |
return; |
|
1932 |
} |
|
1933 |
||
1934 |
if (master->debug_level) { |
|
1921 | 1935 |
EC_SLAVE_DBG(slave, 1, "Upload response:\n"); |
436 | 1936 |
ec_print_data(data, rec_size); |
1937 |
} |
|
1938 |
||
1939 |
if (mbox_prot != 0x03) { // CoE |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1940 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1941 |
fsm->state = ec_fsm_coe_error; |
1921 | 1942 |
EC_SLAVE_WARN(slave, "Received mailbox protocol 0x%02X" |
1943 |
" as response.\n", mbox_prot); |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1944 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1945 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1946 |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1947 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1948 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1949 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1950 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1951 |
fsm->state = ec_fsm_coe_up_check; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1952 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1953 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1954 |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1955 |
if (rec_size < 6) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1956 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1957 |
fsm->state = ec_fsm_coe_error; |
1921 | 1958 |
EC_SLAVE_ERR(slave, "Received currupted SDO upload response" |
1959 |
" (%zu bytes)!\n", rec_size); |
|
436 | 1960 |
ec_print_data(data, rec_size); |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1961 |
return; |
436 | 1962 |
} |
1963 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1964 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1965 |
EC_READ_U8(data + 2) >> 5 == 0x4) { // abort SDO transfer request |
1921 | 1966 |
EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X aborted.\n", |
1967 |
request->index, request->subindex); |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1968 |
if (rec_size >= 10) { |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1969 |
request->abort_code = EC_READ_U32(data + 6); |
1921 | 1970 |
ec_canopen_abort_msg(slave, request->abort_code); |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1971 |
} else { |
1921 | 1972 |
EC_SLAVE_ERR(slave, "No abort message.\n"); |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1973 |
} |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1974 |
request->errno = EIO; |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1975 |
fsm->state = ec_fsm_coe_error; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1976 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1977 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1978 |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1979 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1980 |
EC_READ_U8(data + 2) >> 5 != 0x2) { // upload response |
1921 | 1981 |
EC_SLAVE_ERR(slave, "Received unknown response while" |
1982 |
" uploading SDO 0x%04X:%02X.\n", |
|
1983 |
request->index, request->subindex); |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1984 |
ec_print_data(data, rec_size); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1985 |
request->errno = EIO; |
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1986 |
fsm->state = ec_fsm_coe_error; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1987 |
return; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1988 |
} |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1989 |
|
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1990 |
rec_index = EC_READ_U16(data + 3); |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1991 |
rec_subindex = EC_READ_U8(data + 5); |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1992 |
|
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1993 |
if (rec_index != request->index || rec_subindex != request->subindex) { |
1921 | 1994 |
EC_SLAVE_ERR(slave, "Received upload response for wrong SDO" |
1995 |
" (0x%04X:%02X, requested: 0x%04X:%02X).\n", |
|
1996 |
rec_index, rec_subindex, request->index, request->subindex); |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1997 |
ec_print_data(data, rec_size); |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1998 |
|
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1999 |
// check for CoE response again |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2000 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2001 |
fsm->retries = EC_FSM_RETRIES; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2002 |
fsm->state = ec_fsm_coe_up_check; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2003 |
return; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2004 |
} |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2005 |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2006 |
// normal or expedited? |
436 | 2007 |
expedited = EC_READ_U8(data + 2) & 0x02; |
2008 |
||
2009 |
if (expedited) { |
|
2010 |
size_specified = EC_READ_U8(data + 2) & 0x01; |
|
2011 |
if (size_specified) { |
|
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2012 |
fsm->complete_size = 4 - ((EC_READ_U8(data + 2) & 0x0C) >> 2); |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2013 |
} else { |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2014 |
fsm->complete_size = 4; |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2015 |
} |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2016 |
|
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2017 |
if (rec_size < 6 + fsm->complete_size) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2018 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
2019 |
fsm->state = ec_fsm_coe_error; |
1921 | 2020 |
EC_SLAVE_ERR(slave, "Received corrupted SDO expedited upload" |
1543
373cd456dc26
Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2021 |
" response (only %zu bytes)!\n", rec_size); |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2022 |
ec_print_data(data, rec_size); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2023 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2024 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2025 |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2026 |
ret = ec_sdo_request_copy_data(request, data + 6, fsm->complete_size); |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2027 |
if (ret) { |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2028 |
request->errno = -ret; |
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2029 |
fsm->state = ec_fsm_coe_error; |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2030 |
return; |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2031 |
} |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2032 |
} else { // normal |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2033 |
if (rec_size < 10) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2034 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
2035 |
fsm->state = ec_fsm_coe_error; |
1921 | 2036 |
EC_SLAVE_ERR(slave, "Received currupted SDO normal upload" |
1543
373cd456dc26
Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2037 |
" response (only %zu bytes)!\n", rec_size); |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2038 |
ec_print_data(data, rec_size); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2039 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2040 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2041 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2042 |
data_size = rec_size - 10; |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2043 |
fsm->complete_size = EC_READ_U32(data + 6); |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2044 |
|
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2045 |
if (!fsm->complete_size) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2046 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
2047 |
fsm->state = ec_fsm_coe_error; |
1921 | 2048 |
EC_SLAVE_ERR(slave, "No complete size supplied!\n"); |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2049 |
ec_print_data(data, rec_size); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2050 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2051 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2052 |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2053 |
ret = ec_sdo_request_alloc(request, fsm->complete_size); |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2054 |
if (ret) { |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2055 |
request->errno = -ret; |
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2056 |
fsm->state = ec_fsm_coe_error; |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2057 |
return; |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2058 |
} |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2059 |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2060 |
ret = ec_sdo_request_copy_data(request, data + 10, data_size); |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2061 |
if (ret) { |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2062 |
request->errno = -ret; |
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2063 |
fsm->state = ec_fsm_coe_error; |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2064 |
return; |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2065 |
} |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2066 |
|
436 | 2067 |
fsm->toggle = 0; |
2068 |
||
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2069 |
if (data_size < fsm->complete_size) { |
1921 | 2070 |
EC_SLAVE_DBG(slave, 1, "SDO data incomplete (%zu / %u)." |
2071 |
" Segmenting...\n", data_size, fsm->complete_size); |
|
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2072 |
ec_fsm_coe_up_prepare_segment_request(fsm); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2073 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2074 |
fsm->state = ec_fsm_coe_up_seg_request; |
2075 |
return; |
|
2076 |
} |
|
2077 |
} |
|
2078 |
||
874 | 2079 |
if (master->debug_level) { |
1921 | 2080 |
EC_SLAVE_DBG(slave, 1, "Uploaded data:\n"); |
874 | 2081 |
ec_print_data(request->data, request->data_size); |
2082 |
} |
|
2083 |
||
436 | 2084 |
fsm->state = ec_fsm_coe_end; // success |
2085 |
} |
|
2086 |
||
2087 |
/*****************************************************************************/ |
|
2088 |
||
2089 |
/** |
|
2090 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2091 |
\todo Timeout behavior |
436 | 2092 |
*/ |
2093 |
||
2094 |
void ec_fsm_coe_up_seg_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2095 |
{ |
|
2096 |
ec_datagram_t *datagram = fsm->datagram; |
|
2097 |
ec_slave_t *slave = fsm->slave; |
|
2098 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
2099 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
2100 |
return; // FIXME: check for response first? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2101 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2102 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2103 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2104 |
fsm->state = ec_fsm_coe_error; |
1921 | 2105 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload segment" |
2106 |
" request datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
2107 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2108 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2109 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2110 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2111 |
if (datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2112 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2113 |
fsm->state = ec_fsm_coe_error; |
1921 | 2114 |
EC_SLAVE_ERR(slave, "Reception of CoE upload segment" |
2115 |
" request failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
2116 |
ec_datagram_print_wc_error(datagram); |
436 | 2117 |
return; |
2118 |
} |
|
2119 |
||
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
2120 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 2121 |
|
2122 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2123 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2124 |
fsm->state = ec_fsm_coe_up_seg_check; |
2125 |
} |
|
2126 |
||
2127 |
/*****************************************************************************/ |
|
2128 |
||
2129 |
/** |
|
2130 |
CoE state: UP CHECK. |
|
2131 |
*/ |
|
2132 |
||
2133 |
void ec_fsm_coe_up_seg_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2134 |
{ |
|
2135 |
ec_datagram_t *datagram = fsm->datagram; |
|
2136 |
ec_slave_t *slave = fsm->slave; |
|
2137 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
2138 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
2139 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2140 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2141 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2142 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2143 |
fsm->state = ec_fsm_coe_error; |
1921 | 2144 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check" |
2145 |
" datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
2146 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2147 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2148 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2149 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2150 |
if (datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2151 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2152 |
fsm->state = ec_fsm_coe_error; |
1921 | 2153 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check datagram" |
2154 |
" failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
2155 |
ec_datagram_print_wc_error(datagram); |
436 | 2156 |
return; |
2157 |
} |
|
2158 |
||
2159 |
if (!ec_slave_mbox_check(datagram)) { |
|
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
2160 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
2161 |
(datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ; |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2162 |
if (diff_ms >= fsm->request->response_timeout) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2163 |
fsm->request->errno = EIO; |
436 | 2164 |
fsm->state = ec_fsm_coe_error; |
1921 | 2165 |
EC_SLAVE_ERR(slave, "Timeout while waiting for SDO upload" |
2166 |
" segment response.\n"); |
|
436 | 2167 |
return; |
2168 |
} |
|
2169 |
||
2170 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2171 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2172 |
return; |
2173 |
} |
|
2174 |
||
2175 |
// Fetch response |
|
2176 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2177 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2178 |
fsm->state = ec_fsm_coe_up_seg_response; |
2179 |
} |
|
2180 |
||
2181 |
/*****************************************************************************/ |
|
2182 |
||
2183 |
/** |
|
2184 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2185 |
\todo Timeout behavior |
436 | 2186 |
*/ |
2187 |
||
2188 |
void ec_fsm_coe_up_seg_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2189 |
{ |
|
2190 |
ec_datagram_t *datagram = fsm->datagram; |
|
2191 |
ec_slave_t *slave = fsm->slave; |
|
2192 |
ec_master_t *master = slave->master; |
|
2193 |
uint8_t *data, mbox_prot; |
|
2194 |
size_t rec_size, data_size; |
|
2195 |
ec_sdo_request_t *request = fsm->request; |
|
2196 |
unsigned int last_segment; |
|
2197 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
2198 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
2199 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2200 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2201 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2202 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2203 |
fsm->state = ec_fsm_coe_error; |
1921 | 2204 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload segment" |
2205 |
" response datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
2206 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2207 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2208 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2209 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2210 |
if (datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2211 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2212 |
fsm->state = ec_fsm_coe_error; |
1921 | 2213 |
EC_SLAVE_ERR(slave, "Reception of CoE upload segment" |
2214 |
" response failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
2215 |
ec_datagram_print_wc_error(datagram); |
436 | 2216 |
return; |
2217 |
} |
|
2218 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
2219 |
data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
2220 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2221 |
request->errno = PTR_ERR(data); |
436 | 2222 |
fsm->state = ec_fsm_coe_error; |
2223 |
return; |
|
2224 |
} |
|
2225 |
||
2226 |
if (master->debug_level) { |
|
1921 | 2227 |
EC_SLAVE_DBG(slave, 1, "Upload segment response:\n"); |
436 | 2228 |
ec_print_data(data, rec_size); |
2229 |
} |
|
2230 |
||
2231 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 2232 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
2233 |
mbox_prot); |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2234 |
request->errno = EIO; |
436 | 2235 |
fsm->state = ec_fsm_coe_error; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2236 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2237 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2238 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2239 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2240 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2241 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2242 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2243 |
fsm->state = ec_fsm_coe_up_seg_check; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2244 |
return; |
436 | 2245 |
} |
2246 |
||
2247 |
if (rec_size < 10) { |
|
1921 | 2248 |
EC_SLAVE_ERR(slave, "Received currupted SDO upload" |
2249 |
" segment response!\n"); |
|
436 | 2250 |
ec_print_data(data, rec_size); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2251 |
request->errno = EIO; |
436 | 2252 |
fsm->state = ec_fsm_coe_error; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2253 |
return; |
436 | 2254 |
} |
2255 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
2256 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2257 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
1921 | 2258 |
EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X aborted.\n", |
2259 |
request->index, request->subindex); |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
2260 |
request->abort_code = EC_READ_U32(data + 6); |
1921 | 2261 |
ec_canopen_abort_msg(slave, request->abort_code); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2262 |
request->errno = EIO; |
436 | 2263 |
fsm->state = ec_fsm_coe_error; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2264 |
return; |
436 | 2265 |
} |
2266 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
2267 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
436 | 2268 |
EC_READ_U8 (data + 2) >> 5 != 0x0) { // upload segment response |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2269 |
if (fsm->slave->master->debug_level) { |
1921 | 2270 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO upload segment response!\n"); |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2271 |
ec_print_data(data, rec_size); |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2272 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2273 |
// check for CoE response again |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2274 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2275 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2276 |
fsm->state = ec_fsm_coe_up_seg_check; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2277 |
return; |
436 | 2278 |
} |
2279 |
||
1533
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2280 |
data_size = rec_size - 3; /* Header of segment upload is smaller than |
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2281 |
normal upload */ |
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2282 |
if (rec_size == 10) { |
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2283 |
uint8_t seg_size = (EC_READ_U8(data + 2) & 0xE) >> 1; |
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2284 |
data_size -= seg_size; |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2285 |
} |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2286 |
|
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2287 |
if (request->data_size + data_size > fsm->complete_size) { |
1921 | 2288 |
EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X failed: Fragment" |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2289 |
" exceeding complete size!\n", |
1921 | 2290 |
request->index, request->subindex); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2291 |
request->errno = EOVERFLOW; |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2292 |
fsm->state = ec_fsm_coe_error; |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2293 |
return; |
436 | 2294 |
} |
2295 |
||
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2296 |
memcpy(request->data + request->data_size, data + 3, data_size); |
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2297 |
request->data_size += data_size; |
436 | 2298 |
|
1533
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2299 |
last_segment = EC_READ_U8(data + 2) & 0x01; |
436 | 2300 |
if (!last_segment) { |
2301 |
fsm->toggle = !fsm->toggle; |
|
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2302 |
ec_fsm_coe_up_prepare_segment_request(fsm); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2303 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2304 |
fsm->state = ec_fsm_coe_up_seg_request; |
2305 |
return; |
|
2306 |
} |
|
2307 |
||
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2308 |
if (request->data_size != fsm->complete_size) { |
1921 | 2309 |
EC_SLAVE_WARN(slave, "SDO upload 0x%04X:%02X: Assembled data" |
1543
373cd456dc26
Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2310 |
" size (%zu) does not match complete size (%u)!\n", |
1921 | 2311 |
request->index, request->subindex, |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2312 |
request->data_size, fsm->complete_size); |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2313 |
} |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2314 |
|
874 | 2315 |
if (master->debug_level) { |
1921 | 2316 |
EC_SLAVE_DBG(slave, 1, "Uploaded data:\n"); |
874 | 2317 |
ec_print_data(request->data, request->data_size); |
2318 |
} |
|
2319 |
||
436 | 2320 |
fsm->state = ec_fsm_coe_end; // success |
2321 |
} |
|
2322 |
||
2323 |
/*****************************************************************************/ |
|
2324 |
||
2325 |
/** |
|
2326 |
State: ERROR. |
|
2327 |
*/ |
|
2328 |
||
2329 |
void ec_fsm_coe_error(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2330 |
{ |
|
2331 |
} |
|
2332 |
||
2333 |
/*****************************************************************************/ |
|
2334 |
||
2335 |
/** |
|
2336 |
State: END. |
|
2337 |
*/ |
|
2338 |
||
2339 |
void ec_fsm_coe_end(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2340 |
{ |
|
2341 |
} |
|
2342 |
||
2343 |
/*****************************************************************************/ |