author | Florian Pose <fp@igh-essen.com> |
Thu, 16 Sep 2010 09:08:11 +0200 | |
changeset 1961 | 48f536aefc18 |
parent 1931 | 831f2d34664c |
child 1948 | fa1c4fb0a8da |
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 |
* |
|
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1339
diff
changeset
|
22 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1339
diff
changeset
|
23 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1339
diff
changeset
|
24 |
* The license mentioned above concerns the source code only. Using the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1339
diff
changeset
|
25 |
* EtherCAT technology and brand is only permitted in compliance with the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1339
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
436 | 27 |
* |
28 |
*****************************************************************************/ |
|
29 |
||
30 |
/** |
|
31 |
\file |
|
32 |
EtherCAT CoE state machines. |
|
33 |
*/ |
|
34 |
||
35 |
/*****************************************************************************/ |
|
36 |
||
37 |
#include "globals.h" |
|
38 |
#include "master.h" |
|
39 |
#include "mailbox.h" |
|
40 |
#include "fsm_coe.h" |
|
41 |
||
42 |
/*****************************************************************************/ |
|
43 |
||
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
44 |
/** 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
|
45 |
*/ |
1794
94e0e1756dec
Reduced CoE timeouts to 1000 ms.
Florian Pose <fp@igh-essen.com>
parents:
1793
diff
changeset
|
46 |
#define EC_FSM_COE_DICT_TIMEOUT 1000 |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
47 |
|
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
48 |
/** CoE download request header size. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
49 |
*/ |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
50 |
#define EC_COE_DOWN_REQ_HEADER_SIZE 10 |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
51 |
|
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
52 |
/** CoE download segment request header size. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
53 |
*/ |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
54 |
#define EC_COE_DOWN_SEG_REQ_HEADER_SIZE 3 |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
55 |
|
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
56 |
/** Minimum size of download segment. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
57 |
*/ |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
58 |
#define EC_COE_DOWN_SEG_MIN_DATA_SIZE 7 |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
59 |
|
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
60 |
/** Enable debug output for CoE retries. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
61 |
*/ |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
62 |
#define DEBUG_RETRIES 0 |
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
63 |
|
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
64 |
/** Enable warning output if transfers take too long. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
65 |
*/ |
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
66 |
#define DEBUG_LONG 0 |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
67 |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
68 |
/*****************************************************************************/ |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
69 |
|
436 | 70 |
void ec_fsm_coe_dict_start(ec_fsm_coe_t *); |
71 |
void ec_fsm_coe_dict_request(ec_fsm_coe_t *); |
|
72 |
void ec_fsm_coe_dict_check(ec_fsm_coe_t *); |
|
73 |
void ec_fsm_coe_dict_response(ec_fsm_coe_t *); |
|
74 |
void ec_fsm_coe_dict_desc_request(ec_fsm_coe_t *); |
|
75 |
void ec_fsm_coe_dict_desc_check(ec_fsm_coe_t *); |
|
76 |
void ec_fsm_coe_dict_desc_response(ec_fsm_coe_t *); |
|
77 |
void ec_fsm_coe_dict_entry_request(ec_fsm_coe_t *); |
|
78 |
void ec_fsm_coe_dict_entry_check(ec_fsm_coe_t *); |
|
79 |
void ec_fsm_coe_dict_entry_response(ec_fsm_coe_t *); |
|
80 |
||
81 |
void ec_fsm_coe_down_start(ec_fsm_coe_t *); |
|
82 |
void ec_fsm_coe_down_request(ec_fsm_coe_t *); |
|
83 |
void ec_fsm_coe_down_check(ec_fsm_coe_t *); |
|
84 |
void ec_fsm_coe_down_response(ec_fsm_coe_t *); |
|
1562 | 85 |
void ec_fsm_coe_down_seg_check(ec_fsm_coe_t *); |
86 |
void ec_fsm_coe_down_seg_response(ec_fsm_coe_t *); |
|
436 | 87 |
|
88 |
void ec_fsm_coe_up_start(ec_fsm_coe_t *); |
|
89 |
void ec_fsm_coe_up_request(ec_fsm_coe_t *); |
|
90 |
void ec_fsm_coe_up_check(ec_fsm_coe_t *); |
|
91 |
void ec_fsm_coe_up_response(ec_fsm_coe_t *); |
|
92 |
void ec_fsm_coe_up_seg_request(ec_fsm_coe_t *); |
|
93 |
void ec_fsm_coe_up_seg_check(ec_fsm_coe_t *); |
|
94 |
void ec_fsm_coe_up_seg_response(ec_fsm_coe_t *); |
|
95 |
||
96 |
void ec_fsm_coe_end(ec_fsm_coe_t *); |
|
97 |
void ec_fsm_coe_error(ec_fsm_coe_t *); |
|
98 |
||
99 |
/*****************************************************************************/ |
|
100 |
||
101 |
/** |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
102 |
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
|
103 |
The "abort SDO transfer request" supplies an abort code, |
436 | 104 |
which can be translated to clear text. This table does |
105 |
the mapping of the codes and messages. |
|
106 |
*/ |
|
107 |
||
108 |
const ec_code_msg_t sdo_abort_messages[] = { |
|
109 |
{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
|
110 |
{0x05040000, "SDO protocol timeout"}, |
436 | 111 |
{0x05040001, "Client/Server command specifier not valid or unknown"}, |
112 |
{0x05040005, "Out of memory"}, |
|
113 |
{0x06010000, "Unsupported access to an object"}, |
|
114 |
{0x06010001, "Attempt to read a write-only object"}, |
|
115 |
{0x06010002, "Attempt to write a read-only object"}, |
|
116 |
{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
|
117 |
{0x06040041, "The object cannot be mapped into the PDO"}, |
436 | 118 |
{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
|
119 |
" exceed the PDO length"}, |
436 | 120 |
{0x06040043, "General parameter incompatibility reason"}, |
121 |
{0x06040047, "Gerneral internal incompatibility in device"}, |
|
122 |
{0x06060000, "Access failure due to a hardware error"}, |
|
123 |
{0x06070010, "Data type does not match, length of service parameter does" |
|
124 |
" not match"}, |
|
125 |
{0x06070012, "Data type does not match, length of service parameter too" |
|
126 |
" high"}, |
|
127 |
{0x06070013, "Data type does not match, length of service parameter too" |
|
128 |
" low"}, |
|
129 |
{0x06090011, "Subindex does not exist"}, |
|
130 |
{0x06090030, "Value range of parameter exceeded"}, |
|
131 |
{0x06090031, "Value of parameter written too high"}, |
|
132 |
{0x06090032, "Value of parameter written too low"}, |
|
133 |
{0x06090036, "Maximum value is less than minimum value"}, |
|
134 |
{0x08000000, "General error"}, |
|
135 |
{0x08000020, "Data cannot be transferred or stored to the application"}, |
|
136 |
{0x08000021, "Data cannot be transferred or stored to the application" |
|
137 |
" because of local control"}, |
|
138 |
{0x08000022, "Data cannot be transferred or stored to the application" |
|
139 |
" because of the present device state"}, |
|
140 |
{0x08000023, "Object dictionary dynamic generation fails or no object" |
|
141 |
" dictionary is present"}, |
|
142 |
{} |
|
143 |
}; |
|
144 |
||
145 |
/*****************************************************************************/ |
|
146 |
||
1921 | 147 |
/** Outputs an SDO abort message. |
148 |
*/ |
|
149 |
void ec_canopen_abort_msg(const ec_slave_t *slave, uint32_t abort_code) |
|
436 | 150 |
{ |
151 |
const ec_code_msg_t *abort_msg; |
|
152 |
||
153 |
for (abort_msg = sdo_abort_messages; abort_msg->code; abort_msg++) { |
|
154 |
if (abort_msg->code == abort_code) { |
|
1921 | 155 |
EC_SLAVE_ERR(slave, "SDO abort message 0x%08X: \"%s\".\n", |
436 | 156 |
abort_msg->code, abort_msg->message); |
157 |
return; |
|
158 |
} |
|
159 |
} |
|
160 |
||
1921 | 161 |
EC_SLAVE_ERR(slave, "Unknown SDO abort code 0x%08X.\n", abort_code); |
436 | 162 |
} |
163 |
||
164 |
/*****************************************************************************/ |
|
165 |
||
166 |
/** |
|
167 |
Constructor. |
|
168 |
*/ |
|
169 |
||
170 |
void ec_fsm_coe_init(ec_fsm_coe_t *fsm, /**< finite state machine */ |
|
171 |
ec_datagram_t *datagram /**< datagram */ |
|
172 |
) |
|
173 |
{ |
|
174 |
fsm->state = NULL; |
|
175 |
fsm->datagram = datagram; |
|
176 |
} |
|
177 |
||
178 |
/*****************************************************************************/ |
|
179 |
||
180 |
/** |
|
181 |
Destructor. |
|
182 |
*/ |
|
183 |
||
184 |
void ec_fsm_coe_clear(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
185 |
{ |
|
186 |
} |
|
187 |
||
188 |
/*****************************************************************************/ |
|
189 |
||
190 |
/** |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
191 |
Starts reading a slaves' SDO dictionary. |
436 | 192 |
*/ |
193 |
||
194 |
void ec_fsm_coe_dictionary(ec_fsm_coe_t *fsm, /**< finite state machine */ |
|
195 |
ec_slave_t *slave /**< EtherCAT slave */ |
|
196 |
) |
|
197 |
{ |
|
198 |
fsm->slave = slave; |
|
199 |
fsm->state = ec_fsm_coe_dict_start; |
|
200 |
} |
|
201 |
||
202 |
/*****************************************************************************/ |
|
203 |
||
204 |
/** |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
205 |
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
|
206 |
*/ |
233e32f428e1
Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents:
854
diff
changeset
|
207 |
|
233e32f428e1
Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents:
854
diff
changeset
|
208 |
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
|
209 |
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
|
210 |
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
|
211 |
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
|
212 |
) |
436 | 213 |
{ |
214 |
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
|
215 |
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
|
216 |
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
|
217 |
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
|
218 |
else |
233e32f428e1
Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents:
854
diff
changeset
|
219 |
fsm->state = ec_fsm_coe_up_start; |
436 | 220 |
} |
221 |
||
222 |
/*****************************************************************************/ |
|
223 |
||
224 |
/** |
|
225 |
Executes the current state of the state machine. |
|
226 |
\return false, if state machine has terminated |
|
227 |
*/ |
|
228 |
||
229 |
int ec_fsm_coe_exec(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
230 |
{ |
|
231 |
fsm->state(fsm); |
|
232 |
||
233 |
return fsm->state != ec_fsm_coe_end && fsm->state != ec_fsm_coe_error; |
|
234 |
} |
|
235 |
||
236 |
/*****************************************************************************/ |
|
237 |
||
238 |
/** |
|
239 |
Returns, if the state machine terminated with success. |
|
240 |
\return non-zero if successful. |
|
241 |
*/ |
|
242 |
||
243 |
int ec_fsm_coe_success(ec_fsm_coe_t *fsm /**< Finite state machine */) |
|
244 |
{ |
|
245 |
return fsm->state == ec_fsm_coe_end; |
|
246 |
} |
|
247 |
||
895
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 |
|
1092 | 250 |
/** Check if the received data are a CoE emergency request. |
251 |
* |
|
252 |
* If the check is positive, the emergency request is output. |
|
253 |
* |
|
254 |
* \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
|
255 |
*/ |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
256 |
int ec_fsm_coe_check_emergency( |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
257 |
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
|
258 |
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
|
259 |
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
|
260 |
) |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
261 |
{ |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
262 |
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
|
263 |
return 0; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
264 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
265 |
if (size < 10) { |
1921 | 266 |
EC_SLAVE_WARN(fsm->slave, "Received incomplete CoE Emergency" |
267 |
" request:\n"); |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
268 |
ec_print_data(data, size); |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
269 |
return 1; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
270 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
271 |
|
1921 | 272 |
EC_SLAVE_WARN(fsm->slave, "CoE Emergency Request received:\n" |
273 |
"Error code 0x%04X, Error register 0x%02X, data:\n", |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
274 |
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
|
275 |
ec_print_data(data + 5, 5); |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
276 |
return 1; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
277 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
278 |
|
436 | 279 |
/****************************************************************************** |
280 |
* CoE dictionary state machine |
|
281 |
*****************************************************************************/ |
|
282 |
||
283 |
/** |
|
284 |
CoE state: DICT START. |
|
285 |
*/ |
|
286 |
||
287 |
void ec_fsm_coe_dict_start(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
288 |
{ |
|
289 |
ec_datagram_t *datagram = fsm->datagram; |
|
290 |
ec_slave_t *slave = fsm->slave; |
|
291 |
uint8_t *data; |
|
292 |
||
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
293 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
1921 | 294 |
EC_SLAVE_ERR(slave, "Slave does not support CoE!\n"); |
825
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
295 |
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
|
296 |
return; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
297 |
} |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
298 |
|
1219
aa030fb1e980
Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents:
1169
diff
changeset
|
299 |
if (slave->sii.has_general && !slave->sii.coe_details.enable_sdo_info) { |
1921 | 300 |
EC_SLAVE_ERR(slave, "Slave does not support" |
301 |
" 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
|
302 |
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
|
303 |
return; |
aa030fb1e980
Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents:
1169
diff
changeset
|
304 |
} |
aa030fb1e980
Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents:
1169
diff
changeset
|
305 |
|
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
306 |
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
|
307 |
if (IS_ERR(data)) { |
436 | 308 |
fsm->state = ec_fsm_coe_error; |
309 |
return; |
|
310 |
} |
|
311 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
312 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 313 |
EC_WRITE_U8 (data + 2, 0x01); // Get OD List Request |
314 |
EC_WRITE_U8 (data + 3, 0x00); |
|
315 |
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
|
316 |
EC_WRITE_U16(data + 6, 0x0001); // deliver all SDOs! |
436 | 317 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
318 |
fsm->retries = EC_FSM_RETRIES; |
436 | 319 |
fsm->state = ec_fsm_coe_dict_request; |
320 |
} |
|
321 |
||
322 |
/*****************************************************************************/ |
|
323 |
||
324 |
/** |
|
325 |
CoE state: DICT REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
326 |
\todo Timeout behavior |
436 | 327 |
*/ |
328 |
||
329 |
void ec_fsm_coe_dict_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
330 |
{ |
|
331 |
ec_datagram_t *datagram = fsm->datagram; |
|
332 |
ec_slave_t *slave = fsm->slave; |
|
333 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
334 |
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
|
335 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
336 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
337 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
338 |
fsm->state = ec_fsm_coe_error; |
1921 | 339 |
EC_SLAVE_ERR(slave, "Failed to receive CoE dictionary" |
340 |
" request datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
341 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
342 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
343 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
344 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
345 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
346 |
fsm->state = ec_fsm_coe_error; |
1921 | 347 |
EC_SLAVE_ERR(slave, "Reception of CoE dictionary request failed: "); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
348 |
ec_datagram_print_wc_error(datagram); |
436 | 349 |
return; |
350 |
} |
|
351 |
||
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
352 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 353 |
|
354 |
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
|
355 |
fsm->retries = EC_FSM_RETRIES; |
436 | 356 |
fsm->state = ec_fsm_coe_dict_check; |
357 |
} |
|
358 |
||
359 |
/*****************************************************************************/ |
|
360 |
||
361 |
/** |
|
362 |
CoE state: DICT CHECK. |
|
363 |
*/ |
|
364 |
||
365 |
void ec_fsm_coe_dict_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
366 |
{ |
|
367 |
ec_datagram_t *datagram = fsm->datagram; |
|
368 |
ec_slave_t *slave = fsm->slave; |
|
369 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
370 |
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
|
371 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
372 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
373 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
374 |
fsm->state = ec_fsm_coe_error; |
1921 | 375 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: "); |
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
376 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
377 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
378 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
379 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
380 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
381 |
fsm->state = ec_fsm_coe_error; |
1921 | 382 |
EC_SLAVE_ERR(slave,"Reception of CoE mailbox check" |
383 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
384 |
ec_datagram_print_wc_error(datagram); |
436 | 385 |
return; |
386 |
} |
|
387 |
||
388 |
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
|
389 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
390 |
(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
|
391 |
if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) { |
436 | 392 |
fsm->state = ec_fsm_coe_error; |
1921 | 393 |
EC_SLAVE_ERR(slave, "Timeout while waiting for" |
394 |
" SDO dictionary list response.\n"); |
|
436 | 395 |
return; |
396 |
} |
|
397 |
||
398 |
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
|
399 |
fsm->retries = EC_FSM_RETRIES; |
436 | 400 |
return; |
401 |
} |
|
402 |
||
403 |
// Fetch response |
|
404 |
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
|
405 |
fsm->retries = EC_FSM_RETRIES; |
436 | 406 |
fsm->state = ec_fsm_coe_dict_response; |
407 |
} |
|
408 |
||
409 |
/*****************************************************************************/ |
|
410 |
||
411 |
/** |
|
412 |
CoE state: DICT RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
413 |
\todo Timeout behavior |
436 | 414 |
*/ |
415 |
||
416 |
void ec_fsm_coe_dict_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
417 |
{ |
|
418 |
ec_datagram_t *datagram = fsm->datagram; |
|
419 |
ec_slave_t *slave = fsm->slave; |
|
420 |
uint8_t *data, mbox_prot; |
|
421 |
size_t rec_size; |
|
422 |
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
|
423 |
uint16_t sdo_index, fragments_left; |
436 | 424 |
ec_sdo_t *sdo; |
425 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
426 |
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
|
427 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
428 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
429 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
430 |
fsm->state = ec_fsm_coe_error; |
1921 | 431 |
EC_SLAVE_ERR(slave, "Failed to receive CoE dictionary" |
432 |
" response datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
433 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
434 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
435 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
436 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
437 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
438 |
fsm->state = ec_fsm_coe_error; |
1921 | 439 |
EC_SLAVE_ERR(slave, "Reception of CoE dictionary response failed: "); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
440 |
ec_datagram_print_wc_error(datagram); |
436 | 441 |
return; |
442 |
} |
|
443 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
444 |
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
|
445 |
if (IS_ERR(data)) { |
436 | 446 |
fsm->state = ec_fsm_coe_error; |
447 |
return; |
|
448 |
} |
|
449 |
||
450 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 451 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
452 |
mbox_prot); |
|
436 | 453 |
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
|
454 |
return; |
436 | 455 |
} |
456 |
||
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
457 |
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
|
458 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
459 |
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
|
460 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
461 |
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
|
462 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
463 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
464 |
|
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
|
465 |
if (rec_size < 3) { |
1921 | 466 |
EC_SLAVE_ERR(slave, "Received corrupted SDO dictionary response" |
467 |
" (size %zu).\n", 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
|
468 |
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
|
469 |
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
|
470 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
471 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
472 |
if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information |
436 | 473 |
(EC_READ_U8(data + 2) & 0x7F) == 0x07) { // error response |
1921 | 474 |
EC_SLAVE_ERR(slave, "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
|
475 |
if (rec_size < 10) { |
1921 | 476 |
EC_SLAVE_ERR(slave, "Incomplete SDO information" |
477 |
" 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
|
478 |
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
|
479 |
} else { |
1921 | 480 |
ec_canopen_abort_msg(slave, EC_READ_U32(data + 6)); |
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
|
481 |
} |
436 | 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 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
486 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
436 | 487 |
(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
|
488 |
if (fsm->slave->master->debug_level) { |
1921 | 489 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO list response!" |
490 |
" Retrying...\n"); |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
491 |
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
|
492 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
493 |
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
|
494 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
495 |
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
|
496 |
return; |
436 | 497 |
} |
498 |
||
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
|
499 |
if (rec_size < 8 || rec_size % 2) { |
1921 | 500 |
EC_SLAVE_ERR(slave, "Invalid data size %zu!\n", rec_size); |
436 | 501 |
ec_print_data(data, rec_size); |
502 |
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
|
503 |
return; |
436 | 504 |
} |
505 |
||
506 |
sdo_count = (rec_size - 8) / 2; |
|
507 |
||
508 |
for (i = 0; i < sdo_count; i++) { |
|
509 |
sdo_index = EC_READ_U16(data + 8 + i * 2); |
|
510 |
if (!sdo_index) { |
|
1921 | 511 |
EC_SLAVE_DBG(slave, 1, "SDO dictionary contains index 0x0000.\n"); |
436 | 512 |
continue; |
513 |
} |
|
514 |
||
998
05a24788f3b2
Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents:
992
diff
changeset
|
515 |
if (!(sdo = (ec_sdo_t *) kmalloc(sizeof(ec_sdo_t), GFP_KERNEL))) { |
1921 | 516 |
EC_SLAVE_ERR(slave, "Failed to allocate memory for SDO!\n"); |
436 | 517 |
fsm->state = ec_fsm_coe_error; |
518 |
return; |
|
519 |
} |
|
520 |
||
992
50a44cbd30af
Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents:
991
diff
changeset
|
521 |
ec_sdo_init(sdo, slave, sdo_index); |
436 | 522 |
list_add_tail(&sdo->list, &slave->sdo_dictionary); |
523 |
} |
|
524 |
||
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
525 |
fragments_left = EC_READ_U16(data + 4); |
1923 | 526 |
if (fragments_left) { |
1921 | 527 |
EC_SLAVE_DBG(slave, 1, "SDO list fragments left: %u\n", |
528 |
fragments_left); |
|
529 |
} |
|
530 |
||
531 |
if (EC_READ_U8(data + 2) & 0x80 || fragments_left) { |
|
532 |
// 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
|
533 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 534 |
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
|
535 |
fsm->retries = EC_FSM_RETRIES; |
436 | 536 |
fsm->state = ec_fsm_coe_dict_check; |
537 |
return; |
|
538 |
} |
|
539 |
||
540 |
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
|
541 |
// no SDOs in dictionary. finished. |
436 | 542 |
fsm->state = ec_fsm_coe_end; // success |
543 |
return; |
|
544 |
} |
|
545 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
546 |
// fetch SDO descriptions |
436 | 547 |
fsm->sdo = list_entry(slave->sdo_dictionary.next, ec_sdo_t, list); |
548 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
549 |
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
|
550 |
if (IS_ERR(data)) { |
436 | 551 |
fsm->state = ec_fsm_coe_error; |
552 |
return; |
|
553 |
} |
|
554 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
555 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 556 |
EC_WRITE_U8 (data + 2, 0x03); // Get object description request |
557 |
EC_WRITE_U8 (data + 3, 0x00); |
|
558 |
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
|
559 |
EC_WRITE_U16(data + 6, fsm->sdo->index); // SDO index |
436 | 560 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
561 |
fsm->retries = EC_FSM_RETRIES; |
436 | 562 |
fsm->state = ec_fsm_coe_dict_desc_request; |
563 |
} |
|
564 |
||
565 |
/*****************************************************************************/ |
|
566 |
||
567 |
/** |
|
568 |
CoE state: DICT DESC REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
569 |
\todo Timeout behavior |
436 | 570 |
*/ |
571 |
||
572 |
void ec_fsm_coe_dict_desc_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
573 |
{ |
|
574 |
ec_datagram_t *datagram = fsm->datagram; |
|
575 |
ec_slave_t *slave = fsm->slave; |
|
576 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
577 |
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
|
578 |
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
|
579 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
580 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
581 |
fsm->state = ec_fsm_coe_error; |
1921 | 582 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO" |
583 |
" description request datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
584 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
585 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
586 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
587 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
588 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
589 |
fsm->state = ec_fsm_coe_error; |
1921 | 590 |
EC_SLAVE_ERR(slave, "Reception of CoE SDO description" |
591 |
" request failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
592 |
ec_datagram_print_wc_error(datagram); |
436 | 593 |
return; |
594 |
} |
|
595 |
||
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
596 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 597 |
|
598 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
599 |
fsm->retries = EC_FSM_RETRIES; |
436 | 600 |
fsm->state = ec_fsm_coe_dict_desc_check; |
601 |
} |
|
602 |
||
603 |
/*****************************************************************************/ |
|
604 |
||
605 |
/** |
|
606 |
CoE state: DICT DESC CHECK. |
|
607 |
*/ |
|
608 |
||
609 |
void ec_fsm_coe_dict_desc_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
610 |
{ |
|
611 |
ec_datagram_t *datagram = fsm->datagram; |
|
612 |
ec_slave_t *slave = fsm->slave; |
|
613 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
614 |
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
|
615 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
616 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
617 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
618 |
fsm->state = ec_fsm_coe_error; |
1921 | 619 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: "); |
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
620 |
ec_datagram_print_state(datagram); |
436 | 621 |
return; |
622 |
} |
|
623 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
624 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
625 |
fsm->state = ec_fsm_coe_error; |
1921 | 626 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
627 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
628 |
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
|
629 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
630 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
631 |
|
436 | 632 |
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
|
633 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
634 |
(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
|
635 |
if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) { |
436 | 636 |
fsm->state = ec_fsm_coe_error; |
1921 | 637 |
EC_SLAVE_ERR(slave, "Timeout while waiting for" |
638 |
" SDO 0x%04x object description response.\n", |
|
639 |
fsm->sdo->index); |
|
436 | 640 |
return; |
641 |
} |
|
642 |
||
643 |
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
|
644 |
fsm->retries = EC_FSM_RETRIES; |
436 | 645 |
return; |
646 |
} |
|
647 |
||
648 |
// Fetch response |
|
649 |
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
|
650 |
fsm->retries = EC_FSM_RETRIES; |
436 | 651 |
fsm->state = ec_fsm_coe_dict_desc_response; |
652 |
} |
|
653 |
||
654 |
/*****************************************************************************/ |
|
655 |
||
656 |
/** |
|
657 |
CoE state: DICT DESC RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
658 |
\todo Timeout behavior |
436 | 659 |
*/ |
660 |
||
661 |
void ec_fsm_coe_dict_desc_response(ec_fsm_coe_t *fsm |
|
662 |
/**< finite state machine */) |
|
663 |
{ |
|
664 |
ec_datagram_t *datagram = fsm->datagram; |
|
665 |
ec_slave_t *slave = fsm->slave; |
|
666 |
ec_sdo_t *sdo = fsm->sdo; |
|
667 |
uint8_t *data, mbox_prot; |
|
668 |
size_t rec_size, name_size; |
|
669 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
670 |
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
|
671 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
672 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
673 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
674 |
fsm->state = ec_fsm_coe_error; |
1921 | 675 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO description" |
676 |
" response datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
677 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
678 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
679 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
680 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
681 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
682 |
fsm->state = ec_fsm_coe_error; |
1921 | 683 |
EC_SLAVE_ERR(slave, "Reception of CoE SDO description" |
684 |
" response failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
685 |
ec_datagram_print_wc_error(datagram); |
436 | 686 |
return; |
687 |
} |
|
688 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
689 |
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
|
690 |
if (IS_ERR(data)) { |
436 | 691 |
fsm->state = ec_fsm_coe_error; |
692 |
return; |
|
693 |
} |
|
694 |
||
695 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 696 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
697 |
mbox_prot); |
|
436 | 698 |
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
|
699 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
700 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
701 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
702 |
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
|
703 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
704 |
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
|
705 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
706 |
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
|
707 |
return; |
436 | 708 |
} |
709 |
||
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
|
710 |
if (rec_size < 3) { |
1921 | 711 |
EC_SLAVE_ERR(slave, "Received corrupted SDO description response" |
712 |
" (size %zu).\n", 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
|
713 |
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
|
714 |
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
|
715 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
716 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
717 |
if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information |
436 | 718 |
(EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response |
1921 | 719 |
EC_SLAVE_ERR(slave, "SDO information error response while" |
720 |
" fetching SDO 0x%04X!\n", sdo->index); |
|
721 |
ec_canopen_abort_msg(slave, EC_READ_U32(data + 6)); |
|
436 | 722 |
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
|
723 |
return; |
436 | 724 |
} |
725 |
||
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
|
726 |
if (rec_size < 8) { |
1921 | 727 |
EC_SLAVE_ERR(slave, "Received corrupted SDO" |
728 |
" description response (size %zu).\n", 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
|
729 |
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
|
730 |
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
|
731 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
732 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
733 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
436 | 734 |
(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
|
735 |
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
|
736 |
if (fsm->slave->master->debug_level) { |
1921 | 737 |
EC_SLAVE_DBG(slave, 1, "Invalid object description response while" |
738 |
" fetching SDO 0x%04X!\n", sdo->index); |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
739 |
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
|
740 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
741 |
// check for CoE response again |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
742 |
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
|
743 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
744 |
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
|
745 |
return; |
436 | 746 |
} |
747 |
||
748 |
if (rec_size < 12) { |
|
1921 | 749 |
EC_SLAVE_ERR(slave, "Invalid data size!\n"); |
436 | 750 |
ec_print_data(data, rec_size); |
751 |
fsm->state = ec_fsm_coe_error; |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
752 |
return; |
436 | 753 |
} |
754 |
||
962
ea83a7aab57a
Renamed subindices to max_subindex.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
755 |
sdo->max_subindex = EC_READ_U8(data + 10); |
436 | 756 |
sdo->object_code = EC_READ_U8(data + 11); |
757 |
||
758 |
name_size = rec_size - 12; |
|
759 |
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
|
760 |
if (!(sdo->name = kmalloc(name_size + 1, GFP_KERNEL))) { |
1921 | 761 |
EC_SLAVE_ERR(slave, "Failed to allocate SDO name!\n"); |
436 | 762 |
fsm->state = ec_fsm_coe_error; |
763 |
return; |
|
764 |
} |
|
765 |
||
766 |
memcpy(sdo->name, data + 12, name_size); |
|
767 |
sdo->name[name_size] = 0; |
|
768 |
} |
|
769 |
||
770 |
if (EC_READ_U8(data + 2) & 0x80) { |
|
1921 | 771 |
EC_SLAVE_ERR(slave, "Fragment follows (not implemented)!\n"); |
436 | 772 |
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
|
773 |
return; |
436 | 774 |
} |
775 |
||
776 |
// start fetching entries |
|
777 |
||
778 |
fsm->subindex = 0; |
|
779 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
780 |
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
|
781 |
if (IS_ERR(data)) { |
436 | 782 |
fsm->state = ec_fsm_coe_error; |
783 |
return; |
|
784 |
} |
|
785 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
786 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 787 |
EC_WRITE_U8 (data + 2, 0x05); // Get entry description request |
788 |
EC_WRITE_U8 (data + 3, 0x00); |
|
789 |
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
|
790 |
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
|
791 |
EC_WRITE_U8 (data + 8, fsm->subindex); // SDO subindex |
1382
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
792 |
EC_WRITE_U8 (data + 9, 0x01); // value info (access rights only) |
436 | 793 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
794 |
fsm->retries = EC_FSM_RETRIES; |
436 | 795 |
fsm->state = ec_fsm_coe_dict_entry_request; |
796 |
} |
|
797 |
||
798 |
/*****************************************************************************/ |
|
799 |
||
800 |
/** |
|
801 |
CoE state: DICT ENTRY REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
802 |
\todo Timeout behavior |
436 | 803 |
*/ |
804 |
||
805 |
void ec_fsm_coe_dict_entry_request(ec_fsm_coe_t *fsm |
|
806 |
/**< finite state machine */) |
|
807 |
{ |
|
808 |
ec_datagram_t *datagram = fsm->datagram; |
|
809 |
ec_slave_t *slave = fsm->slave; |
|
810 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
811 |
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
|
812 |
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
|
813 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
814 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
815 |
fsm->state = ec_fsm_coe_error; |
1921 | 816 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO entry" |
817 |
" request datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
818 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
819 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
820 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
821 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
822 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
823 |
fsm->state = ec_fsm_coe_error; |
1921 | 824 |
EC_SLAVE_ERR(slave, "Reception of CoE SDO entry request failed: "); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
825 |
ec_datagram_print_wc_error(datagram); |
436 | 826 |
return; |
827 |
} |
|
828 |
||
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
829 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 830 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
831 |
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
|
832 |
fsm->retries = EC_FSM_RETRIES; |
436 | 833 |
fsm->state = ec_fsm_coe_dict_entry_check; |
834 |
} |
|
835 |
||
836 |
/*****************************************************************************/ |
|
837 |
||
838 |
/** |
|
839 |
CoE state: DICT ENTRY CHECK. |
|
840 |
*/ |
|
841 |
||
842 |
void ec_fsm_coe_dict_entry_check(ec_fsm_coe_t *fsm |
|
843 |
/**< finite state machine */) |
|
844 |
{ |
|
845 |
ec_datagram_t *datagram = fsm->datagram; |
|
846 |
ec_slave_t *slave = fsm->slave; |
|
847 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
848 |
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
|
849 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
850 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
851 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
852 |
fsm->state = ec_fsm_coe_error; |
1921 | 853 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: "); |
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
854 |
ec_datagram_print_state(datagram); |
436 | 855 |
return; |
856 |
} |
|
857 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
858 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
859 |
fsm->state = ec_fsm_coe_error; |
1921 | 860 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
861 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
862 |
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
|
863 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
864 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
865 |
|
436 | 866 |
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
|
867 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
868 |
(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
|
869 |
if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) { |
436 | 870 |
fsm->state = ec_fsm_coe_error; |
1921 | 871 |
EC_SLAVE_ERR(slave, "Timeout while waiting for" |
872 |
" SDO entry 0x%04x:%x description response.\n", |
|
873 |
fsm->sdo->index, fsm->subindex); |
|
436 | 874 |
return; |
875 |
} |
|
876 |
||
877 |
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
|
878 |
fsm->retries = EC_FSM_RETRIES; |
436 | 879 |
return; |
880 |
} |
|
881 |
||
882 |
// Fetch response |
|
883 |
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
|
884 |
fsm->retries = EC_FSM_RETRIES; |
436 | 885 |
fsm->state = ec_fsm_coe_dict_entry_response; |
886 |
} |
|
887 |
||
888 |
/*****************************************************************************/ |
|
889 |
||
890 |
/** |
|
891 |
CoE state: DICT ENTRY RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
892 |
\todo Timeout behavior |
436 | 893 |
*/ |
894 |
||
895 |
void ec_fsm_coe_dict_entry_response(ec_fsm_coe_t *fsm |
|
896 |
/**< finite state machine */) |
|
897 |
{ |
|
898 |
ec_datagram_t *datagram = fsm->datagram; |
|
899 |
ec_slave_t *slave = fsm->slave; |
|
900 |
ec_sdo_t *sdo = fsm->sdo; |
|
901 |
uint8_t *data, mbox_prot; |
|
902 |
size_t rec_size, data_size; |
|
903 |
ec_sdo_entry_t *entry; |
|
1382
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
904 |
u16 word; |
436 | 905 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
906 |
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
|
907 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
908 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
909 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
910 |
fsm->state = ec_fsm_coe_error; |
1921 | 911 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO" |
912 |
" description response datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
913 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
914 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
915 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
916 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
917 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
918 |
fsm->state = ec_fsm_coe_error; |
1921 | 919 |
EC_SLAVE_ERR(slave, "Reception of CoE SDO description" |
920 |
" response failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
921 |
ec_datagram_print_wc_error(datagram); |
436 | 922 |
return; |
923 |
} |
|
924 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
925 |
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
|
926 |
if (IS_ERR(data)) { |
436 | 927 |
fsm->state = ec_fsm_coe_error; |
928 |
return; |
|
929 |
} |
|
930 |
||
931 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 932 |
EC_SLAVE_ERR(slave, "Received mailbox protocol" |
933 |
" 0x%02X as response.\n", mbox_prot); |
|
436 | 934 |
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
|
935 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
936 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
937 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
938 |
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
|
939 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
940 |
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
|
941 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
942 |
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
|
943 |
return; |
436 | 944 |
} |
945 |
||
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
|
946 |
if (rec_size < 3) { |
1921 | 947 |
EC_SLAVE_ERR(slave, "Received corrupted SDO entry" |
948 |
" description response (size %zu).\n", 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
|
949 |
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
|
950 |
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
|
951 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
952 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
953 |
if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information |
436 | 954 |
(EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response |
1921 | 955 |
EC_SLAVE_ERR(slave, "SDO information error response while" |
956 |
" fetching SDO entry 0x%04X:%02X!\n", |
|
436 | 957 |
sdo->index, fsm->subindex); |
1921 | 958 |
ec_canopen_abort_msg(slave, EC_READ_U32(data + 6)); |
436 | 959 |
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
|
960 |
return; |
436 | 961 |
} |
962 |
||
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
|
963 |
if (rec_size < 9) { |
1921 | 964 |
EC_SLAVE_ERR(slave, "Received corrupted SDO entry" |
965 |
" description response (size %zu).\n", 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
|
966 |
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
|
967 |
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
|
968 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
969 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
970 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
436 | 971 |
(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
|
972 |
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
|
973 |
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
|
974 |
if (fsm->slave->master->debug_level) { |
1921 | 975 |
EC_SLAVE_DBG(slave, 1, "Invalid entry description response while" |
976 |
" fetching SDO entry 0x%04X:%02X!\n", |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
977 |
sdo->index, fsm->subindex); |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
978 |
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
|
979 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
980 |
// check for CoE response again |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
981 |
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
|
982 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
983 |
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
|
984 |
return; |
436 | 985 |
} |
986 |
||
987 |
if (rec_size < 16) { |
|
1921 | 988 |
EC_SLAVE_ERR(slave, "Invalid data size %zu!\n", rec_size); |
436 | 989 |
ec_print_data(data, rec_size); |
990 |
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
|
991 |
return; |
436 | 992 |
} |
993 |
||
994 |
data_size = rec_size - 16; |
|
995 |
||
996 |
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
|
997 |
kmalloc(sizeof(ec_sdo_entry_t), GFP_KERNEL))) { |
1921 | 998 |
EC_SLAVE_ERR(slave, "Failed to allocate entry!\n"); |
436 | 999 |
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
|
1000 |
return; |
436 | 1001 |
} |
1002 |
||
991
2548ca639b1f
Removed kobject from sdo entry.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
1003 |
ec_sdo_entry_init(entry, sdo, fsm->subindex); |
436 | 1004 |
entry->data_type = EC_READ_U16(data + 10); |
1005 |
entry->bit_length = EC_READ_U16(data + 12); |
|
1006 |
||
1382
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1007 |
// read access rights |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1008 |
word = EC_READ_U16(data + 14); |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1009 |
entry->read_access[EC_SDO_ENTRY_ACCESS_PREOP] = word & 0x0001; |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1010 |
entry->read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = (word >> 1) & 0x0001; |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1011 |
entry->read_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 2) & 0x0001; |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1012 |
entry->write_access[EC_SDO_ENTRY_ACCESS_PREOP] = (word >> 3) & 0x0001; |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1013 |
entry->write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = (word >> 4) & 0x0001; |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1014 |
entry->write_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 5) & 0x0001; |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1015 |
|
436 | 1016 |
if (data_size) { |
484
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
1017 |
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
|
1018 |
if (!(desc = kmalloc(data_size + 1, GFP_KERNEL))) { |
1921 | 1019 |
EC_SLAVE_ERR(slave, "Failed to allocate SDO entry name!\n"); |
436 | 1020 |
fsm->state = ec_fsm_coe_error; |
1021 |
return; |
|
1022 |
} |
|
484
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
1023 |
memcpy(desc, data + 16, data_size); |
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
1024 |
desc[data_size] = 0; |
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
1025 |
entry->description = desc; |
436 | 1026 |
} |
1027 |
||
1028 |
list_add_tail(&entry->list, &sdo->entries); |
|
1029 |
||
962
ea83a7aab57a
Renamed subindices to max_subindex.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
1030 |
if (fsm->subindex < sdo->max_subindex) { |
436 | 1031 |
fsm->subindex++; |
1032 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1033 |
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
|
1034 |
if (IS_ERR(data)) { |
436 | 1035 |
fsm->state = ec_fsm_coe_error; |
1036 |
return; |
|
1037 |
} |
|
1038 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1039 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 1040 |
EC_WRITE_U8 (data + 2, 0x05); // Get entry description request |
1041 |
EC_WRITE_U8 (data + 3, 0x00); |
|
1042 |
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
|
1043 |
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
|
1044 |
EC_WRITE_U8 (data + 8, fsm->subindex); // SDO subindex |
436 | 1045 |
EC_WRITE_U8 (data + 9, 0x00); // value info (no values) |
1046 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1047 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1048 |
fsm->state = ec_fsm_coe_dict_entry_request; |
1049 |
return; |
|
1050 |
} |
|
1051 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1052 |
// another SDO description to fetch? |
436 | 1053 |
if (fsm->sdo->list.next != &slave->sdo_dictionary) { |
1054 |
fsm->sdo = list_entry(fsm->sdo->list.next, ec_sdo_t, list); |
|
1055 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1056 |
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
|
1057 |
if (IS_ERR(data)) { |
436 | 1058 |
fsm->state = ec_fsm_coe_error; |
1059 |
return; |
|
1060 |
} |
|
1061 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1062 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 1063 |
EC_WRITE_U8 (data + 2, 0x03); // Get object description request |
1064 |
EC_WRITE_U8 (data + 3, 0x00); |
|
1065 |
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
|
1066 |
EC_WRITE_U16(data + 6, fsm->sdo->index); // SDO index |
436 | 1067 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1068 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1069 |
fsm->state = ec_fsm_coe_dict_desc_request; |
1070 |
return; |
|
1071 |
} |
|
1072 |
||
1073 |
fsm->state = ec_fsm_coe_end; |
|
1074 |
} |
|
1075 |
||
1076 |
/****************************************************************************** |
|
1077 |
* CoE state machine |
|
1078 |
*****************************************************************************/ |
|
1079 |
||
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1080 |
/** CoE state: DOWN START. |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1081 |
*/ |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1082 |
void ec_fsm_coe_down_start( |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1083 |
ec_fsm_coe_t *fsm /**< finite state machine */ |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1084 |
) |
436 | 1085 |
{ |
1086 |
ec_datagram_t *datagram = fsm->datagram; |
|
1087 |
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
|
1088 |
ec_sdo_request_t *request = fsm->request; |
436 | 1089 |
uint8_t *data; |
1562 | 1090 |
uint8_t data_set_size; |
436 | 1091 |
|
874 | 1092 |
if (fsm->slave->master->debug_level) { |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1093 |
char subidxstr[10]; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1094 |
if (request->complete_access) { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1095 |
subidxstr[0] = 0x00; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1096 |
} else { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1097 |
sprintf(subidxstr, ":%02X", request->subindex); |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1098 |
} |
1921 | 1099 |
EC_SLAVE_DBG(slave, 1, "Downloading SDO 0x%04X%s.\n", |
1100 |
request->index, subidxstr); |
|
874 | 1101 |
ec_print_data(request->data, request->data_size); |
1102 |
} |
|
436 | 1103 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
1104 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
1921 | 1105 |
EC_SLAVE_ERR(slave, "Slave does not support CoE!\n"); |
825
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1106 |
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
|
1107 |
return; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1108 |
} |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1109 |
|
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1110 |
if (slave->configured_rx_mailbox_size < |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1111 |
EC_MBOX_HEADER_SIZE + EC_COE_DOWN_REQ_HEADER_SIZE) { |
1921 | 1112 |
EC_SLAVE_ERR(slave, "Mailbox too small!\n"); |
1562 | 1113 |
fsm->state = ec_fsm_coe_error; |
1114 |
return; |
|
1115 |
} |
|
1116 |
||
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1117 |
if (request->data_size <= 4) { // use expedited transfer type |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1118 |
data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1119 |
EC_COE_DOWN_REQ_HEADER_SIZE); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1120 |
if (IS_ERR(data)) { |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1121 |
fsm->state = ec_fsm_coe_error; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1122 |
return; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1123 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1124 |
|
1562 | 1125 |
fsm->remaining = 0; |
1126 |
||
1127 |
data_set_size = 4 - request->data_size; |
|
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1128 |
|
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1129 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1130 |
EC_WRITE_U8 (data + 2, (0x3 // size specified, expedited |
1562 | 1131 |
| data_set_size << 2 |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1132 |
| ((request->complete_access ? 1 : 0) << 4) |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1133 |
| 0x1 << 5)); // Download request |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1134 |
EC_WRITE_U16(data + 3, request->index); |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1135 |
EC_WRITE_U8 (data + 5, |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1136 |
request->complete_access ? 0x00 : request->subindex); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1137 |
memcpy(data + 6, request->data, request->data_size); |
1457
ec3ad6641d65
Slightly improved CoE download expedited request.
Florian Pose <fp@igh-essen.com>
parents:
1382
diff
changeset
|
1138 |
memset(data + 6 + request->data_size, 0x00, 4 - request->data_size); |
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1139 |
|
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1140 |
if (slave->master->debug_level) { |
1921 | 1141 |
EC_SLAVE_DBG(slave, 1, "Expedited download request:\n"); |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1142 |
ec_print_data(data, EC_COE_DOWN_REQ_HEADER_SIZE); |
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1143 |
} |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1144 |
} |
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1145 |
else { // request->data_size > 4, use normal transfer type |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1146 |
size_t data_size, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1147 |
max_data_size = |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1148 |
slave->configured_rx_mailbox_size - EC_MBOX_HEADER_SIZE, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1149 |
required_data_size = |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1150 |
EC_COE_DOWN_REQ_HEADER_SIZE + request->data_size; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1151 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1152 |
if (max_data_size < required_data_size) { |
1562 | 1153 |
// segmenting needed |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1154 |
data_size = max_data_size; |
1562 | 1155 |
} else { |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1156 |
data_size = required_data_size; |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1157 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1158 |
|
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1159 |
data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, |
1562 | 1160 |
data_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1161 |
if (IS_ERR(data)) { |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1162 |
fsm->state = ec_fsm_coe_error; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1163 |
return; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1164 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1165 |
|
1562 | 1166 |
fsm->offset = 0; |
1167 |
fsm->remaining = request->data_size; |
|
1168 |
||
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1169 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1170 |
EC_WRITE_U8(data + 2, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1171 |
0x1 // size indicator, normal |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1172 |
| ((request->complete_access ? 1 : 0) << 4) |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1173 |
| 0x1 << 5); // Download request |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1174 |
EC_WRITE_U16(data + 3, request->index); |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1175 |
EC_WRITE_U8 (data + 5, |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1176 |
request->complete_access ? 0x00 : request->subindex); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1177 |
EC_WRITE_U32(data + 6, request->data_size); |
1562 | 1178 |
|
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1179 |
if (data_size > EC_COE_DOWN_REQ_HEADER_SIZE) { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1180 |
size_t segment_size = data_size - EC_COE_DOWN_REQ_HEADER_SIZE; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1181 |
memcpy(data + EC_COE_DOWN_REQ_HEADER_SIZE, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1182 |
request->data, segment_size); |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1183 |
fsm->offset += segment_size; |
1562 | 1184 |
fsm->remaining -= segment_size; |
1185 |
} |
|
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1186 |
|
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1187 |
if (slave->master->debug_level) { |
1921 | 1188 |
EC_SLAVE_DBG(slave, 1, "Normal download request:\n"); |
1562 | 1189 |
ec_print_data(data, data_size); |
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1190 |
} |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1191 |
} |
975
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1192 |
|
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1193 |
fsm->request->jiffies_sent = jiffies; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1194 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1195 |
fsm->state = ec_fsm_coe_down_request; |
1196 |
} |
|
1197 |
||
1198 |
/*****************************************************************************/ |
|
1199 |
||
1200 |
/** |
|
1201 |
CoE state: DOWN REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1202 |
\todo Timeout behavior |
436 | 1203 |
*/ |
1204 |
||
1205 |
void ec_fsm_coe_down_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1206 |
{ |
|
1207 |
ec_datagram_t *datagram = fsm->datagram; |
|
1208 |
ec_slave_t *slave = fsm->slave; |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1209 |
unsigned long diff_ms; |
436 | 1210 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1211 |
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
|
1212 |
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
|
1213 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1214 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1215 |
fsm->state = ec_fsm_coe_error; |
1921 | 1216 |
EC_SLAVE_ERR(slave, "Failed to receive CoE download" |
1217 |
" request datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1218 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1219 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1220 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1221 |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1222 |
diff_ms = (jiffies - fsm->request->jiffies_sent) * 1000 / HZ; |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1223 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1224 |
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
|
1225 |
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
|
1226 |
if (diff_ms < fsm->request->response_timeout) { |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1227 |
#if DEBUG_RETRIES |
1931 | 1228 |
EC_SLAVE_DBG(slave, 1, "Slave did not respond to SDO" |
1229 |
" download request. Retrying after %lu ms...\n", |
|
1230 |
diff_ms); |
|
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1231 |
#endif |
1112
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1232 |
// no response; send request datagram again |
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1233 |
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
|
1234 |
} |
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1235 |
} |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1236 |
fsm->state = ec_fsm_coe_error; |
1921 | 1237 |
EC_SLAVE_ERR(slave, "Reception of CoE download request" |
1931 | 1238 |
" for SDO 0x%04x:%x failed with timeout after %lu ms: ", |
1239 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1240 |
ec_datagram_print_wc_error(datagram); |
436 | 1241 |
return; |
1242 |
} |
|
1243 |
||
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1244 |
#if DEBUG_LONG |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1245 |
if (diff_ms > 200) { |
1931 | 1246 |
EC_SLAVE_WARN(slave, "SDO 0x%04x:%x download took %lu ms.\n", |
1247 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1248 |
} |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1249 |
#endif |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1250 |
|
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1251 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 1252 |
|
1253 |
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
|
1254 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1255 |
fsm->state = ec_fsm_coe_down_check; |
1256 |
} |
|
1257 |
||
1258 |
/*****************************************************************************/ |
|
1259 |
||
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1260 |
/** CoE state: DOWN CHECK. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1261 |
*/ |
436 | 1262 |
void ec_fsm_coe_down_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
1263 |
{ |
|
1264 |
ec_datagram_t *datagram = fsm->datagram; |
|
1265 |
ec_slave_t *slave = fsm->slave; |
|
1266 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1267 |
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
|
1268 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1269 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1270 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1271 |
fsm->state = ec_fsm_coe_error; |
1921 | 1272 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check" |
1273 |
" datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1274 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1275 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1276 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1277 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1278 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1279 |
fsm->state = ec_fsm_coe_error; |
1921 | 1280 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
1281 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1282 |
ec_datagram_print_wc_error(datagram); |
436 | 1283 |
return; |
1284 |
} |
|
1285 |
||
1286 |
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
|
1287 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1288 |
(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
|
1289 |
if (diff_ms >= fsm->request->response_timeout) { |
436 | 1290 |
fsm->state = ec_fsm_coe_error; |
1931 | 1291 |
EC_SLAVE_ERR(slave, "Timeout after %lu ms while waiting" |
1292 |
" for SDO 0x%04x:%x download response.\n", diff_ms, |
|
1921 | 1293 |
fsm->request->index, fsm->request->subindex); |
436 | 1294 |
return; |
1295 |
} |
|
1296 |
||
1297 |
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
|
1298 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1299 |
return; |
1300 |
} |
|
1301 |
||
1302 |
// Fetch response |
|
1303 |
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
|
1304 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1305 |
fsm->state = ec_fsm_coe_down_response; |
1306 |
} |
|
1307 |
||
1308 |
/*****************************************************************************/ |
|
1309 |
||
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1310 |
/** Prepare a download segment request. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1311 |
*/ |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1312 |
void ec_fsm_coe_down_prepare_segment_request( |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1313 |
ec_fsm_coe_t *fsm /**< finite state machine */ |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1314 |
) |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1315 |
{ |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1316 |
ec_datagram_t *datagram = fsm->datagram; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1317 |
ec_slave_t *slave = fsm->slave; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1318 |
ec_sdo_request_t *request = fsm->request; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1319 |
size_t max_segment_size = |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1320 |
slave->configured_rx_mailbox_size |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1321 |
- EC_MBOX_HEADER_SIZE |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1322 |
- EC_COE_DOWN_SEG_REQ_HEADER_SIZE; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1323 |
size_t segment_size, data_size; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1324 |
uint8_t last_segment, seg_data_size, *data; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1325 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1326 |
if (fsm->remaining > max_segment_size) { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1327 |
segment_size = max_segment_size; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1328 |
last_segment = 0; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1329 |
} else { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1330 |
segment_size = fsm->remaining; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1331 |
last_segment = 1; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1332 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1333 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1334 |
if (segment_size > EC_COE_DOWN_SEG_MIN_DATA_SIZE) { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1335 |
seg_data_size = 0x00; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1336 |
data_size = EC_COE_DOWN_SEG_REQ_HEADER_SIZE + segment_size; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1337 |
} else { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1338 |
seg_data_size = EC_COE_DOWN_SEG_MIN_DATA_SIZE - segment_size; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1339 |
data_size = EC_COE_DOWN_SEG_REQ_HEADER_SIZE |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1340 |
+ EC_COE_DOWN_SEG_MIN_DATA_SIZE; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1341 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1342 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1343 |
data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1344 |
data_size); |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1345 |
if (IS_ERR(data)) { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1346 |
fsm->state = ec_fsm_coe_error; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1347 |
return; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1348 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1349 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1350 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1351 |
EC_WRITE_U8(data + 2, (last_segment ? 1 : 0) |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1352 |
| (seg_data_size << 1) |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1353 |
| (fsm->toggle << 4) |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1354 |
| (0x00 << 5)); // Download segment request |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1355 |
memcpy(data + EC_COE_DOWN_SEG_REQ_HEADER_SIZE, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1356 |
request->data + fsm->offset, segment_size); |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1357 |
if (segment_size < EC_COE_DOWN_SEG_MIN_DATA_SIZE) { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1358 |
memset(data + EC_COE_DOWN_SEG_REQ_HEADER_SIZE + segment_size, 0x00, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1359 |
EC_COE_DOWN_SEG_MIN_DATA_SIZE - segment_size); |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1360 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1361 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1362 |
fsm->offset += segment_size; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1363 |
fsm->remaining -= segment_size; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1364 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1365 |
if (slave->master->debug_level) { |
1921 | 1366 |
EC_SLAVE_DBG(slave, 1, "Download segment request:\n"); |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1367 |
ec_print_data(data, data_size); |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1368 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1369 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1370 |
fsm->state = ec_fsm_coe_down_seg_check; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1371 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1372 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1373 |
/*****************************************************************************/ |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1374 |
|
436 | 1375 |
/** |
1376 |
CoE state: DOWN RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1377 |
\todo Timeout behavior |
436 | 1378 |
*/ |
1379 |
||
1380 |
void ec_fsm_coe_down_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1381 |
{ |
|
1382 |
ec_datagram_t *datagram = fsm->datagram; |
|
1383 |
ec_slave_t *slave = fsm->slave; |
|
1384 |
uint8_t *data, mbox_prot; |
|
1385 |
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
|
1386 |
ec_sdo_request_t *request = fsm->request; |
436 | 1387 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1388 |
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
|
1389 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1390 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1391 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1392 |
fsm->state = ec_fsm_coe_error; |
1921 | 1393 |
EC_SLAVE_ERR(slave, "Failed to receive CoE download" |
1394 |
" response datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1395 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1396 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1397 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1398 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1399 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1400 |
fsm->state = ec_fsm_coe_error; |
1921 | 1401 |
EC_SLAVE_ERR(slave, "Reception of CoE download response failed: "); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1402 |
ec_datagram_print_wc_error(datagram); |
436 | 1403 |
return; |
1404 |
} |
|
1405 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1406 |
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
|
1407 |
if (IS_ERR(data)) { |
436 | 1408 |
fsm->state = ec_fsm_coe_error; |
1409 |
return; |
|
1410 |
} |
|
1411 |
||
1412 |
if (mbox_prot != 0x03) { // CoE |
|
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1413 |
fsm->state = ec_fsm_coe_error; |
1921 | 1414 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
1415 |
mbox_prot); |
|
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1416 |
return; |
436 | 1417 |
} |
1418 |
||
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1419 |
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
|
1420 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1421 |
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
|
1422 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1423 |
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
|
1424 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1425 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1426 |
|
975
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1427 |
if (slave->master->debug_level) { |
1921 | 1428 |
EC_SLAVE_DBG(slave, 1, "Download response:\n"); |
975
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1429 |
ec_print_data(data, rec_size); |
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1430 |
} |
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1431 |
|
436 | 1432 |
if (rec_size < 6) { |
1433 |
fsm->state = ec_fsm_coe_error; |
|
1921 | 1434 |
EC_SLAVE_ERR(slave, "Received data are too small (%zu bytes):\n", |
1435 |
rec_size); |
|
436 | 1436 |
ec_print_data(data, rec_size); |
1437 |
return; |
|
1438 |
} |
|
1439 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1440 |
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
|
1441 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1442 |
char subidxstr[10]; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1443 |
fsm->state = ec_fsm_coe_error; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1444 |
if (request->complete_access) { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1445 |
subidxstr[0] = 0x00; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1446 |
} else { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1447 |
sprintf(subidxstr, ":%02X", request->subindex); |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1448 |
} |
1921 | 1449 |
EC_SLAVE_ERR(slave, "SDO download 0x%04X%s (%zu bytes) aborted.\n", |
1450 |
request->index, subidxstr, request->data_size); |
|
436 | 1451 |
if (rec_size < 10) { |
1921 | 1452 |
EC_SLAVE_ERR(slave, "Incomplete abort command:\n"); |
436 | 1453 |
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
|
1454 |
} 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
|
1455 |
fsm->request->abort_code = EC_READ_U32(data + 6); |
1921 | 1456 |
ec_canopen_abort_msg(slave, fsm->request->abort_code); |
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
|
1457 |
} |
436 | 1458 |
return; |
1459 |
} |
|
1460 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1461 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
436 | 1462 |
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
|
1463 |
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
|
1464 |
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
|
1465 |
if (slave->master->debug_level) { |
1921 | 1466 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO download response!" |
1467 |
" Retrying...\n"); |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1468 |
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
|
1469 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1470 |
// check for CoE response again |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1471 |
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
|
1472 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1473 |
fsm->state = ec_fsm_coe_down_check; |
436 | 1474 |
return; |
1475 |
} |
|
1476 |
||
1562 | 1477 |
if (fsm->remaining) { // more segments to download |
1478 |
fsm->toggle = 0; |
|
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1479 |
ec_fsm_coe_down_prepare_segment_request(fsm); |
1562 | 1480 |
} else { |
1481 |
fsm->state = ec_fsm_coe_end; // success |
|
1482 |
} |
|
1483 |
} |
|
1484 |
||
1485 |
/*****************************************************************************/ |
|
1486 |
||
1487 |
/** |
|
1488 |
CoE state: DOWN SEG CHECK. |
|
1489 |
*/ |
|
1490 |
||
1491 |
void ec_fsm_coe_down_seg_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1492 |
{ |
|
1493 |
ec_datagram_t *datagram = fsm->datagram; |
|
1494 |
ec_slave_t *slave = fsm->slave; |
|
1495 |
||
1496 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
|
1497 |
return; |
|
1498 |
||
1499 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
|
1500 |
fsm->state = ec_fsm_coe_error; |
|
1921 | 1501 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: "); |
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1502 |
ec_datagram_print_state(datagram); |
1562 | 1503 |
return; |
1504 |
} |
|
1505 |
||
1506 |
if (datagram->working_counter != 1) { |
|
1507 |
fsm->state = ec_fsm_coe_error; |
|
1921 | 1508 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox segment check" |
1509 |
" datagram failed: "); |
|
1562 | 1510 |
ec_datagram_print_wc_error(datagram); |
1511 |
return; |
|
1512 |
} |
|
1513 |
||
1514 |
if (!ec_slave_mbox_check(datagram)) { |
|
1515 |
unsigned long diff_ms = |
|
1516 |
(datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ; |
|
1517 |
if (diff_ms >= fsm->request->response_timeout) { |
|
1518 |
fsm->state = ec_fsm_coe_error; |
|
1921 | 1519 |
EC_SLAVE_ERR(slave, "Timeout while waiting for SDO download" |
1520 |
" segment response.\n"); |
|
1562 | 1521 |
return; |
1522 |
} |
|
1523 |
||
1524 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
1525 |
fsm->retries = EC_FSM_RETRIES; |
|
1526 |
return; |
|
1527 |
} |
|
1528 |
||
1529 |
// Fetch response |
|
1530 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
|
1531 |
fsm->retries = EC_FSM_RETRIES; |
|
1532 |
fsm->state = ec_fsm_coe_down_seg_response; |
|
1533 |
} |
|
1534 |
||
1535 |
/*****************************************************************************/ |
|
1536 |
||
1537 |
/** |
|
1538 |
CoE state: DOWN SEG RESPONSE. |
|
1539 |
\todo Timeout behavior |
|
1540 |
*/ |
|
1541 |
||
1542 |
void ec_fsm_coe_down_seg_response( |
|
1543 |
ec_fsm_coe_t *fsm /**< finite state machine */ |
|
1544 |
) |
|
1545 |
{ |
|
1546 |
ec_datagram_t *datagram = fsm->datagram; |
|
1547 |
ec_slave_t *slave = fsm->slave; |
|
1548 |
uint8_t *data, mbox_prot; |
|
1549 |
size_t rec_size; |
|
1550 |
ec_sdo_request_t *request = fsm->request; |
|
1551 |
||
1552 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
|
1553 |
return; // FIXME: request again? |
|
1554 |
||
1555 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
|
1556 |
fsm->state = ec_fsm_coe_error; |
|
1921 | 1557 |
EC_SLAVE_ERR(slave, "Failed to receive CoE download response" |
1558 |
" datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1559 |
ec_datagram_print_state(datagram); |
1562 | 1560 |
return; |
1561 |
} |
|
1562 |
||
1563 |
if (datagram->working_counter != 1) { |
|
1564 |
fsm->state = ec_fsm_coe_error; |
|
1921 | 1565 |
EC_SLAVE_ERR(slave, "Reception of CoE download response failed: "); |
1562 | 1566 |
ec_datagram_print_wc_error(datagram); |
1567 |
return; |
|
1568 |
} |
|
1569 |
||
1570 |
data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size); |
|
1571 |
if (IS_ERR(data)) { |
|
1572 |
fsm->state = ec_fsm_coe_error; |
|
1573 |
return; |
|
1574 |
} |
|
1575 |
||
1576 |
if (mbox_prot != 0x03) { // CoE |
|
1577 |
fsm->state = ec_fsm_coe_error; |
|
1921 | 1578 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
1579 |
mbox_prot); |
|
1562 | 1580 |
return; |
1581 |
} |
|
1582 |
||
1583 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
|
1584 |
// check for CoE response again |
|
1585 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
1586 |
fsm->retries = EC_FSM_RETRIES; |
|
1587 |
fsm->state = ec_fsm_coe_down_check; |
|
1588 |
return; |
|
1589 |
} |
|
1590 |
||
1591 |
if (slave->master->debug_level) { |
|
1921 | 1592 |
EC_SLAVE_DBG(slave, 1, "Download response:\n"); |
1562 | 1593 |
ec_print_data(data, rec_size); |
1594 |
} |
|
1595 |
||
1596 |
if (rec_size < 6) { |
|
1597 |
fsm->state = ec_fsm_coe_error; |
|
1921 | 1598 |
EC_SLAVE_ERR(slave, "Received data are too small (%zu bytes):\n", |
1599 |
rec_size); |
|
1562 | 1600 |
ec_print_data(data, rec_size); |
1601 |
return; |
|
1602 |
} |
|
1603 |
||
1604 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
|
1605 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
|
1606 |
char subidxstr[10]; |
|
1607 |
fsm->state = ec_fsm_coe_error; |
|
1608 |
if (request->complete_access) { |
|
1609 |
subidxstr[0] = 0x00; |
|
1610 |
} else { |
|
1611 |
sprintf(subidxstr, ":%02X", request->subindex); |
|
1612 |
} |
|
1921 | 1613 |
EC_SLAVE_ERR(slave, "SDO download 0x%04X%s (%zu bytes) aborted.\n", |
1614 |
request->index, subidxstr, request->data_size); |
|
1562 | 1615 |
if (rec_size < 10) { |
1921 | 1616 |
EC_SLAVE_ERR(slave, "Incomplete abort command:\n"); |
1562 | 1617 |
ec_print_data(data, rec_size); |
1618 |
} else { |
|
1619 |
fsm->request->abort_code = EC_READ_U32(data + 6); |
|
1921 | 1620 |
ec_canopen_abort_msg(slave, fsm->request->abort_code); |
1562 | 1621 |
} |
1622 |
return; |
|
1623 |
} |
|
1624 |
||
1625 |
if (EC_READ_U16(data) >> 12 != 0x3 || |
|
1626 |
((EC_READ_U8(data + 2) >> 5) != 0x01)) { // segment response |
|
1627 |
if (slave->master->debug_level) { |
|
1921 | 1628 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO download response!" |
1629 |
" Retrying...\n"); |
|
1562 | 1630 |
ec_print_data(data, rec_size); |
1631 |
} |
|
1632 |
// check for CoE response again |
|
1633 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
1634 |
fsm->retries = EC_FSM_RETRIES; |
|
1635 |
fsm->state = ec_fsm_coe_down_seg_check; |
|
1636 |
return; |
|
1637 |
} |
|
1638 |
||
1639 |
if (((EC_READ_U8(data + 2) >> 4) & 0x01) != fsm->toggle) { |
|
1921 | 1640 |
EC_SLAVE_ERR(slave, "Invalid toggle received during" |
1641 |
" segmented download:\n"); |
|
1562 | 1642 |
ec_print_data(data, rec_size); |
1643 |
fsm->state = ec_fsm_coe_error; |
|
1644 |
return; |
|
1645 |
} |
|
1646 |
||
1647 |
if (fsm->remaining) { // more segments to download |
|
1648 |
fsm->toggle = !fsm->toggle; |
|
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1649 |
ec_fsm_coe_down_prepare_segment_request(fsm); |
1562 | 1650 |
} else { |
1651 |
fsm->state = ec_fsm_coe_end; // success |
|
1652 |
} |
|
436 | 1653 |
} |
1654 |
||
1655 |
/*****************************************************************************/ |
|
1656 |
||
1657 |
/** |
|
1658 |
CoE state: UP START. |
|
1659 |
*/ |
|
1660 |
||
1661 |
void ec_fsm_coe_up_start(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1662 |
{ |
|
1663 |
ec_datagram_t *datagram = fsm->datagram; |
|
1664 |
ec_slave_t *slave = fsm->slave; |
|
1665 |
ec_master_t *master = slave->master; |
|
1666 |
ec_sdo_request_t *request = fsm->request; |
|
1667 |
uint8_t *data; |
|
1668 |
||
1921 | 1669 |
EC_SLAVE_DBG(slave, 1, "Uploading SDO 0x%04X:%02X.\n", |
1670 |
request->index, request->subindex); |
|
436 | 1671 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
1672 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
1921 | 1673 |
EC_SLAVE_ERR(slave, "Slave does not support CoE!\n"); |
825
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1674 |
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
|
1675 |
return; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1676 |
} |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1677 |
|
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1678 |
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
|
1679 |
if (IS_ERR(data)) { |
436 | 1680 |
fsm->state = ec_fsm_coe_error; |
1681 |
return; |
|
1682 |
} |
|
1683 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1684 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
436 | 1685 |
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
|
1686 |
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
|
1687 |
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
|
1688 |
memset(data + 6, 0x00, 4); |
436 | 1689 |
|
1690 |
if (master->debug_level) { |
|
1921 | 1691 |
EC_SLAVE_DBG(slave, 1, "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
|
1692 |
ec_print_data(data, 10); |
436 | 1693 |
} |
1694 |
||
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1695 |
fsm->request->jiffies_sent = jiffies; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1696 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1697 |
fsm->state = ec_fsm_coe_up_request; |
1698 |
} |
|
1699 |
||
1700 |
/*****************************************************************************/ |
|
1701 |
||
1702 |
/** |
|
1703 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1704 |
\todo Timeout behavior |
436 | 1705 |
*/ |
1706 |
||
1707 |
void ec_fsm_coe_up_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1708 |
{ |
|
1709 |
ec_datagram_t *datagram = fsm->datagram; |
|
1710 |
ec_slave_t *slave = fsm->slave; |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1711 |
unsigned long diff_ms; |
436 | 1712 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1713 |
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
|
1714 |
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
|
1715 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1716 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1717 |
fsm->state = ec_fsm_coe_error; |
1921 | 1718 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload request: "); |
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1719 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1720 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1721 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1722 |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1723 |
diff_ms = (jiffies - fsm->request->jiffies_sent) * 1000 / HZ; |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1724 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1725 |
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
|
1726 |
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
|
1727 |
if (diff_ms < fsm->request->response_timeout) { |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1728 |
#if DEBUG_RETRIES |
1921 | 1729 |
EC_SLAVE_DBG(slave, 1, "Slave did not respond to" |
1931 | 1730 |
" SDO upload request. Retrying after %lu ms...\n", |
1731 |
diff_ms); |
|
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1732 |
#endif |
1112
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1733 |
// no response; send request datagram again |
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1734 |
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
|
1735 |
} |
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1736 |
} |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1737 |
fsm->state = ec_fsm_coe_error; |
1921 | 1738 |
EC_SLAVE_ERR(slave, "Reception of CoE upload request for" |
1931 | 1739 |
" SDO 0x%04x:%x failed with timeout after %lu ms: ", |
1740 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1741 |
ec_datagram_print_wc_error(datagram); |
436 | 1742 |
return; |
1743 |
} |
|
1744 |
||
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1745 |
#if DEBUG_LONG |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1746 |
if (diff_ms > 200) { |
1931 | 1747 |
EC_SLAVE_WARN(slave, "SDO 0x%04x:%x upload took %lu ms.\n", |
1748 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1749 |
} |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1750 |
#endif |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1751 |
|
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1752 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 1753 |
|
1754 |
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
|
1755 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1756 |
fsm->state = ec_fsm_coe_up_check; |
1757 |
} |
|
1758 |
||
1759 |
/*****************************************************************************/ |
|
1760 |
||
1761 |
/** |
|
1762 |
CoE state: UP CHECK. |
|
1763 |
*/ |
|
1764 |
||
1765 |
void ec_fsm_coe_up_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1766 |
{ |
|
1767 |
ec_datagram_t *datagram = fsm->datagram; |
|
1768 |
ec_slave_t *slave = fsm->slave; |
|
1769 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1770 |
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
|
1771 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1772 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1773 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1774 |
fsm->state = ec_fsm_coe_error; |
1921 | 1775 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: "); |
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1776 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1777 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1778 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1779 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1780 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1781 |
fsm->state = ec_fsm_coe_error; |
1921 | 1782 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
1783 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1784 |
ec_datagram_print_wc_error(datagram); |
436 | 1785 |
return; |
1786 |
} |
|
1787 |
||
1788 |
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
|
1789 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1790 |
(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
|
1791 |
if (diff_ms >= fsm->request->response_timeout) { |
436 | 1792 |
fsm->state = ec_fsm_coe_error; |
1931 | 1793 |
EC_SLAVE_ERR(slave, "Timeout after %lu ms while waiting for" |
1794 |
" SDO 0x%04x:%x upload response.\n", diff_ms, |
|
1921 | 1795 |
fsm->request->index, fsm->request->subindex); |
436 | 1796 |
return; |
1797 |
} |
|
1798 |
||
1799 |
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
|
1800 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1801 |
return; |
1802 |
} |
|
1803 |
||
1804 |
// Fetch response |
|
1805 |
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
|
1806 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1807 |
fsm->state = ec_fsm_coe_up_response; |
1808 |
} |
|
1809 |
||
1810 |
/*****************************************************************************/ |
|
1811 |
||
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1812 |
/** Prepare an SDO upload segment request. |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1813 |
*/ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1814 |
void ec_fsm_coe_up_prepare_segment_request( |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1815 |
ec_fsm_coe_t *fsm /**< Finite state machine */ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1816 |
) |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1817 |
{ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1818 |
uint8_t *data = |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1819 |
ec_slave_mbox_prepare_send(fsm->slave, fsm->datagram, 0x03, 10); |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1820 |
if (IS_ERR(data)) { |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1821 |
fsm->state = ec_fsm_coe_error; |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1822 |
return; |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1823 |
} |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1824 |
|
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1825 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1826 |
EC_WRITE_U8 (data + 2, (fsm->toggle << 4 // toggle |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1827 |
| 0x3 << 5)); // upload segment request |
1550
81a16ba13ae6
Avoid zeroing mailbox datagram because of VoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
1544
diff
changeset
|
1828 |
memset(data + 3, 0x00, 7); |
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1829 |
|
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1830 |
if (fsm->slave->master->debug_level) { |
1921 | 1831 |
EC_SLAVE_DBG(fsm->slave, 1, "Upload segment request:\n"); |
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1832 |
ec_print_data(data, 10); |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1833 |
} |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1834 |
} |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1835 |
|
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1836 |
/*****************************************************************************/ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1837 |
|
436 | 1838 |
/** |
1839 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1840 |
\todo Timeout behavior |
436 | 1841 |
*/ |
1842 |
||
1843 |
void ec_fsm_coe_up_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1844 |
{ |
|
1845 |
ec_datagram_t *datagram = fsm->datagram; |
|
1846 |
ec_slave_t *slave = fsm->slave; |
|
1847 |
ec_master_t *master = slave->master; |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1848 |
uint16_t rec_index; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1849 |
uint8_t *data, mbox_prot, rec_subindex; |
436 | 1850 |
size_t rec_size, data_size; |
1851 |
ec_sdo_request_t *request = fsm->request; |
|
1852 |
unsigned int expedited, size_specified; |
|
1853 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1854 |
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
|
1855 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1856 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1857 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1858 |
fsm->state = ec_fsm_coe_error; |
1921 | 1859 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload response" |
1860 |
" datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
1861 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1862 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1863 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1864 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1865 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1866 |
fsm->state = ec_fsm_coe_error; |
1921 | 1867 |
EC_SLAVE_ERR(slave, "Reception of CoE upload response failed: "); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1868 |
ec_datagram_print_wc_error(datagram); |
436 | 1869 |
return; |
1870 |
} |
|
1871 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1872 |
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
|
1873 |
if (IS_ERR(data)) { |
436 | 1874 |
fsm->state = ec_fsm_coe_error; |
1875 |
return; |
|
1876 |
} |
|
1877 |
||
1878 |
if (master->debug_level) { |
|
1921 | 1879 |
EC_SLAVE_DBG(slave, 1, "Upload response:\n"); |
436 | 1880 |
ec_print_data(data, rec_size); |
1881 |
} |
|
1882 |
||
1883 |
if (mbox_prot != 0x03) { // CoE |
|
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1884 |
fsm->state = ec_fsm_coe_error; |
1921 | 1885 |
EC_SLAVE_WARN(slave, "Received mailbox protocol 0x%02X" |
1886 |
" 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
|
1887 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1888 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1889 |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1890 |
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
|
1891 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1892 |
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
|
1893 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1894 |
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
|
1895 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1896 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1897 |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1898 |
if (rec_size < 6) { |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1899 |
fsm->state = ec_fsm_coe_error; |
1921 | 1900 |
EC_SLAVE_ERR(slave, "Received currupted SDO upload response" |
1901 |
" (%zu bytes)!\n", rec_size); |
|
436 | 1902 |
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
|
1903 |
return; |
436 | 1904 |
} |
1905 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1906 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1907 |
EC_READ_U8(data + 2) >> 5 == 0x4) { // abort SDO transfer request |
1921 | 1908 |
EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X aborted.\n", |
1909 |
request->index, request->subindex); |
|
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
|
1910 |
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
|
1911 |
request->abort_code = EC_READ_U32(data + 6); |
1921 | 1912 |
ec_canopen_abort_msg(slave, request->abort_code); |
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
|
1913 |
} else { |
1921 | 1914 |
EC_SLAVE_ERR(slave, "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
|
1915 |
} |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1916 |
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
|
1917 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1918 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1919 |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1920 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1921 |
EC_READ_U8(data + 2) >> 5 != 0x2) { // upload response |
1921 | 1922 |
EC_SLAVE_ERR(slave, "Received unknown response while" |
1923 |
" uploading SDO 0x%04X:%02X.\n", |
|
1924 |
request->index, request->subindex); |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1925 |
ec_print_data(data, rec_size); |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1926 |
fsm->state = ec_fsm_coe_error; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1927 |
return; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1928 |
} |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1929 |
|
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1930 |
rec_index = EC_READ_U16(data + 3); |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1931 |
rec_subindex = EC_READ_U8(data + 5); |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1932 |
|
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1933 |
if (rec_index != request->index || rec_subindex != request->subindex) { |
1921 | 1934 |
EC_SLAVE_ERR(slave, "Received upload response for wrong SDO" |
1935 |
" (0x%04X:%02X, requested: 0x%04X:%02X).\n", |
|
1936 |
rec_index, rec_subindex, request->index, request->subindex); |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1937 |
ec_print_data(data, rec_size); |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1938 |
|
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1939 |
// check for CoE response again |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1940 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1941 |
fsm->retries = EC_FSM_RETRIES; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1942 |
fsm->state = ec_fsm_coe_up_check; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1943 |
return; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1944 |
} |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1945 |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1946 |
// normal or expedited? |
436 | 1947 |
expedited = EC_READ_U8(data + 2) & 0x02; |
1948 |
||
1949 |
if (expedited) { |
|
1950 |
size_specified = EC_READ_U8(data + 2) & 0x01; |
|
1951 |
if (size_specified) { |
|
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
1952 |
fsm->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
|
1953 |
} else { |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
1954 |
fsm->complete_size = 4; |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
1955 |
} |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
1956 |
|
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
1957 |
if (rec_size < 6 + fsm->complete_size) { |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1958 |
fsm->state = ec_fsm_coe_error; |
1921 | 1959 |
EC_SLAVE_ERR(slave, "Received corrupted SDO expedited upload" |
1543
373cd456dc26
Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
1960 |
" response (only %zu bytes)!\n", 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
|
1961 |
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
|
1962 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1963 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1964 |
|
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
1965 |
if (ec_sdo_request_copy_data(request, data + 6, fsm->complete_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
|
1966 |
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
|
1967 |
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
|
1968 |
} |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1969 |
} else { // normal |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1970 |
if (rec_size < 10) { |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1971 |
fsm->state = ec_fsm_coe_error; |
1921 | 1972 |
EC_SLAVE_ERR(slave, "Received currupted SDO normal upload" |
1543
373cd456dc26
Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
1973 |
" response (only %zu bytes)!\n", 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
|
1974 |
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
|
1975 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1976 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1977 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1978 |
data_size = rec_size - 10; |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
1979 |
fsm->complete_size = EC_READ_U32(data + 6); |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
1980 |
|
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
1981 |
if (!fsm->complete_size) { |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1982 |
fsm->state = ec_fsm_coe_error; |
1921 | 1983 |
EC_SLAVE_ERR(slave, "No complete size supplied!\n"); |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1984 |
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
|
1985 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1986 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1987 |
|
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
1988 |
if (ec_sdo_request_alloc(request, fsm->complete_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
|
1989 |
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
|
1990 |
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
|
1991 |
} |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
1992 |
|
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
1993 |
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
|
1994 |
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
|
1995 |
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
|
1996 |
} |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
1997 |
|
436 | 1998 |
fsm->toggle = 0; |
1999 |
||
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2000 |
if (data_size < fsm->complete_size) { |
1921 | 2001 |
EC_SLAVE_DBG(slave, 1, "SDO data incomplete (%zu / %u)." |
2002 |
" Segmenting...\n", data_size, fsm->complete_size); |
|
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2003 |
ec_fsm_coe_up_prepare_segment_request(fsm); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2004 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2005 |
fsm->state = ec_fsm_coe_up_seg_request; |
2006 |
return; |
|
2007 |
} |
|
2008 |
} |
|
2009 |
||
874 | 2010 |
if (master->debug_level) { |
1921 | 2011 |
EC_SLAVE_DBG(slave, 1, "Uploaded data:\n"); |
874 | 2012 |
ec_print_data(request->data, request->data_size); |
2013 |
} |
|
2014 |
||
436 | 2015 |
fsm->state = ec_fsm_coe_end; // success |
2016 |
} |
|
2017 |
||
2018 |
/*****************************************************************************/ |
|
2019 |
||
2020 |
/** |
|
2021 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2022 |
\todo Timeout behavior |
436 | 2023 |
*/ |
2024 |
||
2025 |
void ec_fsm_coe_up_seg_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2026 |
{ |
|
2027 |
ec_datagram_t *datagram = fsm->datagram; |
|
2028 |
ec_slave_t *slave = fsm->slave; |
|
2029 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
2030 |
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
|
2031 |
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
|
2032 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2033 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2034 |
fsm->state = ec_fsm_coe_error; |
1921 | 2035 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload segment" |
2036 |
" request datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
2037 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2038 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2039 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2040 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2041 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2042 |
fsm->state = ec_fsm_coe_error; |
1921 | 2043 |
EC_SLAVE_ERR(slave, "Reception of CoE upload segment" |
2044 |
" request failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
2045 |
ec_datagram_print_wc_error(datagram); |
436 | 2046 |
return; |
2047 |
} |
|
2048 |
||
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
2049 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 2050 |
|
2051 |
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
|
2052 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2053 |
fsm->state = ec_fsm_coe_up_seg_check; |
2054 |
} |
|
2055 |
||
2056 |
/*****************************************************************************/ |
|
2057 |
||
2058 |
/** |
|
2059 |
CoE state: UP CHECK. |
|
2060 |
*/ |
|
2061 |
||
2062 |
void ec_fsm_coe_up_seg_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2063 |
{ |
|
2064 |
ec_datagram_t *datagram = fsm->datagram; |
|
2065 |
ec_slave_t *slave = fsm->slave; |
|
2066 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
2067 |
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
|
2068 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2069 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2070 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2071 |
fsm->state = ec_fsm_coe_error; |
1921 | 2072 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check" |
2073 |
" datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
2074 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2075 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2076 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2077 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2078 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2079 |
fsm->state = ec_fsm_coe_error; |
1921 | 2080 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check datagram" |
2081 |
" failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
2082 |
ec_datagram_print_wc_error(datagram); |
436 | 2083 |
return; |
2084 |
} |
|
2085 |
||
2086 |
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
|
2087 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
2088 |
(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
|
2089 |
if (diff_ms >= fsm->request->response_timeout) { |
436 | 2090 |
fsm->state = ec_fsm_coe_error; |
1921 | 2091 |
EC_SLAVE_ERR(slave, "Timeout while waiting for SDO upload" |
2092 |
" segment response.\n"); |
|
436 | 2093 |
return; |
2094 |
} |
|
2095 |
||
2096 |
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
|
2097 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2098 |
return; |
2099 |
} |
|
2100 |
||
2101 |
// Fetch response |
|
2102 |
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
|
2103 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2104 |
fsm->state = ec_fsm_coe_up_seg_response; |
2105 |
} |
|
2106 |
||
2107 |
/*****************************************************************************/ |
|
2108 |
||
2109 |
/** |
|
2110 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2111 |
\todo Timeout behavior |
436 | 2112 |
*/ |
2113 |
||
2114 |
void ec_fsm_coe_up_seg_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2115 |
{ |
|
2116 |
ec_datagram_t *datagram = fsm->datagram; |
|
2117 |
ec_slave_t *slave = fsm->slave; |
|
2118 |
ec_master_t *master = slave->master; |
|
2119 |
uint8_t *data, mbox_prot; |
|
2120 |
size_t rec_size, data_size; |
|
2121 |
ec_sdo_request_t *request = fsm->request; |
|
2122 |
unsigned int last_segment; |
|
2123 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
2124 |
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
|
2125 |
return; // FIXME: request again? |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2126 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2127 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2128 |
fsm->state = ec_fsm_coe_error; |
1921 | 2129 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload segment" |
2130 |
" response datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1794
diff
changeset
|
2131 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2132 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2133 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2134 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2135 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2136 |
fsm->state = ec_fsm_coe_error; |
1921 | 2137 |
EC_SLAVE_ERR(slave, "Reception of CoE upload segment" |
2138 |
" response failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
2139 |
ec_datagram_print_wc_error(datagram); |
436 | 2140 |
return; |
2141 |
} |
|
2142 |
||
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
2143 |
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
|
2144 |
if (IS_ERR(data)) { |
436 | 2145 |
fsm->state = ec_fsm_coe_error; |
2146 |
return; |
|
2147 |
} |
|
2148 |
||
2149 |
if (master->debug_level) { |
|
1921 | 2150 |
EC_SLAVE_DBG(slave, 1, "Upload segment response:\n"); |
436 | 2151 |
ec_print_data(data, rec_size); |
2152 |
} |
|
2153 |
||
2154 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 2155 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
2156 |
mbox_prot); |
|
436 | 2157 |
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
|
2158 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2159 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2160 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2161 |
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
|
2162 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2163 |
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
|
2164 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2165 |
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
|
2166 |
return; |
436 | 2167 |
} |
2168 |
||
2169 |
if (rec_size < 10) { |
|
1921 | 2170 |
EC_SLAVE_ERR(slave, "Received currupted SDO upload" |
2171 |
" segment response!\n"); |
|
436 | 2172 |
ec_print_data(data, rec_size); |
2173 |
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
|
2174 |
return; |
436 | 2175 |
} |
2176 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
2177 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2178 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
1921 | 2179 |
EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X aborted.\n", |
2180 |
request->index, request->subindex); |
|
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
|
2181 |
request->abort_code = EC_READ_U32(data + 6); |
1921 | 2182 |
ec_canopen_abort_msg(slave, request->abort_code); |
436 | 2183 |
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
|
2184 |
return; |
436 | 2185 |
} |
2186 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
2187 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
436 | 2188 |
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
|
2189 |
if (fsm->slave->master->debug_level) { |
1921 | 2190 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO upload segment response!\n"); |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2191 |
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
|
2192 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2193 |
// check for CoE response again |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2194 |
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
|
2195 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2196 |
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
|
2197 |
return; |
436 | 2198 |
} |
2199 |
||
1533
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2200 |
data_size = rec_size - 3; /* Header of segment upload is smaller than |
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2201 |
normal upload */ |
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2202 |
if (rec_size == 10) { |
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2203 |
uint8_t seg_size = (EC_READ_U8(data + 2) & 0xE) >> 1; |
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2204 |
data_size -= seg_size; |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2205 |
} |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2206 |
|
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2207 |
if (request->data_size + data_size > fsm->complete_size) { |
1921 | 2208 |
EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X failed: Fragment" |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2209 |
" exceeding complete size!\n", |
1921 | 2210 |
request->index, request->subindex); |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2211 |
fsm->state = ec_fsm_coe_error; |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2212 |
return; |
436 | 2213 |
} |
2214 |
||
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2215 |
memcpy(request->data + request->data_size, data + 3, data_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
|
2216 |
request->data_size += data_size; |
436 | 2217 |
|
1533
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2218 |
last_segment = EC_READ_U8(data + 2) & 0x01; |
436 | 2219 |
if (!last_segment) { |
2220 |
fsm->toggle = !fsm->toggle; |
|
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2221 |
ec_fsm_coe_up_prepare_segment_request(fsm); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2222 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2223 |
fsm->state = ec_fsm_coe_up_seg_request; |
2224 |
return; |
|
2225 |
} |
|
2226 |
||
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2227 |
if (request->data_size != fsm->complete_size) { |
1921 | 2228 |
EC_SLAVE_WARN(slave, "SDO upload 0x%04X:%02X: Assembled data" |
1543
373cd456dc26
Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2229 |
" size (%zu) does not match complete size (%u)!\n", |
1921 | 2230 |
request->index, request->subindex, |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2231 |
request->data_size, fsm->complete_size); |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2232 |
} |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2233 |
|
874 | 2234 |
if (master->debug_level) { |
1921 | 2235 |
EC_SLAVE_DBG(slave, 1, "Uploaded data:\n"); |
874 | 2236 |
ec_print_data(request->data, request->data_size); |
2237 |
} |
|
2238 |
||
436 | 2239 |
fsm->state = ec_fsm_coe_end; // success |
2240 |
} |
|
2241 |
||
2242 |
/*****************************************************************************/ |
|
2243 |
||
2244 |
/** |
|
2245 |
State: ERROR. |
|
2246 |
*/ |
|
2247 |
||
2248 |
void ec_fsm_coe_error(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2249 |
{ |
|
2250 |
} |
|
2251 |
||
2252 |
/*****************************************************************************/ |
|
2253 |
||
2254 |
/** |
|
2255 |
State: END. |
|
2256 |
*/ |
|
2257 |
||
2258 |
void ec_fsm_coe_end(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2259 |
{ |
|
2260 |
} |
|
2261 |
||
2262 |
/*****************************************************************************/ |