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