author | Florian Pose <fp@igh-essen.com> |
Mon, 31 Mar 2008 09:42:37 +0000 | |
changeset 878 | 40c379697ebf |
parent 874 | 022f869ea40f |
child 895 | 5c2125247dde |
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 |
||
874 | 948 |
if (fsm->slave->master->debug_level) { |
949 |
EC_DBG("Downloading Sdo 0x%04X:%u to slave %u.\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); |
874 | 951 |
ec_print_data(request->data, request->data_size); |
952 |
} |
|
436 | 953 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
954 |
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
|
955 |
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
|
956 |
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
|
957 |
return; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
958 |
} |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
959 |
|
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
|
960 |
if (slave->sii.rx_mailbox_size < 6 + 10 + request->data_size) { |
814 | 961 |
EC_ERR("Sdo fragmenting not supported yet!\n"); |
436 | 962 |
fsm->state = ec_fsm_coe_error; |
963 |
return; |
|
964 |
} |
|
965 |
||
966 |
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
|
967 |
request->data_size + 10))) { |
436 | 968 |
fsm->state = ec_fsm_coe_error; |
969 |
return; |
|
970 |
} |
|
971 |
||
814 | 972 |
EC_WRITE_U16(data, 0x2 << 12); // Sdo request |
436 | 973 |
EC_WRITE_U8 (data + 2, (0x1 // size specified |
974 |
| 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
|
975 |
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
|
976 |
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
|
977 |
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
|
978 |
memcpy(data + 10, request->data, request->data_size); |
436 | 979 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
980 |
fsm->retries = EC_FSM_RETRIES; |
436 | 981 |
fsm->state = ec_fsm_coe_down_request; |
982 |
} |
|
983 |
||
984 |
/*****************************************************************************/ |
|
985 |
||
986 |
/** |
|
987 |
CoE state: DOWN REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
988 |
\todo Timeout behavior |
436 | 989 |
*/ |
990 |
||
991 |
void ec_fsm_coe_down_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
992 |
{ |
|
993 |
ec_datagram_t *datagram = fsm->datagram; |
|
994 |
ec_slave_t *slave = fsm->slave; |
|
995 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
996 |
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
|
997 |
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
|
998 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
999 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1000 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1001 |
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
|
1002 |
" 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
|
1003 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1004 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1005 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1006 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1007 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1008 |
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
|
1009 |
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
|
1010 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1011 |
ec_datagram_print_wc_error(datagram); |
436 | 1012 |
return; |
1013 |
} |
|
1014 |
||
1015 |
fsm->cycles_start = datagram->cycles_sent; |
|
1016 |
||
1017 |
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
|
1018 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1019 |
fsm->state = ec_fsm_coe_down_check; |
1020 |
} |
|
1021 |
||
1022 |
/*****************************************************************************/ |
|
1023 |
||
1024 |
/** |
|
1025 |
CoE state: DOWN CHECK. |
|
1026 |
*/ |
|
1027 |
||
1028 |
void ec_fsm_coe_down_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1029 |
{ |
|
1030 |
ec_datagram_t *datagram = fsm->datagram; |
|
1031 |
ec_slave_t *slave = fsm->slave; |
|
1032 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1033 |
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
|
1034 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1035 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1036 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1037 |
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
|
1038 |
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
|
1039 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1040 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1041 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1042 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1043 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1044 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1045 |
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
|
1046 |
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
|
1047 |
" 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
|
1048 |
ec_datagram_print_wc_error(datagram); |
436 | 1049 |
return; |
1050 |
} |
|
1051 |
||
1052 |
if (!ec_slave_mbox_check(datagram)) { |
|
1053 |
if (datagram->cycles_received |
|
1054 |
- fsm->cycles_start >= (cycles_t) 100 * cpu_khz) { |
|
1055 |
fsm->state = ec_fsm_coe_error; |
|
814 | 1056 |
EC_ERR("Timeout while checking Sdo configuration on slave %i.\n", |
436 | 1057 |
slave->ring_position); |
1058 |
return; |
|
1059 |
} |
|
1060 |
||
1061 |
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
|
1062 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1063 |
return; |
1064 |
} |
|
1065 |
||
1066 |
// Fetch response |
|
1067 |
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
|
1068 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1069 |
fsm->state = ec_fsm_coe_down_response; |
1070 |
} |
|
1071 |
||
1072 |
/*****************************************************************************/ |
|
1073 |
||
1074 |
/** |
|
1075 |
CoE state: DOWN RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1076 |
\todo Timeout behavior |
436 | 1077 |
*/ |
1078 |
||
1079 |
void ec_fsm_coe_down_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1080 |
{ |
|
1081 |
ec_datagram_t *datagram = fsm->datagram; |
|
1082 |
ec_slave_t *slave = fsm->slave; |
|
1083 |
uint8_t *data, mbox_prot; |
|
1084 |
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
|
1085 |
ec_sdo_request_t *request = fsm->request; |
436 | 1086 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1087 |
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
|
1088 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1089 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1090 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1091 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1092 |
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
|
1093 |
" 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
|
1094 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1095 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1096 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1097 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1098 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1099 |
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
|
1100 |
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
|
1101 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1102 |
ec_datagram_print_wc_error(datagram); |
436 | 1103 |
return; |
1104 |
} |
|
1105 |
||
1106 |
if (!(data = ec_slave_mbox_fetch(slave, datagram, |
|
1107 |
&mbox_prot, &rec_size))) { |
|
1108 |
fsm->state = ec_fsm_coe_error; |
|
1109 |
return; |
|
1110 |
} |
|
1111 |
||
1112 |
if (mbox_prot != 0x03) { // CoE |
|
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1113 |
fsm->state = ec_fsm_coe_error; |
446 | 1114 |
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
|
1115 |
return; |
436 | 1116 |
} |
1117 |
||
1118 |
if (rec_size < 6) { |
|
1119 |
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
|
1120 |
EC_ERR("Received data is too small (%u bytes):\n", rec_size); |
436 | 1121 |
ec_print_data(data, rec_size); |
1122 |
return; |
|
1123 |
} |
|
1124 |
||
814 | 1125 |
if (EC_READ_U16(data) >> 12 == 0x2 && // Sdo request |
1126 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort Sdo transfer request |
|
1127 |
fsm->state = ec_fsm_coe_error; |
|
1128 |
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
|
1129 |
request->index, request->subindex, request->data_size, |
436 | 1130 |
slave->ring_position); |
1131 |
if (rec_size < 10) { |
|
1132 |
EC_ERR("Incomplete Abort command:\n"); |
|
1133 |
ec_print_data(data, rec_size); |
|
1134 |
} |
|
1135 |
else |
|
1136 |
ec_canopen_abort_msg(EC_READ_U32(data + 6)); |
|
1137 |
return; |
|
1138 |
} |
|
1139 |
||
814 | 1140 |
if (EC_READ_U16(data) >> 12 != 0x3 || // Sdo response |
436 | 1141 |
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
|
1142 |
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
|
1143 |
EC_READ_U8 (data + 5) != request->subindex) { // subindex |
436 | 1144 |
fsm->state = ec_fsm_coe_error; |
814 | 1145 |
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
|
1146 |
request->index, request->subindex, request->data_size); |
814 | 1147 |
EC_ERR("Invalid Sdo download response at slave %i!\n", |
436 | 1148 |
slave->ring_position); |
1149 |
ec_print_data(data, rec_size); |
|
1150 |
return; |
|
1151 |
} |
|
1152 |
||
1153 |
fsm->state = ec_fsm_coe_end; // success |
|
1154 |
} |
|
1155 |
||
1156 |
/*****************************************************************************/ |
|
1157 |
||
1158 |
/** |
|
1159 |
CoE state: UP START. |
|
1160 |
*/ |
|
1161 |
||
1162 |
void ec_fsm_coe_up_start(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1163 |
{ |
|
1164 |
ec_datagram_t *datagram = fsm->datagram; |
|
1165 |
ec_slave_t *slave = fsm->slave; |
|
1166 |
ec_master_t *master = slave->master; |
|
1167 |
ec_sdo_request_t *request = fsm->request; |
|
1168 |
uint8_t *data; |
|
1169 |
||
459
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
1170 |
if (master->debug_level) |
874 | 1171 |
EC_DBG("Uploading Sdo 0x%04X:%u from slave %u.\n", |
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1172 |
request->index, request->subindex, slave->ring_position); |
436 | 1173 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
1174 |
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
|
1175 |
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
|
1176 |
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
|
1177 |
return; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1178 |
} |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1179 |
|
476
fd7c0ee645f8
Fixed CoE Upload Request, now 10 bytes of Mailbox Service Data.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1180 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10))) { |
436 | 1181 |
fsm->state = ec_fsm_coe_error; |
1182 |
return; |
|
1183 |
} |
|
1184 |
||
814 | 1185 |
EC_WRITE_U16(data, 0x2 << 12); // Sdo request |
436 | 1186 |
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
|
1187 |
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
|
1188 |
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
|
1189 |
memset(data + 6, 0x00, 4); |
436 | 1190 |
|
1191 |
if (master->debug_level) { |
|
1192 |
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
|
1193 |
ec_print_data(data, 10); |
436 | 1194 |
} |
1195 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1196 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1197 |
fsm->state = ec_fsm_coe_up_request; |
1198 |
} |
|
1199 |
||
1200 |
/*****************************************************************************/ |
|
1201 |
||
1202 |
/** |
|
1203 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1204 |
\todo Timeout behavior |
436 | 1205 |
*/ |
1206 |
||
1207 |
void ec_fsm_coe_up_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1208 |
{ |
|
1209 |
ec_datagram_t *datagram = fsm->datagram; |
|
1210 |
ec_slave_t *slave = fsm->slave; |
|
1211 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1212 |
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
|
1213 |
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
|
1214 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1215 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1216 |
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
|
1217 |
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
|
1218 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1219 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1220 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1221 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1222 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1223 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1224 |
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
|
1225 |
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
|
1226 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1227 |
ec_datagram_print_wc_error(datagram); |
436 | 1228 |
return; |
1229 |
} |
|
1230 |
||
1231 |
fsm->cycles_start = datagram->cycles_sent; |
|
1232 |
||
1233 |
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
|
1234 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1235 |
fsm->state = ec_fsm_coe_up_check; |
1236 |
} |
|
1237 |
||
1238 |
/*****************************************************************************/ |
|
1239 |
||
1240 |
/** |
|
1241 |
CoE state: UP CHECK. |
|
1242 |
*/ |
|
1243 |
||
1244 |
void ec_fsm_coe_up_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1245 |
{ |
|
1246 |
ec_datagram_t *datagram = fsm->datagram; |
|
1247 |
ec_slave_t *slave = fsm->slave; |
|
1248 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1249 |
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
|
1250 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1251 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1252 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1253 |
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
|
1254 |
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
|
1255 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1256 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1257 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1258 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1259 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1260 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1261 |
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
|
1262 |
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
|
1263 |
" 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
|
1264 |
ec_datagram_print_wc_error(datagram); |
436 | 1265 |
return; |
1266 |
} |
|
1267 |
||
1268 |
if (!ec_slave_mbox_check(datagram)) { |
|
1269 |
if (datagram->cycles_received |
|
1270 |
- fsm->cycles_start >= (cycles_t) 100 * cpu_khz) { |
|
1271 |
fsm->state = ec_fsm_coe_error; |
|
814 | 1272 |
EC_ERR("Timeout while checking Sdo upload on slave %i.\n", |
436 | 1273 |
slave->ring_position); |
1274 |
return; |
|
1275 |
} |
|
1276 |
||
1277 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1278 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1279 |
return; |
1280 |
} |
|
1281 |
||
1282 |
// Fetch response |
|
1283 |
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
|
1284 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1285 |
fsm->state = ec_fsm_coe_up_response; |
1286 |
} |
|
1287 |
||
1288 |
/*****************************************************************************/ |
|
1289 |
||
1290 |
/** |
|
1291 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1292 |
\todo Timeout behavior |
436 | 1293 |
*/ |
1294 |
||
1295 |
void ec_fsm_coe_up_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1296 |
{ |
|
1297 |
ec_datagram_t *datagram = fsm->datagram; |
|
1298 |
ec_slave_t *slave = fsm->slave; |
|
1299 |
ec_master_t *master = slave->master; |
|
1300 |
uint8_t *data, mbox_prot; |
|
1301 |
size_t rec_size, data_size; |
|
1302 |
ec_sdo_request_t *request = fsm->request; |
|
1303 |
uint32_t complete_size; |
|
1304 |
unsigned int expedited, size_specified; |
|
1305 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1306 |
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
|
1307 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1308 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1309 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1310 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1311 |
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
|
1312 |
" 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
|
1313 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1314 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1315 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1316 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1317 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1318 |
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
|
1319 |
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
|
1320 |
slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1321 |
ec_datagram_print_wc_error(datagram); |
436 | 1322 |
return; |
1323 |
} |
|
1324 |
||
1325 |
if (!(data = ec_slave_mbox_fetch(slave, datagram, |
|
1326 |
&mbox_prot, &rec_size))) { |
|
1327 |
fsm->state = ec_fsm_coe_error; |
|
1328 |
return; |
|
1329 |
} |
|
1330 |
||
1331 |
if (master->debug_level) { |
|
1332 |
EC_DBG("Upload response:\n"); |
|
1333 |
ec_print_data(data, rec_size); |
|
1334 |
} |
|
1335 |
||
1336 |
if (mbox_prot != 0x03) { // CoE |
|
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1337 |
fsm->state = ec_fsm_coe_error; |
436 | 1338 |
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
|
1339 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1340 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1341 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1342 |
if (rec_size < 3) { |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1343 |
fsm->state = ec_fsm_coe_error; |
814 | 1344 |
EC_ERR("Received currupted Sdo upload response (%u bytes)!\n", rec_size); |
436 | 1345 |
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
|
1346 |
return; |
436 | 1347 |
} |
1348 |
||
814 | 1349 |
if (EC_READ_U16(data) >> 12 == 0x2 && // Sdo request |
1350 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort Sdo transfer request |
|
1351 |
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
|
1352 |
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
|
1353 |
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
|
1354 |
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
|
1355 |
else |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1356 |
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
|
1357 |
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
|
1358 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1359 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1360 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1361 |
// normal or expedited? |
436 | 1362 |
expedited = EC_READ_U8(data + 2) & 0x02; |
1363 |
||
1364 |
if (expedited) { |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1365 |
if (rec_size < 7) { |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1366 |
fsm->state = ec_fsm_coe_error; |
814 | 1367 |
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
|
1368 |
" 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
|
1369 |
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
|
1370 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1371 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1372 |
|
814 | 1373 |
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
|
1374 |
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
|
1375 |
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
|
1376 |
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
|
1377 |
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
|
1378 |
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
|
1379 |
request->index, request->subindex); |
814 | 1380 |
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
|
1381 |
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
|
1382 |
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
|
1383 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1384 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1385 |
|
436 | 1386 |
size_specified = EC_READ_U8(data + 2) & 0x01; |
1387 |
if (size_specified) { |
|
1388 |
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
|
1389 |
} else { |
436 | 1390 |
complete_size = 4; |
1391 |
} |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1392 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1393 |
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
|
1394 |
fsm->state = ec_fsm_coe_error; |
814 | 1395 |
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
|
1396 |
" 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
|
1397 |
ec_print_data(data, rec_size); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1398 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1399 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1400 |
|
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
|
1401 |
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
|
1402 |
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
|
1403 |
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
|
1404 |
} |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1405 |
} else { // normal |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1406 |
if (rec_size < 10) { |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1407 |
fsm->state = ec_fsm_coe_error; |
814 | 1408 |
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
|
1409 |
" 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
|
1410 |
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
|
1411 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1412 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1413 |
|
814 | 1414 |
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
|
1415 |
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
|
1416 |
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
|
1417 |
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
|
1418 |
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
|
1419 |
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
|
1420 |
request->index, request->subindex); |
814 | 1421 |
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
|
1422 |
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
|
1423 |
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
|
1424 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1425 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1426 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1427 |
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
|
1428 |
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
|
1429 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1430 |
if (!complete_size) { |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1431 |
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
|
1432 |
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
|
1433 |
ec_print_data(data, rec_size); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1434 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1435 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1436 |
|
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
|
1437 |
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
|
1438 |
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
|
1439 |
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
|
1440 |
} |
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 |
|
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 |
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
|
1443 |
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
|
1444 |
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
|
1445 |
} |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
1446 |
|
436 | 1447 |
fsm->toggle = 0; |
1448 |
||
1449 |
if (data_size < complete_size) { |
|
814 | 1450 |
EC_WARN("Sdo data incomplete (%i / %i).\n", |
446 | 1451 |
data_size, complete_size); |
1452 |
||
1453 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, |
|
1454 |
0x03, 3))) { |
|
436 | 1455 |
fsm->state = ec_fsm_coe_error; |
1456 |
return; |
|
1457 |
} |
|
1458 |
||
814 | 1459 |
EC_WRITE_U16(data, 0x2 << 12); // Sdo request |
436 | 1460 |
EC_WRITE_U8 (data + 2, (fsm->toggle << 4 // toggle |
1461 |
| 0x3 << 5)); // upload segment request |
|
1462 |
||
1463 |
if (master->debug_level) { |
|
1464 |
EC_DBG("Upload segment request:\n"); |
|
1465 |
ec_print_data(data, 3); |
|
1466 |
} |
|
1467 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1468 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1469 |
fsm->state = ec_fsm_coe_up_seg_request; |
1470 |
return; |
|
1471 |
} |
|
1472 |
} |
|
1473 |
||
874 | 1474 |
if (master->debug_level) { |
1475 |
EC_DBG("Uploaded data:\n"); |
|
1476 |
ec_print_data(request->data, request->data_size); |
|
1477 |
} |
|
1478 |
||
436 | 1479 |
fsm->state = ec_fsm_coe_end; // success |
1480 |
} |
|
1481 |
||
1482 |
/*****************************************************************************/ |
|
1483 |
||
1484 |
/** |
|
1485 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1486 |
\todo Timeout behavior |
436 | 1487 |
*/ |
1488 |
||
1489 |
void ec_fsm_coe_up_seg_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1490 |
{ |
|
1491 |
ec_datagram_t *datagram = fsm->datagram; |
|
1492 |
ec_slave_t *slave = fsm->slave; |
|
1493 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1494 |
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
|
1495 |
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
|
1496 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1497 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1498 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1499 |
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
|
1500 |
" 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
|
1501 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1502 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1503 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1504 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1505 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1506 |
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
|
1507 |
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
|
1508 |
" 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
|
1509 |
ec_datagram_print_wc_error(datagram); |
436 | 1510 |
return; |
1511 |
} |
|
1512 |
||
1513 |
fsm->cycles_start = datagram->cycles_sent; |
|
1514 |
||
1515 |
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
|
1516 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1517 |
fsm->state = ec_fsm_coe_up_seg_check; |
1518 |
} |
|
1519 |
||
1520 |
/*****************************************************************************/ |
|
1521 |
||
1522 |
/** |
|
1523 |
CoE state: UP CHECK. |
|
1524 |
*/ |
|
1525 |
||
1526 |
void ec_fsm_coe_up_seg_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1527 |
{ |
|
1528 |
ec_datagram_t *datagram = fsm->datagram; |
|
1529 |
ec_slave_t *slave = fsm->slave; |
|
1530 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1531 |
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
|
1532 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1533 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1534 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1535 |
fsm->state = ec_fsm_coe_error; |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1536 |
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
|
1537 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
1538 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1539 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1540 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1541 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1542 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1543 |
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
|
1544 |
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
|
1545 |
" 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
|
1546 |
ec_datagram_print_wc_error(datagram); |
436 | 1547 |
return; |
1548 |
} |
|
1549 |
||
1550 |
if (!ec_slave_mbox_check(datagram)) { |
|
1551 |
if (datagram->cycles_received |
|
1552 |
- fsm->cycles_start >= (cycles_t) 100 * cpu_khz) { |
|
1553 |
fsm->state = ec_fsm_coe_error; |
|
814 | 1554 |
EC_ERR("Timeout while checking Sdo upload segment on slave %i.\n", |
436 | 1555 |
slave->ring_position); |
1556 |
return; |
|
1557 |
} |
|
1558 |
||
1559 |
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
|
1560 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1561 |
return; |
1562 |
} |
|
1563 |
||
1564 |
// Fetch response |
|
1565 |
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
|
1566 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1567 |
fsm->state = ec_fsm_coe_up_seg_response; |
1568 |
} |
|
1569 |
||
1570 |
/*****************************************************************************/ |
|
1571 |
||
1572 |
/** |
|
1573 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1574 |
\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
|
1575 |
\todo Check for \a data_size exceeding \a complete_size. |
436 | 1576 |
*/ |
1577 |
||
1578 |
void ec_fsm_coe_up_seg_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1579 |
{ |
|
1580 |
ec_datagram_t *datagram = fsm->datagram; |
|
1581 |
ec_slave_t *slave = fsm->slave; |
|
1582 |
ec_master_t *master = slave->master; |
|
1583 |
uint8_t *data, mbox_prot; |
|
1584 |
size_t rec_size, data_size; |
|
1585 |
ec_sdo_request_t *request = fsm->request; |
|
1586 |
uint32_t seg_size; |
|
1587 |
unsigned int last_segment; |
|
1588 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1589 |
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
|
1590 |
return; // FIXME: request again? |
505
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 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1593 |
fsm->state = ec_fsm_coe_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1594 |
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
|
1595 |
" 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
|
1596 |
slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1597 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1598 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1599 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1600 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1601 |
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
|
1602 |
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
|
1603 |
" 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
|
1604 |
ec_datagram_print_wc_error(datagram); |
436 | 1605 |
return; |
1606 |
} |
|
1607 |
||
1608 |
if (!(data = ec_slave_mbox_fetch(slave, datagram, |
|
1609 |
&mbox_prot, &rec_size))) { |
|
1610 |
fsm->state = ec_fsm_coe_error; |
|
1611 |
return; |
|
1612 |
} |
|
1613 |
||
1614 |
if (master->debug_level) { |
|
1615 |
EC_DBG("Upload segment response:\n"); |
|
1616 |
ec_print_data(data, rec_size); |
|
1617 |
} |
|
1618 |
||
1619 |
if (mbox_prot != 0x03) { // CoE |
|
446 | 1620 |
EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot); |
436 | 1621 |
fsm->state = ec_fsm_coe_error; |
1622 |
return; |
|
1623 |
} |
|
1624 |
||
1625 |
if (rec_size < 10) { |
|
814 | 1626 |
EC_ERR("Received currupted Sdo upload segment response!\n"); |
436 | 1627 |
ec_print_data(data, rec_size); |
1628 |
fsm->state = ec_fsm_coe_error; |
|
1629 |
return; |
|
1630 |
} |
|
1631 |
||
814 | 1632 |
if (EC_READ_U16(data) >> 12 == 0x2 && // Sdo request |
1633 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort Sdo transfer request |
|
1634 |
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
|
1635 |
request->index, request->subindex, slave->ring_position); |
436 | 1636 |
ec_canopen_abort_msg(EC_READ_U32(data + 6)); |
1637 |
fsm->state = ec_fsm_coe_error; |
|
1638 |
return; |
|
1639 |
} |
|
1640 |
||
814 | 1641 |
if (EC_READ_U16(data) >> 12 != 0x3 || // Sdo response |
436 | 1642 |
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
|
1643 |
EC_ERR("Sdo upload 0x%04X:%X failed:\n", request->index, request->subindex); |
814 | 1644 |
EC_ERR("Invalid Sdo upload segment response at slave %i!\n", |
436 | 1645 |
slave->ring_position); |
1646 |
ec_print_data(data, rec_size); |
|
1647 |
fsm->state = ec_fsm_coe_error; |
|
1648 |
return; |
|
1649 |
} |
|
1650 |
||
1651 |
last_segment = EC_READ_U8(data + 2) & 0x01; |
|
1652 |
seg_size = (EC_READ_U8(data + 2) & 0xE) >> 1; |
|
1653 |
data_size = rec_size - 10; |
|
1654 |
||
1655 |
if (data_size != seg_size) { |
|
814 | 1656 |
EC_WARN("Sdo segment data invalid (%i / %i)" |
436 | 1657 |
" - Fragmenting not implemented.\n", |
1658 |
data_size, seg_size); |
|
1659 |
} |
|
1660 |
||
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
|
1661 |
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
|
1662 |
request->data_size += data_size; |
436 | 1663 |
|
1664 |
if (!last_segment) { |
|
1665 |
fsm->toggle = !fsm->toggle; |
|
1666 |
||
1667 |
if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 3))) { |
|
1668 |
fsm->state = ec_fsm_coe_error; |
|
1669 |
return; |
|
1670 |
} |
|
1671 |
||
814 | 1672 |
EC_WRITE_U16(data, 0x2 << 12); // Sdo request |
436 | 1673 |
EC_WRITE_U8 (data + 2, (fsm->toggle << 4 // toggle |
1674 |
| 0x3 << 5)); // upload segment request |
|
1675 |
||
1676 |
if (master->debug_level) { |
|
1677 |
EC_DBG("Upload segment request:\n"); |
|
1678 |
ec_print_data(data, 3); |
|
1679 |
} |
|
1680 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1681 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1682 |
fsm->state = ec_fsm_coe_up_seg_request; |
1683 |
return; |
|
1684 |
} |
|
1685 |
||
874 | 1686 |
if (master->debug_level) { |
1687 |
EC_DBG("Uploaded data:\n"); |
|
1688 |
ec_print_data(request->data, request->data_size); |
|
1689 |
} |
|
1690 |
||
436 | 1691 |
fsm->state = ec_fsm_coe_end; // success |
1692 |
} |
|
1693 |
||
1694 |
/*****************************************************************************/ |
|
1695 |
||
1696 |
/** |
|
1697 |
State: ERROR. |
|
1698 |
*/ |
|
1699 |
||
1700 |
void ec_fsm_coe_error(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1701 |
{ |
|
1702 |
} |
|
1703 |
||
1704 |
/*****************************************************************************/ |
|
1705 |
||
1706 |
/** |
|
1707 |
State: END. |
|
1708 |
*/ |
|
1709 |
||
1710 |
void ec_fsm_coe_end(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1711 |
{ |
|
1712 |
} |
|
1713 |
||
1714 |
/*****************************************************************************/ |