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