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