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