author | Florian Pose <fp@igh-essen.com> |
Wed, 02 Jul 2008 14:06:10 +0000 | |
changeset 1082 | ff06c58e269c |
parent 1039 | 2881a83d084f |
child 1123 | 17bef224061d |
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 |
||
758
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
755
diff
changeset
|
46 |
/** |
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
755
diff
changeset
|
47 |
* Read/Write timeout. [ms] |
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
755
diff
changeset
|
48 |
*/ |
872 | 49 |
#define SII_TIMEOUT 10 |
758
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
755
diff
changeset
|
50 |
|
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
755
diff
changeset
|
51 |
/** |
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
755
diff
changeset
|
52 |
* Time before evaluating answer at writing. [ms] |
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
755
diff
changeset
|
53 |
*/ |
872 | 54 |
#define SII_INHIBIT 5 |
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
55 |
|
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
56 |
//#define SII_DEBUG |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
57 |
|
433 | 58 |
/*****************************************************************************/ |
59 |
||
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
60 |
void ec_fsm_sii_state_start_reading(ec_fsm_sii_t *); |
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
61 |
void ec_fsm_sii_state_read_check(ec_fsm_sii_t *); |
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
62 |
void ec_fsm_sii_state_read_fetch(ec_fsm_sii_t *); |
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
63 |
void ec_fsm_sii_state_start_writing(ec_fsm_sii_t *); |
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
64 |
void ec_fsm_sii_state_write_check(ec_fsm_sii_t *); |
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
65 |
void ec_fsm_sii_state_write_check2(ec_fsm_sii_t *); |
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
66 |
void ec_fsm_sii_state_end(ec_fsm_sii_t *); |
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
67 |
void ec_fsm_sii_state_error(ec_fsm_sii_t *); |
433 | 68 |
|
69 |
/*****************************************************************************/ |
|
70 |
||
71 |
/** |
|
72 |
Constructor. |
|
73 |
*/ |
|
74 |
||
75 |
void ec_fsm_sii_init(ec_fsm_sii_t *fsm, /**< finite state machine */ |
|
76 |
ec_datagram_t *datagram /**< datagram structure to use */ |
|
77 |
) |
|
78 |
{ |
|
79 |
fsm->state = NULL; |
|
80 |
fsm->datagram = datagram; |
|
81 |
} |
|
82 |
||
83 |
/*****************************************************************************/ |
|
84 |
||
85 |
/** |
|
86 |
Destructor. |
|
87 |
*/ |
|
88 |
||
89 |
void ec_fsm_sii_clear(ec_fsm_sii_t *fsm /**< finite state machine */) |
|
90 |
{ |
|
91 |
} |
|
92 |
||
93 |
/*****************************************************************************/ |
|
94 |
||
95 |
/** |
|
96 |
Initializes the SII read state machine. |
|
97 |
*/ |
|
98 |
||
99 |
void ec_fsm_sii_read(ec_fsm_sii_t *fsm, /**< finite state machine */ |
|
100 |
ec_slave_t *slave, /**< slave to read from */ |
|
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
101 |
uint16_t word_offset, /**< offset to read from */ |
433 | 102 |
ec_fsm_sii_addressing_t mode /**< addressing scheme */ |
103 |
) |
|
104 |
{ |
|
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
105 |
fsm->state = ec_fsm_sii_state_start_reading; |
433 | 106 |
fsm->slave = slave; |
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
107 |
fsm->word_offset = word_offset; |
433 | 108 |
fsm->mode = mode; |
109 |
} |
|
110 |
||
111 |
/*****************************************************************************/ |
|
112 |
||
113 |
/** |
|
114 |
Initializes the SII write state machine. |
|
115 |
*/ |
|
116 |
||
117 |
void ec_fsm_sii_write(ec_fsm_sii_t *fsm, /**< finite state machine */ |
|
118 |
ec_slave_t *slave, /**< slave to read from */ |
|
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
119 |
uint16_t word_offset, /**< offset to read from */ |
979
405cc2d033e0
Renamed some fields in ec_sii_request_t to word addressing.
Florian Pose <fp@igh-essen.com>
parents:
872
diff
changeset
|
120 |
const uint16_t *value, /**< pointer to 2 bytes of data */ |
433 | 121 |
ec_fsm_sii_addressing_t mode /**< addressing scheme */ |
122 |
) |
|
123 |
{ |
|
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
124 |
fsm->state = ec_fsm_sii_state_start_writing; |
433 | 125 |
fsm->slave = slave; |
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
126 |
fsm->word_offset = word_offset; |
433 | 127 |
fsm->mode = mode; |
128 |
memcpy(fsm->value, value, 2); |
|
129 |
} |
|
130 |
||
131 |
/*****************************************************************************/ |
|
132 |
||
133 |
/** |
|
134 |
Executes the SII state machine. |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
135 |
\return false, if the state machine has terminated |
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
136 |
*/ |
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
137 |
|
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
138 |
int ec_fsm_sii_exec(ec_fsm_sii_t *fsm /**< finite state machine */) |
433 | 139 |
{ |
140 |
fsm->state(fsm); |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
141 |
|
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
142 |
return fsm->state != ec_fsm_sii_state_end |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
143 |
&& fsm->state != ec_fsm_sii_state_error; |
433 | 144 |
} |
145 |
||
146 |
/*****************************************************************************/ |
|
147 |
||
148 |
/** |
|
149 |
Returns, if the master startup state machine terminated with success. |
|
150 |
\return non-zero if successful. |
|
151 |
*/ |
|
152 |
||
153 |
int ec_fsm_sii_success(ec_fsm_sii_t *fsm /**< Finite state machine */) |
|
154 |
{ |
|
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
155 |
return fsm->state == ec_fsm_sii_state_end; |
433 | 156 |
} |
157 |
||
158 |
/****************************************************************************** |
|
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
159 |
* state functions |
433 | 160 |
*****************************************************************************/ |
161 |
||
162 |
/** |
|
163 |
SII state: START READING. |
|
164 |
Starts reading the slave information interface. |
|
165 |
*/ |
|
166 |
||
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
167 |
void ec_fsm_sii_state_start_reading( |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
168 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
169 |
) |
433 | 170 |
{ |
171 |
ec_datagram_t *datagram = fsm->datagram; |
|
172 |
||
173 |
// initiate read operation |
|
174 |
switch (fsm->mode) { |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
175 |
case EC_FSM_SII_USE_INCREMENT_ADDRESS: |
433 | 176 |
ec_datagram_apwr(datagram, fsm->slave->ring_position, 0x502, 4); |
177 |
break; |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
178 |
case EC_FSM_SII_USE_CONFIGURED_ADDRESS: |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
179 |
ec_datagram_fpwr(datagram, fsm->slave->station_address, 0x502, 4); |
433 | 180 |
break; |
181 |
} |
|
182 |
||
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
183 |
EC_WRITE_U8 (datagram->data, 0x80); // two address octets |
433 | 184 |
EC_WRITE_U8 (datagram->data + 1, 0x01); // request read operation |
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
185 |
EC_WRITE_U16(datagram->data + 2, fsm->word_offset); |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
186 |
|
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
187 |
#ifdef SII_DEBUG |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
188 |
EC_DBG("reading SII data:\n"); |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
189 |
ec_print_data(datagram->data, 4); |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
190 |
#endif |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
191 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
192 |
fsm->retries = EC_FSM_RETRIES; |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
193 |
fsm->state = ec_fsm_sii_state_read_check; |
433 | 194 |
} |
195 |
||
196 |
/*****************************************************************************/ |
|
197 |
||
198 |
/** |
|
199 |
SII state: READ CHECK. |
|
200 |
Checks, if the SII-read-datagram has been sent and issues a fetch datagram. |
|
201 |
*/ |
|
202 |
||
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
203 |
void ec_fsm_sii_state_read_check( |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
204 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
205 |
) |
433 | 206 |
{ |
207 |
ec_datagram_t *datagram = fsm->datagram; |
|
208 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
600
diff
changeset
|
209 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
600
diff
changeset
|
210 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
211 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
212 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
213 |
fsm->state = ec_fsm_sii_state_error; |
986
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
979
diff
changeset
|
214 |
EC_ERR("Failed to receive SII read datagram from slave %u" |
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
979
diff
changeset
|
215 |
" (datagram state %u).\n", |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
216 |
fsm->slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
217 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
218 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
219 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
220 |
if (datagram->working_counter != 1) { |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
221 |
fsm->state = ec_fsm_sii_state_error; |
986
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
979
diff
changeset
|
222 |
EC_ERR("Reception of SII read datagram failed on slave %u: ", |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
223 |
fsm->slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
224 |
ec_datagram_print_wc_error(datagram); |
433 | 225 |
return; |
226 |
} |
|
227 |
||
1039
2881a83d084f
Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
228 |
fsm->jiffies_start = datagram->jiffies_sent; |
433 | 229 |
fsm->check_once_more = 1; |
230 |
||
231 |
// issue check/fetch datagram |
|
232 |
switch (fsm->mode) { |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
233 |
case EC_FSM_SII_USE_INCREMENT_ADDRESS: |
433 | 234 |
ec_datagram_aprd(datagram, fsm->slave->ring_position, 0x502, 10); |
235 |
break; |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
236 |
case EC_FSM_SII_USE_CONFIGURED_ADDRESS: |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
237 |
ec_datagram_fprd(datagram, fsm->slave->station_address, 0x502, 10); |
433 | 238 |
break; |
239 |
} |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
600
diff
changeset
|
240 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
241 |
fsm->retries = EC_FSM_RETRIES; |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
242 |
fsm->state = ec_fsm_sii_state_read_fetch; |
433 | 243 |
} |
244 |
||
245 |
/*****************************************************************************/ |
|
246 |
||
247 |
/** |
|
248 |
SII state: READ FETCH. |
|
249 |
Fetches the result of an SII-read datagram. |
|
250 |
*/ |
|
251 |
||
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
252 |
void ec_fsm_sii_state_read_fetch( |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
253 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
254 |
) |
433 | 255 |
{ |
256 |
ec_datagram_t *datagram = fsm->datagram; |
|
257 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
600
diff
changeset
|
258 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
600
diff
changeset
|
259 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
260 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
261 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
262 |
fsm->state = ec_fsm_sii_state_error; |
986
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
979
diff
changeset
|
263 |
EC_ERR("Failed to receive SII check/fetch datagram from slave %u" |
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
979
diff
changeset
|
264 |
" (datagram state %u).\n", |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
265 |
fsm->slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
266 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
267 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
268 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
269 |
if (datagram->working_counter != 1) { |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
270 |
fsm->state = ec_fsm_sii_state_error; |
986
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
979
diff
changeset
|
271 |
EC_ERR("Reception of SII check/fetch datagram failed on slave %u: ", |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
272 |
fsm->slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
273 |
ec_datagram_print_wc_error(datagram); |
433 | 274 |
return; |
275 |
} |
|
276 |
||
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
277 |
#ifdef SII_DEBUG |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
278 |
EC_DBG("checking SII read state:\n"); |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
279 |
ec_print_data(datagram->data, 10); |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
280 |
#endif |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
281 |
|
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
282 |
if (EC_READ_U8(datagram->data + 1) & 0x20) { |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
283 |
EC_ERR("SII: Error on last SII command!\n"); |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
284 |
fsm->state = ec_fsm_sii_state_error; |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
285 |
return; |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
286 |
} |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
287 |
|
433 | 288 |
// check "busy bit" |
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
289 |
if (EC_READ_U8(datagram->data + 1) & 0x81) { // busy bit or |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
290 |
// read operation busy |
433 | 291 |
// still busy... timeout? |
1039
2881a83d084f
Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
292 |
unsigned long diff_ms = |
2881a83d084f
Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
293 |
(datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ; |
2881a83d084f
Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
294 |
if (diff_ms >= SII_TIMEOUT) { |
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
295 |
if (fsm->check_once_more) { |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
296 |
fsm->check_once_more = 0; |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
297 |
} else { |
433 | 298 |
EC_ERR("SII: Read timeout.\n"); |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
299 |
fsm->state = ec_fsm_sii_state_error; |
433 | 300 |
return; |
301 |
} |
|
302 |
} |
|
303 |
||
304 |
// issue check/fetch datagram again |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
305 |
fsm->retries = EC_FSM_RETRIES; |
433 | 306 |
return; |
307 |
} |
|
308 |
||
309 |
// SII value received. |
|
310 |
memcpy(fsm->value, datagram->data + 6, 4); |
|
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
311 |
fsm->state = ec_fsm_sii_state_end; |
433 | 312 |
} |
313 |
||
314 |
/*****************************************************************************/ |
|
315 |
||
316 |
/** |
|
317 |
SII state: START WRITING. |
|
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
318 |
Starts writing a word through the slave information interface. |
433 | 319 |
*/ |
320 |
||
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
321 |
void ec_fsm_sii_state_start_writing( |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
322 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
323 |
) |
433 | 324 |
{ |
325 |
ec_datagram_t *datagram = fsm->datagram; |
|
326 |
||
327 |
// initiate write operation |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
328 |
ec_datagram_fpwr(datagram, fsm->slave->station_address, 0x502, 8); |
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
329 |
EC_WRITE_U8 (datagram->data, 0x81); // two address octets |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
330 |
// + enable write access |
433 | 331 |
EC_WRITE_U8 (datagram->data + 1, 0x02); // request write operation |
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
332 |
EC_WRITE_U16(datagram->data + 2, fsm->word_offset); |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
333 |
memset(datagram->data + 4, 0x00, 2); |
433 | 334 |
memcpy(datagram->data + 6, fsm->value, 2); |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
600
diff
changeset
|
335 |
|
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
336 |
#ifdef SII_DEBUG |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
337 |
EC_DBG("writing SII data:\n"); |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
338 |
ec_print_data(datagram->data, 8); |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
339 |
#endif |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
340 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
341 |
fsm->retries = EC_FSM_RETRIES; |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
342 |
fsm->state = ec_fsm_sii_state_write_check; |
433 | 343 |
} |
344 |
||
345 |
/*****************************************************************************/ |
|
346 |
||
347 |
/** |
|
348 |
SII state: WRITE CHECK. |
|
349 |
*/ |
|
350 |
||
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
351 |
void ec_fsm_sii_state_write_check( |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
352 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
353 |
) |
433 | 354 |
{ |
355 |
ec_datagram_t *datagram = fsm->datagram; |
|
356 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
600
diff
changeset
|
357 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
600
diff
changeset
|
358 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
359 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
360 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
361 |
fsm->state = ec_fsm_sii_state_error; |
986
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
979
diff
changeset
|
362 |
EC_ERR("Failed to receive SII write datagram for slave %u" |
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
979
diff
changeset
|
363 |
" (datagram state %u).\n", |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
364 |
fsm->slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
365 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
366 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
367 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
368 |
if (datagram->working_counter != 1) { |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
369 |
fsm->state = ec_fsm_sii_state_error; |
986
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
979
diff
changeset
|
370 |
EC_ERR("Reception of SII write datagram failed on slave %u: ", |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
371 |
fsm->slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
372 |
ec_datagram_print_wc_error(datagram); |
433 | 373 |
return; |
374 |
} |
|
375 |
||
1039
2881a83d084f
Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
376 |
fsm->jiffies_start = datagram->jiffies_sent; |
433 | 377 |
fsm->check_once_more = 1; |
378 |
||
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
379 |
// issue check datagram |
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
380 |
ec_datagram_fprd(datagram, fsm->slave->station_address, 0x502, 2); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
381 |
fsm->retries = EC_FSM_RETRIES; |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
382 |
fsm->state = ec_fsm_sii_state_write_check2; |
433 | 383 |
} |
384 |
||
385 |
/*****************************************************************************/ |
|
386 |
||
387 |
/** |
|
388 |
SII state: WRITE CHECK 2. |
|
389 |
*/ |
|
390 |
||
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
391 |
void ec_fsm_sii_state_write_check2( |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
392 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
393 |
) |
433 | 394 |
{ |
395 |
ec_datagram_t *datagram = fsm->datagram; |
|
1039
2881a83d084f
Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
396 |
unsigned long diff_ms; |
433 | 397 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
600
diff
changeset
|
398 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
600
diff
changeset
|
399 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
400 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
401 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
402 |
fsm->state = ec_fsm_sii_state_error; |
986
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
979
diff
changeset
|
403 |
EC_ERR("Failed to receive SII write check datagram from slave %u" |
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
979
diff
changeset
|
404 |
" (datagram state %u).\n", |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
505
diff
changeset
|
405 |
fsm->slave->ring_position, datagram->state); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
406 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
407 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
408 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
409 |
if (datagram->working_counter != 1) { |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
410 |
fsm->state = ec_fsm_sii_state_error; |
986
a486591ba86b
Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents:
979
diff
changeset
|
411 |
EC_ERR("Reception of SII write check datagram failed on slave %u: ", |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
412 |
fsm->slave->ring_position); |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
413 |
ec_datagram_print_wc_error(datagram); |
433 | 414 |
return; |
415 |
} |
|
416 |
||
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
417 |
#ifdef SII_DEBUG |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
418 |
EC_DBG("checking SII write state:\n"); |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
419 |
ec_print_data(datagram->data, 2); |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
420 |
#endif |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
421 |
|
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
422 |
if (EC_READ_U8(datagram->data + 1) & 0x20) { |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
423 |
EC_ERR("SII: Error on last SII command!\n"); |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
424 |
fsm->state = ec_fsm_sii_state_error; |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
425 |
return; |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
426 |
} |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
427 |
|
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
428 |
/* FIXME: some slaves never answer with the busy flag set... |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
429 |
* wait a few ms for the write operation to complete. */ |
1039
2881a83d084f
Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
430 |
diff_ms = (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ; |
2881a83d084f
Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
431 |
if (diff_ms < SII_INHIBIT) { |
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
432 |
#ifdef SII_DEBUG |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
433 |
EC_DBG("too early.\n"); |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
434 |
#endif |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
435 |
// issue check datagram again |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
436 |
fsm->retries = EC_FSM_RETRIES; |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
437 |
return; |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
438 |
} |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
439 |
|
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
440 |
if (EC_READ_U8(datagram->data + 1) & 0x82) { // busy bit or |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
441 |
// write operation busy bit |
433 | 442 |
// still busy... timeout? |
1039
2881a83d084f
Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
443 |
if (diff_ms >= SII_TIMEOUT) { |
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
444 |
if (fsm->check_once_more) { |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
445 |
fsm->check_once_more = 0; |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
446 |
} else { |
433 | 447 |
EC_ERR("SII: Write timeout.\n"); |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
448 |
fsm->state = ec_fsm_sii_state_error; |
433 | 449 |
return; |
450 |
} |
|
451 |
} |
|
452 |
||
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
453 |
// issue check datagram again |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
454 |
fsm->retries = EC_FSM_RETRIES; |
433 | 455 |
return; |
456 |
} |
|
457 |
||
458 |
if (EC_READ_U8(datagram->data + 1) & 0x40) { |
|
459 |
EC_ERR("SII: Write operation failed!\n"); |
|
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
460 |
fsm->state = ec_fsm_sii_state_error; |
433 | 461 |
return; |
462 |
} |
|
463 |
||
464 |
// success |
|
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
465 |
fsm->state = ec_fsm_sii_state_end; |
433 | 466 |
} |
467 |
||
468 |
/*****************************************************************************/ |
|
469 |
||
470 |
/** |
|
471 |
State: ERROR. |
|
472 |
*/ |
|
473 |
||
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
474 |
void ec_fsm_sii_state_error( |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
475 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
476 |
) |
433 | 477 |
{ |
478 |
} |
|
479 |
||
480 |
/*****************************************************************************/ |
|
481 |
||
482 |
/** |
|
483 |
State: END. |
|
484 |
*/ |
|
485 |
||
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
486 |
void ec_fsm_sii_state_end( |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
487 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
488 |
) |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
489 |
{ |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
490 |
} |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
491 |
|
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
492 |
/*****************************************************************************/ |