author | Florian Pose <fp@igh-essen.com> |
Fri, 28 Oct 2011 11:31:54 +0200 | |
changeset 2126 | 0383b71b88e4 |
parent 2094 | 83e9160319ec |
child 2194 | 1b583b3110cb |
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 |
||
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
|
510 |
if (rec_size < 8 || rec_size % 2) { |
1921 | 511 |
EC_SLAVE_ERR(slave, "Invalid data size %zu!\n", rec_size); |
436 | 512 |
ec_print_data(data, rec_size); |
513 |
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
|
514 |
return; |
436 | 515 |
} |
516 |
||
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
|
517 |
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
|
518 |
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
|
519 |
|
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 |
1921 | 986 |
EC_SLAVE_ERR(slave, "SDO information error response while" |
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)); |
436 | 990 |
fsm->state = ec_fsm_coe_error; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
991 |
return; |
436 | 992 |
} |
993 |
||
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
|
994 |
if (rec_size < 9) { |
1921 | 995 |
EC_SLAVE_ERR(slave, "Received corrupted SDO entry" |
996 |
" 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
|
997 |
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
|
998 |
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
|
999 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1000 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1001 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
436 | 1002 |
(EC_READ_U8(data + 2) & 0x7F) != 0x06 || // Entry desc. response |
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1003 |
EC_READ_U16(data + 6) != sdo->index || // SDO index |
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1004 |
EC_READ_U8(data + 8) != fsm->subindex) { // SDO subindex |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1005 |
if (fsm->slave->master->debug_level) { |
1921 | 1006 |
EC_SLAVE_DBG(slave, 1, "Invalid entry description response while" |
1007 |
" fetching SDO entry 0x%04X:%02X!\n", |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1008 |
sdo->index, fsm->subindex); |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1009 |
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
|
1010 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1011 |
// 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
|
1012 |
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
|
1013 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1014 |
fsm->state = ec_fsm_coe_dict_entry_check; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1015 |
return; |
436 | 1016 |
} |
1017 |
||
1018 |
if (rec_size < 16) { |
|
1921 | 1019 |
EC_SLAVE_ERR(slave, "Invalid data size %zu!\n", rec_size); |
436 | 1020 |
ec_print_data(data, rec_size); |
1021 |
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
|
1022 |
return; |
436 | 1023 |
} |
1024 |
||
1025 |
data_size = rec_size - 16; |
|
1026 |
||
1027 |
if (!(entry = (ec_sdo_entry_t *) |
|
998
05a24788f3b2
Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents:
992
diff
changeset
|
1028 |
kmalloc(sizeof(ec_sdo_entry_t), GFP_KERNEL))) { |
1921 | 1029 |
EC_SLAVE_ERR(slave, "Failed to allocate entry!\n"); |
436 | 1030 |
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
|
1031 |
return; |
436 | 1032 |
} |
1033 |
||
991
2548ca639b1f
Removed kobject from sdo entry.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
1034 |
ec_sdo_entry_init(entry, sdo, fsm->subindex); |
436 | 1035 |
entry->data_type = EC_READ_U16(data + 10); |
1036 |
entry->bit_length = EC_READ_U16(data + 12); |
|
1037 |
||
1382
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1038 |
// read access rights |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1039 |
word = EC_READ_U16(data + 14); |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1040 |
entry->read_access[EC_SDO_ENTRY_ACCESS_PREOP] = word & 0x0001; |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1041 |
entry->read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = (word >> 1) & 0x0001; |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1042 |
entry->read_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 2) & 0x0001; |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1043 |
entry->write_access[EC_SDO_ENTRY_ACCESS_PREOP] = (word >> 3) & 0x0001; |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1044 |
entry->write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = (word >> 4) & 0x0001; |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1045 |
entry->write_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 5) & 0x0001; |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1046 |
|
436 | 1047 |
if (data_size) { |
484
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
1048 |
uint8_t *desc; |
998
05a24788f3b2
Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents:
992
diff
changeset
|
1049 |
if (!(desc = kmalloc(data_size + 1, GFP_KERNEL))) { |
1921 | 1050 |
EC_SLAVE_ERR(slave, "Failed to allocate SDO entry name!\n"); |
436 | 1051 |
fsm->state = ec_fsm_coe_error; |
1052 |
return; |
|
1053 |
} |
|
484
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
1054 |
memcpy(desc, data + 16, data_size); |
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
1055 |
desc[data_size] = 0; |
9fde4a17b820
kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents:
476
diff
changeset
|
1056 |
entry->description = desc; |
436 | 1057 |
} |
1058 |
||
1059 |
list_add_tail(&entry->list, &sdo->entries); |
|
1060 |
||
962
ea83a7aab57a
Renamed subindices to max_subindex.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
1061 |
if (fsm->subindex < sdo->max_subindex) { |
436 | 1062 |
fsm->subindex++; |
1063 |
||
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
|
1064 |
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
|
1065 |
if (IS_ERR(data)) { |
436 | 1066 |
fsm->state = ec_fsm_coe_error; |
1067 |
return; |
|
1068 |
} |
|
1069 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1070 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 1071 |
EC_WRITE_U8 (data + 2, 0x05); // Get entry description request |
1072 |
EC_WRITE_U8 (data + 3, 0x00); |
|
1073 |
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
|
1074 |
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
|
1075 |
EC_WRITE_U8 (data + 8, fsm->subindex); // SDO subindex |
436 | 1076 |
EC_WRITE_U8 (data + 9, 0x00); // value info (no values) |
1077 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1078 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1079 |
fsm->state = ec_fsm_coe_dict_entry_request; |
1080 |
return; |
|
1081 |
} |
|
1082 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1083 |
// another SDO description to fetch? |
436 | 1084 |
if (fsm->sdo->list.next != &slave->sdo_dictionary) { |
1085 |
fsm->sdo = list_entry(fsm->sdo->list.next, ec_sdo_t, list); |
|
1086 |
||
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
|
1087 |
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
|
1088 |
if (IS_ERR(data)) { |
436 | 1089 |
fsm->state = ec_fsm_coe_error; |
1090 |
return; |
|
1091 |
} |
|
1092 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1093 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 1094 |
EC_WRITE_U8 (data + 2, 0x03); // Get object description request |
1095 |
EC_WRITE_U8 (data + 3, 0x00); |
|
1096 |
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
|
1097 |
EC_WRITE_U16(data + 6, fsm->sdo->index); // SDO index |
436 | 1098 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1099 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1100 |
fsm->state = ec_fsm_coe_dict_desc_request; |
1101 |
return; |
|
1102 |
} |
|
1103 |
||
1104 |
fsm->state = ec_fsm_coe_end; |
|
1105 |
} |
|
1106 |
||
1107 |
/****************************************************************************** |
|
1108 |
* CoE state machine |
|
1109 |
*****************************************************************************/ |
|
1110 |
||
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1111 |
/** 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
|
1112 |
*/ |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1113 |
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
|
1114 |
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
|
1115 |
) |
436 | 1116 |
{ |
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
|
1117 |
ec_mailbox_t *mbox = fsm->mbox; |
436 | 1118 |
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
|
1119 |
ec_sdo_request_t *request = fsm->request; |
436 | 1120 |
uint8_t *data; |
1562 | 1121 |
uint8_t data_set_size; |
436 | 1122 |
|
874 | 1123 |
if (fsm->slave->master->debug_level) { |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1124 |
char subidxstr[10]; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1125 |
if (request->complete_access) { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1126 |
subidxstr[0] = 0x00; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1127 |
} else { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1128 |
sprintf(subidxstr, ":%02X", request->subindex); |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1129 |
} |
1921 | 1130 |
EC_SLAVE_DBG(slave, 1, "Downloading SDO 0x%04X%s.\n", |
1131 |
request->index, subidxstr); |
|
874 | 1132 |
ec_print_data(request->data, request->data_size); |
1133 |
} |
|
436 | 1134 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
1135 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
1921 | 1136 |
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
|
1137 |
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
|
1138 |
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
|
1139 |
return; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1140 |
} |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1141 |
|
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1142 |
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
|
1143 |
EC_MBOX_HEADER_SIZE + EC_COE_DOWN_REQ_HEADER_SIZE) { |
1921 | 1144 |
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
|
1145 |
request->errno = EOVERFLOW; |
1562 | 1146 |
fsm->state = ec_fsm_coe_error; |
1147 |
return; |
|
1148 |
} |
|
1149 |
||
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1150 |
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
|
1151 |
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
|
1152 |
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
|
1153 |
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
|
1154 |
request->errno = PTR_ERR(data); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1155 |
fsm->state = ec_fsm_coe_error; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1156 |
return; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1157 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1158 |
|
1562 | 1159 |
fsm->remaining = 0; |
1160 |
||
1161 |
data_set_size = 4 - request->data_size; |
|
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1162 |
|
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1163 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1164 |
EC_WRITE_U8 (data + 2, (0x3 // size specified, expedited |
1562 | 1165 |
| data_set_size << 2 |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1166 |
| ((request->complete_access ? 1 : 0) << 4) |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1167 |
| 0x1 << 5)); // Download request |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1168 |
EC_WRITE_U16(data + 3, request->index); |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1169 |
EC_WRITE_U8 (data + 5, |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1170 |
request->complete_access ? 0x00 : request->subindex); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1171 |
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
|
1172 |
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
|
1173 |
|
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1174 |
if (slave->master->debug_level) { |
1921 | 1175 |
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
|
1176 |
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
|
1177 |
} |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1178 |
} |
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1179 |
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
|
1180 |
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
|
1181 |
max_data_size = |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1182 |
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
|
1183 |
required_data_size = |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1184 |
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
|
1185 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1186 |
if (max_data_size < required_data_size) { |
1562 | 1187 |
// segmenting needed |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1188 |
data_size = max_data_size; |
1562 | 1189 |
} else { |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1190 |
data_size = required_data_size; |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1191 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1192 |
|
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
|
1193 |
data = ec_slave_mbox_prepare_send(slave, mbox, 0x03, |
1562 | 1194 |
data_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1195 |
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
|
1196 |
request->errno = PTR_ERR(data); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1197 |
fsm->state = ec_fsm_coe_error; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1198 |
return; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1199 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1200 |
|
1562 | 1201 |
fsm->offset = 0; |
1202 |
fsm->remaining = request->data_size; |
|
1203 |
||
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1204 |
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
|
1205 |
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
|
1206 |
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
|
1207 |
| ((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
|
1208 |
| 0x1 << 5); // Download request |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1209 |
EC_WRITE_U16(data + 3, request->index); |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1210 |
EC_WRITE_U8 (data + 5, |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1211 |
request->complete_access ? 0x00 : request->subindex); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1212 |
EC_WRITE_U32(data + 6, request->data_size); |
1562 | 1213 |
|
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1214 |
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
|
1215 |
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
|
1216 |
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
|
1217 |
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
|
1218 |
fsm->offset += segment_size; |
1562 | 1219 |
fsm->remaining -= segment_size; |
1220 |
} |
|
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1221 |
|
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1222 |
if (slave->master->debug_level) { |
1921 | 1223 |
EC_SLAVE_DBG(slave, 1, "Normal download request:\n"); |
1562 | 1224 |
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
|
1225 |
} |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1226 |
} |
975
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1227 |
|
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1228 |
fsm->request->jiffies_sent = jiffies; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1229 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1230 |
fsm->state = ec_fsm_coe_down_request; |
1231 |
} |
|
1232 |
||
1233 |
/*****************************************************************************/ |
|
1234 |
||
1235 |
/** |
|
1236 |
CoE state: DOWN REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1237 |
\todo Timeout behavior |
436 | 1238 |
*/ |
1239 |
||
1240 |
void ec_fsm_coe_down_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1241 |
{ |
|
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
|
1242 |
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
|
1243 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 1244 |
ec_slave_t *slave = fsm->slave; |
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1245 |
unsigned long diff_ms; |
436 | 1246 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1247 |
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
|
1248 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1249 |
return; // FIXME: check for response first? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1250 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1251 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1252 |
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
|
1253 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1254 |
fsm->state = ec_fsm_coe_error; |
1921 | 1255 |
EC_SLAVE_ERR(slave, "Failed to receive CoE download" |
1256 |
" 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
|
1257 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1258 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1259 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1260 |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1261 |
diff_ms = (jiffies - fsm->request->jiffies_sent) * 1000 / HZ; |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1262 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1263 |
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
|
1264 |
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
|
1265 |
if (diff_ms < fsm->request->response_timeout) { |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1266 |
#if DEBUG_RETRIES |
1931 | 1267 |
EC_SLAVE_DBG(slave, 1, "Slave did not respond to SDO" |
1268 |
" download request. Retrying after %lu ms...\n", |
|
1269 |
diff_ms); |
|
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1270 |
#endif |
1112
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1271 |
// no response; send request datagram again |
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1272 |
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
|
1273 |
} |
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1274 |
} |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1275 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1276 |
fsm->state = ec_fsm_coe_error; |
1921 | 1277 |
EC_SLAVE_ERR(slave, "Reception of CoE download request" |
1931 | 1278 |
" for SDO 0x%04x:%x failed with timeout after %lu ms: ", |
1279 |
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
|
1280 |
ec_datagram_print_wc_error(datagram); |
436 | 1281 |
return; |
1282 |
} |
|
1283 |
||
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1284 |
#if DEBUG_LONG |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1285 |
if (diff_ms > 200) { |
1931 | 1286 |
EC_SLAVE_WARN(slave, "SDO 0x%04x:%x download took %lu ms.\n", |
1287 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1288 |
} |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1289 |
#endif |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1290 |
|
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1291 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 1292 |
|
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
|
1293 |
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
|
1294 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1295 |
fsm->state = ec_fsm_coe_down_check; |
1296 |
} |
|
1297 |
||
1298 |
/*****************************************************************************/ |
|
1299 |
||
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1300 |
/** CoE state: DOWN CHECK. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1301 |
*/ |
436 | 1302 |
void ec_fsm_coe_down_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
1303 |
{ |
|
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
|
1304 |
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
|
1305 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 1306 |
ec_slave_t *slave = fsm->slave; |
1307 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1308 |
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
|
1309 |
&& fsm->retries--) { |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1310 |
return; |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1311 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1312 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1313 |
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
|
1314 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1315 |
fsm->state = ec_fsm_coe_error; |
1921 | 1316 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check" |
1317 |
" 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
|
1318 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1319 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1320 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1321 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1322 |
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
|
1323 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1324 |
fsm->state = ec_fsm_coe_error; |
1921 | 1325 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
1326 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1327 |
ec_datagram_print_wc_error(datagram); |
436 | 1328 |
return; |
1329 |
} |
|
1330 |
||
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
|
1331 |
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
|
1332 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1333 |
(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
|
1334 |
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
|
1335 |
fsm->request->errno = EIO; |
436 | 1336 |
fsm->state = ec_fsm_coe_error; |
1931 | 1337 |
EC_SLAVE_ERR(slave, "Timeout after %lu ms while waiting" |
1338 |
" for SDO 0x%04x:%x download response.\n", diff_ms, |
|
1921 | 1339 |
fsm->request->index, fsm->request->subindex); |
436 | 1340 |
return; |
1341 |
} |
|
1342 |
||
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
|
1343 |
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
|
1344 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1345 |
return; |
1346 |
} |
|
1347 |
||
1348 |
// 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
|
1349 |
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
|
1350 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1351 |
fsm->state = ec_fsm_coe_down_response; |
1352 |
} |
|
1353 |
||
1354 |
/*****************************************************************************/ |
|
1355 |
||
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1356 |
/** Prepare a download segment request. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1357 |
*/ |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1358 |
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
|
1359 |
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
|
1360 |
) |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1361 |
{ |
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
|
1362 |
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
|
1363 |
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
|
1364 |
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
|
1365 |
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
|
1366 |
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
|
1367 |
- 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
|
1368 |
- 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
|
1369 |
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
|
1370 |
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
|
1371 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1372 |
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
|
1373 |
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
|
1374 |
last_segment = 0; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1375 |
} else { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1376 |
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
|
1377 |
last_segment = 1; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1378 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1379 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1380 |
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
|
1381 |
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
|
1382 |
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
|
1383 |
} else { |
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 = 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
|
1385 |
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
|
1386 |
+ 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
|
1387 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1388 |
|
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
|
1389 |
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
|
1390 |
data_size); |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1391 |
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
|
1392 |
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
|
1393 |
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
|
1394 |
return; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1395 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1396 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1397 |
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
|
1398 |
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
|
1399 |
| (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
|
1400 |
| (fsm->toggle << 4) |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1401 |
| (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
|
1402 |
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
|
1403 |
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
|
1404 |
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
|
1405 |
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
|
1406 |
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
|
1407 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1408 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1409 |
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
|
1410 |
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
|
1411 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1412 |
if (slave->master->debug_level) { |
1921 | 1413 |
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
|
1414 |
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
|
1415 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1416 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1417 |
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
|
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 |
/*****************************************************************************/ |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1421 |
|
436 | 1422 |
/** |
1423 |
CoE state: DOWN RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1424 |
\todo Timeout behavior |
436 | 1425 |
*/ |
1426 |
||
1427 |
void ec_fsm_coe_down_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1428 |
{ |
|
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
|
1429 |
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
|
1430 |
ec_datagram_t *datagram = fsm->mbox->datagram; |
436 | 1431 |
ec_slave_t *slave = fsm->slave; |
1432 |
uint8_t *data, mbox_prot; |
|
1433 |
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
|
1434 |
ec_sdo_request_t *request = fsm->request; |
436 | 1435 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1436 |
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
|
1437 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1438 |
return; // FIXME: request again? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1439 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1440 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1441 |
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
|
1442 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1443 |
fsm->state = ec_fsm_coe_error; |
1921 | 1444 |
EC_SLAVE_ERR(slave, "Failed to receive CoE download" |
1445 |
" 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
|
1446 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1447 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1448 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1449 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1450 |
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
|
1451 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1452 |
fsm->state = ec_fsm_coe_error; |
1921 | 1453 |
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
|
1454 |
ec_datagram_print_wc_error(datagram); |
436 | 1455 |
return; |
1456 |
} |
|
1457 |
||
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
|
1458 |
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
|
1459 |
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
|
1460 |
request->errno = PTR_ERR(data); |
436 | 1461 |
fsm->state = ec_fsm_coe_error; |
1462 |
return; |
|
1463 |
} |
|
1464 |
||
1465 |
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
|
1466 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1467 |
fsm->state = ec_fsm_coe_error; |
1921 | 1468 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
1469 |
mbox_prot); |
|
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1470 |
return; |
436 | 1471 |
} |
1472 |
||
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1473 |
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
|
1474 |
// 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
|
1475 |
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
|
1476 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1477 |
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
|
1478 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1479 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1480 |
|
975
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1481 |
if (slave->master->debug_level) { |
1921 | 1482 |
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
|
1483 |
ec_print_data(data, rec_size); |
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1484 |
} |
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1485 |
|
436 | 1486 |
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
|
1487 |
request->errno = EIO; |
436 | 1488 |
fsm->state = ec_fsm_coe_error; |
1921 | 1489 |
EC_SLAVE_ERR(slave, "Received data are too small (%zu bytes):\n", |
1490 |
rec_size); |
|
436 | 1491 |
ec_print_data(data, rec_size); |
1492 |
return; |
|
1493 |
} |
|
1494 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1495 |
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
|
1496 |
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
|
1497 |
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
|
1498 |
request->errno = EIO; |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1499 |
fsm->state = ec_fsm_coe_error; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1500 |
if (request->complete_access) { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1501 |
subidxstr[0] = 0x00; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1502 |
} else { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1503 |
sprintf(subidxstr, ":%02X", request->subindex); |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1504 |
} |
1921 | 1505 |
EC_SLAVE_ERR(slave, "SDO download 0x%04X%s (%zu bytes) aborted.\n", |
1506 |
request->index, subidxstr, request->data_size); |
|
436 | 1507 |
if (rec_size < 10) { |
1921 | 1508 |
EC_SLAVE_ERR(slave, "Incomplete abort command:\n"); |
436 | 1509 |
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
|
1510 |
} 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
|
1511 |
fsm->request->abort_code = EC_READ_U32(data + 6); |
1921 | 1512 |
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
|
1513 |
} |
436 | 1514 |
return; |
1515 |
} |
|
1516 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1517 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
436 | 1518 |
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
|
1519 |
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
|
1520 |
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
|
1521 |
if (slave->master->debug_level) { |
1921 | 1522 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO download response!" |
1523 |
" Retrying...\n"); |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1524 |
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
|
1525 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1526 |
// 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
|
1527 |
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
|
1528 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1529 |
fsm->state = ec_fsm_coe_down_check; |
436 | 1530 |
return; |
1531 |
} |
|
1532 |
||
1562 | 1533 |
if (fsm->remaining) { // more segments to download |
1534 |
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
|
1535 |
ec_fsm_coe_down_prepare_segment_request(fsm); |
1562 | 1536 |
} else { |
1537 |
fsm->state = ec_fsm_coe_end; // success |
|
1538 |
} |
|
1539 |
} |
|
1540 |
||
1541 |
/*****************************************************************************/ |
|
1542 |
||
1543 |
/** |
|
1544 |
CoE state: DOWN SEG CHECK. |
|
1545 |
*/ |
|
1546 |
||
1547 |
void ec_fsm_coe_down_seg_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1548 |
{ |
|
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
|
1549 |
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
|
1550 |
ec_datagram_t *datagram = mbox->datagram; |
1562 | 1551 |
ec_slave_t *slave = fsm->slave; |
1552 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1553 |
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
|
1554 |
&& fsm->retries--) { |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1555 |
return; |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1556 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1557 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1558 |
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
|
1559 |
fsm->request->errno = EIO; |
1562 | 1560 |
fsm->state = ec_fsm_coe_error; |
1921 | 1561 |
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
|
1562 |
ec_datagram_print_state(datagram); |
1562 | 1563 |
return; |
1564 |
} |
|
1565 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1566 |
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
|
1567 |
fsm->request->errno = EIO; |
1562 | 1568 |
fsm->state = ec_fsm_coe_error; |
1921 | 1569 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox segment check" |
1570 |
" datagram failed: "); |
|
1562 | 1571 |
ec_datagram_print_wc_error(datagram); |
1572 |
return; |
|
1573 |
} |
|
1574 |
||
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
|
1575 |
if (!ec_slave_mbox_check(mbox)) { |
1562 | 1576 |
unsigned long diff_ms = |
1577 |
(datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ; |
|
1578 |
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
|
1579 |
fsm->request->errno = EIO; |
1562 | 1580 |
fsm->state = ec_fsm_coe_error; |
1921 | 1581 |
EC_SLAVE_ERR(slave, "Timeout while waiting for SDO download" |
1582 |
" segment response.\n"); |
|
1562 | 1583 |
return; |
1584 |
} |
|
1585 |
||
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
|
1586 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
1562 | 1587 |
fsm->retries = EC_FSM_RETRIES; |
1588 |
return; |
|
1589 |
} |
|
1590 |
||
1591 |
// 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
|
1592 |
ec_slave_mbox_prepare_fetch(slave, mbox); // can not fail. |
1562 | 1593 |
fsm->retries = EC_FSM_RETRIES; |
1594 |
fsm->state = ec_fsm_coe_down_seg_response; |
|
1595 |
} |
|
1596 |
||
1597 |
/*****************************************************************************/ |
|
1598 |
||
1599 |
/** |
|
1600 |
CoE state: DOWN SEG RESPONSE. |
|
1601 |
\todo Timeout behavior |
|
1602 |
*/ |
|
1603 |
||
1604 |
void ec_fsm_coe_down_seg_response( |
|
1605 |
ec_fsm_coe_t *fsm /**< finite state machine */ |
|
1606 |
) |
|
1607 |
{ |
|
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
|
1608 |
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
|
1609 |
ec_datagram_t *datagram = mbox->datagram; |
1562 | 1610 |
ec_slave_t *slave = fsm->slave; |
1611 |
uint8_t *data, mbox_prot; |
|
1612 |
size_t rec_size; |
|
1613 |
ec_sdo_request_t *request = fsm->request; |
|
1614 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1615 |
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
|
1616 |
&& fsm->retries--) { |
1562 | 1617 |
return; // FIXME: request again? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1618 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1619 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1620 |
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
|
1621 |
request->errno = EIO; |
1562 | 1622 |
fsm->state = ec_fsm_coe_error; |
1921 | 1623 |
EC_SLAVE_ERR(slave, "Failed to receive CoE download response" |
1624 |
" 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
|
1625 |
ec_datagram_print_state(datagram); |
1562 | 1626 |
return; |
1627 |
} |
|
1628 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1629 |
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
|
1630 |
request->errno = EIO; |
1562 | 1631 |
fsm->state = ec_fsm_coe_error; |
1921 | 1632 |
EC_SLAVE_ERR(slave, "Reception of CoE download response failed: "); |
1562 | 1633 |
ec_datagram_print_wc_error(datagram); |
1634 |
return; |
|
1635 |
} |
|
1636 |
||
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
|
1637 |
data = ec_slave_mbox_fetch(slave, mbox, &mbox_prot, &rec_size); |
1562 | 1638 |
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
|
1639 |
request->errno = PTR_ERR(data); |
1562 | 1640 |
fsm->state = ec_fsm_coe_error; |
1641 |
return; |
|
1642 |
} |
|
1643 |
||
1644 |
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
|
1645 |
request->errno = EIO; |
1562 | 1646 |
fsm->state = ec_fsm_coe_error; |
1921 | 1647 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
1648 |
mbox_prot); |
|
1562 | 1649 |
return; |
1650 |
} |
|
1651 |
||
1652 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
|
1653 |
// 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
|
1654 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
1562 | 1655 |
fsm->retries = EC_FSM_RETRIES; |
1656 |
fsm->state = ec_fsm_coe_down_check; |
|
1657 |
return; |
|
1658 |
} |
|
1659 |
||
1660 |
if (slave->master->debug_level) { |
|
1921 | 1661 |
EC_SLAVE_DBG(slave, 1, "Download response:\n"); |
1562 | 1662 |
ec_print_data(data, rec_size); |
1663 |
} |
|
1664 |
||
1665 |
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
|
1666 |
request->errno = EIO; |
1562 | 1667 |
fsm->state = ec_fsm_coe_error; |
1921 | 1668 |
EC_SLAVE_ERR(slave, "Received data are too small (%zu bytes):\n", |
1669 |
rec_size); |
|
1562 | 1670 |
ec_print_data(data, rec_size); |
1671 |
return; |
|
1672 |
} |
|
1673 |
||
1674 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
|
1675 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
|
1676 |
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
|
1677 |
request->errno = EIO; |
1562 | 1678 |
fsm->state = ec_fsm_coe_error; |
1679 |
if (request->complete_access) { |
|
1680 |
subidxstr[0] = 0x00; |
|
1681 |
} else { |
|
1682 |
sprintf(subidxstr, ":%02X", request->subindex); |
|
1683 |
} |
|
1921 | 1684 |
EC_SLAVE_ERR(slave, "SDO download 0x%04X%s (%zu bytes) aborted.\n", |
1685 |
request->index, subidxstr, request->data_size); |
|
1562 | 1686 |
if (rec_size < 10) { |
1921 | 1687 |
EC_SLAVE_ERR(slave, "Incomplete abort command:\n"); |
1562 | 1688 |
ec_print_data(data, rec_size); |
1689 |
} else { |
|
1690 |
fsm->request->abort_code = EC_READ_U32(data + 6); |
|
1921 | 1691 |
ec_canopen_abort_msg(slave, fsm->request->abort_code); |
1562 | 1692 |
} |
1693 |
return; |
|
1694 |
} |
|
1695 |
||
1696 |
if (EC_READ_U16(data) >> 12 != 0x3 || |
|
1697 |
((EC_READ_U8(data + 2) >> 5) != 0x01)) { // segment response |
|
1698 |
if (slave->master->debug_level) { |
|
1921 | 1699 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO download response!" |
1700 |
" Retrying...\n"); |
|
1562 | 1701 |
ec_print_data(data, rec_size); |
1702 |
} |
|
1703 |
// 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
|
1704 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
1562 | 1705 |
fsm->retries = EC_FSM_RETRIES; |
1706 |
fsm->state = ec_fsm_coe_down_seg_check; |
|
1707 |
return; |
|
1708 |
} |
|
1709 |
||
1710 |
if (((EC_READ_U8(data + 2) >> 4) & 0x01) != fsm->toggle) { |
|
1921 | 1711 |
EC_SLAVE_ERR(slave, "Invalid toggle received during" |
1712 |
" segmented download:\n"); |
|
1562 | 1713 |
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
|
1714 |
request->errno = EIO; |
1562 | 1715 |
fsm->state = ec_fsm_coe_error; |
1716 |
return; |
|
1717 |
} |
|
1718 |
||
1719 |
if (fsm->remaining) { // more segments to download |
|
1720 |
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
|
1721 |
ec_fsm_coe_down_prepare_segment_request(fsm); |
1562 | 1722 |
} else { |
1723 |
fsm->state = ec_fsm_coe_end; // success |
|
1724 |
} |
|
436 | 1725 |
} |
1726 |
||
1727 |
/*****************************************************************************/ |
|
1728 |
||
1729 |
/** |
|
1730 |
CoE state: UP START. |
|
1731 |
*/ |
|
1732 |
||
1733 |
void ec_fsm_coe_up_start(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1734 |
{ |
|
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
|
1735 |
ec_mailbox_t *mbox = fsm->mbox; |
436 | 1736 |
ec_slave_t *slave = fsm->slave; |
1737 |
ec_master_t *master = slave->master; |
|
1738 |
ec_sdo_request_t *request = fsm->request; |
|
1739 |
uint8_t *data; |
|
1740 |
||
1921 | 1741 |
EC_SLAVE_DBG(slave, 1, "Uploading SDO 0x%04X:%02X.\n", |
1742 |
request->index, request->subindex); |
|
436 | 1743 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
1744 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
1921 | 1745 |
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
|
1746 |
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
|
1747 |
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
|
1748 |
return; |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1749 |
} |
3771f5a0ed90
CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1750 |
|
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
|
1751 |
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
|
1752 |
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
|
1753 |
request->errno = PTR_ERR(data); |
436 | 1754 |
fsm->state = ec_fsm_coe_error; |
1755 |
return; |
|
1756 |
} |
|
1757 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1758 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
436 | 1759 |
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
|
1760 |
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
|
1761 |
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
|
1762 |
memset(data + 6, 0x00, 4); |
436 | 1763 |
|
1764 |
if (master->debug_level) { |
|
1921 | 1765 |
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
|
1766 |
ec_print_data(data, 10); |
436 | 1767 |
} |
1768 |
||
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1769 |
fsm->request->jiffies_sent = jiffies; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1770 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1771 |
fsm->state = ec_fsm_coe_up_request; |
1772 |
} |
|
1773 |
||
1774 |
/*****************************************************************************/ |
|
1775 |
||
1776 |
/** |
|
1777 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1778 |
\todo Timeout behavior |
436 | 1779 |
*/ |
1780 |
||
1781 |
void ec_fsm_coe_up_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1782 |
{ |
|
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
|
1783 |
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
|
1784 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 1785 |
ec_slave_t *slave = fsm->slave; |
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1786 |
unsigned long diff_ms; |
436 | 1787 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1788 |
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
|
1789 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1790 |
return; // FIXME: check for response first? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1791 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1792 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1793 |
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
|
1794 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1795 |
fsm->state = ec_fsm_coe_error; |
1921 | 1796 |
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
|
1797 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1798 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1799 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1800 |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1801 |
diff_ms = (jiffies - fsm->request->jiffies_sent) * 1000 / HZ; |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1802 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1803 |
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
|
1804 |
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
|
1805 |
if (diff_ms < fsm->request->response_timeout) { |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1806 |
#if DEBUG_RETRIES |
1921 | 1807 |
EC_SLAVE_DBG(slave, 1, "Slave did not respond to" |
1931 | 1808 |
" SDO upload request. Retrying after %lu ms...\n", |
1809 |
diff_ms); |
|
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1810 |
#endif |
1112
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1811 |
// no response; send request datagram again |
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1812 |
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
|
1813 |
} |
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1814 |
} |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1815 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1816 |
fsm->state = ec_fsm_coe_error; |
1921 | 1817 |
EC_SLAVE_ERR(slave, "Reception of CoE upload request for" |
1931 | 1818 |
" SDO 0x%04x:%x failed with timeout after %lu ms: ", |
1819 |
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
|
1820 |
ec_datagram_print_wc_error(datagram); |
436 | 1821 |
return; |
1822 |
} |
|
1823 |
||
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1824 |
#if DEBUG_LONG |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1825 |
if (diff_ms > 200) { |
1931 | 1826 |
EC_SLAVE_WARN(slave, "SDO 0x%04x:%x upload took %lu ms.\n", |
1827 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1828 |
} |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1829 |
#endif |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1830 |
|
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1831 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 1832 |
|
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
|
1833 |
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
|
1834 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1835 |
fsm->state = ec_fsm_coe_up_check; |
1836 |
} |
|
1837 |
||
1838 |
/*****************************************************************************/ |
|
1839 |
||
1840 |
/** |
|
1841 |
CoE state: UP CHECK. |
|
1842 |
*/ |
|
1843 |
||
1844 |
void ec_fsm_coe_up_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1845 |
{ |
|
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
|
1846 |
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
|
1847 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 1848 |
ec_slave_t *slave = fsm->slave; |
1849 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1850 |
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
|
1851 |
&& fsm->retries--) { |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1852 |
return; |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1853 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1854 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1855 |
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
|
1856 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1857 |
fsm->state = ec_fsm_coe_error; |
1921 | 1858 |
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
|
1859 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1860 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1861 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1862 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1863 |
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
|
1864 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1865 |
fsm->state = ec_fsm_coe_error; |
1921 | 1866 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
1867 |
" datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
1868 |
ec_datagram_print_wc_error(datagram); |
436 | 1869 |
return; |
1870 |
} |
|
1871 |
||
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
|
1872 |
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
|
1873 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1874 |
(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
|
1875 |
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
|
1876 |
fsm->request->errno = EIO; |
436 | 1877 |
fsm->state = ec_fsm_coe_error; |
1931 | 1878 |
EC_SLAVE_ERR(slave, "Timeout after %lu ms while waiting for" |
1879 |
" SDO 0x%04x:%x upload response.\n", diff_ms, |
|
1921 | 1880 |
fsm->request->index, fsm->request->subindex); |
436 | 1881 |
return; |
1882 |
} |
|
1883 |
||
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
|
1884 |
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
|
1885 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1886 |
return; |
1887 |
} |
|
1888 |
||
1889 |
// 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
|
1890 |
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
|
1891 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1892 |
fsm->state = ec_fsm_coe_up_response; |
1893 |
} |
|
1894 |
||
1895 |
/*****************************************************************************/ |
|
1896 |
||
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1897 |
/** 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
|
1898 |
*/ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1899 |
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
|
1900 |
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
|
1901 |
) |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1902 |
{ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1903 |
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
|
1904 |
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
|
1905 |
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
|
1906 |
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
|
1907 |
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
|
1908 |
return; |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1909 |
} |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1910 |
|
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1911 |
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
|
1912 |
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
|
1913 |
| 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
|
1914 |
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
|
1915 |
|
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1916 |
if (fsm->slave->master->debug_level) { |
1921 | 1917 |
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
|
1918 |
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
|
1919 |
} |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1920 |
} |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
1921 |
|
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 |
|
436 | 1924 |
/** |
1925 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1926 |
\todo Timeout behavior |
436 | 1927 |
*/ |
1928 |
||
1929 |
void ec_fsm_coe_up_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
1930 |
{ |
|
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
|
1931 |
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
|
1932 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 1933 |
ec_slave_t *slave = fsm->slave; |
1934 |
ec_master_t *master = slave->master; |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1935 |
uint16_t rec_index; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1936 |
uint8_t *data, mbox_prot, rec_subindex; |
436 | 1937 |
size_t rec_size, data_size; |
1938 |
ec_sdo_request_t *request = fsm->request; |
|
1939 |
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
|
1940 |
int ret; |
436 | 1941 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1942 |
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
|
1943 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1944 |
return; // FIXME: request again? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1945 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1946 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1947 |
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
|
1948 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1949 |
fsm->state = ec_fsm_coe_error; |
1921 | 1950 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload response" |
1951 |
" 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
|
1952 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1953 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1954 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1955 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
1956 |
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
|
1957 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1958 |
fsm->state = ec_fsm_coe_error; |
1921 | 1959 |
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
|
1960 |
ec_datagram_print_wc_error(datagram); |
436 | 1961 |
return; |
1962 |
} |
|
1963 |
||
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
|
1964 |
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
|
1965 |
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
|
1966 |
request->errno = PTR_ERR(data); |
436 | 1967 |
fsm->state = ec_fsm_coe_error; |
1968 |
return; |
|
1969 |
} |
|
1970 |
||
1971 |
if (master->debug_level) { |
|
1921 | 1972 |
EC_SLAVE_DBG(slave, 1, "Upload response:\n"); |
436 | 1973 |
ec_print_data(data, rec_size); |
1974 |
} |
|
1975 |
||
1976 |
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
|
1977 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1978 |
fsm->state = ec_fsm_coe_error; |
1921 | 1979 |
EC_SLAVE_WARN(slave, "Received mailbox protocol 0x%02X" |
1980 |
" 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
|
1981 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1982 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1983 |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1984 |
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
|
1985 |
// 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
|
1986 |
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
|
1987 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1988 |
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
|
1989 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1990 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1991 |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
1992 |
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
|
1993 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1994 |
fsm->state = ec_fsm_coe_error; |
1921 | 1995 |
EC_SLAVE_ERR(slave, "Received currupted SDO upload response" |
1996 |
" (%zu bytes)!\n", rec_size); |
|
436 | 1997 |
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
|
1998 |
return; |
436 | 1999 |
} |
2000 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
2001 |
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
|
2002 |
EC_READ_U8(data + 2) >> 5 == 0x4) { // abort SDO transfer request |
1921 | 2003 |
EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X aborted.\n", |
2004 |
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
|
2005 |
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
|
2006 |
request->abort_code = EC_READ_U32(data + 6); |
1921 | 2007 |
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
|
2008 |
} else { |
1921 | 2009 |
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
|
2010 |
} |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2011 |
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
|
2012 |
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
|
2013 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2014 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2015 |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2016 |
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
|
2017 |
EC_READ_U8(data + 2) >> 5 != 0x2) { // upload response |
1921 | 2018 |
EC_SLAVE_ERR(slave, "Received unknown response while" |
2019 |
" uploading SDO 0x%04X:%02X.\n", |
|
2020 |
request->index, request->subindex); |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2021 |
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
|
2022 |
request->errno = EIO; |
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2023 |
fsm->state = ec_fsm_coe_error; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2024 |
return; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2025 |
} |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2026 |
|
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2027 |
rec_index = EC_READ_U16(data + 3); |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2028 |
rec_subindex = EC_READ_U8(data + 5); |
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 |
if (rec_index != request->index || rec_subindex != request->subindex) { |
1921 | 2031 |
EC_SLAVE_ERR(slave, "Received upload response for wrong SDO" |
2032 |
" (0x%04X:%02X, requested: 0x%04X:%02X).\n", |
|
2033 |
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
|
2034 |
ec_print_data(data, rec_size); |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2035 |
|
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2036 |
// 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
|
2037 |
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
|
2038 |
fsm->retries = EC_FSM_RETRIES; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2039 |
fsm->state = ec_fsm_coe_up_check; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2040 |
return; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2041 |
} |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2042 |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2043 |
// normal or expedited? |
436 | 2044 |
expedited = EC_READ_U8(data + 2) & 0x02; |
2045 |
||
2046 |
if (expedited) { |
|
2047 |
size_specified = EC_READ_U8(data + 2) & 0x01; |
|
2048 |
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
|
2049 |
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
|
2050 |
} 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
|
2051 |
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
|
2052 |
} |
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
|
2053 |
|
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 |
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
|
2055 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
2056 |
fsm->state = ec_fsm_coe_error; |
1921 | 2057 |
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
|
2058 |
" 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
|
2059 |
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
|
2060 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2061 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2062 |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2063 |
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
|
2064 |
if (ret) { |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2065 |
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
|
2066 |
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
|
2067 |
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
|
2068 |
} |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2069 |
} else { // normal |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2070 |
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
|
2071 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
2072 |
fsm->state = ec_fsm_coe_error; |
1921 | 2073 |
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
|
2074 |
" 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
|
2075 |
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
|
2076 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2077 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2078 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2079 |
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
|
2080 |
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
|
2081 |
|
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
|
2082 |
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
|
2083 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
2084 |
fsm->state = ec_fsm_coe_error; |
1921 | 2085 |
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
|
2086 |
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
|
2087 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2088 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2089 |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2090 |
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
|
2091 |
if (ret) { |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2092 |
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
|
2093 |
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
|
2094 |
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
|
2095 |
} |
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 |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2097 |
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
|
2098 |
if (ret) { |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2099 |
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
|
2100 |
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
|
2101 |
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
|
2102 |
} |
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 |
|
436 | 2104 |
fsm->toggle = 0; |
2105 |
||
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
|
2106 |
if (data_size < fsm->complete_size) { |
1921 | 2107 |
EC_SLAVE_DBG(slave, 1, "SDO data incomplete (%zu / %u)." |
2108 |
" 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
|
2109 |
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
|
2110 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2111 |
fsm->state = ec_fsm_coe_up_seg_request; |
2112 |
return; |
|
2113 |
} |
|
2114 |
} |
|
2115 |
||
874 | 2116 |
if (master->debug_level) { |
1921 | 2117 |
EC_SLAVE_DBG(slave, 1, "Uploaded data:\n"); |
874 | 2118 |
ec_print_data(request->data, request->data_size); |
2119 |
} |
|
2120 |
||
436 | 2121 |
fsm->state = ec_fsm_coe_end; // success |
2122 |
} |
|
2123 |
||
2124 |
/*****************************************************************************/ |
|
2125 |
||
2126 |
/** |
|
2127 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2128 |
\todo Timeout behavior |
436 | 2129 |
*/ |
2130 |
||
2131 |
void ec_fsm_coe_up_seg_request(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2132 |
{ |
|
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
|
2133 |
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
|
2134 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 2135 |
ec_slave_t *slave = fsm->slave; |
2136 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2137 |
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
|
2138 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
2139 |
return; // FIXME: check for response first? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2140 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2141 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2142 |
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
|
2143 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2144 |
fsm->state = ec_fsm_coe_error; |
1921 | 2145 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload segment" |
2146 |
" 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
|
2147 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2148 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2149 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2150 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2151 |
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
|
2152 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2153 |
fsm->state = ec_fsm_coe_error; |
1921 | 2154 |
EC_SLAVE_ERR(slave, "Reception of CoE upload segment" |
2155 |
" request failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
2156 |
ec_datagram_print_wc_error(datagram); |
436 | 2157 |
return; |
2158 |
} |
|
2159 |
||
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
2160 |
fsm->jiffies_start = datagram->jiffies_sent; |
436 | 2161 |
|
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
|
2162 |
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
|
2163 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2164 |
fsm->state = ec_fsm_coe_up_seg_check; |
2165 |
} |
|
2166 |
||
2167 |
/*****************************************************************************/ |
|
2168 |
||
2169 |
/** |
|
2170 |
CoE state: UP CHECK. |
|
2171 |
*/ |
|
2172 |
||
2173 |
void ec_fsm_coe_up_seg_check(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2174 |
{ |
|
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
|
2175 |
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
|
2176 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 2177 |
ec_slave_t *slave = fsm->slave; |
2178 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2179 |
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
|
2180 |
&& fsm->retries--) { |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2181 |
return; |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2182 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2183 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2184 |
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
|
2185 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2186 |
fsm->state = ec_fsm_coe_error; |
1921 | 2187 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check" |
2188 |
" 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
|
2189 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2190 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2191 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2192 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2193 |
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
|
2194 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2195 |
fsm->state = ec_fsm_coe_error; |
1921 | 2196 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check datagram" |
2197 |
" failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
2198 |
ec_datagram_print_wc_error(datagram); |
436 | 2199 |
return; |
2200 |
} |
|
2201 |
||
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
|
2202 |
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
|
2203 |
unsigned long diff_ms = |
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
2204 |
(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
|
2205 |
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
|
2206 |
fsm->request->errno = EIO; |
436 | 2207 |
fsm->state = ec_fsm_coe_error; |
1921 | 2208 |
EC_SLAVE_ERR(slave, "Timeout while waiting for SDO upload" |
2209 |
" segment response.\n"); |
|
436 | 2210 |
return; |
2211 |
} |
|
2212 |
||
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
|
2213 |
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
|
2214 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2215 |
return; |
2216 |
} |
|
2217 |
||
2218 |
// 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
|
2219 |
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
|
2220 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2221 |
fsm->state = ec_fsm_coe_up_seg_response; |
2222 |
} |
|
2223 |
||
2224 |
/*****************************************************************************/ |
|
2225 |
||
2226 |
/** |
|
2227 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2228 |
\todo Timeout behavior |
436 | 2229 |
*/ |
2230 |
||
2231 |
void ec_fsm_coe_up_seg_response(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2232 |
{ |
|
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
|
2233 |
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
|
2234 |
ec_datagram_t *datagram = mbox->datagram; |
436 | 2235 |
ec_slave_t *slave = fsm->slave; |
2236 |
ec_master_t *master = slave->master; |
|
2237 |
uint8_t *data, mbox_prot; |
|
2238 |
size_t rec_size, data_size; |
|
2239 |
ec_sdo_request_t *request = fsm->request; |
|
2240 |
unsigned int last_segment; |
|
2241 |
||
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2242 |
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
|
2243 |
&& fsm->retries--) { |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
2244 |
return; // FIXME: request again? |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2245 |
} |
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2246 |
|
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2247 |
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
|
2248 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2249 |
fsm->state = ec_fsm_coe_error; |
1921 | 2250 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload segment" |
2251 |
" 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
|
2252 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2253 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2254 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2255 |
|
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2047
diff
changeset
|
2256 |
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
|
2257 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2258 |
fsm->state = ec_fsm_coe_error; |
1921 | 2259 |
EC_SLAVE_ERR(slave, "Reception of CoE upload segment" |
2260 |
" response failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
2261 |
ec_datagram_print_wc_error(datagram); |
436 | 2262 |
return; |
2263 |
} |
|
2264 |
||
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
|
2265 |
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
|
2266 |
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
|
2267 |
request->errno = PTR_ERR(data); |
436 | 2268 |
fsm->state = ec_fsm_coe_error; |
2269 |
return; |
|
2270 |
} |
|
2271 |
||
2272 |
if (master->debug_level) { |
|
1921 | 2273 |
EC_SLAVE_DBG(slave, 1, "Upload segment response:\n"); |
436 | 2274 |
ec_print_data(data, rec_size); |
2275 |
} |
|
2276 |
||
2277 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 2278 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
2279 |
mbox_prot); |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2280 |
request->errno = EIO; |
436 | 2281 |
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
|
2282 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2283 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2284 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2285 |
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
|
2286 |
// 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
|
2287 |
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
|
2288 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2289 |
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
|
2290 |
return; |
436 | 2291 |
} |
2292 |
||
2293 |
if (rec_size < 10) { |
|
1921 | 2294 |
EC_SLAVE_ERR(slave, "Received currupted SDO upload" |
2295 |
" segment response!\n"); |
|
436 | 2296 |
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
|
2297 |
request->errno = EIO; |
436 | 2298 |
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
|
2299 |
return; |
436 | 2300 |
} |
2301 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
2302 |
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
|
2303 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
1921 | 2304 |
EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X aborted.\n", |
2305 |
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
|
2306 |
request->abort_code = EC_READ_U32(data + 6); |
1921 | 2307 |
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
|
2308 |
request->errno = EIO; |
436 | 2309 |
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
|
2310 |
return; |
436 | 2311 |
} |
2312 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
2313 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
436 | 2314 |
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
|
2315 |
if (fsm->slave->master->debug_level) { |
1921 | 2316 |
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
|
2317 |
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
|
2318 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2319 |
// 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
|
2320 |
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
|
2321 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2322 |
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
|
2323 |
return; |
436 | 2324 |
} |
2325 |
||
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
|
2326 |
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
|
2327 |
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
|
2328 |
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
|
2329 |
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
|
2330 |
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
|
2331 |
} |
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
|
2332 |
|
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
|
2333 |
if (request->data_size + data_size > fsm->complete_size) { |
1921 | 2334 |
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
|
2335 |
" exceeding complete size!\n", |
1921 | 2336 |
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
|
2337 |
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
|
2338 |
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
|
2339 |
return; |
436 | 2340 |
} |
2341 |
||
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2342 |
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
|
2343 |
request->data_size += data_size; |
436 | 2344 |
|
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
|
2345 |
last_segment = EC_READ_U8(data + 2) & 0x01; |
436 | 2346 |
if (!last_segment) { |
2347 |
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
|
2348 |
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
|
2349 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2350 |
fsm->state = ec_fsm_coe_up_seg_request; |
2351 |
return; |
|
2352 |
} |
|
2353 |
||
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
|
2354 |
if (request->data_size != fsm->complete_size) { |
1921 | 2355 |
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
|
2356 |
" size (%zu) does not match complete size (%u)!\n", |
1921 | 2357 |
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
|
2358 |
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
|
2359 |
} |
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
|
2360 |
|
874 | 2361 |
if (master->debug_level) { |
1921 | 2362 |
EC_SLAVE_DBG(slave, 1, "Uploaded data:\n"); |
874 | 2363 |
ec_print_data(request->data, request->data_size); |
2364 |
} |
|
2365 |
||
436 | 2366 |
fsm->state = ec_fsm_coe_end; // success |
2367 |
} |
|
2368 |
||
2369 |
/*****************************************************************************/ |
|
2370 |
||
2371 |
/** |
|
2372 |
State: ERROR. |
|
2373 |
*/ |
|
2374 |
||
2375 |
void ec_fsm_coe_error(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2376 |
{ |
|
2377 |
} |
|
2378 |
||
2379 |
/*****************************************************************************/ |
|
2380 |
||
2381 |
/** |
|
2382 |
State: END. |
|
2383 |
*/ |
|
2384 |
||
2385 |
void ec_fsm_coe_end(ec_fsm_coe_t *fsm /**< finite state machine */) |
|
2386 |
{ |
|
2387 |
} |
|
2388 |
||
2389 |
/*****************************************************************************/ |