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