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