author | Florian Pose <fp@igh-essen.com> |
Thu, 28 Feb 2008 11:23:34 +0000 | |
changeset 838 | 3cb5769059f4 |
parent 834 | 0791aac03180 |
child 854 | f4f53be425ac |
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 |
/** |
|
814 | 78 |
Sdo abort messages. |
79 |
The "abort Sdo transfer request" supplies an abort code, |
|
436 | 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"}, |
|
814 | 86 |
{0x05040000, "Sdo protocol timeout"}, |
436 | 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"}, |
|
814 | 93 |
{0x06040041, "The object cannot be mapped into the Pdo"}, |
436 | 94 |
{0x06040042, "The number and length of the objects to be mapped would" |
814 | 95 |
" exceed the Pdo length"}, |
436 | 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 |
/** |
|
814 | 124 |
Outputs an Sdo abort message. |
436 | 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) { |
|
814 | 133 |
EC_ERR("Sdo abort message 0x%08X: \"%s\".\n", |
436 | 134 |
abort_msg->code, abort_msg->message); |
135 |
return; |
|
136 |
} |
|
137 |
} |
|
138 |
||
814 | 139 |
EC_ERR("Unknown Sdo abort code 0x%08X.\n", abort_code); |
436 | 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 |
/** |
|
814 | 169 |
Starts reading a slaves' Sdo dictionary. |
436 | 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 |
/** |
|
814 | 183 |
Starts to download an Sdo to a slave. |
436 | 184 |
*/ |
185 |
||
186 |
void ec_fsm_coe_download(ec_fsm_coe_t *fsm, /**< finite state machine */ |
|
187 |
ec_slave_t *slave, /**< EtherCAT slave */ |
|
814 | 188 |
ec_sdo_data_t *sdodata /**< Sdo data object */ |
436 | 189 |
) |
190 |
{ |
|
191 |
fsm->slave = slave; |
|
192 |
fsm->sdodata = sdodata; |
|
193 |
fsm->state = ec_fsm_coe_down_start; |
|
194 |
} |
|
195 |
||
196 |
/*****************************************************************************/ |
|
197 |
||
198 |
/** |
|
814 | 199 |
Starts to upload an Sdo from a slave. |
436 | 200 |
*/ |
201 |
||
202 |
void ec_fsm_coe_upload(ec_fsm_coe_t *fsm, /**< finite state machine */ |
|
203 |
ec_slave_t *slave, /**< EtherCAT slave */ |
|
814 | 204 |
ec_sdo_request_t *request /**< Sdo request */ |
436 | 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 |
||
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
252 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
825
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
253 |
EC_ERR("Slave %u does not support CoE!\n", slave->ring_position); |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
254 |
fsm->state = ec_fsm_coe_error; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
255 |
return; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
256 |
} |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
257 |
|
436 | 258 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8))) { |
259 |
fsm->state = ec_fsm_coe_error; |
|
260 |
return; |
|
261 |
} |
|
262 |
||
814 | 263 |
EC_WRITE_U16(data, 0x8 << 12); // Sdo information |
436 | 264 |
EC_WRITE_U8 (data + 2, 0x01); // Get OD List Request |
265 |
EC_WRITE_U8 (data + 3, 0x00); |
|
266 |
EC_WRITE_U16(data + 4, 0x0000); |
|
814 | 267 |
EC_WRITE_U16(data + 6, 0x0001); // deliver all Sdos! |
436 | 268 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
269 |
fsm->retries = EC_FSM_RETRIES; |
436 | 270 |
fsm->state = ec_fsm_coe_dict_request; |
271 |
} |
|
272 |
||
273 |
/*****************************************************************************/ |
|
274 |
||
275 |
/** |
|
276 |
CoE state: DICT REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
277 |
\todo Timeout behavior |
436 | 278 |
*/ |
279 |
||
280 |
void ec_fsm_coe_dict_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
281 |
{ |
|
282 |
ec_datagram_t *datagram = fsm->datagram; |
|
283 |
ec_slave_t *slave = fsm->slave; |
|
284 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
285 |
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
|
286 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
287 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
288 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
289 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
290 |
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
|
291 |
" 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
|
292 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
293 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
294 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
295 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
296 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
297 |
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
|
298 |
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
|
299 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
300 |
ec_datagram_print_wc_error(datagram); |
436 | 301 |
return; |
302 |
} |
|
303 |
||
304 |
fsm->cycles_start = datagram->cycles_sent; |
|
305 |
||
306 |
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
|
307 |
fsm->retries = EC_FSM_RETRIES; |
436 | 308 |
fsm->state = ec_fsm_coe_dict_check; |
309 |
} |
|
310 |
||
311 |
/*****************************************************************************/ |
|
312 |
||
313 |
/** |
|
314 |
CoE state: DICT CHECK. |
|
315 |
*/ |
|
316 |
||
317 |
void ec_fsm_coe_dict_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
318 |
{ |
|
319 |
ec_datagram_t *datagram = fsm->datagram; |
|
320 |
ec_slave_t *slave = fsm->slave; |
|
321 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
322 |
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
|
323 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
324 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
325 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
326 |
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
|
327 |
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
|
328 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
329 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
330 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
331 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
332 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
333 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
334 |
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
|
335 |
EC_ERR("Reception of CoE mailbox check datagram failed on slave %i: ", |
436 | 336 |
slave->ring_position); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
337 |
ec_datagram_print_wc_error(datagram); |
436 | 338 |
return; |
339 |
} |
|
340 |
||
341 |
if (!ec_slave_mbox_check(datagram)) { |
|
342 |
if (datagram->cycles_received |
|
343 |
- fsm->cycles_start >= (cycles_t) 100 * cpu_khz) { |
|
344 |
fsm->state = ec_fsm_coe_error; |
|
814 | 345 |
EC_ERR("Timeout while checking Sdo dictionary on slave %i.\n", |
436 | 346 |
slave->ring_position); |
347 |
return; |
|
348 |
} |
|
349 |
||
350 |
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
|
351 |
fsm->retries = EC_FSM_RETRIES; |
436 | 352 |
return; |
353 |
} |
|
354 |
||
355 |
// Fetch response |
|
356 |
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
|
357 |
fsm->retries = EC_FSM_RETRIES; |
436 | 358 |
fsm->state = ec_fsm_coe_dict_response; |
359 |
} |
|
360 |
||
361 |
/*****************************************************************************/ |
|
362 |
||
363 |
/** |
|
364 |
CoE state: DICT RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
365 |
\todo Timeout behavior |
436 | 366 |
*/ |
367 |
||
368 |
void ec_fsm_coe_dict_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
369 |
{ |
|
370 |
ec_datagram_t *datagram = fsm->datagram; |
|
371 |
ec_slave_t *slave = fsm->slave; |
|
372 |
uint8_t *data, mbox_prot; |
|
373 |
size_t rec_size; |
|
374 |
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
|
375 |
uint16_t sdo_index, fragments_left; |
436 | 376 |
ec_sdo_t *sdo; |
377 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
378 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
379 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
380 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
381 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
382 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
383 |
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
|
384 |
" 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
|
385 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
386 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
387 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
388 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
389 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
390 |
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
|
391 |
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
|
392 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
393 |
ec_datagram_print_wc_error(datagram); |
436 | 394 |
return; |
395 |
} |
|
396 |
||
397 |
if (!(data = ec_slave_mbox_fetch(slave, datagram, |
|
398 |
&mbox_prot, &rec_size))) { |
|
399 |
fsm->state = ec_fsm_coe_error; |
|
400 |
return; |
|
401 |
} |
|
402 |
||
403 |
if (mbox_prot != 0x03) { // CoE |
|
446 | 404 |
EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot); |
436 | 405 |
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
|
406 |
return; |
436 | 407 |
} |
408 |
||
814 | 409 |
if (EC_READ_U16(data) >> 12 == 0x8 && // Sdo information |
436 | 410 |
(EC_READ_U8(data + 2) & 0x7F) == 0x07) { // error response |
814 | 411 |
EC_ERR("Sdo information error response at slave %i!\n", |
436 | 412 |
slave->ring_position); |
413 |
ec_canopen_abort_msg(EC_READ_U32(data + 6)); |
|
414 |
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
|
415 |
return; |
436 | 416 |
} |
417 |
||
814 | 418 |
if (EC_READ_U16(data) >> 12 != 0x8 || // Sdo information |
436 | 419 |
(EC_READ_U8 (data + 2) & 0x7F) != 0x02) { // Get OD List response |
814 | 420 |
EC_ERR("Invalid Sdo list response at slave %i!\n", |
436 | 421 |
slave->ring_position); |
422 |
ec_print_data(data, rec_size); |
|
423 |
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
|
424 |
return; |
436 | 425 |
} |
426 |
||
427 |
if (rec_size < 8) { |
|
428 |
EC_ERR("Invalid data size!\n"); |
|
429 |
ec_print_data(data, rec_size); |
|
430 |
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
|
431 |
return; |
436 | 432 |
} |
433 |
||
434 |
sdo_count = (rec_size - 8) / 2; |
|
435 |
||
436 |
for (i = 0; i < sdo_count; i++) { |
|
437 |
sdo_index = EC_READ_U16(data + 8 + i * 2); |
|
438 |
if (!sdo_index) { |
|
461
b9eda9235173
Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
459
diff
changeset
|
439 |
if (slave->master->debug_level) |
814 | 440 |
EC_WARN("Sdo dictionary of slave %i contains index 0x0000.\n", |
461
b9eda9235173
Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
459
diff
changeset
|
441 |
slave->ring_position); |
436 | 442 |
continue; |
443 |
} |
|
444 |
||
445 |
if (!(sdo = (ec_sdo_t *) kmalloc(sizeof(ec_sdo_t), GFP_ATOMIC))) { |
|
814 | 446 |
EC_ERR("Failed to allocate memory for Sdo!\n"); |
436 | 447 |
fsm->state = ec_fsm_coe_error; |
448 |
return; |
|
449 |
} |
|
450 |
||
451 |
if (ec_sdo_init(sdo, sdo_index, slave)) { |
|
814 | 452 |
EC_ERR("Failed to init Sdo!\n"); |
436 | 453 |
fsm->state = ec_fsm_coe_error; |
454 |
return; |
|
455 |
} |
|
456 |
||
457 |
list_add_tail(&sdo->list, &slave->sdo_dictionary); |
|
458 |
} |
|
459 |
||
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
460 |
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
|
461 |
if (slave->master->debug_level && fragments_left) { |
814 | 462 |
EC_DBG("Sdo list fragments left: %u\n", fragments_left); |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
463 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
464 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
465 |
if (EC_READ_U8(data + 2) & 0x80 || fragments_left) { // more messages waiting. check again. |
436 | 466 |
fsm->cycles_start = datagram->cycles_sent; |
467 |
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
|
468 |
fsm->retries = EC_FSM_RETRIES; |
436 | 469 |
fsm->state = ec_fsm_coe_dict_check; |
470 |
return; |
|
471 |
} |
|
472 |
||
473 |
if (list_empty(&slave->sdo_dictionary)) { |
|
814 | 474 |
// no Sdos in dictionary. finished. |
436 | 475 |
fsm->state = ec_fsm_coe_end; // success |
476 |
return; |
|
477 |
} |
|
478 |
||
814 | 479 |
// fetch Sdo descriptions |
436 | 480 |
fsm->sdo = list_entry(slave->sdo_dictionary.next, ec_sdo_t, list); |
481 |
||
482 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8))) { |
|
483 |
fsm->state = ec_fsm_coe_error; |
|
484 |
return; |
|
485 |
} |
|
486 |
||
814 | 487 |
EC_WRITE_U16(data, 0x8 << 12); // Sdo information |
436 | 488 |
EC_WRITE_U8 (data + 2, 0x03); // Get object description request |
489 |
EC_WRITE_U8 (data + 3, 0x00); |
|
490 |
EC_WRITE_U16(data + 4, 0x0000); |
|
814 | 491 |
EC_WRITE_U16(data + 6, fsm->sdo->index); // Sdo index |
436 | 492 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
493 |
fsm->retries = EC_FSM_RETRIES; |
436 | 494 |
fsm->state = ec_fsm_coe_dict_desc_request; |
495 |
} |
|
496 |
||
497 |
/*****************************************************************************/ |
|
498 |
||
499 |
/** |
|
500 |
CoE state: DICT DESC REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
501 |
\todo Timeout behavior |
436 | 502 |
*/ |
503 |
||
504 |
void ec_fsm_coe_dict_desc_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
505 |
{ |
|
506 |
ec_datagram_t *datagram = fsm->datagram; |
|
507 |
ec_slave_t *slave = fsm->slave; |
|
508 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
509 |
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
|
510 |
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
|
511 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
512 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
513 |
fsm->state = ec_fsm_coe_error; |
814 | 514 |
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
|
515 |
" 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
|
516 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
517 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
518 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
519 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
520 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
521 |
fsm->state = ec_fsm_coe_error; |
814 | 522 |
EC_ERR("Reception of CoE Sdo description" |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
523 |
" 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
|
524 |
ec_datagram_print_wc_error(datagram); |
436 | 525 |
return; |
526 |
} |
|
527 |
||
528 |
fsm->cycles_start = datagram->cycles_sent; |
|
529 |
||
530 |
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
|
531 |
fsm->retries = EC_FSM_RETRIES; |
436 | 532 |
fsm->state = ec_fsm_coe_dict_desc_check; |
533 |
} |
|
534 |
||
535 |
/*****************************************************************************/ |
|
536 |
||
537 |
/** |
|
538 |
CoE state: DICT DESC CHECK. |
|
539 |
*/ |
|
540 |
||
541 |
void ec_fsm_coe_dict_desc_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
542 |
{ |
|
543 |
ec_datagram_t *datagram = fsm->datagram; |
|
544 |
ec_slave_t *slave = fsm->slave; |
|
545 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
546 |
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
|
547 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
548 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
549 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
550 |
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
|
551 |
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
|
552 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
553 |
slave->ring_position, datagram->state); |
436 | 554 |
return; |
555 |
} |
|
556 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
557 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
558 |
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
|
559 |
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
|
560 |
" 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
|
561 |
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
|
562 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
563 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
564 |
|
436 | 565 |
if (!ec_slave_mbox_check(datagram)) { |
566 |
if (datagram->cycles_received |
|
567 |
- fsm->cycles_start >= (cycles_t) 100 * cpu_khz) { |
|
568 |
fsm->state = ec_fsm_coe_error; |
|
814 | 569 |
EC_ERR("Timeout while checking Sdo description on slave %i.\n", |
436 | 570 |
slave->ring_position); |
571 |
return; |
|
572 |
} |
|
573 |
||
574 |
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
|
575 |
fsm->retries = EC_FSM_RETRIES; |
436 | 576 |
return; |
577 |
} |
|
578 |
||
579 |
// Fetch response |
|
580 |
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
|
581 |
fsm->retries = EC_FSM_RETRIES; |
436 | 582 |
fsm->state = ec_fsm_coe_dict_desc_response; |
583 |
} |
|
584 |
||
585 |
/*****************************************************************************/ |
|
586 |
||
587 |
/** |
|
588 |
CoE state: DICT DESC RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
589 |
\todo Timeout behavior |
436 | 590 |
*/ |
591 |
||
592 |
void ec_fsm_coe_dict_desc_response(ec_fsm_coe_t *fsm |
|
593 |
/**< finite state machine */) |
|
594 |
{ |
|
595 |
ec_datagram_t *datagram = fsm->datagram; |
|
596 |
ec_slave_t *slave = fsm->slave; |
|
597 |
ec_sdo_t *sdo = fsm->sdo; |
|
598 |
uint8_t *data, mbox_prot; |
|
599 |
size_t rec_size, name_size; |
|
600 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
601 |
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
|
602 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
603 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
604 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
605 |
fsm->state = ec_fsm_coe_error; |
814 | 606 |
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
|
607 |
" 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
|
608 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
609 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
610 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
611 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
612 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
613 |
fsm->state = ec_fsm_coe_error; |
814 | 614 |
EC_ERR("Reception of CoE Sdo description" |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
615 |
" 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
|
616 |
ec_datagram_print_wc_error(datagram); |
436 | 617 |
return; |
618 |
} |
|
619 |
||
620 |
if (!(data = ec_slave_mbox_fetch(slave, datagram, |
|
621 |
&mbox_prot, &rec_size))) { |
|
622 |
fsm->state = ec_fsm_coe_error; |
|
623 |
return; |
|
624 |
} |
|
625 |
||
626 |
if (mbox_prot != 0x03) { // CoE |
|
446 | 627 |
EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot); |
436 | 628 |
fsm->state = ec_fsm_coe_error; |
629 |
return; |
|
630 |
} |
|
631 |
||
814 | 632 |
if (EC_READ_U16(data) >> 12 == 0x8 && // Sdo information |
436 | 633 |
(EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response |
814 | 634 |
EC_ERR("Sdo information error response at slave %i while" |
635 |
" fetching Sdo 0x%04X!\n", slave->ring_position, |
|
436 | 636 |
sdo->index); |
637 |
ec_canopen_abort_msg(EC_READ_U32(data + 6)); |
|
638 |
fsm->state = ec_fsm_coe_error; |
|
639 |
return; |
|
640 |
} |
|
641 |
||
814 | 642 |
if (EC_READ_U16(data) >> 12 != 0x8 || // Sdo information |
436 | 643 |
(EC_READ_U8 (data + 2) & 0x7F) != 0x04 || // Object desc. response |
814 | 644 |
EC_READ_U16(data + 6) != sdo->index) { // Sdo index |
436 | 645 |
EC_ERR("Invalid object description response at slave %i while" |
814 | 646 |
" fetching Sdo 0x%04X!\n", slave->ring_position, |
436 | 647 |
sdo->index); |
648 |
ec_print_data(data, rec_size); |
|
649 |
fsm->state = ec_fsm_coe_error; |
|
650 |
return; |
|
651 |
} |
|
652 |
||
653 |
if (rec_size < 12) { |
|
654 |
EC_ERR("Invalid data size!\n"); |
|
655 |
ec_print_data(data, rec_size); |
|
656 |
fsm->state = ec_fsm_coe_error; |
|
657 |
return; |
|
658 |
} |
|
659 |
||
660 |
sdo->subindices = EC_READ_U8(data + 10); |
|
661 |
sdo->object_code = EC_READ_U8(data + 11); |
|
662 |
||
663 |
name_size = rec_size - 12; |
|
664 |
if (name_size) { |
|
665 |
if (!(sdo->name = kmalloc(name_size + 1, GFP_ATOMIC))) { |
|
814 | 666 |
EC_ERR("Failed to allocate Sdo name!\n"); |
436 | 667 |
fsm->state = ec_fsm_coe_error; |
668 |
return; |
|
669 |
} |
|
670 |
||
671 |
memcpy(sdo->name, data + 12, name_size); |
|
672 |
sdo->name[name_size] = 0; |
|
673 |
} |
|
674 |
||
675 |
if (EC_READ_U8(data + 2) & 0x80) { |
|
676 |
EC_ERR("Fragment follows (not implemented)!\n"); |
|
677 |
fsm->state = ec_fsm_coe_error; |
|
678 |
return; |
|
679 |
} |
|
680 |
||
681 |
// start fetching entries |
|
682 |
||
683 |
fsm->subindex = 0; |
|
684 |
||
685 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10))) { |
|
686 |
fsm->state = ec_fsm_coe_error; |
|
687 |
return; |
|
688 |
} |
|
689 |
||
814 | 690 |
EC_WRITE_U16(data, 0x8 << 12); // Sdo information |
436 | 691 |
EC_WRITE_U8 (data + 2, 0x05); // Get entry description request |
692 |
EC_WRITE_U8 (data + 3, 0x00); |
|
693 |
EC_WRITE_U16(data + 4, 0x0000); |
|
814 | 694 |
EC_WRITE_U16(data + 6, sdo->index); // Sdo index |
695 |
EC_WRITE_U8 (data + 8, fsm->subindex); // Sdo subindex |
|
436 | 696 |
EC_WRITE_U8 (data + 9, 0x00); // value info (no values) |
697 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
698 |
fsm->retries = EC_FSM_RETRIES; |
436 | 699 |
fsm->state = ec_fsm_coe_dict_entry_request; |
700 |
} |
|
701 |
||
702 |
/*****************************************************************************/ |
|
703 |
||
704 |
/** |
|
705 |
CoE state: DICT ENTRY REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
706 |
\todo Timeout behavior |
436 | 707 |
*/ |
708 |
||
709 |
void ec_fsm_coe_dict_entry_request(ec_fsm_coe_t *fsm |
|
710 |
/**< finite state machine */) |
|
711 |
{ |
|
712 |
ec_datagram_t *datagram = fsm->datagram; |
|
713 |
ec_slave_t *slave = fsm->slave; |
|
714 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
715 |
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
|
716 |
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
|
717 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
718 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
719 |
fsm->state = ec_fsm_coe_error; |
814 | 720 |
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
|
721 |
" 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
|
722 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
723 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
724 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
725 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
726 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
727 |
fsm->state = ec_fsm_coe_error; |
814 | 728 |
EC_ERR("Reception of CoE Sdo entry request failed on slave %i: ", |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
729 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
730 |
ec_datagram_print_wc_error(datagram); |
436 | 731 |
return; |
732 |
} |
|
733 |
||
734 |
fsm->cycles_start = datagram->cycles_sent; |
|
735 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
736 |
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
|
737 |
fsm->retries = EC_FSM_RETRIES; |
436 | 738 |
fsm->state = ec_fsm_coe_dict_entry_check; |
739 |
} |
|
740 |
||
741 |
/*****************************************************************************/ |
|
742 |
||
743 |
/** |
|
744 |
CoE state: DICT ENTRY CHECK. |
|
745 |
*/ |
|
746 |
||
747 |
void ec_fsm_coe_dict_entry_check(ec_fsm_coe_t *fsm |
|
748 |
/**< finite state machine */) |
|
749 |
{ |
|
750 |
ec_datagram_t *datagram = fsm->datagram; |
|
751 |
ec_slave_t *slave = fsm->slave; |
|
752 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
753 |
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
|
754 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
755 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
756 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
757 |
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
|
758 |
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
|
759 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
760 |
slave->ring_position, datagram->state); |
436 | 761 |
return; |
762 |
} |
|
763 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
764 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
765 |
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
|
766 |
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
|
767 |
" 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
|
768 |
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
|
769 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
770 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
771 |
|
436 | 772 |
if (!ec_slave_mbox_check(datagram)) { |
773 |
if (datagram->cycles_received |
|
774 |
- fsm->cycles_start >= (cycles_t) 100 * cpu_khz) { |
|
775 |
fsm->state = ec_fsm_coe_error; |
|
814 | 776 |
EC_ERR("Timeout while checking Sdo entry on slave %i.\n", |
436 | 777 |
slave->ring_position); |
778 |
return; |
|
779 |
} |
|
780 |
||
781 |
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
|
782 |
fsm->retries = EC_FSM_RETRIES; |
436 | 783 |
return; |
784 |
} |
|
785 |
||
786 |
// Fetch response |
|
787 |
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
|
788 |
fsm->retries = EC_FSM_RETRIES; |
436 | 789 |
fsm->state = ec_fsm_coe_dict_entry_response; |
790 |
} |
|
791 |
||
792 |
/*****************************************************************************/ |
|
793 |
||
794 |
/** |
|
795 |
CoE state: DICT ENTRY RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
796 |
\todo Timeout behavior |
436 | 797 |
*/ |
798 |
||
799 |
void ec_fsm_coe_dict_entry_response(ec_fsm_coe_t *fsm |
|
800 |
/**< finite state machine */) |
|
801 |
{ |
|
802 |
ec_datagram_t *datagram = fsm->datagram; |
|
803 |
ec_slave_t *slave = fsm->slave; |
|
804 |
ec_sdo_t *sdo = fsm->sdo; |
|
805 |
uint8_t *data, mbox_prot; |
|
806 |
size_t rec_size, data_size; |
|
807 |
ec_sdo_entry_t *entry; |
|
808 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
809 |
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
|
810 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
811 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
812 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
813 |
fsm->state = ec_fsm_coe_error; |
814 | 814 |
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
|
815 |
" 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
|
816 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
817 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
818 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
819 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
820 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
821 |
fsm->state = ec_fsm_coe_error; |
814 | 822 |
EC_ERR("Reception of CoE Sdo description" |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
823 |
" 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
|
824 |
ec_datagram_print_wc_error(datagram); |
436 | 825 |
return; |
826 |
} |
|
827 |
||
828 |
if (!(data = ec_slave_mbox_fetch(slave, datagram, |
|
829 |
&mbox_prot, &rec_size))) { |
|
830 |
fsm->state = ec_fsm_coe_error; |
|
831 |
return; |
|
832 |
} |
|
833 |
||
834 |
if (mbox_prot != 0x03) { // CoE |
|
446 | 835 |
EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot); |
436 | 836 |
fsm->state = ec_fsm_coe_error; |
837 |
return; |
|
838 |
} |
|
839 |
||
814 | 840 |
if (EC_READ_U16(data) >> 12 == 0x8 && // Sdo information |
436 | 841 |
(EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response |
814 | 842 |
EC_ERR("Sdo information error response at slave %i while" |
843 |
" fetching Sdo entry 0x%04X:%i!\n", slave->ring_position, |
|
436 | 844 |
sdo->index, fsm->subindex); |
845 |
ec_canopen_abort_msg(EC_READ_U32(data + 6)); |
|
846 |
fsm->state = ec_fsm_coe_error; |
|
847 |
return; |
|
848 |
} |
|
849 |
||
814 | 850 |
if (EC_READ_U16(data) >> 12 != 0x8 || // Sdo information |
436 | 851 |
(EC_READ_U8(data + 2) & 0x7F) != 0x06 || // Entry desc. response |
814 | 852 |
EC_READ_U16(data + 6) != sdo->index || // Sdo index |
853 |
EC_READ_U8(data + 8) != fsm->subindex) { // Sdo subindex |
|
436 | 854 |
EC_ERR("Invalid entry description response at slave %i while" |
814 | 855 |
" fetching Sdo entry 0x%04X:%i!\n", slave->ring_position, |
436 | 856 |
sdo->index, fsm->subindex); |
857 |
ec_print_data(data, rec_size); |
|
858 |
fsm->state = ec_fsm_coe_error; |
|
859 |
return; |
|
860 |
} |
|
861 |
||
862 |
if (rec_size < 16) { |
|
863 |
EC_ERR("Invalid data size!\n"); |
|
864 |
ec_print_data(data, rec_size); |
|
865 |
fsm->state = ec_fsm_coe_error; |
|
866 |
return; |
|
867 |
} |
|
868 |
||
869 |
data_size = rec_size - 16; |
|
870 |
||
871 |
if (!(entry = (ec_sdo_entry_t *) |
|
872 |
kmalloc(sizeof(ec_sdo_entry_t), GFP_ATOMIC))) { |
|
873 |
EC_ERR("Failed to allocate entry!\n"); |
|
874 |
fsm->state = ec_fsm_coe_error; |
|
875 |
return; |
|
876 |
} |
|
877 |
||
878 |
if (ec_sdo_entry_init(entry, fsm->subindex, sdo)) { |
|
879 |
EC_ERR("Failed to init entry!\n"); |
|
880 |
fsm->state = ec_fsm_coe_error; |
|
881 |
return; |
|
882 |
} |
|
883 |
||
884 |
entry->data_type = EC_READ_U16(data + 10); |
|
885 |
entry->bit_length = EC_READ_U16(data + 12); |
|
886 |
||
887 |
if (data_size) { |
|
484
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
888 |
uint8_t *desc; |
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
889 |
if (!(desc = kmalloc(data_size + 1, GFP_ATOMIC))) { |
814 | 890 |
EC_ERR("Failed to allocate Sdo entry name!\n"); |
436 | 891 |
fsm->state = ec_fsm_coe_error; |
892 |
return; |
|
893 |
} |
|
484
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
894 |
memcpy(desc, data + 16, data_size); |
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
895 |
desc[data_size] = 0; |
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
896 |
entry->description = desc; |
436 | 897 |
} |
898 |
||
899 |
list_add_tail(&entry->list, &sdo->entries); |
|
900 |
||
901 |
if (fsm->subindex < sdo->subindices) { |
|
902 |
fsm->subindex++; |
|
903 |
||
904 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10))) { |
|
905 |
fsm->state = ec_fsm_coe_error; |
|
906 |
return; |
|
907 |
} |
|
908 |
||
814 | 909 |
EC_WRITE_U16(data, 0x8 << 12); // Sdo information |
436 | 910 |
EC_WRITE_U8 (data + 2, 0x05); // Get entry description request |
911 |
EC_WRITE_U8 (data + 3, 0x00); |
|
912 |
EC_WRITE_U16(data + 4, 0x0000); |
|
814 | 913 |
EC_WRITE_U16(data + 6, sdo->index); // Sdo index |
914 |
EC_WRITE_U8 (data + 8, fsm->subindex); // Sdo subindex |
|
436 | 915 |
EC_WRITE_U8 (data + 9, 0x00); // value info (no values) |
916 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
917 |
fsm->retries = EC_FSM_RETRIES; |
436 | 918 |
fsm->state = ec_fsm_coe_dict_entry_request; |
919 |
return; |
|
920 |
} |
|
921 |
||
814 | 922 |
// another Sdo description to fetch? |
436 | 923 |
if (fsm->sdo->list.next != &slave->sdo_dictionary) { |
924 |
fsm->sdo = list_entry(fsm->sdo->list.next, ec_sdo_t, list); |
|
925 |
||
926 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8))) { |
|
927 |
fsm->state = ec_fsm_coe_error; |
|
928 |
return; |
|
929 |
} |
|
930 |
||
814 | 931 |
EC_WRITE_U16(data, 0x8 << 12); // Sdo information |
436 | 932 |
EC_WRITE_U8 (data + 2, 0x03); // Get object description request |
933 |
EC_WRITE_U8 (data + 3, 0x00); |
|
934 |
EC_WRITE_U16(data + 4, 0x0000); |
|
814 | 935 |
EC_WRITE_U16(data + 6, fsm->sdo->index); // Sdo index |
436 | 936 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
937 |
fsm->retries = EC_FSM_RETRIES; |
436 | 938 |
fsm->state = ec_fsm_coe_dict_desc_request; |
939 |
return; |
|
940 |
} |
|
941 |
||
942 |
fsm->state = ec_fsm_coe_end; |
|
943 |
} |
|
944 |
||
945 |
/****************************************************************************** |
|
946 |
* CoE state machine |
|
947 |
*****************************************************************************/ |
|
948 |
||
949 |
/** |
|
950 |
CoE state: DOWN START. |
|
951 |
*/ |
|
952 |
||
953 |
void ec_fsm_coe_down_start(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
954 |
{ |
|
955 |
ec_datagram_t *datagram = fsm->datagram; |
|
956 |
ec_slave_t *slave = fsm->slave; |
|
957 |
ec_sdo_data_t *sdodata = fsm->sdodata; |
|
958 |
uint8_t *data; |
|
959 |
||
459
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
960 |
if (fsm->slave->master->debug_level) |
814 | 961 |
EC_DBG("Downloading Sdo 0x%04X:%i to slave %i.\n", |
459
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
962 |
sdodata->index, sdodata->subindex, slave->ring_position); |
436 | 963 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
964 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
825
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
965 |
EC_ERR("Slave %u does not support CoE!\n", slave->ring_position); |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
966 |
fsm->state = ec_fsm_coe_error; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
967 |
return; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
968 |
} |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
969 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
970 |
if (slave->sii.rx_mailbox_size < 6 + 10 + sdodata->size) { |
814 | 971 |
EC_ERR("Sdo fragmenting not supported yet!\n"); |
436 | 972 |
fsm->state = ec_fsm_coe_error; |
973 |
return; |
|
974 |
} |
|
975 |
||
976 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, |
|
977 |
sdodata->size + 10))) { |
|
978 |
fsm->state = ec_fsm_coe_error; |
|
979 |
return; |
|
980 |
} |
|
981 |
||
814 | 982 |
EC_WRITE_U16(data, 0x2 << 12); // Sdo request |
436 | 983 |
EC_WRITE_U8 (data + 2, (0x1 // size specified |
984 |
| 0x1 << 5)); // Download request |
|
985 |
EC_WRITE_U16(data + 3, sdodata->index); |
|
986 |
EC_WRITE_U8 (data + 5, sdodata->subindex); |
|
987 |
EC_WRITE_U32(data + 6, sdodata->size); |
|
988 |
memcpy(data + 10, sdodata->data, sdodata->size); |
|
989 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
990 |
fsm->retries = EC_FSM_RETRIES; |
436 | 991 |
fsm->state = ec_fsm_coe_down_request; |
992 |
} |
|
993 |
||
994 |
/*****************************************************************************/ |
|
995 |
||
996 |
/** |
|
997 |
CoE state: DOWN REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
998 |
\todo Timeout behavior |
436 | 999 |
*/ |
1000 |
||
1001 |
void ec_fsm_coe_down_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1002 |
{ |
|
1003 |
ec_datagram_t *datagram = fsm->datagram; |
|
1004 |
ec_slave_t *slave = fsm->slave; |
|
1005 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1006 |
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
|
1007 |
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
|
1008 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1009 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1010 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1011 |
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
|
1012 |
" 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
|
1013 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1014 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1015 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1016 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1017 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1018 |
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
|
1019 |
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
|
1020 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1021 |
ec_datagram_print_wc_error(datagram); |
436 | 1022 |
return; |
1023 |
} |
|
1024 |
||
1025 |
fsm->cycles_start = datagram->cycles_sent; |
|
1026 |
||
1027 |
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
|
1028 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1029 |
fsm->state = ec_fsm_coe_down_check; |
1030 |
} |
|
1031 |
||
1032 |
/*****************************************************************************/ |
|
1033 |
||
1034 |
/** |
|
1035 |
CoE state: DOWN CHECK. |
|
1036 |
*/ |
|
1037 |
||
1038 |
void ec_fsm_coe_down_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1039 |
{ |
|
1040 |
ec_datagram_t *datagram = fsm->datagram; |
|
1041 |
ec_slave_t *slave = fsm->slave; |
|
1042 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1043 |
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
|
1044 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1045 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1046 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1047 |
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
|
1048 |
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
|
1049 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1050 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1051 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1052 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1053 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1054 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1055 |
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
|
1056 |
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
|
1057 |
" 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
|
1058 |
ec_datagram_print_wc_error(datagram); |
436 | 1059 |
return; |
1060 |
} |
|
1061 |
||
1062 |
if (!ec_slave_mbox_check(datagram)) { |
|
1063 |
if (datagram->cycles_received |
|
1064 |
- fsm->cycles_start >= (cycles_t) 100 * cpu_khz) { |
|
1065 |
fsm->state = ec_fsm_coe_error; |
|
814 | 1066 |
EC_ERR("Timeout while checking Sdo configuration on slave %i.\n", |
436 | 1067 |
slave->ring_position); |
1068 |
return; |
|
1069 |
} |
|
1070 |
||
1071 |
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
|
1072 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1073 |
return; |
1074 |
} |
|
1075 |
||
1076 |
// Fetch response |
|
1077 |
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
|
1078 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1079 |
fsm->state = ec_fsm_coe_down_response; |
1080 |
} |
|
1081 |
||
1082 |
/*****************************************************************************/ |
|
1083 |
||
1084 |
/** |
|
1085 |
CoE state: DOWN RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1086 |
\todo Timeout behavior |
436 | 1087 |
*/ |
1088 |
||
1089 |
void ec_fsm_coe_down_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1090 |
{ |
|
1091 |
ec_datagram_t *datagram = fsm->datagram; |
|
1092 |
ec_slave_t *slave = fsm->slave; |
|
1093 |
uint8_t *data, mbox_prot; |
|
1094 |
size_t rec_size; |
|
1095 |
ec_sdo_data_t *sdodata = fsm->sdodata; |
|
1096 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1097 |
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
|
1098 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1099 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1100 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1101 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1102 |
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
|
1103 |
" 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
|
1104 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1105 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1106 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1107 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1108 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1109 |
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
|
1110 |
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
|
1111 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1112 |
ec_datagram_print_wc_error(datagram); |
436 | 1113 |
return; |
1114 |
} |
|
1115 |
||
1116 |
if (!(data = ec_slave_mbox_fetch(slave, datagram, |
|
1117 |
&mbox_prot, &rec_size))) { |
|
1118 |
fsm->state = ec_fsm_coe_error; |
|
1119 |
return; |
|
1120 |
} |
|
1121 |
||
1122 |
if (mbox_prot != 0x03) { // CoE |
|
446 | 1123 |
EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot); |
436 | 1124 |
fsm->state = ec_fsm_coe_error; |
1125 |
return; |
|
1126 |
} |
|
1127 |
||
1128 |
if (rec_size < 6) { |
|
1129 |
fsm->state = ec_fsm_coe_error; |
|
1130 |
EC_ERR("Received data is too small (%i bytes):\n", rec_size); |
|
1131 |
ec_print_data(data, rec_size); |
|
1132 |
return; |
|
1133 |
} |
|
1134 |
||
814 | 1135 |
if (EC_READ_U16(data) >> 12 == 0x2 && // Sdo request |
1136 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort Sdo transfer request |
|
1137 |
fsm->state = ec_fsm_coe_error; |
|
1138 |
EC_ERR("Sdo download 0x%04X:%X (%i bytes) aborted on slave %i.\n", |
|
436 | 1139 |
sdodata->index, sdodata->subindex, sdodata->size, |
1140 |
slave->ring_position); |
|
1141 |
if (rec_size < 10) { |
|
1142 |
EC_ERR("Incomplete Abort command:\n"); |
|
1143 |
ec_print_data(data, rec_size); |
|
1144 |
} |
|
1145 |
else |
|
1146 |
ec_canopen_abort_msg(EC_READ_U32(data + 6)); |
|
1147 |
return; |
|
1148 |
} |
|
1149 |
||
814 | 1150 |
if (EC_READ_U16(data) >> 12 != 0x3 || // Sdo response |
436 | 1151 |
EC_READ_U8 (data + 2) >> 5 != 0x3 || // Download response |
1152 |
EC_READ_U16(data + 3) != sdodata->index || // index |
|
1153 |
EC_READ_U8 (data + 5) != sdodata->subindex) { // subindex |
|
1154 |
fsm->state = ec_fsm_coe_error; |
|
814 | 1155 |
EC_ERR("Sdo download 0x%04X:%X (%i bytes) failed:\n", |
436 | 1156 |
sdodata->index, sdodata->subindex, sdodata->size); |
814 | 1157 |
EC_ERR("Invalid Sdo download response at slave %i!\n", |
436 | 1158 |
slave->ring_position); |
1159 |
ec_print_data(data, rec_size); |
|
1160 |
return; |
|
1161 |
} |
|
1162 |
||
1163 |
fsm->state = ec_fsm_coe_end; // success |
|
1164 |
} |
|
1165 |
||
1166 |
/*****************************************************************************/ |
|
1167 |
||
1168 |
/** |
|
1169 |
CoE state: UP START. |
|
1170 |
*/ |
|
1171 |
||
1172 |
void ec_fsm_coe_up_start(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1173 |
{ |
|
1174 |
ec_datagram_t *datagram = fsm->datagram; |
|
1175 |
ec_slave_t *slave = fsm->slave; |
|
1176 |
ec_master_t *master = slave->master; |
|
1177 |
ec_sdo_request_t *request = fsm->request; |
|
1178 |
uint8_t *data; |
|
1179 |
||
459
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
1180 |
if (master->debug_level) |
814 | 1181 |
EC_DBG("Uploading Sdo 0x%04X:%i from slave %i.\n", |
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1182 |
request->index, request->subindex, slave->ring_position); |
436 | 1183 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
1184 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
825
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1185 |
EC_ERR("Slave %u does not support CoE!\n", slave->ring_position); |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1186 |
fsm->state = ec_fsm_coe_error; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1187 |
return; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1188 |
} |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1189 |
|
476
fd7c0ee645f8
Fixed CoE Upload Request, now 10 bytes of Mailbox Service Data.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1190 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10))) { |
436 | 1191 |
fsm->state = ec_fsm_coe_error; |
1192 |
return; |
|
1193 |
} |
|
1194 |
||
814 | 1195 |
EC_WRITE_U16(data, 0x2 << 12); // Sdo request |
436 | 1196 |
EC_WRITE_U8 (data + 2, 0x2 << 5); // initiate upload request |
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1197 |
EC_WRITE_U16(data + 3, request->index); |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1198 |
EC_WRITE_U8 (data + 5, request->subindex); |
476
fd7c0ee645f8
Fixed CoE Upload Request, now 10 bytes of Mailbox Service Data.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1199 |
memset(data + 6, 0x00, 4); |
436 | 1200 |
|
1201 |
if (master->debug_level) { |
|
1202 |
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
|
1203 |
ec_print_data(data, 10); |
436 | 1204 |
} |
1205 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1206 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1207 |
fsm->state = ec_fsm_coe_up_request; |
1208 |
} |
|
1209 |
||
1210 |
/*****************************************************************************/ |
|
1211 |
||
1212 |
/** |
|
1213 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1214 |
\todo Timeout behavior |
436 | 1215 |
*/ |
1216 |
||
1217 |
void ec_fsm_coe_up_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1218 |
{ |
|
1219 |
ec_datagram_t *datagram = fsm->datagram; |
|
1220 |
ec_slave_t *slave = fsm->slave; |
|
1221 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1222 |
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
|
1223 |
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
|
1224 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1225 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1226 |
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
|
1227 |
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
|
1228 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1229 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1230 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1231 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1232 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1233 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1234 |
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
|
1235 |
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
|
1236 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1237 |
ec_datagram_print_wc_error(datagram); |
436 | 1238 |
return; |
1239 |
} |
|
1240 |
||
1241 |
fsm->cycles_start = datagram->cycles_sent; |
|
1242 |
||
1243 |
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
|
1244 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1245 |
fsm->state = ec_fsm_coe_up_check; |
1246 |
} |
|
1247 |
||
1248 |
/*****************************************************************************/ |
|
1249 |
||
1250 |
/** |
|
1251 |
CoE state: UP CHECK. |
|
1252 |
*/ |
|
1253 |
||
1254 |
void ec_fsm_coe_up_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1255 |
{ |
|
1256 |
ec_datagram_t *datagram = fsm->datagram; |
|
1257 |
ec_slave_t *slave = fsm->slave; |
|
1258 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1259 |
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
|
1260 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1261 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1262 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1263 |
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
|
1264 |
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
|
1265 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1266 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1267 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1268 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1269 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1270 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1271 |
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
|
1272 |
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
|
1273 |
" 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
|
1274 |
ec_datagram_print_wc_error(datagram); |
436 | 1275 |
return; |
1276 |
} |
|
1277 |
||
1278 |
if (!ec_slave_mbox_check(datagram)) { |
|
1279 |
if (datagram->cycles_received |
|
1280 |
- fsm->cycles_start >= (cycles_t) 100 * cpu_khz) { |
|
1281 |
fsm->state = ec_fsm_coe_error; |
|
814 | 1282 |
EC_ERR("Timeout while checking Sdo upload on slave %i.\n", |
436 | 1283 |
slave->ring_position); |
1284 |
return; |
|
1285 |
} |
|
1286 |
||
1287 |
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
|
1288 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1289 |
return; |
1290 |
} |
|
1291 |
||
1292 |
// Fetch response |
|
1293 |
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
|
1294 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1295 |
fsm->state = ec_fsm_coe_up_response; |
1296 |
} |
|
1297 |
||
1298 |
/*****************************************************************************/ |
|
1299 |
||
1300 |
/** |
|
1301 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1302 |
\todo Timeout behavior |
436 | 1303 |
*/ |
1304 |
||
1305 |
void ec_fsm_coe_up_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1306 |
{ |
|
1307 |
ec_datagram_t *datagram = fsm->datagram; |
|
1308 |
ec_slave_t *slave = fsm->slave; |
|
1309 |
ec_master_t *master = slave->master; |
|
1310 |
uint8_t *data, mbox_prot; |
|
1311 |
size_t rec_size, data_size; |
|
1312 |
ec_sdo_request_t *request = fsm->request; |
|
1313 |
uint32_t complete_size; |
|
1314 |
unsigned int expedited, size_specified; |
|
1315 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1316 |
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
|
1317 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1318 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1319 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1320 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1321 |
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
|
1322 |
" 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
|
1323 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1324 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1325 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1326 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1327 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1328 |
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
|
1329 |
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
|
1330 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1331 |
ec_datagram_print_wc_error(datagram); |
436 | 1332 |
return; |
1333 |
} |
|
1334 |
||
1335 |
if (!(data = ec_slave_mbox_fetch(slave, datagram, |
|
1336 |
&mbox_prot, &rec_size))) { |
|
1337 |
fsm->state = ec_fsm_coe_error; |
|
1338 |
return; |
|
1339 |
} |
|
1340 |
||
1341 |
if (master->debug_level) { |
|
1342 |
EC_DBG("Upload response:\n"); |
|
1343 |
ec_print_data(data, rec_size); |
|
1344 |
} |
|
1345 |
||
1346 |
if (mbox_prot != 0x03) { // CoE |
|
1347 |
EC_WARN("Received mailbox protocol 0x%02X as response.\n", mbox_prot); |
|
1348 |
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
|
1349 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1350 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1351 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1352 |
if (rec_size < 3) { |
814 | 1353 |
EC_ERR("Received currupted Sdo upload response (%u bytes)!\n", rec_size); |
436 | 1354 |
ec_print_data(data, rec_size); |
1355 |
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
|
1356 |
return; |
436 | 1357 |
} |
1358 |
||
814 | 1359 |
if (EC_READ_U16(data) >> 12 == 0x2 && // Sdo request |
1360 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort Sdo transfer request |
|
1361 |
EC_ERR("Sdo upload 0x%04X:%X aborted on slave %i.\n", |
|
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1362 |
request->index, request->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
|
1363 |
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
|
1364 |
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
|
1365 |
else |
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("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
|
1367 |
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
|
1368 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1369 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1370 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1371 |
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
|
1372 |
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
|
1373 |
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
|
1374 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1375 |
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
|
1376 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1377 |
// normal or expedited? |
436 | 1378 |
expedited = EC_READ_U8(data + 2) & 0x02; |
1379 |
||
1380 |
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
|
1381 |
if (rec_size < 7) { |
814 | 1382 |
EC_ERR("Received currupted Sdo expedited upload" |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1383 |
" 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
|
1384 |
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
|
1385 |
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
|
1386 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1387 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1388 |
|
814 | 1389 |
if (EC_READ_U16(data) >> 12 != 0x3 || // Sdo response |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1390 |
EC_READ_U8 (data + 2) >> 5 != 0x2 || // upload response |
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1391 |
EC_READ_U16(data + 3) != request->index || // index |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1392 |
EC_READ_U8 (data + 5) != request->subindex) { // subindex |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1393 |
EC_ERR("Sdo upload 0x%04X:%X failed:\n", |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1394 |
request->index, request->subindex); |
814 | 1395 |
EC_ERR("Invalid Sdo upload response at slave %i!\n", |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1396 |
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
|
1397 |
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
|
1398 |
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
|
1399 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1400 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1401 |
|
436 | 1402 |
size_specified = EC_READ_U8(data + 2) & 0x01; |
1403 |
if (size_specified) { |
|
1404 |
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
|
1405 |
} else { |
436 | 1406 |
complete_size = 4; |
1407 |
} |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1408 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1409 |
if (rec_size < 6 + complete_size) { |
814 | 1410 |
EC_ERR("Received currupted Sdo expedited upload" |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1411 |
" 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
|
1412 |
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
|
1413 |
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
|
1414 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1415 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1416 |
|
446 | 1417 |
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
|
1418 |
kmalloc(complete_size + 1, GFP_ATOMIC))) { |
814 | 1419 |
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
|
1420 |
complete_size); |
436 | 1421 |
fsm->state = ec_fsm_coe_error; |
1422 |
return; |
|
1423 |
} |
|
1424 |
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
|
1425 |
|
436 | 1426 |
memcpy(request->data, data + 6, complete_size); |
1427 |
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
|
1428 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1429 |
} else { // normal |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1430 |
if (rec_size < 10) { |
814 | 1431 |
EC_ERR("Received currupted Sdo normal upload" |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1432 |
" 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
|
1433 |
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
|
1434 |
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
|
1435 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1436 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1437 |
|
814 | 1438 |
if (EC_READ_U16(data) >> 12 != 0x3 || // Sdo response |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1439 |
EC_READ_U8 (data + 2) >> 5 != 0x2 || // upload response |
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1440 |
EC_READ_U16(data + 3) != request->index || // index |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1441 |
EC_READ_U8 (data + 5) != request->subindex) { // subindex |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1442 |
EC_ERR("Sdo upload 0x%04X:%X failed:\n", |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1443 |
request->index, request->subindex); |
814 | 1444 |
EC_ERR("Invalid Sdo upload response at slave %i!\n", |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1445 |
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
|
1446 |
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
|
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 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1451 |
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
|
1452 |
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
|
1453 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1454 |
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
|
1455 |
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
|
1456 |
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
|
1457 |
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
|
1458 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1459 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1460 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1461 |
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
|
1462 |
kmalloc(complete_size + 1, GFP_ATOMIC))) { |
814 | 1463 |
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
|
1464 |
complete_size); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1465 |
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
|
1466 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1467 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1468 |
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
|
1469 |
|
436 | 1470 |
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
|
1471 |
request->size = complete_size; |
436 | 1472 |
fsm->toggle = 0; |
1473 |
||
1474 |
if (data_size < complete_size) { |
|
814 | 1475 |
EC_WARN("Sdo data incomplete (%i / %i).\n", |
446 | 1476 |
data_size, complete_size); |
1477 |
||
1478 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, |
|
1479 |
0x03, 3))) { |
|
436 | 1480 |
fsm->state = ec_fsm_coe_error; |
1481 |
return; |
|
1482 |
} |
|
1483 |
||
814 | 1484 |
EC_WRITE_U16(data, 0x2 << 12); // Sdo request |
436 | 1485 |
EC_WRITE_U8 (data + 2, (fsm->toggle << 4 // toggle |
1486 |
| 0x3 << 5)); // upload segment request |
|
1487 |
||
1488 |
if (master->debug_level) { |
|
1489 |
EC_DBG("Upload segment request:\n"); |
|
1490 |
ec_print_data(data, 3); |
|
1491 |
} |
|
1492 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1493 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1494 |
fsm->state = ec_fsm_coe_up_seg_request; |
1495 |
return; |
|
1496 |
} |
|
1497 |
} |
|
1498 |
||
1499 |
fsm->state = ec_fsm_coe_end; // success |
|
1500 |
} |
|
1501 |
||
1502 |
/*****************************************************************************/ |
|
1503 |
||
1504 |
/** |
|
1505 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1506 |
\todo Timeout behavior |
436 | 1507 |
*/ |
1508 |
||
1509 |
void ec_fsm_coe_up_seg_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1510 |
{ |
|
1511 |
ec_datagram_t *datagram = fsm->datagram; |
|
1512 |
ec_slave_t *slave = fsm->slave; |
|
1513 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1514 |
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
|
1515 |
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
|
1516 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1517 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1518 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1519 |
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
|
1520 |
" 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
|
1521 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1522 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1523 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1524 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1525 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1526 |
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
|
1527 |
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
|
1528 |
" 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
|
1529 |
ec_datagram_print_wc_error(datagram); |
436 | 1530 |
return; |
1531 |
} |
|
1532 |
||
1533 |
fsm->cycles_start = datagram->cycles_sent; |
|
1534 |
||
1535 |
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
|
1536 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1537 |
fsm->state = ec_fsm_coe_up_seg_check; |
1538 |
} |
|
1539 |
||
1540 |
/*****************************************************************************/ |
|
1541 |
||
1542 |
/** |
|
1543 |
CoE state: UP CHECK. |
|
1544 |
*/ |
|
1545 |
||
1546 |
void ec_fsm_coe_up_seg_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1547 |
{ |
|
1548 |
ec_datagram_t *datagram = fsm->datagram; |
|
1549 |
ec_slave_t *slave = fsm->slave; |
|
1550 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1551 |
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
|
1552 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1553 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1554 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1555 |
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
|
1556 |
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
|
1557 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1558 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1559 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1560 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1561 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1562 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1563 |
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
|
1564 |
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
|
1565 |
" 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
|
1566 |
ec_datagram_print_wc_error(datagram); |
436 | 1567 |
return; |
1568 |
} |
|
1569 |
||
1570 |
if (!ec_slave_mbox_check(datagram)) { |
|
1571 |
if (datagram->cycles_received |
|
1572 |
- fsm->cycles_start >= (cycles_t) 100 * cpu_khz) { |
|
1573 |
fsm->state = ec_fsm_coe_error; |
|
814 | 1574 |
EC_ERR("Timeout while checking Sdo upload segment on slave %i.\n", |
436 | 1575 |
slave->ring_position); |
1576 |
return; |
|
1577 |
} |
|
1578 |
||
1579 |
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
|
1580 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1581 |
return; |
1582 |
} |
|
1583 |
||
1584 |
// Fetch response |
|
1585 |
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
|
1586 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1587 |
fsm->state = ec_fsm_coe_up_seg_response; |
1588 |
} |
|
1589 |
||
1590 |
/*****************************************************************************/ |
|
1591 |
||
1592 |
/** |
|
1593 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1594 |
\todo Timeout behavior |
436 | 1595 |
*/ |
1596 |
||
1597 |
void ec_fsm_coe_up_seg_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1598 |
{ |
|
1599 |
ec_datagram_t *datagram = fsm->datagram; |
|
1600 |
ec_slave_t *slave = fsm->slave; |
|
1601 |
ec_master_t *master = slave->master; |
|
1602 |
uint8_t *data, mbox_prot; |
|
1603 |
size_t rec_size, data_size; |
|
1604 |
ec_sdo_request_t *request = fsm->request; |
|
1605 |
uint32_t seg_size; |
|
1606 |
unsigned int last_segment; |
|
1607 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1608 |
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
|
1609 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1610 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1611 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1612 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1613 |
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
|
1614 |
" 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
|
1615 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1616 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1617 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1618 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1619 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1620 |
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
|
1621 |
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
|
1622 |
" 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
|
1623 |
ec_datagram_print_wc_error(datagram); |
436 | 1624 |
return; |
1625 |
} |
|
1626 |
||
1627 |
if (!(data = ec_slave_mbox_fetch(slave, datagram, |
|
1628 |
&mbox_prot, &rec_size))) { |
|
1629 |
fsm->state = ec_fsm_coe_error; |
|
1630 |
return; |
|
1631 |
} |
|
1632 |
||
1633 |
if (master->debug_level) { |
|
1634 |
EC_DBG("Upload segment response:\n"); |
|
1635 |
ec_print_data(data, rec_size); |
|
1636 |
} |
|
1637 |
||
1638 |
if (mbox_prot != 0x03) { // CoE |
|
446 | 1639 |
EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot); |
436 | 1640 |
fsm->state = ec_fsm_coe_error; |
1641 |
return; |
|
1642 |
} |
|
1643 |
||
1644 |
if (rec_size < 10) { |
|
814 | 1645 |
EC_ERR("Received currupted Sdo upload segment response!\n"); |
436 | 1646 |
ec_print_data(data, rec_size); |
1647 |
fsm->state = ec_fsm_coe_error; |
|
1648 |
return; |
|
1649 |
} |
|
1650 |
||
814 | 1651 |
if (EC_READ_U16(data) >> 12 == 0x2 && // Sdo request |
1652 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort Sdo transfer request |
|
1653 |
EC_ERR("Sdo upload 0x%04X:%X aborted on slave %i.\n", |
|
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1654 |
request->index, request->subindex, slave->ring_position); |
436 | 1655 |
ec_canopen_abort_msg(EC_READ_U32(data + 6)); |
1656 |
fsm->state = ec_fsm_coe_error; |
|
1657 |
return; |
|
1658 |
} |
|
1659 |
||
814 | 1660 |
if (EC_READ_U16(data) >> 12 != 0x3 || // Sdo response |
436 | 1661 |
EC_READ_U8 (data + 2) >> 5 != 0x0) { // upload segment response |
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1662 |
EC_ERR("Sdo upload 0x%04X:%X failed:\n", request->index, request->subindex); |
814 | 1663 |
EC_ERR("Invalid Sdo upload segment response at slave %i!\n", |
436 | 1664 |
slave->ring_position); |
1665 |
ec_print_data(data, rec_size); |
|
1666 |
fsm->state = ec_fsm_coe_error; |
|
1667 |
return; |
|
1668 |
} |
|
1669 |
||
1670 |
last_segment = EC_READ_U8(data + 2) & 0x01; |
|
1671 |
seg_size = (EC_READ_U8(data + 2) & 0xE) >> 1; |
|
1672 |
data_size = rec_size - 10; |
|
1673 |
||
1674 |
if (data_size != seg_size) { |
|
814 | 1675 |
EC_WARN("Sdo segment data invalid (%i / %i)" |
436 | 1676 |
" - Fragmenting not implemented.\n", |
1677 |
data_size, seg_size); |
|
1678 |
} |
|
1679 |
||
1680 |
memcpy(request->data + request->size, data + 10, data_size); |
|
1681 |
request->size += data_size; |
|
1682 |
||
1683 |
if (!last_segment) { |
|
1684 |
fsm->toggle = !fsm->toggle; |
|
1685 |
||
1686 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 3))) { |
|
1687 |
fsm->state = ec_fsm_coe_error; |
|
1688 |
return; |
|
1689 |
} |
|
1690 |
||
814 | 1691 |
EC_WRITE_U16(data, 0x2 << 12); // Sdo request |
436 | 1692 |
EC_WRITE_U8 (data + 2, (fsm->toggle << 4 // toggle |
1693 |
| 0x3 << 5)); // upload segment request |
|
1694 |
||
1695 |
if (master->debug_level) { |
|
1696 |
EC_DBG("Upload segment request:\n"); |
|
1697 |
ec_print_data(data, 3); |
|
1698 |
} |
|
1699 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1700 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1701 |
fsm->state = ec_fsm_coe_up_seg_request; |
1702 |
return; |
|
1703 |
} |
|
1704 |
||
1705 |
fsm->state = ec_fsm_coe_end; // success |
|
1706 |
} |
|
1707 |
||
1708 |
/*****************************************************************************/ |
|
1709 |
||
1710 |
/** |
|
1711 |
State: ERROR. |
|
1712 |
*/ |
|
1713 |
||
1714 |
void ec_fsm_coe_error(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1715 |
{ |
|
1716 |
} |
|
1717 |
||
1718 |
/*****************************************************************************/ |
|
1719 |
||
1720 |
/** |
|
1721 |
State: END. |
|
1722 |
*/ |
|
1723 |
||
1724 |
void ec_fsm_coe_end(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1725 |
{ |
|
1726 |
} |
|
1727 |
||
1728 |
/*****************************************************************************/ |