author | Florian Pose <fp@igh-essen.com> |
Tue, 06 Feb 2007 15:13:51 +0000 | |
changeset 538 | 84beb49d1b11 |
parent 505 | bc443ca0077f |
child 594 | 07dd2a7df66e |
permissions | -rw-r--r-- |
433 | 1 |
/****************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
4 |
* |
|
5 |
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
|
6 |
* |
|
7 |
* This file is part of the IgH EtherCAT Master. |
|
8 |
* |
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it |
|
10 |
* and/or modify it under the terms of the GNU General Public License |
|
11 |
* as published by the Free Software Foundation; either version 2 of the |
|
12 |
* License, or (at your option) any later version. |
|
13 |
* |
|
14 |
* The IgH EtherCAT Master is distributed in the hope that it will be |
|
15 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with the IgH EtherCAT Master; if not, write to the Free Software |
|
21 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
22 |
* |
|
23 |
* The right to use EtherCAT Technology is granted and comes free of |
|
24 |
* charge under condition of compatibility of product made by |
|
25 |
* Licensee. People intending to distribute/sell products based on the |
|
26 |
* code, have to sign an agreement to guarantee that products using |
|
27 |
* software based on IgH EtherCAT master stay compatible with the actual |
|
28 |
* EtherCAT specification (which are released themselves as an open |
|
29 |
* standard) as the (only) precondition to have the right to use EtherCAT |
|
30 |
* Technology, IP and trade marks. |
|
31 |
* |
|
32 |
*****************************************************************************/ |
|
33 |
||
34 |
/** |
|
35 |
\file |
|
36 |
EtherCAT slave information interface FSM. |
|
37 |
*/ |
|
38 |
||
39 |
/*****************************************************************************/ |
|
40 |
||
41 |
#include "globals.h" |
|
42 |
#include "mailbox.h" |
|
43 |
#include "master.h" |
|
44 |
#include "fsm_sii.h" |
|
45 |
||
46 |
/*****************************************************************************/ |
|
47 |
||
48 |
void ec_fsm_sii_start_reading(ec_fsm_sii_t *); |
|
49 |
void ec_fsm_sii_read_check(ec_fsm_sii_t *); |
|
50 |
void ec_fsm_sii_read_fetch(ec_fsm_sii_t *); |
|
51 |
void ec_fsm_sii_start_writing(ec_fsm_sii_t *); |
|
52 |
void ec_fsm_sii_write_check(ec_fsm_sii_t *); |
|
53 |
void ec_fsm_sii_write_check2(ec_fsm_sii_t *); |
|
54 |
void ec_fsm_sii_end(ec_fsm_sii_t *); |
|
55 |
void ec_fsm_sii_error(ec_fsm_sii_t *); |
|
56 |
||
57 |
/*****************************************************************************/ |
|
58 |
||
59 |
/** |
|
60 |
Constructor. |
|
61 |
*/ |
|
62 |
||
63 |
void ec_fsm_sii_init(ec_fsm_sii_t *fsm, /**< finite state machine */ |
|
64 |
ec_datagram_t *datagram /**< datagram structure to use */ |
|
65 |
) |
|
66 |
{ |
|
67 |
fsm->state = NULL; |
|
68 |
fsm->datagram = datagram; |
|
69 |
} |
|
70 |
||
71 |
/*****************************************************************************/ |
|
72 |
||
73 |
/** |
|
74 |
Destructor. |
|
75 |
*/ |
|
76 |
||
77 |
void ec_fsm_sii_clear(ec_fsm_sii_t *fsm /**< finite state machine */) |
|
78 |
{ |
|
79 |
} |
|
80 |
||
81 |
/*****************************************************************************/ |
|
82 |
||
83 |
/** |
|
84 |
Initializes the SII read state machine. |
|
85 |
*/ |
|
86 |
||
87 |
void ec_fsm_sii_read(ec_fsm_sii_t *fsm, /**< finite state machine */ |
|
88 |
ec_slave_t *slave, /**< slave to read from */ |
|
89 |
uint16_t offset, /**< offset to read from */ |
|
90 |
ec_fsm_sii_addressing_t mode /**< addressing scheme */ |
|
91 |
) |
|
92 |
{ |
|
93 |
fsm->state = ec_fsm_sii_start_reading; |
|
94 |
fsm->slave = slave; |
|
95 |
fsm->offset = offset; |
|
96 |
fsm->mode = mode; |
|
97 |
} |
|
98 |
||
99 |
/*****************************************************************************/ |
|
100 |
||
101 |
/** |
|
102 |
Initializes the SII write state machine. |
|
103 |
*/ |
|
104 |
||
105 |
void ec_fsm_sii_write(ec_fsm_sii_t *fsm, /**< finite state machine */ |
|
106 |
ec_slave_t *slave, /**< slave to read from */ |
|
107 |
uint16_t offset, /**< offset to read from */ |
|
108 |
uint16_t *value, /**< pointer to 2 bytes of data */ |
|
109 |
ec_fsm_sii_addressing_t mode /**< addressing scheme */ |
|
110 |
) |
|
111 |
{ |
|
112 |
fsm->state = ec_fsm_sii_start_writing; |
|
113 |
fsm->slave = slave; |
|
114 |
fsm->offset = offset; |
|
115 |
fsm->mode = mode; |
|
116 |
memcpy(fsm->value, value, 2); |
|
117 |
} |
|
118 |
||
119 |
/*****************************************************************************/ |
|
120 |
||
121 |
/** |
|
122 |
Executes the SII state machine. |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
123 |
\return false, if the state machine has terminated |
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
124 |
*/ |
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
125 |
|
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
126 |
int ec_fsm_sii_exec(ec_fsm_sii_t *fsm /**< finite state machine */) |
433 | 127 |
{ |
128 |
fsm->state(fsm); |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
129 |
|
433 | 130 |
return fsm->state != ec_fsm_sii_end && fsm->state != ec_fsm_sii_error; |
131 |
} |
|
132 |
||
133 |
/*****************************************************************************/ |
|
134 |
||
135 |
/** |
|
136 |
Returns, if the master startup state machine terminated with success. |
|
137 |
\return non-zero if successful. |
|
138 |
*/ |
|
139 |
||
140 |
int ec_fsm_sii_success(ec_fsm_sii_t *fsm /**< Finite state machine */) |
|
141 |
{ |
|
142 |
return fsm->state == ec_fsm_sii_end; |
|
143 |
} |
|
144 |
||
145 |
/****************************************************************************** |
|
146 |
* SII state machine |
|
147 |
*****************************************************************************/ |
|
148 |
||
149 |
/** |
|
150 |
SII state: START READING. |
|
151 |
Starts reading the slave information interface. |
|
152 |
*/ |
|
153 |
||
154 |
void ec_fsm_sii_start_reading(ec_fsm_sii_t *fsm /**< finite state machine */) |
|
155 |
{ |
|
156 |
ec_datagram_t *datagram = fsm->datagram; |
|
157 |
||
158 |
// initiate read operation |
|
159 |
switch (fsm->mode) { |
|
160 |
case EC_FSM_SII_POSITION: |
|
161 |
ec_datagram_apwr(datagram, fsm->slave->ring_position, 0x502, 4); |
|
162 |
break; |
|
163 |
case EC_FSM_SII_NODE: |
|
164 |
ec_datagram_npwr(datagram, fsm->slave->station_address, 0x502, 4); |
|
165 |
break; |
|
166 |
} |
|
167 |
||
168 |
EC_WRITE_U8 (datagram->data, 0x00); // read-only access |
|
169 |
EC_WRITE_U8 (datagram->data + 1, 0x01); // request read operation |
|
170 |
EC_WRITE_U16(datagram->data + 2, fsm->offset); |
|
171 |
ec_master_queue_datagram(fsm->slave->master, datagram); |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
172 |
fsm->retries = EC_FSM_RETRIES; |
433 | 173 |
fsm->state = ec_fsm_sii_read_check; |
174 |
} |
|
175 |
||
176 |
/*****************************************************************************/ |
|
177 |
||
178 |
/** |
|
179 |
SII state: READ CHECK. |
|
180 |
Checks, if the SII-read-datagram has been sent and issues a fetch datagram. |
|
181 |
*/ |
|
182 |
||
183 |
void ec_fsm_sii_read_check(ec_fsm_sii_t *fsm /**< finite state machine */) |
|
184 |
{ |
|
185 |
ec_datagram_t *datagram = fsm->datagram; |
|
186 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
187 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
188 |
ec_master_queue_datagram(fsm->slave->master, datagram); |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
189 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
190 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
191 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
192 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
193 |
fsm->state = ec_fsm_sii_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
194 |
EC_ERR("Failed to receive SII read datagram from slave %i.\n", |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
195 |
fsm->slave->ring_position); |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
196 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
197 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
198 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
199 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
200 |
fsm->state = ec_fsm_sii_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
201 |
EC_ERR("Reception of SII read datagram failed - slave %i did not" |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
202 |
" respond.\n", fsm->slave->ring_position); |
433 | 203 |
return; |
204 |
} |
|
205 |
||
206 |
fsm->cycles_start = datagram->cycles_sent; |
|
207 |
fsm->check_once_more = 1; |
|
208 |
||
209 |
// issue check/fetch datagram |
|
210 |
switch (fsm->mode) { |
|
211 |
case EC_FSM_SII_POSITION: |
|
212 |
ec_datagram_aprd(datagram, fsm->slave->ring_position, 0x502, 10); |
|
213 |
break; |
|
214 |
case EC_FSM_SII_NODE: |
|
215 |
ec_datagram_nprd(datagram, fsm->slave->station_address, 0x502, 10); |
|
216 |
break; |
|
217 |
} |
|
218 |
ec_master_queue_datagram(fsm->slave->master, datagram); |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
219 |
fsm->retries = EC_FSM_RETRIES; |
433 | 220 |
fsm->state = ec_fsm_sii_read_fetch; |
221 |
} |
|
222 |
||
223 |
/*****************************************************************************/ |
|
224 |
||
225 |
/** |
|
226 |
SII state: READ FETCH. |
|
227 |
Fetches the result of an SII-read datagram. |
|
228 |
*/ |
|
229 |
||
230 |
void ec_fsm_sii_read_fetch(ec_fsm_sii_t *fsm /**< finite state machine */) |
|
231 |
{ |
|
232 |
ec_datagram_t *datagram = fsm->datagram; |
|
233 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
234 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
235 |
ec_master_queue_datagram(fsm->slave->master, datagram); |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
236 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
237 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
238 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
239 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
240 |
fsm->state = ec_fsm_sii_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
241 |
EC_ERR("Failed to receive SII check/fetch datagram from slave %i.\n", |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
242 |
fsm->slave->ring_position); |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
243 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
244 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
245 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
246 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
247 |
fsm->state = ec_fsm_sii_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
248 |
EC_ERR("Reception of SII check/fetch datagram failed - slave %i did" |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
249 |
" not respond\n", fsm->slave->ring_position); |
433 | 250 |
return; |
251 |
} |
|
252 |
||
253 |
// check "busy bit" |
|
254 |
if (EC_READ_U8(datagram->data + 1) & 0x81) { |
|
255 |
// still busy... timeout? |
|
256 |
if (datagram->cycles_received |
|
257 |
- fsm->cycles_start >= (cycles_t) 10 * cpu_khz) { |
|
258 |
if (!fsm->check_once_more) { |
|
259 |
EC_ERR("SII: Read timeout.\n"); |
|
260 |
fsm->state = ec_fsm_sii_error; |
|
261 |
#if 0 |
|
262 |
EC_DBG("SII busy: %02X %02X %02X %02X\n", |
|
263 |
EC_READ_U8(datagram->data + 0), |
|
264 |
EC_READ_U8(datagram->data + 1), |
|
265 |
EC_READ_U8(datagram->data + 2), |
|
266 |
EC_READ_U8(datagram->data + 3)); |
|
267 |
#endif |
|
268 |
return; |
|
269 |
} |
|
270 |
fsm->check_once_more = 0; |
|
271 |
} |
|
272 |
||
273 |
// issue check/fetch datagram again |
|
274 |
switch (fsm->mode) { |
|
275 |
case EC_FSM_SII_POSITION: |
|
276 |
ec_datagram_aprd(datagram, fsm->slave->ring_position, 0x502, 10); |
|
277 |
break; |
|
278 |
case EC_FSM_SII_NODE: |
|
279 |
ec_datagram_nprd(datagram, fsm->slave->station_address, 0x502, 10); |
|
280 |
break; |
|
281 |
} |
|
282 |
ec_master_queue_datagram(fsm->slave->master, datagram); |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
283 |
fsm->retries = EC_FSM_RETRIES; |
433 | 284 |
return; |
285 |
} |
|
286 |
||
287 |
#if 0 |
|
288 |
EC_DBG("SII rec: %02X %02X %02X %02X - %02X %02X %02X %02X\n", |
|
289 |
EC_READ_U8(datagram->data + 0), EC_READ_U8(datagram->data + 1), |
|
290 |
EC_READ_U8(datagram->data + 2), EC_READ_U8(datagram->data + 3), |
|
291 |
EC_READ_U8(datagram->data + 6), EC_READ_U8(datagram->data + 7), |
|
292 |
EC_READ_U8(datagram->data + 8), EC_READ_U8(datagram->data + 9)); |
|
293 |
#endif |
|
294 |
||
295 |
// SII value received. |
|
296 |
memcpy(fsm->value, datagram->data + 6, 4); |
|
297 |
fsm->state = ec_fsm_sii_end; |
|
298 |
} |
|
299 |
||
300 |
/*****************************************************************************/ |
|
301 |
||
302 |
/** |
|
303 |
SII state: START WRITING. |
|
304 |
Starts reading the slave information interface. |
|
305 |
*/ |
|
306 |
||
307 |
void ec_fsm_sii_start_writing(ec_fsm_sii_t *fsm /**< finite state machine */) |
|
308 |
{ |
|
309 |
ec_datagram_t *datagram = fsm->datagram; |
|
310 |
||
311 |
// initiate write operation |
|
312 |
ec_datagram_npwr(datagram, fsm->slave->station_address, 0x502, 8); |
|
313 |
EC_WRITE_U8 (datagram->data, 0x01); // enable write access |
|
314 |
EC_WRITE_U8 (datagram->data + 1, 0x02); // request write operation |
|
315 |
EC_WRITE_U32(datagram->data + 2, fsm->offset); |
|
316 |
memcpy(datagram->data + 6, fsm->value, 2); |
|
317 |
ec_master_queue_datagram(fsm->slave->master, datagram); |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
318 |
fsm->retries = EC_FSM_RETRIES; |
433 | 319 |
fsm->state = ec_fsm_sii_write_check; |
320 |
} |
|
321 |
||
322 |
/*****************************************************************************/ |
|
323 |
||
324 |
/** |
|
325 |
SII state: WRITE CHECK. |
|
326 |
*/ |
|
327 |
||
328 |
void ec_fsm_sii_write_check(ec_fsm_sii_t *fsm /**< finite state machine */) |
|
329 |
{ |
|
330 |
ec_datagram_t *datagram = fsm->datagram; |
|
331 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
332 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
333 |
ec_master_queue_datagram(fsm->slave->master, datagram); |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
334 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
335 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
336 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
337 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
338 |
fsm->state = ec_fsm_sii_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
339 |
EC_ERR("Failed to receive SII write datagram for slave %i.\n", |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
340 |
fsm->slave->ring_position); |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
341 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
342 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
343 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
344 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
345 |
fsm->state = ec_fsm_sii_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
346 |
EC_ERR("Reception of SII write datagram failed - slave %i did not" |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
347 |
" respond.\n", fsm->slave->ring_position); |
433 | 348 |
return; |
349 |
} |
|
350 |
||
351 |
fsm->cycles_start = datagram->cycles_sent; |
|
352 |
fsm->check_once_more = 1; |
|
353 |
||
354 |
// issue check/fetch datagram |
|
355 |
ec_datagram_nprd(datagram, fsm->slave->station_address, 0x502, 2); |
|
356 |
ec_master_queue_datagram(fsm->slave->master, datagram); |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
357 |
fsm->retries = EC_FSM_RETRIES; |
433 | 358 |
fsm->state = ec_fsm_sii_write_check2; |
359 |
} |
|
360 |
||
361 |
/*****************************************************************************/ |
|
362 |
||
363 |
/** |
|
364 |
SII state: WRITE CHECK 2. |
|
365 |
*/ |
|
366 |
||
367 |
void ec_fsm_sii_write_check2(ec_fsm_sii_t *fsm /**< finite state machine */) |
|
368 |
{ |
|
369 |
ec_datagram_t *datagram = fsm->datagram; |
|
370 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
371 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
372 |
ec_master_queue_datagram(fsm->slave->master, datagram); |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
373 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
374 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
375 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
376 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
377 |
fsm->state = ec_fsm_sii_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
378 |
EC_ERR("Failed to receive SII write check datagram from slave %i.\n", |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
379 |
fsm->slave->ring_position); |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
380 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
381 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
382 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
383 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
384 |
fsm->state = ec_fsm_sii_error; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
385 |
EC_ERR("Reception of SII write check datagram failed - slave %i did" |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
386 |
" not respond.\n", fsm->slave->ring_position); |
433 | 387 |
return; |
388 |
} |
|
389 |
||
390 |
if (EC_READ_U8(datagram->data + 1) & 0x82) { |
|
391 |
// still busy... timeout? |
|
392 |
if (datagram->cycles_received |
|
393 |
- fsm->cycles_start >= (cycles_t) 10 * cpu_khz) { |
|
394 |
if (!fsm->check_once_more) { |
|
395 |
EC_ERR("SII: Write timeout.\n"); |
|
396 |
fsm->state = ec_fsm_sii_error; |
|
397 |
return; |
|
398 |
} |
|
399 |
fsm->check_once_more = 0; |
|
400 |
} |
|
401 |
||
402 |
// issue check/fetch datagram again |
|
403 |
ec_master_queue_datagram(fsm->slave->master, datagram); |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
404 |
fsm->retries = EC_FSM_RETRIES; |
433 | 405 |
return; |
406 |
} |
|
407 |
||
408 |
if (EC_READ_U8(datagram->data + 1) & 0x40) { |
|
409 |
EC_ERR("SII: Write operation failed!\n"); |
|
410 |
fsm->state = ec_fsm_sii_error; |
|
411 |
return; |
|
412 |
} |
|
413 |
||
414 |
// success |
|
415 |
fsm->state = ec_fsm_sii_end; |
|
416 |
} |
|
417 |
||
418 |
/*****************************************************************************/ |
|
419 |
||
420 |
/** |
|
421 |
State: ERROR. |
|
422 |
*/ |
|
423 |
||
424 |
void ec_fsm_sii_error(ec_fsm_sii_t *fsm /**< finite state machine */) |
|
425 |
{ |
|
426 |
} |
|
427 |
||
428 |
/*****************************************************************************/ |
|
429 |
||
430 |
/** |
|
431 |
State: END. |
|
432 |
*/ |
|
433 |
||
434 |
void ec_fsm_sii_end(ec_fsm_sii_t *fsm /**< finite state machine */) |
|
435 |
{ |
|
436 |
} |
|
437 |
||
438 |
/*****************************************************************************/ |