author | Florian Pose <fp@igh-essen.com> |
Tue, 04 Sep 2012 14:19:06 +0200 | |
changeset 2411 | 01370d59233d |
parent 2195 | d9146c0ff00f |
child 2589 | 2b9c78543663 |
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 */ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
171 |
ec_mailbox_t *mbox /**< mailbox */ |
436 | 172 |
) |
173 |
{ |
|
174 |
fsm->state = NULL; |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
175 |
fsm->mbox = mbox; |
436 | 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 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
289 |
ec_mailbox_t *mbox = fsm->mbox; |
436 | 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 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
306 |
data = ec_slave_mbox_prepare_send(slave, mbox, 0x03, 8); |
1313
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 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
331 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
332 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 333 |
ec_slave_t *slave = fsm->slave; |
334 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
335 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
336 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
337 |
return; // FIXME: request again? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
338 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
339 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
340 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
341 |
fsm->state = ec_fsm_coe_error; |
1921 | 342 |
EC_SLAVE_ERR(slave, "Failed to receive CoE dictionary" |
343 |
" 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
|
344 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
345 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
346 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
347 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
348 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
349 |
fsm->state = ec_fsm_coe_error; |
1921 | 350 |
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
|
351 |
ec_datagram_print_wc_error(datagram); |
436 | 352 |
return; |
353 |
} |
|
354 |
||
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
355 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 356 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
357 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
358 |
fsm->retries = EC_FSM_RETRIES; |
436 | 359 |
fsm->state = ec_fsm_coe_dict_check; |
360 |
} |
|
361 |
||
362 |
/*****************************************************************************/ |
|
363 |
||
364 |
/** |
|
365 |
CoE state: DICT CHECK. |
|
366 |
*/ |
|
367 |
||
368 |
void ec_fsm_coe_dict_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
369 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
370 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
371 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 372 |
ec_slave_t *slave = fsm->slave; |
373 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
374 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
375 |
&& fsm->retries--) { |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
376 |
return; |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
377 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
378 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
379 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
380 |
fsm->state = ec_fsm_coe_error; |
1921 | 381 |
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
|
382 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
383 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
384 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
385 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
386 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
387 |
fsm->state = ec_fsm_coe_error; |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
388 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
1921 | 389 |
" datagram failed: "); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
390 |
ec_datagram_print_wc_error(datagram); |
436 | 391 |
return; |
392 |
} |
|
393 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
394 |
if (!ec_slave_mbox_check(mbox)) { |
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
395 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
396 |
(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
|
397 |
if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) { |
436 | 398 |
fsm->state = ec_fsm_coe_error; |
1921 | 399 |
EC_SLAVE_ERR(slave, "Timeout while waiting for" |
400 |
" SDO dictionary list response.\n"); |
|
436 | 401 |
return; |
402 |
} |
|
403 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
404 |
ec_slave_mbox_prepare_check(slave, mbox); // 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 |
return; |
407 |
} |
|
408 |
||
409 |
// Fetch response |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
410 |
ec_slave_mbox_prepare_fetch(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
411 |
fsm->retries = EC_FSM_RETRIES; |
436 | 412 |
fsm->state = ec_fsm_coe_dict_response; |
413 |
} |
|
414 |
||
415 |
/*****************************************************************************/ |
|
416 |
||
417 |
/** |
|
418 |
CoE state: DICT RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
419 |
\todo Timeout behavior |
436 | 420 |
*/ |
421 |
||
422 |
void ec_fsm_coe_dict_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
423 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
424 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
425 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 426 |
ec_slave_t *slave = fsm->slave; |
427 |
uint8_t *data, mbox_prot; |
|
428 |
size_t rec_size; |
|
429 |
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
|
430 |
uint16_t sdo_index, fragments_left; |
436 | 431 |
ec_sdo_t *sdo; |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
432 |
bool first_segment; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
433 |
size_t index_list_offset; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
434 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
435 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
436 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
437 |
return; // FIXME: request again? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
438 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
439 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
440 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
441 |
fsm->state = ec_fsm_coe_error; |
1921 | 442 |
EC_SLAVE_ERR(slave, "Failed to receive CoE dictionary" |
443 |
" 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
|
444 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
445 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
446 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
447 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
448 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
449 |
fsm->state = ec_fsm_coe_error; |
1921 | 450 |
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
|
451 |
ec_datagram_print_wc_error(datagram); |
436 | 452 |
return; |
453 |
} |
|
454 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
455 |
data = ec_slave_mbox_fetch(slave, mbox, &mbox_prot, &rec_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
456 |
if (IS_ERR(data)) { |
436 | 457 |
fsm->state = ec_fsm_coe_error; |
458 |
return; |
|
459 |
} |
|
460 |
||
461 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 462 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
463 |
mbox_prot); |
|
436 | 464 |
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
|
465 |
return; |
436 | 466 |
} |
467 |
||
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
468 |
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
|
469 |
// check for CoE response again |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
470 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
471 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
472 |
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
|
473 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
474 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
475 |
|
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
|
476 |
if (rec_size < 3) { |
1921 | 477 |
EC_SLAVE_ERR(slave, "Received corrupted SDO dictionary response" |
478 |
" (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
|
479 |
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
|
480 |
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
|
481 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
482 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
483 |
if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information |
436 | 484 |
(EC_READ_U8(data + 2) & 0x7F) == 0x07) { // error response |
1921 | 485 |
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
|
486 |
if (rec_size < 10) { |
1921 | 487 |
EC_SLAVE_ERR(slave, "Incomplete SDO information" |
488 |
" 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
|
489 |
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
|
490 |
} else { |
1921 | 491 |
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
|
492 |
} |
436 | 493 |
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
|
494 |
return; |
436 | 495 |
} |
496 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
497 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
436 | 498 |
(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
|
499 |
if (fsm->slave->master->debug_level) { |
1921 | 500 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO list response!" |
501 |
" Retrying...\n"); |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
502 |
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
|
503 |
} |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
504 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
505 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
506 |
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
|
507 |
return; |
436 | 508 |
} |
509 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
510 |
first_segment = list_empty(&slave->sdo_dictionary) ? true : false; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
511 |
index_list_offset = first_segment ? 8 : 6; |
2041
f5b31f46c38f
Fixed segmented sdo dictionary upload (only first segment contains list type)
Rafael Blank <ch1010866@ch10pc436>
parents:
1948
diff
changeset
|
512 |
|
2194
1b583b3110cb
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
513 |
if (rec_size < index_list_offset || rec_size % 2) { |
1b583b3110cb
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
514 |
EC_SLAVE_ERR(slave, "Invalid data size %zu !\n", rec_size); |
1b583b3110cb
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
515 |
ec_print_data(data, rec_size); |
1b583b3110cb
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
516 |
fsm->state = ec_fsm_coe_error; |
1b583b3110cb
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
517 |
return; |
1b583b3110cb
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
518 |
} |
1b583b3110cb
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
519 |
|
2041
f5b31f46c38f
Fixed segmented sdo dictionary upload (only first segment contains list type)
Rafael Blank <ch1010866@ch10pc436>
parents:
1948
diff
changeset
|
520 |
sdo_count = (rec_size - index_list_offset) / 2; |
436 | 521 |
|
522 |
for (i = 0; i < sdo_count; i++) { |
|
2041
f5b31f46c38f
Fixed segmented sdo dictionary upload (only first segment contains list type)
Rafael Blank <ch1010866@ch10pc436>
parents:
1948
diff
changeset
|
523 |
sdo_index = EC_READ_U16(data + index_list_offset + i * 2); |
436 | 524 |
if (!sdo_index) { |
1921 | 525 |
EC_SLAVE_DBG(slave, 1, "SDO dictionary contains index 0x0000.\n"); |
436 | 526 |
continue; |
527 |
} |
|
528 |
||
998
05a24788f3b2
Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents:
992
diff
changeset
|
529 |
if (!(sdo = (ec_sdo_t *) kmalloc(sizeof(ec_sdo_t), GFP_KERNEL))) { |
1921 | 530 |
EC_SLAVE_ERR(slave, "Failed to allocate memory for SDO!\n"); |
436 | 531 |
fsm->state = ec_fsm_coe_error; |
532 |
return; |
|
533 |
} |
|
534 |
||
992
50a44cbd30af
Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents:
991
diff
changeset
|
535 |
ec_sdo_init(sdo, slave, sdo_index); |
436 | 536 |
list_add_tail(&sdo->list, &slave->sdo_dictionary); |
537 |
} |
|
538 |
||
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
539 |
fragments_left = EC_READ_U16(data + 4); |
1923 | 540 |
if (fragments_left) { |
1921 | 541 |
EC_SLAVE_DBG(slave, 1, "SDO list fragments left: %u\n", |
542 |
fragments_left); |
|
543 |
} |
|
544 |
||
545 |
if (EC_READ_U8(data + 2) & 0x80 || fragments_left) { |
|
546 |
// 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
|
547 |
fsm->jiffies_start = datagram->jiffies_sent; |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
548 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
549 |
fsm->retries = EC_FSM_RETRIES; |
436 | 550 |
fsm->state = ec_fsm_coe_dict_check; |
551 |
return; |
|
552 |
} |
|
553 |
||
554 |
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
|
555 |
// no SDOs in dictionary. finished. |
436 | 556 |
fsm->state = ec_fsm_coe_end; // success |
557 |
return; |
|
558 |
} |
|
559 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
560 |
// fetch SDO descriptions |
436 | 561 |
fsm->sdo = list_entry(slave->sdo_dictionary.next, ec_sdo_t, list); |
562 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
563 |
data = ec_slave_mbox_prepare_send(slave, mbox, 0x03, 8); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
564 |
if (IS_ERR(data)) { |
436 | 565 |
fsm->state = ec_fsm_coe_error; |
566 |
return; |
|
567 |
} |
|
568 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
569 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 570 |
EC_WRITE_U8 (data + 2, 0x03); // Get object description request |
571 |
EC_WRITE_U8 (data + 3, 0x00); |
|
572 |
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
|
573 |
EC_WRITE_U16(data + 6, fsm->sdo->index); // SDO index |
436 | 574 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
575 |
fsm->retries = EC_FSM_RETRIES; |
436 | 576 |
fsm->state = ec_fsm_coe_dict_desc_request; |
577 |
} |
|
578 |
||
579 |
/*****************************************************************************/ |
|
580 |
||
581 |
/** |
|
582 |
CoE state: DICT DESC REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
583 |
\todo Timeout behavior |
436 | 584 |
*/ |
585 |
||
586 |
void ec_fsm_coe_dict_desc_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
587 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
588 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
589 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 590 |
ec_slave_t *slave = fsm->slave; |
591 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
592 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
593 |
&& fsm->retries--) |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
594 |
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
|
595 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
596 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
597 |
fsm->state = ec_fsm_coe_error; |
1921 | 598 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO" |
599 |
" 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
|
600 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
601 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
602 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
603 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
604 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
605 |
fsm->state = ec_fsm_coe_error; |
1921 | 606 |
EC_SLAVE_ERR(slave, "Reception of CoE SDO description" |
607 |
" request failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
608 |
ec_datagram_print_wc_error(datagram); |
436 | 609 |
return; |
610 |
} |
|
611 |
||
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
612 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 613 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
614 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
615 |
fsm->retries = EC_FSM_RETRIES; |
436 | 616 |
fsm->state = ec_fsm_coe_dict_desc_check; |
617 |
} |
|
618 |
||
619 |
/*****************************************************************************/ |
|
620 |
||
621 |
/** |
|
622 |
CoE state: DICT DESC CHECK. |
|
623 |
*/ |
|
624 |
||
625 |
void ec_fsm_coe_dict_desc_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
626 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
627 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
628 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 629 |
ec_slave_t *slave = fsm->slave; |
630 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
631 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
632 |
&& fsm->retries--) { |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
633 |
return; |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
634 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
635 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
636 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
637 |
fsm->state = ec_fsm_coe_error; |
1921 | 638 |
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
|
639 |
ec_datagram_print_state(datagram); |
436 | 640 |
return; |
641 |
} |
|
642 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
643 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
644 |
fsm->state = ec_fsm_coe_error; |
1921 | 645 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
646 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
647 |
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
|
648 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
649 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
650 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
651 |
if (!ec_slave_mbox_check(mbox)) { |
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
652 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
653 |
(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
|
654 |
if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) { |
436 | 655 |
fsm->state = ec_fsm_coe_error; |
1921 | 656 |
EC_SLAVE_ERR(slave, "Timeout while waiting for" |
657 |
" SDO 0x%04x object description response.\n", |
|
658 |
fsm->sdo->index); |
|
436 | 659 |
return; |
660 |
} |
|
661 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
662 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
663 |
fsm->retries = EC_FSM_RETRIES; |
436 | 664 |
return; |
665 |
} |
|
666 |
||
667 |
// Fetch response |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
668 |
ec_slave_mbox_prepare_fetch(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
669 |
fsm->retries = EC_FSM_RETRIES; |
436 | 670 |
fsm->state = ec_fsm_coe_dict_desc_response; |
671 |
} |
|
672 |
||
673 |
/*****************************************************************************/ |
|
674 |
||
675 |
/** |
|
676 |
CoE state: DICT DESC RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
677 |
\todo Timeout behavior |
436 | 678 |
*/ |
679 |
||
680 |
void ec_fsm_coe_dict_desc_response(ec_fsm_coe_t *fsm |
|
681 |
/**< finite state machine */) |
|
682 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
683 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
684 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 685 |
ec_slave_t *slave = fsm->slave; |
686 |
ec_sdo_t *sdo = fsm->sdo; |
|
687 |
uint8_t *data, mbox_prot; |
|
688 |
size_t rec_size, name_size; |
|
689 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
690 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
691 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
692 |
return; // FIXME: request again? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
693 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
694 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
695 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
696 |
fsm->state = ec_fsm_coe_error; |
1921 | 697 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO description" |
698 |
" 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
|
699 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
700 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
701 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
702 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
703 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
704 |
fsm->state = ec_fsm_coe_error; |
1921 | 705 |
EC_SLAVE_ERR(slave, "Reception of CoE SDO description" |
706 |
" response failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
707 |
ec_datagram_print_wc_error(datagram); |
436 | 708 |
return; |
709 |
} |
|
710 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
711 |
data = ec_slave_mbox_fetch(slave, mbox, &mbox_prot, &rec_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
712 |
if (IS_ERR(data)) { |
436 | 713 |
fsm->state = ec_fsm_coe_error; |
714 |
return; |
|
715 |
} |
|
716 |
||
717 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 718 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
719 |
mbox_prot); |
|
436 | 720 |
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
|
721 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
722 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
723 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
724 |
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
|
725 |
// check for CoE response again |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
726 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
727 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
728 |
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
|
729 |
return; |
436 | 730 |
} |
731 |
||
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
|
732 |
if (rec_size < 3) { |
1921 | 733 |
EC_SLAVE_ERR(slave, "Received corrupted SDO description response" |
734 |
" (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
|
735 |
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
|
736 |
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
|
737 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
738 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
739 |
if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information |
436 | 740 |
(EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response |
1921 | 741 |
EC_SLAVE_ERR(slave, "SDO information error response while" |
742 |
" fetching SDO 0x%04X!\n", sdo->index); |
|
743 |
ec_canopen_abort_msg(slave, EC_READ_U32(data + 6)); |
|
436 | 744 |
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
|
745 |
return; |
436 | 746 |
} |
747 |
||
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
|
748 |
if (rec_size < 8) { |
1921 | 749 |
EC_SLAVE_ERR(slave, "Received corrupted SDO" |
750 |
" 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
|
751 |
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
|
752 |
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
|
753 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
754 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
755 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
436 | 756 |
(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
|
757 |
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
|
758 |
if (fsm->slave->master->debug_level) { |
1921 | 759 |
EC_SLAVE_DBG(slave, 1, "Invalid object description response while" |
760 |
" 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
|
761 |
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
|
762 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
763 |
// check for CoE response again |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
764 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
765 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
766 |
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
|
767 |
return; |
436 | 768 |
} |
769 |
||
770 |
if (rec_size < 12) { |
|
1921 | 771 |
EC_SLAVE_ERR(slave, "Invalid data size!\n"); |
436 | 772 |
ec_print_data(data, rec_size); |
773 |
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
|
774 |
return; |
436 | 775 |
} |
776 |
||
962
ea83a7aab57a
Renamed subindices to max_subindex.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
777 |
sdo->max_subindex = EC_READ_U8(data + 10); |
436 | 778 |
sdo->object_code = EC_READ_U8(data + 11); |
779 |
||
780 |
name_size = rec_size - 12; |
|
781 |
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
|
782 |
if (!(sdo->name = kmalloc(name_size + 1, GFP_KERNEL))) { |
1921 | 783 |
EC_SLAVE_ERR(slave, "Failed to allocate SDO name!\n"); |
436 | 784 |
fsm->state = ec_fsm_coe_error; |
785 |
return; |
|
786 |
} |
|
787 |
||
788 |
memcpy(sdo->name, data + 12, name_size); |
|
789 |
sdo->name[name_size] = 0; |
|
790 |
} |
|
791 |
||
792 |
if (EC_READ_U8(data + 2) & 0x80) { |
|
1921 | 793 |
EC_SLAVE_ERR(slave, "Fragment follows (not implemented)!\n"); |
436 | 794 |
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
|
795 |
return; |
436 | 796 |
} |
797 |
||
798 |
// start fetching entries |
|
799 |
||
800 |
fsm->subindex = 0; |
|
801 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
802 |
data = ec_slave_mbox_prepare_send(slave, mbox, 0x03, 10); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
803 |
if (IS_ERR(data)) { |
436 | 804 |
fsm->state = ec_fsm_coe_error; |
805 |
return; |
|
806 |
} |
|
807 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
808 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 809 |
EC_WRITE_U8 (data + 2, 0x05); // Get entry description request |
810 |
EC_WRITE_U8 (data + 3, 0x00); |
|
811 |
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
|
812 |
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
|
813 |
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
|
814 |
EC_WRITE_U8 (data + 9, 0x01); // value info (access rights only) |
436 | 815 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
816 |
fsm->retries = EC_FSM_RETRIES; |
436 | 817 |
fsm->state = ec_fsm_coe_dict_entry_request; |
818 |
} |
|
819 |
||
820 |
/*****************************************************************************/ |
|
821 |
||
822 |
/** |
|
823 |
CoE state: DICT ENTRY REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
824 |
\todo Timeout behavior |
436 | 825 |
*/ |
826 |
||
827 |
void ec_fsm_coe_dict_entry_request(ec_fsm_coe_t *fsm |
|
828 |
/**< finite state machine */) |
|
829 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
830 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
831 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 832 |
ec_slave_t *slave = fsm->slave; |
833 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
834 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
835 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
836 |
return; // FIXME: check for response first? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
837 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
838 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
839 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
840 |
fsm->state = ec_fsm_coe_error; |
1921 | 841 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO entry" |
842 |
" 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
|
843 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
844 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
845 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
846 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
847 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
848 |
fsm->state = ec_fsm_coe_error; |
1921 | 849 |
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
|
850 |
ec_datagram_print_wc_error(datagram); |
436 | 851 |
return; |
852 |
} |
|
853 |
||
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
854 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 855 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
856 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
857 |
fsm->retries = EC_FSM_RETRIES; |
436 | 858 |
fsm->state = ec_fsm_coe_dict_entry_check; |
859 |
} |
|
860 |
||
861 |
/*****************************************************************************/ |
|
862 |
||
863 |
/** |
|
864 |
CoE state: DICT ENTRY CHECK. |
|
865 |
*/ |
|
866 |
||
867 |
void ec_fsm_coe_dict_entry_check(ec_fsm_coe_t *fsm |
|
868 |
/**< finite state machine */) |
|
869 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
870 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
871 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 872 |
ec_slave_t *slave = fsm->slave; |
873 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
874 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
875 |
&& fsm->retries--) { |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
876 |
return; |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
877 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
878 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
879 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
880 |
fsm->state = ec_fsm_coe_error; |
1921 | 881 |
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
|
882 |
ec_datagram_print_state(datagram); |
436 | 883 |
return; |
884 |
} |
|
885 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
886 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
887 |
fsm->state = ec_fsm_coe_error; |
1921 | 888 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
889 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
890 |
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
|
891 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
892 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
893 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
894 |
if (!ec_slave_mbox_check(mbox)) { |
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
895 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
896 |
(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
|
897 |
if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) { |
436 | 898 |
fsm->state = ec_fsm_coe_error; |
1921 | 899 |
EC_SLAVE_ERR(slave, "Timeout while waiting for" |
900 |
" SDO entry 0x%04x:%x description response.\n", |
|
901 |
fsm->sdo->index, fsm->subindex); |
|
436 | 902 |
return; |
903 |
} |
|
904 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
905 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
906 |
fsm->retries = EC_FSM_RETRIES; |
436 | 907 |
return; |
908 |
} |
|
909 |
||
910 |
// Fetch response |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
911 |
ec_slave_mbox_prepare_fetch(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
912 |
fsm->retries = EC_FSM_RETRIES; |
436 | 913 |
fsm->state = ec_fsm_coe_dict_entry_response; |
914 |
} |
|
915 |
||
916 |
/*****************************************************************************/ |
|
917 |
||
918 |
/** |
|
919 |
CoE state: DICT ENTRY RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
920 |
\todo Timeout behavior |
436 | 921 |
*/ |
922 |
||
923 |
void ec_fsm_coe_dict_entry_response(ec_fsm_coe_t *fsm |
|
924 |
/**< finite state machine */) |
|
925 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
926 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
927 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 928 |
ec_slave_t *slave = fsm->slave; |
929 |
ec_sdo_t *sdo = fsm->sdo; |
|
930 |
uint8_t *data, mbox_prot; |
|
931 |
size_t rec_size, data_size; |
|
932 |
ec_sdo_entry_t *entry; |
|
1382
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
933 |
u16 word; |
436 | 934 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
935 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
936 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
937 |
return; // FIXME: request again? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
938 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
939 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
940 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
941 |
fsm->state = ec_fsm_coe_error; |
1921 | 942 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO" |
943 |
" 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
|
944 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
945 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
946 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
947 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
948 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
949 |
fsm->state = ec_fsm_coe_error; |
1921 | 950 |
EC_SLAVE_ERR(slave, "Reception of CoE SDO description" |
951 |
" response failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
952 |
ec_datagram_print_wc_error(datagram); |
436 | 953 |
return; |
954 |
} |
|
955 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
956 |
data = ec_slave_mbox_fetch(slave, mbox, &mbox_prot, &rec_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
957 |
if (IS_ERR(data)) { |
436 | 958 |
fsm->state = ec_fsm_coe_error; |
959 |
return; |
|
960 |
} |
|
961 |
||
962 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 963 |
EC_SLAVE_ERR(slave, "Received mailbox protocol" |
964 |
" 0x%02X as response.\n", mbox_prot); |
|
436 | 965 |
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
|
966 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
967 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
968 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
969 |
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
|
970 |
// check for CoE response again |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
971 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
972 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
973 |
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
|
974 |
return; |
436 | 975 |
} |
976 |
||
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
|
977 |
if (rec_size < 3) { |
1921 | 978 |
EC_SLAVE_ERR(slave, "Received corrupted SDO entry" |
979 |
" 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
|
980 |
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
|
981 |
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
|
982 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
983 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
984 |
if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information |
436 | 985 |
(EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response |
2195
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
986 |
EC_SLAVE_WARN(slave, "SDO information error response while" |
1921 | 987 |
" fetching SDO entry 0x%04X:%02X!\n", |
436 | 988 |
sdo->index, fsm->subindex); |
1921 | 989 |
ec_canopen_abort_msg(slave, EC_READ_U32(data + 6)); |
2195
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
990 |
|
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
991 |
/* There may be gaps in the subindices, so try to continue with next |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
992 |
* subindex. */ |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
993 |
|
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
994 |
} else { |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
995 |
|
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
996 |
if (rec_size < 9) { |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
997 |
EC_SLAVE_ERR(slave, "Received corrupted SDO entry" |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
998 |
" description response (size %zu).\n", rec_size); |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
999 |
fsm->state = ec_fsm_coe_error; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1000 |
return; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1001 |
} |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1002 |
|
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1003 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1004 |
(EC_READ_U8(data + 2) & 0x7F) != 0x06 || // Entry desc. resp. |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1005 |
EC_READ_U16(data + 6) != sdo->index || // SDO index |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1006 |
EC_READ_U8(data + 8) != fsm->subindex) { // SDO subindex |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1007 |
if (fsm->slave->master->debug_level) { |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1008 |
EC_SLAVE_DBG(slave, 1, "Invalid entry description response" |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1009 |
" while fetching SDO entry 0x%04X:%02X!\n", |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1010 |
sdo->index, fsm->subindex); |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1011 |
ec_print_data(data, rec_size); |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1012 |
} |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1013 |
// check for CoE response again |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1014 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1015 |
fsm->retries = EC_FSM_RETRIES; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1016 |
fsm->state = ec_fsm_coe_dict_entry_check; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1017 |
return; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1018 |
} |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1019 |
|
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1020 |
if (rec_size < 16) { |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1021 |
EC_SLAVE_ERR(slave, "Invalid data size %zu!\n", rec_size); |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1022 |
ec_print_data(data, rec_size); |
436 | 1023 |
fsm->state = ec_fsm_coe_error; |
1024 |
return; |
|
1025 |
} |
|
2195
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1026 |
|
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1027 |
data_size = rec_size - 16; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1028 |
|
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1029 |
if (!(entry = (ec_sdo_entry_t *) |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1030 |
kmalloc(sizeof(ec_sdo_entry_t), GFP_KERNEL))) { |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1031 |
EC_SLAVE_ERR(slave, "Failed to allocate entry!\n"); |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1032 |
fsm->state = ec_fsm_coe_error; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1033 |
return; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1034 |
} |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1035 |
|
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1036 |
ec_sdo_entry_init(entry, sdo, fsm->subindex); |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1037 |
entry->data_type = EC_READ_U16(data + 10); |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1038 |
entry->bit_length = EC_READ_U16(data + 12); |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1039 |
|
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1040 |
// read access rights |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1041 |
word = EC_READ_U16(data + 14); |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1042 |
entry->read_access[EC_SDO_ENTRY_ACCESS_PREOP] = word & 0x0001; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1043 |
entry->read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = (word >> 1) & 0x0001; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1044 |
entry->read_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 2) & 0x0001; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1045 |
entry->write_access[EC_SDO_ENTRY_ACCESS_PREOP] = (word >> 3) & 0x0001; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1046 |
entry->write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = (word >> 4) & 0x0001; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1047 |
entry->write_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 5) & 0x0001; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1048 |
|
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1049 |
if (data_size) { |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1050 |
uint8_t *desc; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1051 |
if (!(desc = kmalloc(data_size + 1, GFP_KERNEL))) { |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1052 |
EC_SLAVE_ERR(slave, "Failed to allocate SDO entry name!\n"); |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1053 |
fsm->state = ec_fsm_coe_error; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1054 |
return; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1055 |
} |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1056 |
memcpy(desc, data + 16, data_size); |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1057 |
desc[data_size] = 0; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1058 |
entry->description = desc; |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1059 |
} |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1060 |
|
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1061 |
list_add_tail(&entry->list, &sdo->entries); |
d9146c0ff00f
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2194
diff
changeset
|
1062 |
} |
436 | 1063 |
|
962
ea83a7aab57a
Renamed subindices to max_subindex.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
1064 |
if (fsm->subindex < sdo->max_subindex) { |
436 | 1065 |
fsm->subindex++; |
1066 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1067 |
data = ec_slave_mbox_prepare_send(slave, mbox, 0x03, 10); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1068 |
if (IS_ERR(data)) { |
436 | 1069 |
fsm->state = ec_fsm_coe_error; |
1070 |
return; |
|
1071 |
} |
|
1072 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1073 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 1074 |
EC_WRITE_U8 (data + 2, 0x05); // Get entry description request |
1075 |
EC_WRITE_U8 (data + 3, 0x00); |
|
1076 |
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
|
1077 |
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
|
1078 |
EC_WRITE_U8 (data + 8, fsm->subindex); // SDO subindex |
436 | 1079 |
EC_WRITE_U8 (data + 9, 0x00); // value info (no values) |
1080 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1081 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1082 |
fsm->state = ec_fsm_coe_dict_entry_request; |
1083 |
return; |
|
1084 |
} |
|
1085 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1086 |
// another SDO description to fetch? |
436 | 1087 |
if (fsm->sdo->list.next != &slave->sdo_dictionary) { |
1088 |
fsm->sdo = list_entry(fsm->sdo->list.next, ec_sdo_t, list); |
|
1089 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1090 |
data = ec_slave_mbox_prepare_send(slave, mbox, 0x03, 8); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1091 |
if (IS_ERR(data)) { |
436 | 1092 |
fsm->state = ec_fsm_coe_error; |
1093 |
return; |
|
1094 |
} |
|
1095 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1096 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 1097 |
EC_WRITE_U8 (data + 2, 0x03); // Get object description request |
1098 |
EC_WRITE_U8 (data + 3, 0x00); |
|
1099 |
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
|
1100 |
EC_WRITE_U16(data + 6, fsm->sdo->index); // SDO index |
436 | 1101 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1102 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1103 |
fsm->state = ec_fsm_coe_dict_desc_request; |
1104 |
return; |
|
1105 |
} |
|
1106 |
||
1107 |
fsm->state = ec_fsm_coe_end; |
|
1108 |
} |
|
1109 |
||
1110 |
/****************************************************************************** |
|
1111 |
* CoE state machine |
|
1112 |
*****************************************************************************/ |
|
1113 |
||
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1114 |
/** 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
|
1115 |
*/ |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1116 |
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
|
1117 |
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
|
1118 |
) |
436 | 1119 |
{ |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1120 |
ec_mailbox_t *mbox = fsm->mbox; |
436 | 1121 |
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
|
1122 |
ec_sdo_request_t *request = fsm->request; |
436 | 1123 |
uint8_t *data; |
1562 | 1124 |
uint8_t data_set_size; |
436 | 1125 |
|
874 | 1126 |
if (fsm->slave->master->debug_level) { |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1127 |
char subidxstr[10]; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1128 |
if (request->complete_access) { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1129 |
subidxstr[0] = 0x00; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1130 |
} else { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1131 |
sprintf(subidxstr, ":%02X", request->subindex); |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1132 |
} |
1921 | 1133 |
EC_SLAVE_DBG(slave, 1, "Downloading SDO 0x%04X%s.\n", |
1134 |
request->index, subidxstr); |
|
874 | 1135 |
ec_print_data(request->data, request->data_size); |
1136 |
} |
|
436 | 1137 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
1138 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
1921 | 1139 |
EC_SLAVE_ERR(slave, "Slave does not support CoE!\n"); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1140 |
request->errno = EPROTONOSUPPORT; |
825
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1141 |
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
|
1142 |
return; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1143 |
} |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1144 |
|
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1145 |
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
|
1146 |
EC_MBOX_HEADER_SIZE + EC_COE_DOWN_REQ_HEADER_SIZE) { |
1921 | 1147 |
EC_SLAVE_ERR(slave, "Mailbox too small!\n"); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1148 |
request->errno = EOVERFLOW; |
1562 | 1149 |
fsm->state = ec_fsm_coe_error; |
1150 |
return; |
|
1151 |
} |
|
1152 |
||
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1153 |
if (request->data_size <= 4) { // use expedited transfer type |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1154 |
data = ec_slave_mbox_prepare_send(slave, mbox, 0x03, |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1155 |
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
|
1156 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1157 |
request->errno = PTR_ERR(data); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1158 |
fsm->state = ec_fsm_coe_error; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1159 |
return; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1160 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1161 |
|
1562 | 1162 |
fsm->remaining = 0; |
1163 |
||
1164 |
data_set_size = 4 - request->data_size; |
|
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1165 |
|
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1166 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1167 |
EC_WRITE_U8 (data + 2, (0x3 // size specified, expedited |
1562 | 1168 |
| data_set_size << 2 |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1169 |
| ((request->complete_access ? 1 : 0) << 4) |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1170 |
| 0x1 << 5)); // Download request |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1171 |
EC_WRITE_U16(data + 3, request->index); |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1172 |
EC_WRITE_U8 (data + 5, |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1173 |
request->complete_access ? 0x00 : request->subindex); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1174 |
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
|
1175 |
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
|
1176 |
|
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1177 |
if (slave->master->debug_level) { |
1921 | 1178 |
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
|
1179 |
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
|
1180 |
} |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1181 |
} |
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1182 |
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
|
1183 |
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
|
1184 |
max_data_size = |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1185 |
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
|
1186 |
required_data_size = |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1187 |
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
|
1188 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1189 |
if (max_data_size < required_data_size) { |
1562 | 1190 |
// segmenting needed |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1191 |
data_size = max_data_size; |
1562 | 1192 |
} else { |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1193 |
data_size = required_data_size; |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1194 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1195 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1196 |
data = ec_slave_mbox_prepare_send(slave, mbox, 0x03, |
1562 | 1197 |
data_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1198 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1199 |
request->errno = PTR_ERR(data); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1200 |
fsm->state = ec_fsm_coe_error; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1201 |
return; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1202 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1203 |
|
1562 | 1204 |
fsm->offset = 0; |
1205 |
fsm->remaining = request->data_size; |
|
1206 |
||
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1207 |
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
|
1208 |
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
|
1209 |
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
|
1210 |
| ((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
|
1211 |
| 0x1 << 5); // Download request |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1212 |
EC_WRITE_U16(data + 3, request->index); |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1213 |
EC_WRITE_U8 (data + 5, |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1214 |
request->complete_access ? 0x00 : request->subindex); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1215 |
EC_WRITE_U32(data + 6, request->data_size); |
1562 | 1216 |
|
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1217 |
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
|
1218 |
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
|
1219 |
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
|
1220 |
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
|
1221 |
fsm->offset += segment_size; |
1562 | 1222 |
fsm->remaining -= segment_size; |
1223 |
} |
|
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1224 |
|
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1225 |
if (slave->master->debug_level) { |
1921 | 1226 |
EC_SLAVE_DBG(slave, 1, "Normal download request:\n"); |
1562 | 1227 |
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
|
1228 |
} |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1229 |
} |
975
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1230 |
|
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1231 |
fsm->request->jiffies_sent = jiffies; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1232 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1233 |
fsm->state = ec_fsm_coe_down_request; |
1234 |
} |
|
1235 |
||
1236 |
/*****************************************************************************/ |
|
1237 |
||
1238 |
/** |
|
1239 |
CoE state: DOWN REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1240 |
\todo Timeout behavior |
436 | 1241 |
*/ |
1242 |
||
1243 |
void ec_fsm_coe_down_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1244 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1245 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1246 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 1247 |
ec_slave_t *slave = fsm->slave; |
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1248 |
unsigned long diff_ms; |
436 | 1249 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1250 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1251 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1252 |
return; // FIXME: check for response first? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1253 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1254 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1255 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1256 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1257 |
fsm->state = ec_fsm_coe_error; |
1921 | 1258 |
EC_SLAVE_ERR(slave, "Failed to receive CoE download" |
1259 |
" 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
|
1260 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1261 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1262 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1263 |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1264 |
diff_ms = (jiffies - fsm->request->jiffies_sent) * 1000 / HZ; |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1265 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1266 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1267 |
if (ec_mbox_is_datagram_wc(mbox, 0)) { |
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1268 |
if (diff_ms < fsm->request->response_timeout) { |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1269 |
#if DEBUG_RETRIES |
1931 | 1270 |
EC_SLAVE_DBG(slave, 1, "Slave did not respond to SDO" |
1271 |
" download request. Retrying after %lu ms...\n", |
|
1272 |
diff_ms); |
|
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1273 |
#endif |
1112
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1274 |
// no response; send request datagram again |
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1275 |
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
|
1276 |
} |
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1277 |
} |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1278 |
fsm->request->errno = EIO; |
505
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 download request" |
1931 | 1281 |
" for SDO 0x%04x:%x failed with timeout after %lu ms: ", |
1282 |
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
|
1283 |
ec_datagram_print_wc_error(datagram); |
436 | 1284 |
return; |
1285 |
} |
|
1286 |
||
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1287 |
#if DEBUG_LONG |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1288 |
if (diff_ms > 200) { |
1931 | 1289 |
EC_SLAVE_WARN(slave, "SDO 0x%04x:%x download took %lu ms.\n", |
1290 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1291 |
} |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1292 |
#endif |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1293 |
|
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1294 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 1295 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1296 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1297 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1298 |
fsm->state = ec_fsm_coe_down_check; |
1299 |
} |
|
1300 |
||
1301 |
/*****************************************************************************/ |
|
1302 |
||
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1303 |
/** CoE state: DOWN CHECK. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1304 |
*/ |
436 | 1305 |
void ec_fsm_coe_down_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
1306 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1307 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1308 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 1309 |
ec_slave_t *slave = fsm->slave; |
1310 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1311 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1312 |
&& fsm->retries--) { |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1313 |
return; |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1314 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1315 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1316 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1317 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1318 |
fsm->state = ec_fsm_coe_error; |
1921 | 1319 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check" |
1320 |
" 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
|
1321 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1322 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1323 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1324 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1325 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1326 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1327 |
fsm->state = ec_fsm_coe_error; |
1921 | 1328 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
1329 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1330 |
ec_datagram_print_wc_error(datagram); |
436 | 1331 |
return; |
1332 |
} |
|
1333 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1334 |
if (!ec_slave_mbox_check(mbox)) { |
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1335 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1336 |
(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
|
1337 |
if (diff_ms >= fsm->request->response_timeout) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1338 |
fsm->request->errno = EIO; |
436 | 1339 |
fsm->state = ec_fsm_coe_error; |
1931 | 1340 |
EC_SLAVE_ERR(slave, "Timeout after %lu ms while waiting" |
1341 |
" for SDO 0x%04x:%x download response.\n", diff_ms, |
|
1921 | 1342 |
fsm->request->index, fsm->request->subindex); |
436 | 1343 |
return; |
1344 |
} |
|
1345 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1346 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1347 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1348 |
return; |
1349 |
} |
|
1350 |
||
1351 |
// Fetch response |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1352 |
ec_slave_mbox_prepare_fetch(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1353 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1354 |
fsm->state = ec_fsm_coe_down_response; |
1355 |
} |
|
1356 |
||
1357 |
/*****************************************************************************/ |
|
1358 |
||
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1359 |
/** Prepare a download segment request. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1360 |
*/ |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1361 |
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
|
1362 |
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
|
1363 |
) |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1364 |
{ |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1365 |
ec_mailbox_t *mbox = fsm->mbox; |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1366 |
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
|
1367 |
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
|
1368 |
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
|
1369 |
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
|
1370 |
- 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
|
1371 |
- 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
|
1372 |
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
|
1373 |
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
|
1374 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1375 |
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
|
1376 |
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
|
1377 |
last_segment = 0; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1378 |
} else { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1379 |
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
|
1380 |
last_segment = 1; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1381 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1382 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1383 |
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
|
1384 |
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
|
1385 |
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
|
1386 |
} else { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1387 |
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
|
1388 |
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
|
1389 |
+ 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
|
1390 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1391 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1392 |
data = ec_slave_mbox_prepare_send(slave, mbox, 0x03, |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1393 |
data_size); |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1394 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1395 |
request->errno = PTR_ERR(data); |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1396 |
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
|
1397 |
return; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1398 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1399 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1400 |
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
|
1401 |
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
|
1402 |
| (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
|
1403 |
| (fsm->toggle << 4) |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1404 |
| (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
|
1405 |
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
|
1406 |
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
|
1407 |
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
|
1408 |
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
|
1409 |
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
|
1410 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1411 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1412 |
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
|
1413 |
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
|
1414 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1415 |
if (slave->master->debug_level) { |
1921 | 1416 |
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
|
1417 |
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
|
1418 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1419 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1420 |
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
|
1421 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1422 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1423 |
/*****************************************************************************/ |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1424 |
|
436 | 1425 |
/** |
1426 |
CoE state: DOWN RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1427 |
\todo Timeout behavior |
436 | 1428 |
*/ |
1429 |
||
1430 |
void ec_fsm_coe_down_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1431 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1432 |
ec_mailbox_t *mbox = fsm->mbox; |
2047
f4266c6fce7c
fixed kernel oops bug in ec_fsm_coe_down_response (Blame the C Compiler)
Martin Troxler <ch1010277@ch10pc446>
parents:
2045
diff
changeset
|
1433 |
ec_datagram_t *datagram = fsm->mbox->datagram; |
436 | 1434 |
ec_slave_t *slave = fsm->slave; |
1435 |
uint8_t *data, mbox_prot; |
|
1436 |
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
|
1437 |
ec_sdo_request_t *request = fsm->request; |
436 | 1438 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1439 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1440 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1441 |
return; // FIXME: request again? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1442 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1443 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1444 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1445 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1446 |
fsm->state = ec_fsm_coe_error; |
1921 | 1447 |
EC_SLAVE_ERR(slave, "Failed to receive CoE download" |
1448 |
" 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
|
1449 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1450 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1451 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1452 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1453 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1454 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1455 |
fsm->state = ec_fsm_coe_error; |
1921 | 1456 |
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
|
1457 |
ec_datagram_print_wc_error(datagram); |
436 | 1458 |
return; |
1459 |
} |
|
1460 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1461 |
data = ec_slave_mbox_fetch(slave, mbox, &mbox_prot, &rec_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1462 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1463 |
request->errno = PTR_ERR(data); |
436 | 1464 |
fsm->state = ec_fsm_coe_error; |
1465 |
return; |
|
1466 |
} |
|
1467 |
||
1468 |
if (mbox_prot != 0x03) { // CoE |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1469 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1470 |
fsm->state = ec_fsm_coe_error; |
1921 | 1471 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
1472 |
mbox_prot); |
|
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1473 |
return; |
436 | 1474 |
} |
1475 |
||
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1476 |
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
|
1477 |
// check for CoE response again |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1478 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1479 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1480 |
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
|
1481 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1482 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1483 |
|
975
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1484 |
if (slave->master->debug_level) { |
1921 | 1485 |
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
|
1486 |
ec_print_data(data, rec_size); |
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1487 |
} |
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1488 |
|
436 | 1489 |
if (rec_size < 6) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1490 |
request->errno = EIO; |
436 | 1491 |
fsm->state = ec_fsm_coe_error; |
1921 | 1492 |
EC_SLAVE_ERR(slave, "Received data are too small (%zu bytes):\n", |
1493 |
rec_size); |
|
436 | 1494 |
ec_print_data(data, rec_size); |
1495 |
return; |
|
1496 |
} |
|
1497 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1498 |
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
|
1499 |
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
|
1500 |
char subidxstr[10]; |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1501 |
request->errno = EIO; |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1502 |
fsm->state = ec_fsm_coe_error; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1503 |
if (request->complete_access) { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1504 |
subidxstr[0] = 0x00; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1505 |
} else { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1506 |
sprintf(subidxstr, ":%02X", request->subindex); |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1507 |
} |
1921 | 1508 |
EC_SLAVE_ERR(slave, "SDO download 0x%04X%s (%zu bytes) aborted.\n", |
1509 |
request->index, subidxstr, request->data_size); |
|
436 | 1510 |
if (rec_size < 10) { |
1921 | 1511 |
EC_SLAVE_ERR(slave, "Incomplete abort command:\n"); |
436 | 1512 |
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
|
1513 |
} 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
|
1514 |
fsm->request->abort_code = EC_READ_U32(data + 6); |
1921 | 1515 |
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
|
1516 |
} |
436 | 1517 |
return; |
1518 |
} |
|
1519 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1520 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
436 | 1521 |
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
|
1522 |
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
|
1523 |
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
|
1524 |
if (slave->master->debug_level) { |
1921 | 1525 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO download response!" |
1526 |
" Retrying...\n"); |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1527 |
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
|
1528 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1529 |
// check for CoE response again |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1530 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1531 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1532 |
fsm->state = ec_fsm_coe_down_check; |
436 | 1533 |
return; |
1534 |
} |
|
1535 |
||
1562 | 1536 |
if (fsm->remaining) { // more segments to download |
1537 |
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
|
1538 |
ec_fsm_coe_down_prepare_segment_request(fsm); |
1562 | 1539 |
} else { |
1540 |
fsm->state = ec_fsm_coe_end; // success |
|
1541 |
} |
|
1542 |
} |
|
1543 |
||
1544 |
/*****************************************************************************/ |
|
1545 |
||
1546 |
/** |
|
1547 |
CoE state: DOWN SEG CHECK. |
|
1548 |
*/ |
|
1549 |
||
1550 |
void ec_fsm_coe_down_seg_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1551 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1552 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1553 |
ec_datagram_t *datagram = mbox->datagram; |
1562 | 1554 |
ec_slave_t *slave = fsm->slave; |
1555 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1556 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1557 |
&& fsm->retries--) { |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1558 |
return; |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1559 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1560 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1561 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1562 |
fsm->request->errno = EIO; |
1562 | 1563 |
fsm->state = ec_fsm_coe_error; |
1921 | 1564 |
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
|
1565 |
ec_datagram_print_state(datagram); |
1562 | 1566 |
return; |
1567 |
} |
|
1568 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1569 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1570 |
fsm->request->errno = EIO; |
1562 | 1571 |
fsm->state = ec_fsm_coe_error; |
1921 | 1572 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox segment check" |
1573 |
" datagram failed: "); |
|
1562 | 1574 |
ec_datagram_print_wc_error(datagram); |
1575 |
return; |
|
1576 |
} |
|
1577 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1578 |
if (!ec_slave_mbox_check(mbox)) { |
1562 | 1579 |
unsigned long diff_ms = |
1580 |
(datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ; |
|
1581 |
if (diff_ms >= fsm->request->response_timeout) { |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1582 |
fsm->request->errno = EIO; |
1562 | 1583 |
fsm->state = ec_fsm_coe_error; |
1921 | 1584 |
EC_SLAVE_ERR(slave, "Timeout while waiting for SDO download" |
1585 |
" segment response.\n"); |
|
1562 | 1586 |
return; |
1587 |
} |
|
1588 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1589 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
1562 | 1590 |
fsm->retries = EC_FSM_RETRIES; |
1591 |
return; |
|
1592 |
} |
|
1593 |
||
1594 |
// Fetch response |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1595 |
ec_slave_mbox_prepare_fetch(slave, mbox); // can not fail. |
1562 | 1596 |
fsm->retries = EC_FSM_RETRIES; |
1597 |
fsm->state = ec_fsm_coe_down_seg_response; |
|
1598 |
} |
|
1599 |
||
1600 |
/*****************************************************************************/ |
|
1601 |
||
1602 |
/** |
|
1603 |
CoE state: DOWN SEG RESPONSE. |
|
1604 |
\todo Timeout behavior |
|
1605 |
*/ |
|
1606 |
||
1607 |
void ec_fsm_coe_down_seg_response( |
|
1608 |
ec_fsm_coe_t *fsm /**< finite state machine */ |
|
1609 |
) |
|
1610 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1611 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1612 |
ec_datagram_t *datagram = mbox->datagram; |
1562 | 1613 |
ec_slave_t *slave = fsm->slave; |
1614 |
uint8_t *data, mbox_prot; |
|
1615 |
size_t rec_size; |
|
1616 |
ec_sdo_request_t *request = fsm->request; |
|
1617 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1618 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1619 |
&& fsm->retries--) { |
1562 | 1620 |
return; // FIXME: request again? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1621 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1622 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1623 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1624 |
request->errno = EIO; |
1562 | 1625 |
fsm->state = ec_fsm_coe_error; |
1921 | 1626 |
EC_SLAVE_ERR(slave, "Failed to receive CoE download response" |
1627 |
" 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
|
1628 |
ec_datagram_print_state(datagram); |
1562 | 1629 |
return; |
1630 |
} |
|
1631 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1632 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1633 |
request->errno = EIO; |
1562 | 1634 |
fsm->state = ec_fsm_coe_error; |
1921 | 1635 |
EC_SLAVE_ERR(slave, "Reception of CoE download response failed: "); |
1562 | 1636 |
ec_datagram_print_wc_error(datagram); |
1637 |
return; |
|
1638 |
} |
|
1639 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1640 |
data = ec_slave_mbox_fetch(slave, mbox, &mbox_prot, &rec_size); |
1562 | 1641 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1642 |
request->errno = PTR_ERR(data); |
1562 | 1643 |
fsm->state = ec_fsm_coe_error; |
1644 |
return; |
|
1645 |
} |
|
1646 |
||
1647 |
if (mbox_prot != 0x03) { // CoE |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1648 |
request->errno = EIO; |
1562 | 1649 |
fsm->state = ec_fsm_coe_error; |
1921 | 1650 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
1651 |
mbox_prot); |
|
1562 | 1652 |
return; |
1653 |
} |
|
1654 |
||
1655 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
|
1656 |
// check for CoE response again |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1657 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
1562 | 1658 |
fsm->retries = EC_FSM_RETRIES; |
1659 |
fsm->state = ec_fsm_coe_down_check; |
|
1660 |
return; |
|
1661 |
} |
|
1662 |
||
1663 |
if (slave->master->debug_level) { |
|
1921 | 1664 |
EC_SLAVE_DBG(slave, 1, "Download response:\n"); |
1562 | 1665 |
ec_print_data(data, rec_size); |
1666 |
} |
|
1667 |
||
1668 |
if (rec_size < 6) { |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1669 |
request->errno = EIO; |
1562 | 1670 |
fsm->state = ec_fsm_coe_error; |
1921 | 1671 |
EC_SLAVE_ERR(slave, "Received data are too small (%zu bytes):\n", |
1672 |
rec_size); |
|
1562 | 1673 |
ec_print_data(data, rec_size); |
1674 |
return; |
|
1675 |
} |
|
1676 |
||
1677 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
|
1678 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
|
1679 |
char subidxstr[10]; |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1680 |
request->errno = EIO; |
1562 | 1681 |
fsm->state = ec_fsm_coe_error; |
1682 |
if (request->complete_access) { |
|
1683 |
subidxstr[0] = 0x00; |
|
1684 |
} else { |
|
1685 |
sprintf(subidxstr, ":%02X", request->subindex); |
|
1686 |
} |
|
1921 | 1687 |
EC_SLAVE_ERR(slave, "SDO download 0x%04X%s (%zu bytes) aborted.\n", |
1688 |
request->index, subidxstr, request->data_size); |
|
1562 | 1689 |
if (rec_size < 10) { |
1921 | 1690 |
EC_SLAVE_ERR(slave, "Incomplete abort command:\n"); |
1562 | 1691 |
ec_print_data(data, rec_size); |
1692 |
} else { |
|
1693 |
fsm->request->abort_code = EC_READ_U32(data + 6); |
|
1921 | 1694 |
ec_canopen_abort_msg(slave, fsm->request->abort_code); |
1562 | 1695 |
} |
1696 |
return; |
|
1697 |
} |
|
1698 |
||
1699 |
if (EC_READ_U16(data) >> 12 != 0x3 || |
|
1700 |
((EC_READ_U8(data + 2) >> 5) != 0x01)) { // segment response |
|
1701 |
if (slave->master->debug_level) { |
|
1921 | 1702 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO download response!" |
1703 |
" Retrying...\n"); |
|
1562 | 1704 |
ec_print_data(data, rec_size); |
1705 |
} |
|
1706 |
// check for CoE response again |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1707 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
1562 | 1708 |
fsm->retries = EC_FSM_RETRIES; |
1709 |
fsm->state = ec_fsm_coe_down_seg_check; |
|
1710 |
return; |
|
1711 |
} |
|
1712 |
||
1713 |
if (((EC_READ_U8(data + 2) >> 4) & 0x01) != fsm->toggle) { |
|
1921 | 1714 |
EC_SLAVE_ERR(slave, "Invalid toggle received during" |
1715 |
" segmented download:\n"); |
|
1562 | 1716 |
ec_print_data(data, rec_size); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1717 |
request->errno = EIO; |
1562 | 1718 |
fsm->state = ec_fsm_coe_error; |
1719 |
return; |
|
1720 |
} |
|
1721 |
||
1722 |
if (fsm->remaining) { // more segments to download |
|
1723 |
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
|
1724 |
ec_fsm_coe_down_prepare_segment_request(fsm); |
1562 | 1725 |
} else { |
1726 |
fsm->state = ec_fsm_coe_end; // success |
|
1727 |
} |
|
436 | 1728 |
} |
1729 |
||
1730 |
/*****************************************************************************/ |
|
1731 |
||
1732 |
/** |
|
1733 |
CoE state: UP START. |
|
1734 |
*/ |
|
1735 |
||
1736 |
void ec_fsm_coe_up_start(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1737 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1738 |
ec_mailbox_t *mbox = fsm->mbox; |
436 | 1739 |
ec_slave_t *slave = fsm->slave; |
1740 |
ec_master_t *master = slave->master; |
|
1741 |
ec_sdo_request_t *request = fsm->request; |
|
1742 |
uint8_t *data; |
|
1743 |
||
1921 | 1744 |
EC_SLAVE_DBG(slave, 1, "Uploading SDO 0x%04X:%02X.\n", |
1745 |
request->index, request->subindex); |
|
436 | 1746 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
1747 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
1921 | 1748 |
EC_SLAVE_ERR(slave, "Slave does not support CoE!\n"); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1749 |
request->errno = EPROTONOSUPPORT; |
825
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1750 |
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
|
1751 |
return; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1752 |
} |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1753 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1754 |
data = ec_slave_mbox_prepare_send(slave, mbox, 0x03, 10); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1755 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1756 |
request->errno = PTR_ERR(data); |
436 | 1757 |
fsm->state = ec_fsm_coe_error; |
1758 |
return; |
|
1759 |
} |
|
1760 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1761 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
436 | 1762 |
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
|
1763 |
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
|
1764 |
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
|
1765 |
memset(data + 6, 0x00, 4); |
436 | 1766 |
|
1767 |
if (master->debug_level) { |
|
1921 | 1768 |
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
|
1769 |
ec_print_data(data, 10); |
436 | 1770 |
} |
1771 |
||
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1772 |
fsm->request->jiffies_sent = jiffies; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1773 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1774 |
fsm->state = ec_fsm_coe_up_request; |
1775 |
} |
|
1776 |
||
1777 |
/*****************************************************************************/ |
|
1778 |
||
1779 |
/** |
|
1780 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1781 |
\todo Timeout behavior |
436 | 1782 |
*/ |
1783 |
||
1784 |
void ec_fsm_coe_up_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1785 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1786 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1787 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 1788 |
ec_slave_t *slave = fsm->slave; |
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1789 |
unsigned long diff_ms; |
436 | 1790 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1791 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1792 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1793 |
return; // FIXME: check for response first? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1794 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1795 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1796 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1797 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1798 |
fsm->state = ec_fsm_coe_error; |
1921 | 1799 |
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
|
1800 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1801 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1802 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1803 |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1804 |
diff_ms = (jiffies - fsm->request->jiffies_sent) * 1000 / HZ; |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1805 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1806 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1807 |
if (ec_mbox_is_datagram_wc(mbox, 0)) { |
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1808 |
if (diff_ms < fsm->request->response_timeout) { |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1809 |
#if DEBUG_RETRIES |
1921 | 1810 |
EC_SLAVE_DBG(slave, 1, "Slave did not respond to" |
1931 | 1811 |
" SDO upload request. Retrying after %lu ms...\n", |
1812 |
diff_ms); |
|
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1813 |
#endif |
1112
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1814 |
// no response; send request datagram again |
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1815 |
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
|
1816 |
} |
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1817 |
} |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1818 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1819 |
fsm->state = ec_fsm_coe_error; |
1921 | 1820 |
EC_SLAVE_ERR(slave, "Reception of CoE upload request for" |
1931 | 1821 |
" SDO 0x%04x:%x failed with timeout after %lu ms: ", |
1822 |
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
|
1823 |
ec_datagram_print_wc_error(datagram); |
436 | 1824 |
return; |
1825 |
} |
|
1826 |
||
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1827 |
#if DEBUG_LONG |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1828 |
if (diff_ms > 200) { |
1931 | 1829 |
EC_SLAVE_WARN(slave, "SDO 0x%04x:%x upload took %lu ms.\n", |
1830 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1831 |
} |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1832 |
#endif |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1833 |
|
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1834 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 1835 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1836 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1837 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1838 |
fsm->state = ec_fsm_coe_up_check; |
1839 |
} |
|
1840 |
||
1841 |
/*****************************************************************************/ |
|
1842 |
||
1843 |
/** |
|
1844 |
CoE state: UP CHECK. |
|
1845 |
*/ |
|
1846 |
||
1847 |
void ec_fsm_coe_up_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1848 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1849 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1850 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 1851 |
ec_slave_t *slave = fsm->slave; |
1852 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1853 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1854 |
&& fsm->retries--) { |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1855 |
return; |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1856 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1857 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1858 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1859 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1860 |
fsm->state = ec_fsm_coe_error; |
1921 | 1861 |
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
|
1862 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1863 |
return; |
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 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1866 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1867 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1868 |
fsm->state = ec_fsm_coe_error; |
1921 | 1869 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
1870 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1871 |
ec_datagram_print_wc_error(datagram); |
436 | 1872 |
return; |
1873 |
} |
|
1874 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1875 |
if (!ec_slave_mbox_check(mbox)) { |
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1876 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1877 |
(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
|
1878 |
if (diff_ms >= fsm->request->response_timeout) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1879 |
fsm->request->errno = EIO; |
436 | 1880 |
fsm->state = ec_fsm_coe_error; |
1931 | 1881 |
EC_SLAVE_ERR(slave, "Timeout after %lu ms while waiting for" |
1882 |
" SDO 0x%04x:%x upload response.\n", diff_ms, |
|
1921 | 1883 |
fsm->request->index, fsm->request->subindex); |
436 | 1884 |
return; |
1885 |
} |
|
1886 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1887 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1888 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1889 |
return; |
1890 |
} |
|
1891 |
||
1892 |
// Fetch response |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1893 |
ec_slave_mbox_prepare_fetch(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1894 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1895 |
fsm->state = ec_fsm_coe_up_response; |
1896 |
} |
|
1897 |
||
1898 |
/*****************************************************************************/ |
|
1899 |
||
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1900 |
/** 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
|
1901 |
*/ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1902 |
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
|
1903 |
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
|
1904 |
) |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1905 |
{ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1906 |
uint8_t *data = |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1907 |
ec_slave_mbox_prepare_send(fsm->slave, fsm->mbox, 0x03, 10); |
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1908 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1909 |
fsm->request->errno = PTR_ERR(data); |
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1910 |
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
|
1911 |
return; |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1912 |
} |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1913 |
|
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1914 |
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
|
1915 |
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
|
1916 |
| 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
|
1917 |
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
|
1918 |
|
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1919 |
if (fsm->slave->master->debug_level) { |
1921 | 1920 |
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
|
1921 |
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
|
1922 |
} |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1923 |
} |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1924 |
|
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1925 |
/*****************************************************************************/ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1926 |
|
436 | 1927 |
/** |
1928 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1929 |
\todo Timeout behavior |
436 | 1930 |
*/ |
1931 |
||
1932 |
void ec_fsm_coe_up_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1933 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1934 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1935 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 1936 |
ec_slave_t *slave = fsm->slave; |
1937 |
ec_master_t *master = slave->master; |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1938 |
uint16_t rec_index; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1939 |
uint8_t *data, mbox_prot, rec_subindex; |
436 | 1940 |
size_t rec_size, data_size; |
1941 |
ec_sdo_request_t *request = fsm->request; |
|
1942 |
unsigned int expedited, size_specified; |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1943 |
int ret; |
436 | 1944 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1945 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1946 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1947 |
return; // FIXME: request again? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1948 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1949 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1950 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1951 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1952 |
fsm->state = ec_fsm_coe_error; |
1921 | 1953 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload response" |
1954 |
" 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
|
1955 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1956 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1957 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1958 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1959 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1960 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1961 |
fsm->state = ec_fsm_coe_error; |
1921 | 1962 |
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
|
1963 |
ec_datagram_print_wc_error(datagram); |
436 | 1964 |
return; |
1965 |
} |
|
1966 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1967 |
data = ec_slave_mbox_fetch(slave, mbox, &mbox_prot, &rec_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1968 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1969 |
request->errno = PTR_ERR(data); |
436 | 1970 |
fsm->state = ec_fsm_coe_error; |
1971 |
return; |
|
1972 |
} |
|
1973 |
||
1974 |
if (master->debug_level) { |
|
1921 | 1975 |
EC_SLAVE_DBG(slave, 1, "Upload response:\n"); |
436 | 1976 |
ec_print_data(data, rec_size); |
1977 |
} |
|
1978 |
||
1979 |
if (mbox_prot != 0x03) { // CoE |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1980 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1981 |
fsm->state = ec_fsm_coe_error; |
1921 | 1982 |
EC_SLAVE_WARN(slave, "Received mailbox protocol 0x%02X" |
1983 |
" 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
|
1984 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1985 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1986 |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1987 |
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
|
1988 |
// check for CoE response again |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
1989 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1990 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1991 |
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
|
1992 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1993 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1994 |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1995 |
if (rec_size < 6) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1996 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1997 |
fsm->state = ec_fsm_coe_error; |
1921 | 1998 |
EC_SLAVE_ERR(slave, "Received currupted SDO upload response" |
1999 |
" (%zu bytes)!\n", rec_size); |
|
436 | 2000 |
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
|
2001 |
return; |
436 | 2002 |
} |
2003 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
2004 |
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
|
2005 |
EC_READ_U8(data + 2) >> 5 == 0x4) { // abort SDO transfer request |
1921 | 2006 |
EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X aborted.\n", |
2007 |
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
|
2008 |
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
|
2009 |
request->abort_code = EC_READ_U32(data + 6); |
1921 | 2010 |
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
|
2011 |
} else { |
1921 | 2012 |
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
|
2013 |
} |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2014 |
request->errno = EIO; |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2015 |
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
|
2016 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2017 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2018 |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2019 |
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
|
2020 |
EC_READ_U8(data + 2) >> 5 != 0x2) { // upload response |
1921 | 2021 |
EC_SLAVE_ERR(slave, "Received unknown response while" |
2022 |
" uploading SDO 0x%04X:%02X.\n", |
|
2023 |
request->index, request->subindex); |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2024 |
ec_print_data(data, rec_size); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2025 |
request->errno = EIO; |
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2026 |
fsm->state = ec_fsm_coe_error; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2027 |
return; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2028 |
} |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2029 |
|
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2030 |
rec_index = EC_READ_U16(data + 3); |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2031 |
rec_subindex = EC_READ_U8(data + 5); |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2032 |
|
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2033 |
if (rec_index != request->index || rec_subindex != request->subindex) { |
1921 | 2034 |
EC_SLAVE_ERR(slave, "Received upload response for wrong SDO" |
2035 |
" (0x%04X:%02X, requested: 0x%04X:%02X).\n", |
|
2036 |
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
|
2037 |
ec_print_data(data, rec_size); |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2038 |
|
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2039 |
// check for CoE response again |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
2040 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2041 |
fsm->retries = EC_FSM_RETRIES; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2042 |
fsm->state = ec_fsm_coe_up_check; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2043 |
return; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2044 |
} |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2045 |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2046 |
// normal or expedited? |
436 | 2047 |
expedited = EC_READ_U8(data + 2) & 0x02; |
2048 |
||
2049 |
if (expedited) { |
|
2050 |
size_specified = EC_READ_U8(data + 2) & 0x01; |
|
2051 |
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
|
2052 |
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
|
2053 |
} 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
|
2054 |
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
|
2055 |
} |
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
|
2056 |
|
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
|
2057 |
if (rec_size < 6 + fsm->complete_size) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2058 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
2059 |
fsm->state = ec_fsm_coe_error; |
1921 | 2060 |
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
|
2061 |
" 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
|
2062 |
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
|
2063 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2064 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2065 |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2066 |
ret = ec_sdo_request_copy_data(request, data + 6, fsm->complete_size); |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2067 |
if (ret) { |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2068 |
request->errno = -ret; |
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
|
2069 |
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
|
2070 |
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
|
2071 |
} |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2072 |
} else { // normal |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2073 |
if (rec_size < 10) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2074 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
2075 |
fsm->state = ec_fsm_coe_error; |
1921 | 2076 |
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
|
2077 |
" 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
|
2078 |
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
|
2079 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2080 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2081 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2082 |
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
|
2083 |
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
|
2084 |
|
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
|
2085 |
if (!fsm->complete_size) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2086 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
2087 |
fsm->state = ec_fsm_coe_error; |
1921 | 2088 |
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
|
2089 |
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
|
2090 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2091 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2092 |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2093 |
ret = ec_sdo_request_alloc(request, fsm->complete_size); |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2094 |
if (ret) { |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2095 |
request->errno = -ret; |
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
|
2096 |
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
|
2097 |
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
|
2098 |
} |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2099 |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2100 |
ret = ec_sdo_request_copy_data(request, data + 10, data_size); |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2101 |
if (ret) { |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2102 |
request->errno = -ret; |
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
|
2103 |
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
|
2104 |
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
|
2105 |
} |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2106 |
|
436 | 2107 |
fsm->toggle = 0; |
2108 |
||
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
|
2109 |
if (data_size < fsm->complete_size) { |
1921 | 2110 |
EC_SLAVE_DBG(slave, 1, "SDO data incomplete (%zu / %u)." |
2111 |
" 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
|
2112 |
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
|
2113 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2114 |
fsm->state = ec_fsm_coe_up_seg_request; |
2115 |
return; |
|
2116 |
} |
|
2117 |
} |
|
2118 |
||
874 | 2119 |
if (master->debug_level) { |
1921 | 2120 |
EC_SLAVE_DBG(slave, 1, "Uploaded data:\n"); |
874 | 2121 |
ec_print_data(request->data, request->data_size); |
2122 |
} |
|
2123 |
||
436 | 2124 |
fsm->state = ec_fsm_coe_end; // success |
2125 |
} |
|
2126 |
||
2127 |
/*****************************************************************************/ |
|
2128 |
||
2129 |
/** |
|
2130 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2131 |
\todo Timeout behavior |
436 | 2132 |
*/ |
2133 |
||
2134 |
void ec_fsm_coe_up_seg_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2135 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
2136 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
2137 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 2138 |
ec_slave_t *slave = fsm->slave; |
2139 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2140 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2141 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
2142 |
return; // FIXME: check for response first? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2143 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2144 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2145 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2146 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2147 |
fsm->state = ec_fsm_coe_error; |
1921 | 2148 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload segment" |
2149 |
" 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
|
2150 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2151 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2152 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2153 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2154 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2155 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2156 |
fsm->state = ec_fsm_coe_error; |
1921 | 2157 |
EC_SLAVE_ERR(slave, "Reception of CoE upload segment" |
2158 |
" request failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
2159 |
ec_datagram_print_wc_error(datagram); |
436 | 2160 |
return; |
2161 |
} |
|
2162 |
||
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
2163 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 2164 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
2165 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2166 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2167 |
fsm->state = ec_fsm_coe_up_seg_check; |
2168 |
} |
|
2169 |
||
2170 |
/*****************************************************************************/ |
|
2171 |
||
2172 |
/** |
|
2173 |
CoE state: UP CHECK. |
|
2174 |
*/ |
|
2175 |
||
2176 |
void ec_fsm_coe_up_seg_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2177 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
2178 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
2179 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 2180 |
ec_slave_t *slave = fsm->slave; |
2181 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2182 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2183 |
&& fsm->retries--) { |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2184 |
return; |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2185 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2186 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2187 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2188 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2189 |
fsm->state = ec_fsm_coe_error; |
1921 | 2190 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check" |
2191 |
" 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
|
2192 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2193 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2194 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2195 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2196 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2197 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2198 |
fsm->state = ec_fsm_coe_error; |
1921 | 2199 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check datagram" |
2200 |
" failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
2201 |
ec_datagram_print_wc_error(datagram); |
436 | 2202 |
return; |
2203 |
} |
|
2204 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
2205 |
if (!ec_slave_mbox_check(mbox)) { |
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
2206 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
2207 |
(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
|
2208 |
if (diff_ms >= fsm->request->response_timeout) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2209 |
fsm->request->errno = EIO; |
436 | 2210 |
fsm->state = ec_fsm_coe_error; |
1921 | 2211 |
EC_SLAVE_ERR(slave, "Timeout while waiting for SDO upload" |
2212 |
" segment response.\n"); |
|
436 | 2213 |
return; |
2214 |
} |
|
2215 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
2216 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2217 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2218 |
return; |
2219 |
} |
|
2220 |
||
2221 |
// Fetch response |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
2222 |
ec_slave_mbox_prepare_fetch(slave, mbox); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2223 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2224 |
fsm->state = ec_fsm_coe_up_seg_response; |
2225 |
} |
|
2226 |
||
2227 |
/*****************************************************************************/ |
|
2228 |
||
2229 |
/** |
|
2230 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2231 |
\todo Timeout behavior |
436 | 2232 |
*/ |
2233 |
||
2234 |
void ec_fsm_coe_up_seg_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2235 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
2236 |
ec_mailbox_t *mbox = fsm->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
2237 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 2238 |
ec_slave_t *slave = fsm->slave; |
2239 |
ec_master_t *master = slave->master; |
|
2240 |
uint8_t *data, mbox_prot; |
|
2241 |
size_t rec_size, data_size; |
|
2242 |
ec_sdo_request_t *request = fsm->request; |
|
2243 |
unsigned int last_segment; |
|
2244 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2245 |
if (ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_TIMED_OUT) |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2246 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
2247 |
return; // FIXME: request again? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2248 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2249 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2250 |
if (!ec_mbox_is_datagram_state(mbox, EC_DATAGRAM_RECEIVED)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2251 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2252 |
fsm->state = ec_fsm_coe_error; |
1921 | 2253 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload segment" |
2254 |
" 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
|
2255 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2256 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2257 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2258 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2259 |
if (!ec_mbox_is_datagram_wc(mbox, 1)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2260 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2261 |
fsm->state = ec_fsm_coe_error; |
1921 | 2262 |
EC_SLAVE_ERR(slave, "Reception of CoE upload segment" |
2263 |
" response failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
2264 |
ec_datagram_print_wc_error(datagram); |
436 | 2265 |
return; |
2266 |
} |
|
2267 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
2268 |
data = ec_slave_mbox_fetch(slave, mbox, &mbox_prot, &rec_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
2269 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2270 |
request->errno = PTR_ERR(data); |
436 | 2271 |
fsm->state = ec_fsm_coe_error; |
2272 |
return; |
|
2273 |
} |
|
2274 |
||
2275 |
if (master->debug_level) { |
|
1921 | 2276 |
EC_SLAVE_DBG(slave, 1, "Upload segment response:\n"); |
436 | 2277 |
ec_print_data(data, rec_size); |
2278 |
} |
|
2279 |
||
2280 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 2281 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
2282 |
mbox_prot); |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2283 |
request->errno = EIO; |
436 | 2284 |
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
|
2285 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2286 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2287 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2288 |
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
|
2289 |
// check for CoE response again |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
2290 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2291 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2292 |
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
|
2293 |
return; |
436 | 2294 |
} |
2295 |
||
2296 |
if (rec_size < 10) { |
|
1921 | 2297 |
EC_SLAVE_ERR(slave, "Received currupted SDO upload" |
2298 |
" segment response!\n"); |
|
436 | 2299 |
ec_print_data(data, rec_size); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2300 |
request->errno = EIO; |
436 | 2301 |
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
|
2302 |
return; |
436 | 2303 |
} |
2304 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
2305 |
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
|
2306 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
1921 | 2307 |
EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X aborted.\n", |
2308 |
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
|
2309 |
request->abort_code = EC_READ_U32(data + 6); |
1921 | 2310 |
ec_canopen_abort_msg(slave, request->abort_code); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2311 |
request->errno = EIO; |
436 | 2312 |
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
|
2313 |
return; |
436 | 2314 |
} |
2315 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
2316 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
436 | 2317 |
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
|
2318 |
if (fsm->slave->master->debug_level) { |
1921 | 2319 |
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
|
2320 |
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
|
2321 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2322 |
// check for CoE response again |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
2041
diff
changeset
|
2323 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2324 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2325 |
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
|
2326 |
return; |
436 | 2327 |
} |
2328 |
||
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
|
2329 |
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
|
2330 |
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
|
2331 |
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
|
2332 |
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
|
2333 |
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
|
2334 |
} |
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
|
2335 |
|
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
|
2336 |
if (request->data_size + data_size > fsm->complete_size) { |
1921 | 2337 |
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
|
2338 |
" exceeding complete size!\n", |
1921 | 2339 |
request->index, request->subindex); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2340 |
request->errno = EOVERFLOW; |
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
|
2341 |
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
|
2342 |
return; |
436 | 2343 |
} |
2344 |
||
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2345 |
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
|
2346 |
request->data_size += data_size; |
436 | 2347 |
|
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
|
2348 |
last_segment = EC_READ_U8(data + 2) & 0x01; |
436 | 2349 |
if (!last_segment) { |
2350 |
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
|
2351 |
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
|
2352 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2353 |
fsm->state = ec_fsm_coe_up_seg_request; |
2354 |
return; |
|
2355 |
} |
|
2356 |
||
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
|
2357 |
if (request->data_size != fsm->complete_size) { |
1921 | 2358 |
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
|
2359 |
" size (%zu) does not match complete size (%u)!\n", |
1921 | 2360 |
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
|
2361 |
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
|
2362 |
} |
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
|
2363 |
|
874 | 2364 |
if (master->debug_level) { |
1921 | 2365 |
EC_SLAVE_DBG(slave, 1, "Uploaded data:\n"); |
874 | 2366 |
ec_print_data(request->data, request->data_size); |
2367 |
} |
|
2368 |
||
436 | 2369 |
fsm->state = ec_fsm_coe_end; // success |
2370 |
} |
|
2371 |
||
2372 |
/*****************************************************************************/ |
|
2373 |
||
2374 |
/** |
|
2375 |
State: ERROR. |
|
2376 |
*/ |
|
2377 |
||
2378 |
void ec_fsm_coe_error(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2379 |
{ |
|
2380 |
} |
|
2381 |
||
2382 |
/*****************************************************************************/ |
|
2383 |
||
2384 |
/** |
|
2385 |
State: END. |
|
2386 |
*/ |
|
2387 |
||
2388 |
void ec_fsm_coe_end(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2389 |
{ |
|
2390 |
} |
|
2391 |
||
2392 |
/*****************************************************************************/ |