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