author | Florian Pose <fp@igh-essen.com> |
Thu, 21 Feb 2008 09:24:56 +0000 | |
changeset 806 | ab8daaabbe48 |
parent 769 | 2195c2ea37b4 |
child 814 | a51f857b1b2d |
permissions | -rw-r--r-- |
436 | 1 |
/****************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
4 |
* |
|
5 |
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
|
6 |
* |
|
7 |
* This file is part of the IgH EtherCAT Master. |
|
8 |
* |
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it |
|
10 |
* and/or modify it under the terms of the GNU General Public License |
|
11 |
* as published by the Free Software Foundation; either version 2 of the |
|
12 |
* License, or (at your option) any later version. |
|
13 |
* |
|
14 |
* The IgH EtherCAT Master is distributed in the hope that it will be |
|
15 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with the IgH EtherCAT Master; if not, write to the Free Software |
|
21 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
22 |
* |
|
23 |
* The right to use EtherCAT Technology is granted and comes free of |
|
24 |
* charge under condition of compatibility of product made by |
|
25 |
* Licensee. People intending to distribute/sell products based on the |
|
26 |
* code, have to sign an agreement to guarantee that products using |
|
27 |
* software based on IgH EtherCAT master stay compatible with the actual |
|
28 |
* EtherCAT specification (which are released themselves as an open |
|
29 |
* standard) as the (only) precondition to have the right to use EtherCAT |
|
30 |
* Technology, IP and trade marks. |
|
31 |
* |
|
32 |
*****************************************************************************/ |
|
33 |
||
34 |
/** |
|
35 |
\file |
|
36 |
EtherCAT CoE state machines. |
|
37 |
*/ |
|
38 |
||
39 |
/*****************************************************************************/ |
|
40 |
||
41 |
#include "globals.h" |
|
42 |
#include "master.h" |
|
43 |
#include "mailbox.h" |
|
44 |
#include "fsm_coe.h" |
|
45 |
||
46 |
/*****************************************************************************/ |
|
47 |
||
48 |
void ec_fsm_coe_dict_start(ec_fsm_coe_t *); |
|
49 |
void ec_fsm_coe_dict_request(ec_fsm_coe_t *); |
|
50 |
void ec_fsm_coe_dict_check(ec_fsm_coe_t *); |
|
51 |
void ec_fsm_coe_dict_response(ec_fsm_coe_t *); |
|
52 |
void ec_fsm_coe_dict_desc_request(ec_fsm_coe_t *); |
|
53 |
void ec_fsm_coe_dict_desc_check(ec_fsm_coe_t *); |
|
54 |
void ec_fsm_coe_dict_desc_response(ec_fsm_coe_t *); |
|
55 |
void ec_fsm_coe_dict_entry_request(ec_fsm_coe_t *); |
|
56 |
void ec_fsm_coe_dict_entry_check(ec_fsm_coe_t *); |
|
57 |
void ec_fsm_coe_dict_entry_response(ec_fsm_coe_t *); |
|
58 |
||
59 |
void ec_fsm_coe_down_start(ec_fsm_coe_t *); |
|
60 |
void ec_fsm_coe_down_request(ec_fsm_coe_t *); |
|
61 |
void ec_fsm_coe_down_check(ec_fsm_coe_t *); |
|
62 |
void ec_fsm_coe_down_response(ec_fsm_coe_t *); |
|
63 |
||
64 |
void ec_fsm_coe_up_start(ec_fsm_coe_t *); |
|
65 |
void ec_fsm_coe_up_request(ec_fsm_coe_t *); |
|
66 |
void ec_fsm_coe_up_check(ec_fsm_coe_t *); |
|
67 |
void ec_fsm_coe_up_response(ec_fsm_coe_t *); |
|
68 |
void ec_fsm_coe_up_seg_request(ec_fsm_coe_t *); |
|
69 |
void ec_fsm_coe_up_seg_check(ec_fsm_coe_t *); |
|
70 |
void ec_fsm_coe_up_seg_response(ec_fsm_coe_t *); |
|
71 |
||
72 |
void ec_fsm_coe_end(ec_fsm_coe_t *); |
|
73 |
void ec_fsm_coe_error(ec_fsm_coe_t *); |
|
74 |
||
75 |
/*****************************************************************************/ |
|
76 |
||
77 |
/** |
|
78 |
SDO abort messages. |
|
79 |
The "abort SDO transfer request" supplies an abort code, |
|
80 |
which can be translated to clear text. This table does |
|
81 |
the mapping of the codes and messages. |
|
82 |
*/ |
|
83 |
||
84 |
const ec_code_msg_t sdo_abort_messages[] = { |
|
85 |
{0x05030000, "Toggle bit not changed"}, |
|
86 |
{0x05040000, "SDO protocol timeout"}, |
|
87 |
{0x05040001, "Client/Server command specifier not valid or unknown"}, |
|
88 |
{0x05040005, "Out of memory"}, |
|
89 |
{0x06010000, "Unsupported access to an object"}, |
|
90 |
{0x06010001, "Attempt to read a write-only object"}, |
|
91 |
{0x06010002, "Attempt to write a read-only object"}, |
|
92 |
{0x06020000, "This object does not exist in the object directory"}, |
|
93 |
{0x06040041, "The object cannot be mapped into the PDO"}, |
|
94 |
{0x06040042, "The number and length of the objects to be mapped would" |
|
95 |
" exceed the PDO length"}, |
|
96 |
{0x06040043, "General parameter incompatibility reason"}, |
|
97 |
{0x06040047, "Gerneral internal incompatibility in device"}, |
|
98 |
{0x06060000, "Access failure due to a hardware error"}, |
|
99 |
{0x06070010, "Data type does not match, length of service parameter does" |
|
100 |
" not match"}, |
|
101 |
{0x06070012, "Data type does not match, length of service parameter too" |
|
102 |
" high"}, |
|
103 |
{0x06070013, "Data type does not match, length of service parameter too" |
|
104 |
" low"}, |
|
105 |
{0x06090011, "Subindex does not exist"}, |
|
106 |
{0x06090030, "Value range of parameter exceeded"}, |
|
107 |
{0x06090031, "Value of parameter written too high"}, |
|
108 |
{0x06090032, "Value of parameter written too low"}, |
|
109 |
{0x06090036, "Maximum value is less than minimum value"}, |
|
110 |
{0x08000000, "General error"}, |
|
111 |
{0x08000020, "Data cannot be transferred or stored to the application"}, |
|
112 |
{0x08000021, "Data cannot be transferred or stored to the application" |
|
113 |
" because of local control"}, |
|
114 |
{0x08000022, "Data cannot be transferred or stored to the application" |
|
115 |
" because of the present device state"}, |
|
116 |
{0x08000023, "Object dictionary dynamic generation fails or no object" |
|
117 |
" dictionary is present"}, |
|
118 |
{} |
|
119 |
}; |
|
120 |
||
121 |
/*****************************************************************************/ |
|
122 |
||
123 |
/** |
|
124 |
Outputs an SDO abort message. |
|
125 |
*/ |
|
126 |
||
127 |
void ec_canopen_abort_msg(uint32_t abort_code) |
|
128 |
{ |
|
129 |
const ec_code_msg_t *abort_msg; |
|
130 |
||
131 |
for (abort_msg = sdo_abort_messages; abort_msg->code; abort_msg++) { |
|
132 |
if (abort_msg->code == abort_code) { |
|
133 |
EC_ERR("SDO abort message 0x%08X: \"%s\".\n", |
|
134 |
abort_msg->code, abort_msg->message); |
|
135 |
return; |
|
136 |
} |
|
137 |
} |
|
138 |
||
139 |
EC_ERR("Unknown SDO abort code 0x%08X.\n", abort_code); |
|
140 |
} |
|
141 |
||
142 |
/*****************************************************************************/ |
|
143 |
||
144 |
/** |
|
145 |
Constructor. |
|
146 |
*/ |
|
147 |
||
148 |
void ec_fsm_coe_init(ec_fsm_coe_t *fsm, /**< finite state machine */ |
|
149 |
ec_datagram_t *datagram /**< datagram */ |
|
150 |
) |
|
151 |
{ |
|
152 |
fsm->state = NULL; |
|
153 |
fsm->datagram = datagram; |
|
154 |
} |
|
155 |
||
156 |
/*****************************************************************************/ |
|
157 |
||
158 |
/** |
|
159 |
Destructor. |
|
160 |
*/ |
|
161 |
||
162 |
void ec_fsm_coe_clear(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
163 |
{ |
|
164 |
} |
|
165 |
||
166 |
/*****************************************************************************/ |
|
167 |
||
168 |
/** |
|
169 |
Starts reading a slaves' SDO dictionary. |
|
170 |
*/ |
|
171 |
||
172 |
void ec_fsm_coe_dictionary(ec_fsm_coe_t *fsm, /**< finite state machine */ |
|
173 |
ec_slave_t *slave /**< EtherCAT slave */ |
|
174 |
) |
|
175 |
{ |
|
176 |
fsm->slave = slave; |
|
177 |
fsm->state = ec_fsm_coe_dict_start; |
|
178 |
} |
|
179 |
||
180 |
/*****************************************************************************/ |
|
181 |
||
182 |
/** |
|
183 |
Starts to download an SDO to a slave. |
|
184 |
*/ |
|
185 |
||
186 |
void ec_fsm_coe_download(ec_fsm_coe_t *fsm, /**< finite state machine */ |
|
187 |
ec_slave_t *slave, /**< EtherCAT slave */ |
|
188 |
ec_sdo_data_t *sdodata /**< SDO data object */ |
|
189 |
) |
|
190 |
{ |
|
191 |
fsm->slave = slave; |
|
192 |
fsm->sdodata = sdodata; |
|
193 |
fsm->state = ec_fsm_coe_down_start; |
|
194 |
} |
|
195 |
||
196 |
/*****************************************************************************/ |
|
197 |
||
198 |
/** |
|
199 |
Starts to upload an SDO from a slave. |
|
200 |
*/ |
|
201 |
||
202 |
void ec_fsm_coe_upload(ec_fsm_coe_t *fsm, /**< finite state machine */ |
|
203 |
ec_slave_t *slave, /**< EtherCAT slave */ |
|
204 |
ec_sdo_request_t *request /**< SDO request */ |
|
205 |
) |
|
206 |
{ |
|
207 |
fsm->slave = slave; |
|
208 |
fsm->request = request; |
|
209 |
fsm->state = ec_fsm_coe_up_start; |
|
210 |
} |
|
211 |
||
212 |
/*****************************************************************************/ |
|
213 |
||
214 |
/** |
|
215 |
Executes the current state of the state machine. |
|
216 |
\return false, if state machine has terminated |
|
217 |
*/ |
|
218 |
||
219 |
int ec_fsm_coe_exec(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
220 |
{ |
|
221 |
fsm->state(fsm); |
|
222 |
||
223 |
return fsm->state != ec_fsm_coe_end && fsm->state != ec_fsm_coe_error; |
|
224 |
} |
|
225 |
||
226 |
/*****************************************************************************/ |
|
227 |
||
228 |
/** |
|
229 |
Returns, if the state machine terminated with success. |
|
230 |
\return non-zero if successful. |
|
231 |
*/ |
|
232 |
||
233 |
int ec_fsm_coe_success(ec_fsm_coe_t *fsm /**< Finite state machine */) |
|
234 |
{ |
|
235 |
return fsm->state == ec_fsm_coe_end; |
|
236 |
} |
|
237 |
||
238 |
/****************************************************************************** |
|
239 |
* CoE dictionary state machine |
|
240 |
*****************************************************************************/ |
|
241 |
||
242 |
/** |
|
243 |
CoE state: DICT START. |
|
244 |
*/ |
|
245 |
||
246 |
void ec_fsm_coe_dict_start(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
247 |
{ |
|
248 |
ec_datagram_t *datagram = fsm->datagram; |
|
249 |
ec_slave_t *slave = fsm->slave; |
|
250 |
uint8_t *data; |
|
251 |
||
252 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8))) { |
|
253 |
fsm->state = ec_fsm_coe_error; |
|
254 |
return; |
|
255 |
} |
|
256 |
||
257 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
|
258 |
EC_WRITE_U8 (data + 2, 0x01); // Get OD List Request |
|
259 |
EC_WRITE_U8 (data + 3, 0x00); |
|
260 |
EC_WRITE_U16(data + 4, 0x0000); |
|
261 |
EC_WRITE_U16(data + 6, 0x0001); // deliver all SDOs! |
|
262 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
263 |
fsm->retries = EC_FSM_RETRIES; |
436 | 264 |
fsm->state = ec_fsm_coe_dict_request; |
265 |
} |
|
266 |
||
267 |
/*****************************************************************************/ |
|
268 |
||
269 |
/** |
|
270 |
CoE state: DICT REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
271 |
\todo Timeout behavior |
436 | 272 |
*/ |
273 |
||
274 |
void ec_fsm_coe_dict_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
275 |
{ |
|
276 |
ec_datagram_t *datagram = fsm->datagram; |
|
277 |
ec_slave_t *slave = fsm->slave; |
|
278 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
279 |
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
|
280 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
281 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
282 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
283 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
284 |
EC_ERR("Failed to receive CoE dictionary request datagram for" |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
285 |
" slave %i (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
286 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
287 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
288 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
289 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
290 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
291 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
292 |
EC_ERR("Reception of CoE dictionary request failed on slave %i: ", |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
293 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
294 |
ec_datagram_print_wc_error(datagram); |
436 | 295 |
return; |
296 |
} |
|
297 |
||
298 |
fsm->cycles_start = datagram->cycles_sent; |
|
299 |
||
300 |
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
|
301 |
fsm->retries = EC_FSM_RETRIES; |
436 | 302 |
fsm->state = ec_fsm_coe_dict_check; |
303 |
} |
|
304 |
||
305 |
/*****************************************************************************/ |
|
306 |
||
307 |
/** |
|
308 |
CoE state: DICT CHECK. |
|
309 |
*/ |
|
310 |
||
311 |
void ec_fsm_coe_dict_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
312 |
{ |
|
313 |
ec_datagram_t *datagram = fsm->datagram; |
|
314 |
ec_slave_t *slave = fsm->slave; |
|
315 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
316 |
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
|
317 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
318 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
319 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
320 |
fsm->state = ec_fsm_coe_error; |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
321 |
EC_ERR("Failed to receive CoE mailbox check datagram for slave %i" |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
322 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
323 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
324 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
325 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
326 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
327 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
328 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
329 |
EC_ERR("Reception of CoE mailbox check datagram failed on slave %i: ", |
436 | 330 |
slave->ring_position); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
331 |
ec_datagram_print_wc_error(datagram); |
436 | 332 |
return; |
333 |
} |
|
334 |
||
335 |
if (!ec_slave_mbox_check(datagram)) { |
|
336 |
if (datagram->cycles_received |
|
337 |
- fsm->cycles_start >= (cycles_t) 100 * cpu_khz) { |
|
338 |
fsm->state = ec_fsm_coe_error; |
|
339 |
EC_ERR("Timeout while checking SDO dictionary on slave %i.\n", |
|
340 |
slave->ring_position); |
|
341 |
return; |
|
342 |
} |
|
343 |
||
344 |
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
|
345 |
fsm->retries = EC_FSM_RETRIES; |
436 | 346 |
return; |
347 |
} |
|
348 |
||
349 |
// Fetch response |
|
350 |
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
|
351 |
fsm->retries = EC_FSM_RETRIES; |
436 | 352 |
fsm->state = ec_fsm_coe_dict_response; |
353 |
} |
|
354 |
||
355 |
/*****************************************************************************/ |
|
356 |
||
357 |
/** |
|
358 |
CoE state: DICT RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
359 |
\todo Timeout behavior |
436 | 360 |
*/ |
361 |
||
362 |
void ec_fsm_coe_dict_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
363 |
{ |
|
364 |
ec_datagram_t *datagram = fsm->datagram; |
|
365 |
ec_slave_t *slave = fsm->slave; |
|
366 |
uint8_t *data, mbox_prot; |
|
367 |
size_t rec_size; |
|
368 |
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
|
369 |
uint16_t sdo_index, fragments_left; |
436 | 370 |
ec_sdo_t *sdo; |
371 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
372 |
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
|
373 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
374 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
375 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
376 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
377 |
EC_ERR("Failed to receive CoE dictionary response datagram for" |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
378 |
" slave %i (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
379 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
380 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
381 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
382 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
383 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
384 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
385 |
EC_ERR("Reception of CoE dictionary response failed on slave %i: ", |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
386 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
387 |
ec_datagram_print_wc_error(datagram); |
436 | 388 |
return; |
389 |
} |
|
390 |
||
391 |
if (!(data = ec_slave_mbox_fetch(slave, datagram, |
|
392 |
&mbox_prot, &rec_size))) { |
|
393 |
fsm->state = ec_fsm_coe_error; |
|
394 |
return; |
|
395 |
} |
|
396 |
||
397 |
if (mbox_prot != 0x03) { // CoE |
|
446 | 398 |
EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot); |
436 | 399 |
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
|
400 |
return; |
436 | 401 |
} |
402 |
||
403 |
if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information |
|
404 |
(EC_READ_U8(data + 2) & 0x7F) == 0x07) { // error response |
|
405 |
EC_ERR("SDO information error response at slave %i!\n", |
|
406 |
slave->ring_position); |
|
407 |
ec_canopen_abort_msg(EC_READ_U32(data + 6)); |
|
408 |
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
|
409 |
return; |
436 | 410 |
} |
411 |
||
412 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
|
413 |
(EC_READ_U8 (data + 2) & 0x7F) != 0x02) { // Get OD List response |
|
414 |
EC_ERR("Invalid SDO list response at slave %i!\n", |
|
415 |
slave->ring_position); |
|
416 |
ec_print_data(data, rec_size); |
|
417 |
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
|
418 |
return; |
436 | 419 |
} |
420 |
||
421 |
if (rec_size < 8) { |
|
422 |
EC_ERR("Invalid data size!\n"); |
|
423 |
ec_print_data(data, rec_size); |
|
424 |
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
|
425 |
return; |
436 | 426 |
} |
427 |
||
428 |
sdo_count = (rec_size - 8) / 2; |
|
429 |
||
430 |
for (i = 0; i < sdo_count; i++) { |
|
431 |
sdo_index = EC_READ_U16(data + 8 + i * 2); |
|
432 |
if (!sdo_index) { |
|
461
b9eda9235173
Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
459
diff
changeset
|
433 |
if (slave->master->debug_level) |
b9eda9235173
Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
459
diff
changeset
|
434 |
EC_WARN("SDO dictionary of slave %i contains index 0x0000.\n", |
b9eda9235173
Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
459
diff
changeset
|
435 |
slave->ring_position); |
436 | 436 |
continue; |
437 |
} |
|
438 |
||
439 |
if (!(sdo = (ec_sdo_t *) kmalloc(sizeof(ec_sdo_t), GFP_ATOMIC))) { |
|
440 |
EC_ERR("Failed to allocate memory for SDO!\n"); |
|
441 |
fsm->state = ec_fsm_coe_error; |
|
442 |
return; |
|
443 |
} |
|
444 |
||
445 |
if (ec_sdo_init(sdo, sdo_index, slave)) { |
|
446 |
EC_ERR("Failed to init SDO!\n"); |
|
447 |
fsm->state = ec_fsm_coe_error; |
|
448 |
return; |
|
449 |
} |
|
450 |
||
451 |
list_add_tail(&sdo->list, &slave->sdo_dictionary); |
|
452 |
} |
|
453 |
||
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
454 |
fragments_left = EC_READ_U16(data + 4); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
455 |
if (slave->master->debug_level && fragments_left) { |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
456 |
EC_DBG("SDO list fragments left: %u\n", fragments_left); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
457 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
458 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
459 |
if (EC_READ_U8(data + 2) & 0x80 || fragments_left) { // more messages waiting. check again. |
436 | 460 |
fsm->cycles_start = datagram->cycles_sent; |
461 |
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
|
462 |
fsm->retries = EC_FSM_RETRIES; |
436 | 463 |
fsm->state = ec_fsm_coe_dict_check; |
464 |
return; |
|
465 |
} |
|
466 |
||
467 |
if (list_empty(&slave->sdo_dictionary)) { |
|
468 |
// no SDOs in dictionary. finished. |
|
469 |
fsm->state = ec_fsm_coe_end; // success |
|
470 |
return; |
|
471 |
} |
|
472 |
||
473 |
// fetch SDO descriptions |
|
474 |
fsm->sdo = list_entry(slave->sdo_dictionary.next, ec_sdo_t, list); |
|
475 |
||
476 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8))) { |
|
477 |
fsm->state = ec_fsm_coe_error; |
|
478 |
return; |
|
479 |
} |
|
480 |
||
481 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
|
482 |
EC_WRITE_U8 (data + 2, 0x03); // Get object description request |
|
483 |
EC_WRITE_U8 (data + 3, 0x00); |
|
484 |
EC_WRITE_U16(data + 4, 0x0000); |
|
485 |
EC_WRITE_U16(data + 6, fsm->sdo->index); // SDO index |
|
486 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
487 |
fsm->retries = EC_FSM_RETRIES; |
436 | 488 |
fsm->state = ec_fsm_coe_dict_desc_request; |
489 |
} |
|
490 |
||
491 |
/*****************************************************************************/ |
|
492 |
||
493 |
/** |
|
494 |
CoE state: DICT DESC REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
495 |
\todo Timeout behavior |
436 | 496 |
*/ |
497 |
||
498 |
void ec_fsm_coe_dict_desc_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
499 |
{ |
|
500 |
ec_datagram_t *datagram = fsm->datagram; |
|
501 |
ec_slave_t *slave = fsm->slave; |
|
502 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
503 |
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
|
504 |
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
|
505 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
506 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
507 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
508 |
EC_ERR("Failed to receive CoE SDO description request datagram for" |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
509 |
" slave %i (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
510 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
511 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
512 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
513 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
514 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
515 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
516 |
EC_ERR("Reception of CoE SDO description" |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
517 |
" request failed on slave %i: ", slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
518 |
ec_datagram_print_wc_error(datagram); |
436 | 519 |
return; |
520 |
} |
|
521 |
||
522 |
fsm->cycles_start = datagram->cycles_sent; |
|
523 |
||
524 |
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
|
525 |
fsm->retries = EC_FSM_RETRIES; |
436 | 526 |
fsm->state = ec_fsm_coe_dict_desc_check; |
527 |
} |
|
528 |
||
529 |
/*****************************************************************************/ |
|
530 |
||
531 |
/** |
|
532 |
CoE state: DICT DESC CHECK. |
|
533 |
*/ |
|
534 |
||
535 |
void ec_fsm_coe_dict_desc_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
536 |
{ |
|
537 |
ec_datagram_t *datagram = fsm->datagram; |
|
538 |
ec_slave_t *slave = fsm->slave; |
|
539 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
540 |
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
|
541 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
542 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
543 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
544 |
fsm->state = ec_fsm_coe_error; |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
545 |
EC_ERR("Failed to receive CoE mailbox check datagram from slave %i" |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
546 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
547 |
slave->ring_position, datagram->state); |
436 | 548 |
return; |
549 |
} |
|
550 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
551 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
552 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
553 |
EC_ERR("Reception of CoE mailbox check" |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
554 |
" datagram failed on slave %i: ", slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
555 |
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
|
556 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
557 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
558 |
|
436 | 559 |
if (!ec_slave_mbox_check(datagram)) { |
560 |
if (datagram->cycles_received |
|
561 |
- fsm->cycles_start >= (cycles_t) 100 * cpu_khz) { |
|
562 |
fsm->state = ec_fsm_coe_error; |
|
563 |
EC_ERR("Timeout while checking SDO description on slave %i.\n", |
|
564 |
slave->ring_position); |
|
565 |
return; |
|
566 |
} |
|
567 |
||
568 |
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
|
569 |
fsm->retries = EC_FSM_RETRIES; |
436 | 570 |
return; |
571 |
} |
|
572 |
||
573 |
// Fetch response |
|
574 |
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
|
575 |
fsm->retries = EC_FSM_RETRIES; |
436 | 576 |
fsm->state = ec_fsm_coe_dict_desc_response; |
577 |
} |
|
578 |
||
579 |
/*****************************************************************************/ |
|
580 |
||
581 |
/** |
|
582 |
CoE state: DICT DESC RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
583 |
\todo Timeout behavior |
436 | 584 |
*/ |
585 |
||
586 |
void ec_fsm_coe_dict_desc_response(ec_fsm_coe_t *fsm |
|
587 |
/**< finite state machine */) |
|
588 |
{ |
|
589 |
ec_datagram_t *datagram = fsm->datagram; |
|
590 |
ec_slave_t *slave = fsm->slave; |
|
591 |
ec_sdo_t *sdo = fsm->sdo; |
|
592 |
uint8_t *data, mbox_prot; |
|
593 |
size_t rec_size, name_size; |
|
594 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
595 |
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
|
596 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
597 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
598 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
599 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
600 |
EC_ERR("Failed to receive CoE SDO description response datagram from" |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
601 |
" slave %i (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
602 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
603 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
604 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
605 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
606 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
607 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
608 |
EC_ERR("Reception of CoE SDO description" |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
609 |
" response failed on slave %i: ", slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
610 |
ec_datagram_print_wc_error(datagram); |
436 | 611 |
return; |
612 |
} |
|
613 |
||
614 |
if (!(data = ec_slave_mbox_fetch(slave, datagram, |
|
615 |
&mbox_prot, &rec_size))) { |
|
616 |
fsm->state = ec_fsm_coe_error; |
|
617 |
return; |
|
618 |
} |
|
619 |
||
620 |
if (mbox_prot != 0x03) { // CoE |
|
446 | 621 |
EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot); |
436 | 622 |
fsm->state = ec_fsm_coe_error; |
623 |
return; |
|
624 |
} |
|
625 |
||
626 |
if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information |
|
627 |
(EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response |
|
628 |
EC_ERR("SDO information error response at slave %i while" |
|
629 |
" fetching SDO 0x%04X!\n", slave->ring_position, |
|
630 |
sdo->index); |
|
631 |
ec_canopen_abort_msg(EC_READ_U32(data + 6)); |
|
632 |
fsm->state = ec_fsm_coe_error; |
|
633 |
return; |
|
634 |
} |
|
635 |
||
636 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
|
637 |
(EC_READ_U8 (data + 2) & 0x7F) != 0x04 || // Object desc. response |
|
638 |
EC_READ_U16(data + 6) != sdo->index) { // SDO index |
|
639 |
EC_ERR("Invalid object description response at slave %i while" |
|
640 |
" fetching SDO 0x%04X!\n", slave->ring_position, |
|
641 |
sdo->index); |
|
642 |
ec_print_data(data, rec_size); |
|
643 |
fsm->state = ec_fsm_coe_error; |
|
644 |
return; |
|
645 |
} |
|
646 |
||
647 |
if (rec_size < 12) { |
|
648 |
EC_ERR("Invalid data size!\n"); |
|
649 |
ec_print_data(data, rec_size); |
|
650 |
fsm->state = ec_fsm_coe_error; |
|
651 |
return; |
|
652 |
} |
|
653 |
||
654 |
sdo->subindices = EC_READ_U8(data + 10); |
|
655 |
sdo->object_code = EC_READ_U8(data + 11); |
|
656 |
||
657 |
name_size = rec_size - 12; |
|
658 |
if (name_size) { |
|
659 |
if (!(sdo->name = kmalloc(name_size + 1, GFP_ATOMIC))) { |
|
660 |
EC_ERR("Failed to allocate SDO name!\n"); |
|
661 |
fsm->state = ec_fsm_coe_error; |
|
662 |
return; |
|
663 |
} |
|
664 |
||
665 |
memcpy(sdo->name, data + 12, name_size); |
|
666 |
sdo->name[name_size] = 0; |
|
667 |
} |
|
668 |
||
669 |
if (EC_READ_U8(data + 2) & 0x80) { |
|
670 |
EC_ERR("Fragment follows (not implemented)!\n"); |
|
671 |
fsm->state = ec_fsm_coe_error; |
|
672 |
return; |
|
673 |
} |
|
674 |
||
675 |
// start fetching entries |
|
676 |
||
677 |
fsm->subindex = 0; |
|
678 |
||
679 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10))) { |
|
680 |
fsm->state = ec_fsm_coe_error; |
|
681 |
return; |
|
682 |
} |
|
683 |
||
684 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
|
685 |
EC_WRITE_U8 (data + 2, 0x05); // Get entry description request |
|
686 |
EC_WRITE_U8 (data + 3, 0x00); |
|
687 |
EC_WRITE_U16(data + 4, 0x0000); |
|
688 |
EC_WRITE_U16(data + 6, sdo->index); // SDO index |
|
689 |
EC_WRITE_U8 (data + 8, fsm->subindex); // SDO subindex |
|
690 |
EC_WRITE_U8 (data + 9, 0x00); // value info (no values) |
|
691 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
692 |
fsm->retries = EC_FSM_RETRIES; |
436 | 693 |
fsm->state = ec_fsm_coe_dict_entry_request; |
694 |
} |
|
695 |
||
696 |
/*****************************************************************************/ |
|
697 |
||
698 |
/** |
|
699 |
CoE state: DICT ENTRY REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
700 |
\todo Timeout behavior |
436 | 701 |
*/ |
702 |
||
703 |
void ec_fsm_coe_dict_entry_request(ec_fsm_coe_t *fsm |
|
704 |
/**< finite state machine */) |
|
705 |
{ |
|
706 |
ec_datagram_t *datagram = fsm->datagram; |
|
707 |
ec_slave_t *slave = fsm->slave; |
|
708 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
709 |
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
|
710 |
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
|
711 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
712 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
713 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
714 |
EC_ERR("Failed to receive CoE SDO entry request datagram for" |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
715 |
" slave %i (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
716 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
717 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
718 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
719 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
720 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
721 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
722 |
EC_ERR("Reception of CoE SDO entry request failed on slave %i: ", |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
723 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
724 |
ec_datagram_print_wc_error(datagram); |
436 | 725 |
return; |
726 |
} |
|
727 |
||
728 |
fsm->cycles_start = datagram->cycles_sent; |
|
729 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
730 |
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
|
731 |
fsm->retries = EC_FSM_RETRIES; |
436 | 732 |
fsm->state = ec_fsm_coe_dict_entry_check; |
733 |
} |
|
734 |
||
735 |
/*****************************************************************************/ |
|
736 |
||
737 |
/** |
|
738 |
CoE state: DICT ENTRY CHECK. |
|
739 |
*/ |
|
740 |
||
741 |
void ec_fsm_coe_dict_entry_check(ec_fsm_coe_t *fsm |
|
742 |
/**< finite state machine */) |
|
743 |
{ |
|
744 |
ec_datagram_t *datagram = fsm->datagram; |
|
745 |
ec_slave_t *slave = fsm->slave; |
|
746 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
747 |
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
|
748 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
749 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
750 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
751 |
fsm->state = ec_fsm_coe_error; |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
752 |
EC_ERR("Failed to receive CoE mailbox check datagram from slave %i" |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
753 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
754 |
slave->ring_position, datagram->state); |
436 | 755 |
return; |
756 |
} |
|
757 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
758 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
759 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
760 |
EC_ERR("Reception of CoE mailbox check" |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
761 |
" datagram failed on slave %i: ", slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
762 |
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
|
763 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
764 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
765 |
|
436 | 766 |
if (!ec_slave_mbox_check(datagram)) { |
767 |
if (datagram->cycles_received |
|
768 |
- fsm->cycles_start >= (cycles_t) 100 * cpu_khz) { |
|
769 |
fsm->state = ec_fsm_coe_error; |
|
770 |
EC_ERR("Timeout while checking SDO entry on slave %i.\n", |
|
771 |
slave->ring_position); |
|
772 |
return; |
|
773 |
} |
|
774 |
||
775 |
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
|
776 |
fsm->retries = EC_FSM_RETRIES; |
436 | 777 |
return; |
778 |
} |
|
779 |
||
780 |
// Fetch response |
|
781 |
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
|
782 |
fsm->retries = EC_FSM_RETRIES; |
436 | 783 |
fsm->state = ec_fsm_coe_dict_entry_response; |
784 |
} |
|
785 |
||
786 |
/*****************************************************************************/ |
|
787 |
||
788 |
/** |
|
789 |
CoE state: DICT ENTRY RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
790 |
\todo Timeout behavior |
436 | 791 |
*/ |
792 |
||
793 |
void ec_fsm_coe_dict_entry_response(ec_fsm_coe_t *fsm |
|
794 |
/**< finite state machine */) |
|
795 |
{ |
|
796 |
ec_datagram_t *datagram = fsm->datagram; |
|
797 |
ec_slave_t *slave = fsm->slave; |
|
798 |
ec_sdo_t *sdo = fsm->sdo; |
|
799 |
uint8_t *data, mbox_prot; |
|
800 |
size_t rec_size, data_size; |
|
801 |
ec_sdo_entry_t *entry; |
|
802 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
803 |
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
|
804 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
805 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
806 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
807 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
808 |
EC_ERR("Failed to receive CoE SDO description response datagram from" |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
809 |
" slave %i (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
810 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
811 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
812 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
813 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
814 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
815 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
816 |
EC_ERR("Reception of CoE SDO description" |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
817 |
" response failed on slave %i: ", slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
818 |
ec_datagram_print_wc_error(datagram); |
436 | 819 |
return; |
820 |
} |
|
821 |
||
822 |
if (!(data = ec_slave_mbox_fetch(slave, datagram, |
|
823 |
&mbox_prot, &rec_size))) { |
|
824 |
fsm->state = ec_fsm_coe_error; |
|
825 |
return; |
|
826 |
} |
|
827 |
||
828 |
if (mbox_prot != 0x03) { // CoE |
|
446 | 829 |
EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot); |
436 | 830 |
fsm->state = ec_fsm_coe_error; |
831 |
return; |
|
832 |
} |
|
833 |
||
834 |
if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information |
|
835 |
(EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response |
|
836 |
EC_ERR("SDO information error response at slave %i while" |
|
837 |
" fetching SDO entry 0x%04X:%i!\n", slave->ring_position, |
|
838 |
sdo->index, fsm->subindex); |
|
839 |
ec_canopen_abort_msg(EC_READ_U32(data + 6)); |
|
840 |
fsm->state = ec_fsm_coe_error; |
|
841 |
return; |
|
842 |
} |
|
843 |
||
844 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
|
845 |
(EC_READ_U8(data + 2) & 0x7F) != 0x06 || // Entry desc. response |
|
846 |
EC_READ_U16(data + 6) != sdo->index || // SDO index |
|
847 |
EC_READ_U8(data + 8) != fsm->subindex) { // SDO subindex |
|
848 |
EC_ERR("Invalid entry description response at slave %i while" |
|
849 |
" fetching SDO entry 0x%04X:%i!\n", slave->ring_position, |
|
850 |
sdo->index, fsm->subindex); |
|
851 |
ec_print_data(data, rec_size); |
|
852 |
fsm->state = ec_fsm_coe_error; |
|
853 |
return; |
|
854 |
} |
|
855 |
||
856 |
if (rec_size < 16) { |
|
857 |
EC_ERR("Invalid data size!\n"); |
|
858 |
ec_print_data(data, rec_size); |
|
859 |
fsm->state = ec_fsm_coe_error; |
|
860 |
return; |
|
861 |
} |
|
862 |
||
863 |
data_size = rec_size - 16; |
|
864 |
||
865 |
if (!(entry = (ec_sdo_entry_t *) |
|
866 |
kmalloc(sizeof(ec_sdo_entry_t), GFP_ATOMIC))) { |
|
867 |
EC_ERR("Failed to allocate entry!\n"); |
|
868 |
fsm->state = ec_fsm_coe_error; |
|
869 |
return; |
|
870 |
} |
|
871 |
||
872 |
if (ec_sdo_entry_init(entry, fsm->subindex, sdo)) { |
|
873 |
EC_ERR("Failed to init entry!\n"); |
|
874 |
fsm->state = ec_fsm_coe_error; |
|
875 |
return; |
|
876 |
} |
|
877 |
||
878 |
entry->data_type = EC_READ_U16(data + 10); |
|
879 |
entry->bit_length = EC_READ_U16(data + 12); |
|
880 |
||
881 |
if (data_size) { |
|
484
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
882 |
uint8_t *desc; |
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
883 |
if (!(desc = kmalloc(data_size + 1, GFP_ATOMIC))) { |
436 | 884 |
EC_ERR("Failed to allocate SDO entry name!\n"); |
885 |
fsm->state = ec_fsm_coe_error; |
|
886 |
return; |
|
887 |
} |
|
484
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
888 |
memcpy(desc, data + 16, data_size); |
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
889 |
desc[data_size] = 0; |
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
890 |
entry->description = desc; |
436 | 891 |
} |
892 |
||
893 |
list_add_tail(&entry->list, &sdo->entries); |
|
894 |
||
895 |
if (fsm->subindex < sdo->subindices) { |
|
896 |
fsm->subindex++; |
|
897 |
||
898 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10))) { |
|
899 |
fsm->state = ec_fsm_coe_error; |
|
900 |
return; |
|
901 |
} |
|
902 |
||
903 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
|
904 |
EC_WRITE_U8 (data + 2, 0x05); // Get entry description request |
|
905 |
EC_WRITE_U8 (data + 3, 0x00); |
|
906 |
EC_WRITE_U16(data + 4, 0x0000); |
|
907 |
EC_WRITE_U16(data + 6, sdo->index); // SDO index |
|
908 |
EC_WRITE_U8 (data + 8, fsm->subindex); // SDO subindex |
|
909 |
EC_WRITE_U8 (data + 9, 0x00); // value info (no values) |
|
910 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
911 |
fsm->retries = EC_FSM_RETRIES; |
436 | 912 |
fsm->state = ec_fsm_coe_dict_entry_request; |
913 |
return; |
|
914 |
} |
|
915 |
||
916 |
// another SDO description to fetch? |
|
917 |
if (fsm->sdo->list.next != &slave->sdo_dictionary) { |
|
918 |
fsm->sdo = list_entry(fsm->sdo->list.next, ec_sdo_t, list); |
|
919 |
||
920 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8))) { |
|
921 |
fsm->state = ec_fsm_coe_error; |
|
922 |
return; |
|
923 |
} |
|
924 |
||
925 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
|
926 |
EC_WRITE_U8 (data + 2, 0x03); // Get object description request |
|
927 |
EC_WRITE_U8 (data + 3, 0x00); |
|
928 |
EC_WRITE_U16(data + 4, 0x0000); |
|
929 |
EC_WRITE_U16(data + 6, fsm->sdo->index); // SDO index |
|
930 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
931 |
fsm->retries = EC_FSM_RETRIES; |
436 | 932 |
fsm->state = ec_fsm_coe_dict_desc_request; |
933 |
return; |
|
934 |
} |
|
935 |
||
936 |
fsm->state = ec_fsm_coe_end; |
|
937 |
} |
|
938 |
||
939 |
/****************************************************************************** |
|
940 |
* CoE state machine |
|
941 |
*****************************************************************************/ |
|
942 |
||
943 |
/** |
|
944 |
CoE state: DOWN START. |
|
945 |
*/ |
|
946 |
||
947 |
void ec_fsm_coe_down_start(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
948 |
{ |
|
949 |
ec_datagram_t *datagram = fsm->datagram; |
|
950 |
ec_slave_t *slave = fsm->slave; |
|
951 |
ec_sdo_data_t *sdodata = fsm->sdodata; |
|
952 |
uint8_t *data; |
|
953 |
||
459
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
954 |
if (fsm->slave->master->debug_level) |
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
955 |
EC_DBG("Downloading SDO 0x%04X:%i to slave %i.\n", |
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
956 |
sdodata->index, sdodata->subindex, slave->ring_position); |
436 | 957 |
|
958 |
if (slave->sii_rx_mailbox_size < 6 + 10 + sdodata->size) { |
|
959 |
EC_ERR("SDO fragmenting not supported yet!\n"); |
|
960 |
fsm->state = ec_fsm_coe_error; |
|
961 |
return; |
|
962 |
} |
|
963 |
||
964 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, |
|
965 |
sdodata->size + 10))) { |
|
966 |
fsm->state = ec_fsm_coe_error; |
|
967 |
return; |
|
968 |
} |
|
969 |
||
970 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
|
971 |
EC_WRITE_U8 (data + 2, (0x1 // size specified |
|
972 |
| 0x1 << 5)); // Download request |
|
973 |
EC_WRITE_U16(data + 3, sdodata->index); |
|
974 |
EC_WRITE_U8 (data + 5, sdodata->subindex); |
|
975 |
EC_WRITE_U32(data + 6, sdodata->size); |
|
976 |
memcpy(data + 10, sdodata->data, sdodata->size); |
|
977 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
978 |
fsm->retries = EC_FSM_RETRIES; |
436 | 979 |
fsm->state = ec_fsm_coe_down_request; |
980 |
} |
|
981 |
||
982 |
/*****************************************************************************/ |
|
983 |
||
984 |
/** |
|
985 |
CoE state: DOWN REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
986 |
\todo Timeout behavior |
436 | 987 |
*/ |
988 |
||
989 |
void ec_fsm_coe_down_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
990 |
{ |
|
991 |
ec_datagram_t *datagram = fsm->datagram; |
|
992 |
ec_slave_t *slave = fsm->slave; |
|
993 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
994 |
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
|
995 |
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
|
996 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
997 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
998 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
999 |
EC_ERR("Failed to receive CoE download request datagram for" |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1000 |
" slave %i (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1001 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1002 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1003 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1004 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1005 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1006 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1007 |
EC_ERR("Reception of CoE download request failed on slave %i: ", |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1008 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1009 |
ec_datagram_print_wc_error(datagram); |
436 | 1010 |
return; |
1011 |
} |
|
1012 |
||
1013 |
fsm->cycles_start = datagram->cycles_sent; |
|
1014 |
||
1015 |
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
|
1016 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1017 |
fsm->state = ec_fsm_coe_down_check; |
1018 |
} |
|
1019 |
||
1020 |
/*****************************************************************************/ |
|
1021 |
||
1022 |
/** |
|
1023 |
CoE state: DOWN CHECK. |
|
1024 |
*/ |
|
1025 |
||
1026 |
void ec_fsm_coe_down_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1027 |
{ |
|
1028 |
ec_datagram_t *datagram = fsm->datagram; |
|
1029 |
ec_slave_t *slave = fsm->slave; |
|
1030 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1031 |
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
|
1032 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1033 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1034 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1035 |
fsm->state = ec_fsm_coe_error; |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1036 |
EC_ERR("Failed to receive CoE mailbox check datagram for slave %i" |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1037 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1038 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1039 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1040 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1041 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1042 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1043 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1044 |
EC_ERR("Reception of CoE mailbox check" |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1045 |
" datagram failed on slave %i: ", slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1046 |
ec_datagram_print_wc_error(datagram); |
436 | 1047 |
return; |
1048 |
} |
|
1049 |
||
1050 |
if (!ec_slave_mbox_check(datagram)) { |
|
1051 |
if (datagram->cycles_received |
|
1052 |
- fsm->cycles_start >= (cycles_t) 100 * cpu_khz) { |
|
1053 |
fsm->state = ec_fsm_coe_error; |
|
1054 |
EC_ERR("Timeout while checking SDO configuration on slave %i.\n", |
|
1055 |
slave->ring_position); |
|
1056 |
return; |
|
1057 |
} |
|
1058 |
||
1059 |
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
|
1060 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1061 |
return; |
1062 |
} |
|
1063 |
||
1064 |
// Fetch response |
|
1065 |
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
|
1066 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1067 |
fsm->state = ec_fsm_coe_down_response; |
1068 |
} |
|
1069 |
||
1070 |
/*****************************************************************************/ |
|
1071 |
||
1072 |
/** |
|
1073 |
CoE state: DOWN RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1074 |
\todo Timeout behavior |
436 | 1075 |
*/ |
1076 |
||
1077 |
void ec_fsm_coe_down_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1078 |
{ |
|
1079 |
ec_datagram_t *datagram = fsm->datagram; |
|
1080 |
ec_slave_t *slave = fsm->slave; |
|
1081 |
uint8_t *data, mbox_prot; |
|
1082 |
size_t rec_size; |
|
1083 |
ec_sdo_data_t *sdodata = fsm->sdodata; |
|
1084 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1085 |
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
|
1086 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1087 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1088 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1089 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1090 |
EC_ERR("Failed to receive CoE download response datagram from" |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1091 |
" slave %i (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1092 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1093 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1094 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1095 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1096 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1097 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1098 |
EC_ERR("Reception of CoE download response failed on slave %i: ", |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1099 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1100 |
ec_datagram_print_wc_error(datagram); |
436 | 1101 |
return; |
1102 |
} |
|
1103 |
||
1104 |
if (!(data = ec_slave_mbox_fetch(slave, datagram, |
|
1105 |
&mbox_prot, &rec_size))) { |
|
1106 |
fsm->state = ec_fsm_coe_error; |
|
1107 |
return; |
|
1108 |
} |
|
1109 |
||
1110 |
if (mbox_prot != 0x03) { // CoE |
|
446 | 1111 |
EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot); |
436 | 1112 |
fsm->state = ec_fsm_coe_error; |
1113 |
return; |
|
1114 |
} |
|
1115 |
||
1116 |
if (rec_size < 6) { |
|
1117 |
fsm->state = ec_fsm_coe_error; |
|
1118 |
EC_ERR("Received data is too small (%i bytes):\n", rec_size); |
|
1119 |
ec_print_data(data, rec_size); |
|
1120 |
return; |
|
1121 |
} |
|
1122 |
||
1123 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
|
1124 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
|
1125 |
fsm->state = ec_fsm_coe_error; |
|
1126 |
EC_ERR("SDO download 0x%04X:%X (%i bytes) aborted on slave %i.\n", |
|
1127 |
sdodata->index, sdodata->subindex, sdodata->size, |
|
1128 |
slave->ring_position); |
|
1129 |
if (rec_size < 10) { |
|
1130 |
EC_ERR("Incomplete Abort command:\n"); |
|
1131 |
ec_print_data(data, rec_size); |
|
1132 |
} |
|
1133 |
else |
|
1134 |
ec_canopen_abort_msg(EC_READ_U32(data + 6)); |
|
1135 |
return; |
|
1136 |
} |
|
1137 |
||
1138 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
|
1139 |
EC_READ_U8 (data + 2) >> 5 != 0x3 || // Download response |
|
1140 |
EC_READ_U16(data + 3) != sdodata->index || // index |
|
1141 |
EC_READ_U8 (data + 5) != sdodata->subindex) { // subindex |
|
1142 |
fsm->state = ec_fsm_coe_error; |
|
1143 |
EC_ERR("SDO download 0x%04X:%X (%i bytes) failed:\n", |
|
1144 |
sdodata->index, sdodata->subindex, sdodata->size); |
|
1145 |
EC_ERR("Invalid SDO download response at slave %i!\n", |
|
1146 |
slave->ring_position); |
|
1147 |
ec_print_data(data, rec_size); |
|
1148 |
return; |
|
1149 |
} |
|
1150 |
||
1151 |
fsm->state = ec_fsm_coe_end; // success |
|
1152 |
} |
|
1153 |
||
1154 |
/*****************************************************************************/ |
|
1155 |
||
1156 |
/** |
|
1157 |
CoE state: UP START. |
|
1158 |
*/ |
|
1159 |
||
1160 |
void ec_fsm_coe_up_start(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1161 |
{ |
|
1162 |
ec_datagram_t *datagram = fsm->datagram; |
|
1163 |
ec_slave_t *slave = fsm->slave; |
|
1164 |
ec_master_t *master = slave->master; |
|
1165 |
ec_sdo_request_t *request = fsm->request; |
|
1166 |
ec_sdo_entry_t *entry = request->entry; |
|
1167 |
uint8_t *data; |
|
1168 |
||
459
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
1169 |
if (master->debug_level) |
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
1170 |
EC_DBG("Uploading SDO 0x%04X:%i from slave %i.\n", |
739
4a02162a6301
Removed 'sdo' field from ec_sdo_request_t; Exported
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
1171 |
entry->sdo->index, entry->subindex, slave->ring_position); |
436 | 1172 |
|
476
fd7c0ee645f8
Fixed CoE Upload Request, now 10 bytes of Mailbox Service Data.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1173 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10))) { |
436 | 1174 |
fsm->state = ec_fsm_coe_error; |
1175 |
return; |
|
1176 |
} |
|
1177 |
||
1178 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
|
1179 |
EC_WRITE_U8 (data + 2, 0x2 << 5); // initiate upload request |
|
739
4a02162a6301
Removed 'sdo' field from ec_sdo_request_t; Exported
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
1180 |
EC_WRITE_U16(data + 3, entry->sdo->index); |
436 | 1181 |
EC_WRITE_U8 (data + 5, entry->subindex); |
476
fd7c0ee645f8
Fixed CoE Upload Request, now 10 bytes of Mailbox Service Data.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1182 |
memset(data + 6, 0x00, 4); |
436 | 1183 |
|
1184 |
if (master->debug_level) { |
|
1185 |
EC_DBG("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
|
1186 |
ec_print_data(data, 10); |
436 | 1187 |
} |
1188 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1189 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1190 |
fsm->state = ec_fsm_coe_up_request; |
1191 |
} |
|
1192 |
||
1193 |
/*****************************************************************************/ |
|
1194 |
||
1195 |
/** |
|
1196 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1197 |
\todo Timeout behavior |
436 | 1198 |
*/ |
1199 |
||
1200 |
void ec_fsm_coe_up_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1201 |
{ |
|
1202 |
ec_datagram_t *datagram = fsm->datagram; |
|
1203 |
ec_slave_t *slave = fsm->slave; |
|
1204 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1205 |
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
|
1206 |
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
|
1207 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1208 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1209 |
fsm->state = ec_fsm_coe_error; |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1210 |
EC_ERR("Failed to receive CoE upload request for slave %i" |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1211 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1212 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1213 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1214 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1215 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1216 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1217 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1218 |
EC_ERR("Reception of CoE upload request failed on slave %i: ", |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1219 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1220 |
ec_datagram_print_wc_error(datagram); |
436 | 1221 |
return; |
1222 |
} |
|
1223 |
||
1224 |
fsm->cycles_start = datagram->cycles_sent; |
|
1225 |
||
1226 |
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
|
1227 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1228 |
fsm->state = ec_fsm_coe_up_check; |
1229 |
} |
|
1230 |
||
1231 |
/*****************************************************************************/ |
|
1232 |
||
1233 |
/** |
|
1234 |
CoE state: UP CHECK. |
|
1235 |
*/ |
|
1236 |
||
1237 |
void ec_fsm_coe_up_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1238 |
{ |
|
1239 |
ec_datagram_t *datagram = fsm->datagram; |
|
1240 |
ec_slave_t *slave = fsm->slave; |
|
1241 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1242 |
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
|
1243 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1244 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1245 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1246 |
fsm->state = ec_fsm_coe_error; |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1247 |
EC_ERR("Failed to receive CoE mailbox check datagram from slave %i" |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1248 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1249 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1250 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1251 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1252 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1253 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1254 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1255 |
EC_ERR("Reception of CoE mailbox check" |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1256 |
" datagram failed on slave %i: ", slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1257 |
ec_datagram_print_wc_error(datagram); |
436 | 1258 |
return; |
1259 |
} |
|
1260 |
||
1261 |
if (!ec_slave_mbox_check(datagram)) { |
|
1262 |
if (datagram->cycles_received |
|
1263 |
- fsm->cycles_start >= (cycles_t) 100 * cpu_khz) { |
|
1264 |
fsm->state = ec_fsm_coe_error; |
|
1265 |
EC_ERR("Timeout while checking SDO upload on slave %i.\n", |
|
1266 |
slave->ring_position); |
|
1267 |
return; |
|
1268 |
} |
|
1269 |
||
1270 |
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
|
1271 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1272 |
return; |
1273 |
} |
|
1274 |
||
1275 |
// Fetch response |
|
1276 |
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
|
1277 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1278 |
fsm->state = ec_fsm_coe_up_response; |
1279 |
} |
|
1280 |
||
1281 |
/*****************************************************************************/ |
|
1282 |
||
1283 |
/** |
|
1284 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1285 |
\todo Timeout behavior |
436 | 1286 |
*/ |
1287 |
||
1288 |
void ec_fsm_coe_up_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1289 |
{ |
|
1290 |
ec_datagram_t *datagram = fsm->datagram; |
|
1291 |
ec_slave_t *slave = fsm->slave; |
|
1292 |
ec_master_t *master = slave->master; |
|
1293 |
uint8_t *data, mbox_prot; |
|
1294 |
size_t rec_size, data_size; |
|
1295 |
ec_sdo_request_t *request = fsm->request; |
|
1296 |
ec_sdo_entry_t *entry = request->entry; |
|
1297 |
uint32_t complete_size; |
|
1298 |
unsigned int expedited, size_specified; |
|
1299 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1300 |
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
|
1301 |
return; // FIXME: request again? |
505
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->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1304 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1305 |
EC_ERR("Failed to receive CoE upload response datagram for" |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1306 |
" slave %i (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1307 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1308 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1309 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1310 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1311 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1312 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1313 |
EC_ERR("Reception of CoE upload response failed on slave %i: ", |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1314 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1315 |
ec_datagram_print_wc_error(datagram); |
436 | 1316 |
return; |
1317 |
} |
|
1318 |
||
1319 |
if (!(data = ec_slave_mbox_fetch(slave, datagram, |
|
1320 |
&mbox_prot, &rec_size))) { |
|
1321 |
fsm->state = ec_fsm_coe_error; |
|
1322 |
return; |
|
1323 |
} |
|
1324 |
||
1325 |
if (master->debug_level) { |
|
1326 |
EC_DBG("Upload response:\n"); |
|
1327 |
ec_print_data(data, rec_size); |
|
1328 |
} |
|
1329 |
||
1330 |
if (mbox_prot != 0x03) { // CoE |
|
1331 |
EC_WARN("Received mailbox protocol 0x%02X as response.\n", mbox_prot); |
|
1332 |
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
|
1333 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1334 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1335 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1336 |
if (rec_size < 3) { |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1337 |
EC_ERR("Received currupted SDO upload response (%u bytes)!\n", rec_size); |
436 | 1338 |
ec_print_data(data, rec_size); |
1339 |
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
|
1340 |
return; |
436 | 1341 |
} |
1342 |
||
1343 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
|
1344 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
|
1345 |
EC_ERR("SDO upload 0x%04X:%X aborted on slave %i.\n", |
|
739
4a02162a6301
Removed 'sdo' field from ec_sdo_request_t; Exported
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
1346 |
entry->sdo->index, entry->subindex, slave->ring_position); |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1347 |
if (rec_size >= 10) |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1348 |
ec_canopen_abort_msg(EC_READ_U32(data + 6)); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1349 |
else |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1350 |
EC_ERR("No abort message.\n"); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1351 |
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
|
1352 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1353 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1354 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1355 |
if (request->data) { |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1356 |
kfree(request->data); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1357 |
request->data = NULL; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1358 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1359 |
request->size = 0; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1360 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1361 |
// normal or expedited? |
436 | 1362 |
expedited = EC_READ_U8(data + 2) & 0x02; |
1363 |
||
1364 |
if (expedited) { |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1365 |
if (rec_size < 7) { |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1366 |
EC_ERR("Received currupted SDO expedited upload" |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1367 |
" response (only %u bytes)!\n", rec_size); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1368 |
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
|
1369 |
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
|
1370 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1371 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1372 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1373 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1374 |
EC_READ_U8 (data + 2) >> 5 != 0x2 || // upload response |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1375 |
EC_READ_U16(data + 3) != entry->sdo->index || // index |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1376 |
EC_READ_U8 (data + 5) != entry->subindex) { // subindex |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1377 |
EC_ERR("SDO upload 0x%04X:%X failed:\n", entry->sdo->index, entry->subindex); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1378 |
EC_ERR("Invalid SDO upload response at slave %i!\n", |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1379 |
slave->ring_position); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1380 |
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
|
1381 |
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
|
1382 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1383 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1384 |
|
436 | 1385 |
size_specified = EC_READ_U8(data + 2) & 0x01; |
1386 |
if (size_specified) { |
|
1387 |
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
|
1388 |
} else { |
436 | 1389 |
complete_size = 4; |
1390 |
} |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1391 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1392 |
if (rec_size < 6 + complete_size) { |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1393 |
EC_ERR("Received currupted SDO expedited upload" |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1394 |
" response (only %u bytes)!\n", rec_size); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1395 |
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
|
1396 |
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
|
1397 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1398 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1399 |
|
446 | 1400 |
if (!(request->data = (uint8_t *) |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1401 |
kmalloc(complete_size + 1, GFP_ATOMIC))) { |
446 | 1402 |
EC_ERR("Failed to allocate %i bytes of SDO data!\n", |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1403 |
complete_size); |
436 | 1404 |
fsm->state = ec_fsm_coe_error; |
1405 |
return; |
|
1406 |
} |
|
1407 |
request->data[complete_size] = 0x00; // just to be sure... |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1408 |
|
436 | 1409 |
memcpy(request->data, data + 6, complete_size); |
1410 |
request->size = complete_size; |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1411 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1412 |
} else { // normal |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1413 |
if (rec_size < 10) { |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1414 |
EC_ERR("Received currupted SDO normal upload" |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1415 |
" response (only %u bytes)!\n", rec_size); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1416 |
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
|
1417 |
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
|
1418 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1419 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1420 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1421 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1422 |
EC_READ_U8 (data + 2) >> 5 != 0x2 || // upload response |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1423 |
EC_READ_U16(data + 3) != entry->sdo->index || // index |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1424 |
EC_READ_U8 (data + 5) != entry->subindex) { // subindex |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1425 |
EC_ERR("SDO upload 0x%04X:%X failed:\n", entry->sdo->index, entry->subindex); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1426 |
EC_ERR("Invalid SDO upload response at slave %i!\n", |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1427 |
slave->ring_position); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1428 |
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
|
1429 |
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
|
1430 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1431 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1432 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1433 |
data_size = rec_size - 10; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1434 |
complete_size = EC_READ_U32(data + 6); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1435 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1436 |
if (!complete_size) { |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1437 |
EC_ERR("No complete size supplied!\n"); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1438 |
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
|
1439 |
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
|
1440 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1441 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1442 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1443 |
if (!(request->data = (uint8_t *) |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1444 |
kmalloc(complete_size + 1, GFP_ATOMIC))) { |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1445 |
EC_ERR("Failed to allocate %i bytes of SDO data!\n", |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1446 |
complete_size); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1447 |
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
|
1448 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1449 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1450 |
request->data[complete_size] = 0x00; // just to be sure... |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1451 |
|
436 | 1452 |
memcpy(request->data, data + 10, data_size); |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1453 |
request->size = complete_size; |
436 | 1454 |
fsm->toggle = 0; |
1455 |
||
1456 |
if (data_size < complete_size) { |
|
446 | 1457 |
EC_WARN("SDO data incomplete (%i / %i).\n", |
1458 |
data_size, complete_size); |
|
1459 |
||
1460 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, |
|
1461 |
0x03, 3))) { |
|
436 | 1462 |
fsm->state = ec_fsm_coe_error; |
1463 |
return; |
|
1464 |
} |
|
1465 |
||
1466 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
|
1467 |
EC_WRITE_U8 (data + 2, (fsm->toggle << 4 // toggle |
|
1468 |
| 0x3 << 5)); // upload segment request |
|
1469 |
||
1470 |
if (master->debug_level) { |
|
1471 |
EC_DBG("Upload segment request:\n"); |
|
1472 |
ec_print_data(data, 3); |
|
1473 |
} |
|
1474 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1475 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1476 |
fsm->state = ec_fsm_coe_up_seg_request; |
1477 |
return; |
|
1478 |
} |
|
1479 |
} |
|
1480 |
||
1481 |
fsm->state = ec_fsm_coe_end; // success |
|
1482 |
} |
|
1483 |
||
1484 |
/*****************************************************************************/ |
|
1485 |
||
1486 |
/** |
|
1487 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1488 |
\todo Timeout behavior |
436 | 1489 |
*/ |
1490 |
||
1491 |
void ec_fsm_coe_up_seg_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1492 |
{ |
|
1493 |
ec_datagram_t *datagram = fsm->datagram; |
|
1494 |
ec_slave_t *slave = fsm->slave; |
|
1495 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1496 |
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
|
1497 |
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
|
1498 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1499 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1500 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1501 |
EC_ERR("Failed to receive CoE upload segment request datagram for" |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1502 |
" slave %i (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1503 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1504 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1505 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1506 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1507 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1508 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1509 |
EC_ERR("Reception of CoE upload segment" |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1510 |
" request failed on slave %i: ", slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1511 |
ec_datagram_print_wc_error(datagram); |
436 | 1512 |
return; |
1513 |
} |
|
1514 |
||
1515 |
fsm->cycles_start = datagram->cycles_sent; |
|
1516 |
||
1517 |
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
|
1518 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1519 |
fsm->state = ec_fsm_coe_up_seg_check; |
1520 |
} |
|
1521 |
||
1522 |
/*****************************************************************************/ |
|
1523 |
||
1524 |
/** |
|
1525 |
CoE state: UP CHECK. |
|
1526 |
*/ |
|
1527 |
||
1528 |
void ec_fsm_coe_up_seg_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1529 |
{ |
|
1530 |
ec_datagram_t *datagram = fsm->datagram; |
|
1531 |
ec_slave_t *slave = fsm->slave; |
|
1532 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1533 |
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
|
1534 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1535 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1536 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1537 |
fsm->state = ec_fsm_coe_error; |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1538 |
EC_ERR("Failed to receive CoE mailbox check datagram for slave %i" |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1539 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1540 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1541 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1542 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1543 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1544 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1545 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1546 |
EC_ERR("Reception of CoE mailbox check" |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1547 |
" datagram failed on slave %i: ", slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1548 |
ec_datagram_print_wc_error(datagram); |
436 | 1549 |
return; |
1550 |
} |
|
1551 |
||
1552 |
if (!ec_slave_mbox_check(datagram)) { |
|
1553 |
if (datagram->cycles_received |
|
1554 |
- fsm->cycles_start >= (cycles_t) 100 * cpu_khz) { |
|
1555 |
fsm->state = ec_fsm_coe_error; |
|
1556 |
EC_ERR("Timeout while checking SDO upload segment on slave %i.\n", |
|
1557 |
slave->ring_position); |
|
1558 |
return; |
|
1559 |
} |
|
1560 |
||
1561 |
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
|
1562 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1563 |
return; |
1564 |
} |
|
1565 |
||
1566 |
// Fetch response |
|
1567 |
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
|
1568 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1569 |
fsm->state = ec_fsm_coe_up_seg_response; |
1570 |
} |
|
1571 |
||
1572 |
/*****************************************************************************/ |
|
1573 |
||
1574 |
/** |
|
1575 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1576 |
\todo Timeout behavior |
436 | 1577 |
*/ |
1578 |
||
1579 |
void ec_fsm_coe_up_seg_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1580 |
{ |
|
1581 |
ec_datagram_t *datagram = fsm->datagram; |
|
1582 |
ec_slave_t *slave = fsm->slave; |
|
1583 |
ec_master_t *master = slave->master; |
|
1584 |
uint8_t *data, mbox_prot; |
|
1585 |
size_t rec_size, data_size; |
|
1586 |
ec_sdo_request_t *request = fsm->request; |
|
1587 |
ec_sdo_entry_t *entry = request->entry; |
|
1588 |
uint32_t seg_size; |
|
1589 |
unsigned int last_segment; |
|
1590 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1591 |
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
|
1592 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1593 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1594 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1595 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1596 |
EC_ERR("Failed to receive CoE upload segment response datagram for" |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1597 |
" slave %i (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1598 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1599 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1600 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1601 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1602 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1603 |
fsm->state = ec_fsm_coe_error; |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1604 |
EC_ERR("Reception of CoE upload segment" |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1605 |
" response failed on slave %i: ", slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1606 |
ec_datagram_print_wc_error(datagram); |
436 | 1607 |
return; |
1608 |
} |
|
1609 |
||
1610 |
if (!(data = ec_slave_mbox_fetch(slave, datagram, |
|
1611 |
&mbox_prot, &rec_size))) { |
|
1612 |
fsm->state = ec_fsm_coe_error; |
|
1613 |
return; |
|
1614 |
} |
|
1615 |
||
1616 |
if (master->debug_level) { |
|
1617 |
EC_DBG("Upload segment response:\n"); |
|
1618 |
ec_print_data(data, rec_size); |
|
1619 |
} |
|
1620 |
||
1621 |
if (mbox_prot != 0x03) { // CoE |
|
446 | 1622 |
EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot); |
436 | 1623 |
fsm->state = ec_fsm_coe_error; |
1624 |
return; |
|
1625 |
} |
|
1626 |
||
1627 |
if (rec_size < 10) { |
|
1628 |
EC_ERR("Received currupted SDO upload segment response!\n"); |
|
1629 |
ec_print_data(data, rec_size); |
|
1630 |
fsm->state = ec_fsm_coe_error; |
|
1631 |
return; |
|
1632 |
} |
|
1633 |
||
1634 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
|
1635 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
|
1636 |
EC_ERR("SDO upload 0x%04X:%X aborted on slave %i.\n", |
|
739
4a02162a6301
Removed 'sdo' field from ec_sdo_request_t; Exported
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
1637 |
entry->sdo->index, entry->subindex, slave->ring_position); |
436 | 1638 |
ec_canopen_abort_msg(EC_READ_U32(data + 6)); |
1639 |
fsm->state = ec_fsm_coe_error; |
|
1640 |
return; |
|
1641 |
} |
|
1642 |
||
1643 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
|
1644 |
EC_READ_U8 (data + 2) >> 5 != 0x0) { // upload segment response |
|
739
4a02162a6301
Removed 'sdo' field from ec_sdo_request_t; Exported
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
1645 |
EC_ERR("SDO upload 0x%04X:%X failed:\n", entry->sdo->index, entry->subindex); |
436 | 1646 |
EC_ERR("Invalid SDO upload segment response at slave %i!\n", |
1647 |
slave->ring_position); |
|
1648 |
ec_print_data(data, rec_size); |
|
1649 |
fsm->state = ec_fsm_coe_error; |
|
1650 |
return; |
|
1651 |
} |
|
1652 |
||
1653 |
last_segment = EC_READ_U8(data + 2) & 0x01; |
|
1654 |
seg_size = (EC_READ_U8(data + 2) & 0xE) >> 1; |
|
1655 |
data_size = rec_size - 10; |
|
1656 |
||
1657 |
if (data_size != seg_size) { |
|
1658 |
EC_WARN("SDO segment data invalid (%i / %i)" |
|
1659 |
" - Fragmenting not implemented.\n", |
|
1660 |
data_size, seg_size); |
|
1661 |
} |
|
1662 |
||
1663 |
memcpy(request->data + request->size, data + 10, data_size); |
|
1664 |
request->size += data_size; |
|
1665 |
||
1666 |
if (!last_segment) { |
|
1667 |
fsm->toggle = !fsm->toggle; |
|
1668 |
||
1669 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 3))) { |
|
1670 |
fsm->state = ec_fsm_coe_error; |
|
1671 |
return; |
|
1672 |
} |
|
1673 |
||
1674 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
|
1675 |
EC_WRITE_U8 (data + 2, (fsm->toggle << 4 // toggle |
|
1676 |
| 0x3 << 5)); // upload segment request |
|
1677 |
||
1678 |
if (master->debug_level) { |
|
1679 |
EC_DBG("Upload segment request:\n"); |
|
1680 |
ec_print_data(data, 3); |
|
1681 |
} |
|
1682 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1683 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1684 |
fsm->state = ec_fsm_coe_up_seg_request; |
1685 |
return; |
|
1686 |
} |
|
1687 |
||
1688 |
fsm->state = ec_fsm_coe_end; // success |
|
1689 |
} |
|
1690 |
||
1691 |
/*****************************************************************************/ |
|
1692 |
||
1693 |
/** |
|
1694 |
State: ERROR. |
|
1695 |
*/ |
|
1696 |
||
1697 |
void ec_fsm_coe_error(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1698 |
{ |
|
1699 |
} |
|
1700 |
||
1701 |
/*****************************************************************************/ |
|
1702 |
||
1703 |
/** |
|
1704 |
State: END. |
|
1705 |
*/ |
|
1706 |
||
1707 |
void ec_fsm_coe_end(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1708 |
{ |
|
1709 |
} |
|
1710 |
||
1711 |
/*****************************************************************************/ |