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