author | Florian Pose <fp@igh.de> |
Wed, 13 Dec 2017 15:39:13 +0100 | |
branch | stable-1.5 |
changeset 2693 | 8051d05cb935 |
parent 1957 | b481ccf21272 |
permissions | -rw-r--r-- |
433 | 1 |
/****************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
4 |
* |
|
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1225
diff
changeset
|
5 |
* Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH |
433 | 6 |
* |
7 |
* This file is part of the IgH EtherCAT Master. |
|
8 |
* |
|
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1225
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1225
diff
changeset
|
10 |
* modify it under the terms of the GNU General Public License version 2, as |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1225
diff
changeset
|
11 |
* published by the Free Software Foundation. |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1225
diff
changeset
|
12 |
* |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1225
diff
changeset
|
13 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1225
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1225
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1225
diff
changeset
|
16 |
* Public License for more details. |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1225
diff
changeset
|
17 |
* |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1225
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License along |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1225
diff
changeset
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
433 | 20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
21 |
* |
|
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
22 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
23 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
24 |
* The license mentioned above concerns the source code only. Using the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
25 |
* EtherCAT technology and brand is only permitted in compliance with the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
433 | 27 |
* |
28 |
*****************************************************************************/ |
|
29 |
||
30 |
/** |
|
31 |
\file |
|
32 |
EtherCAT slave information interface FSM. |
|
33 |
*/ |
|
34 |
||
35 |
/*****************************************************************************/ |
|
36 |
||
37 |
#include "globals.h" |
|
38 |
#include "mailbox.h" |
|
39 |
#include "master.h" |
|
40 |
#include "fsm_sii.h" |
|
41 |
||
1123
17bef224061d
Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents:
1039
diff
changeset
|
42 |
/** Read/write timeout [ms]. |
17bef224061d
Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents:
1039
diff
changeset
|
43 |
* |
17bef224061d
Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents:
1039
diff
changeset
|
44 |
* 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
|
45 |
* |
17bef224061d
Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents:
1039
diff
changeset
|
46 |
* \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
|
47 |
* a timer interupt frequency of 100 Hz. |
758
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
755
diff
changeset
|
48 |
*/ |
1123
17bef224061d
Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents:
1039
diff
changeset
|
49 |
#define SII_TIMEOUT 20 |
17bef224061d
Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents:
1039
diff
changeset
|
50 |
|
17bef224061d
Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents:
1039
diff
changeset
|
51 |
/** Time before evaluating answer at writing [ms]. |
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_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
|
54 |
|
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
55 |
//#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
|
56 |
|
433 | 57 |
/*****************************************************************************/ |
58 |
||
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
void ec_fsm_sii_state_error(ec_fsm_sii_t *); |
433 | 67 |
|
68 |
/*****************************************************************************/ |
|
69 |
||
70 |
/** |
|
71 |
Constructor. |
|
72 |
*/ |
|
73 |
||
74 |
void ec_fsm_sii_init(ec_fsm_sii_t *fsm, /**< finite state machine */ |
|
75 |
ec_datagram_t *datagram /**< datagram structure to use */ |
|
76 |
) |
|
77 |
{ |
|
78 |
fsm->state = NULL; |
|
79 |
fsm->datagram = datagram; |
|
80 |
} |
|
81 |
||
82 |
/*****************************************************************************/ |
|
83 |
||
84 |
/** |
|
85 |
Destructor. |
|
86 |
*/ |
|
87 |
||
88 |
void ec_fsm_sii_clear(ec_fsm_sii_t *fsm /**< finite state machine */) |
|
89 |
{ |
|
90 |
} |
|
91 |
||
92 |
/*****************************************************************************/ |
|
93 |
||
94 |
/** |
|
95 |
Initializes the SII read state machine. |
|
96 |
*/ |
|
97 |
||
98 |
void ec_fsm_sii_read(ec_fsm_sii_t *fsm, /**< finite state machine */ |
|
99 |
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
|
100 |
uint16_t word_offset, /**< offset to read from */ |
433 | 101 |
ec_fsm_sii_addressing_t mode /**< addressing scheme */ |
102 |
) |
|
103 |
{ |
|
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
104 |
fsm->state = ec_fsm_sii_state_start_reading; |
433 | 105 |
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
|
106 |
fsm->word_offset = word_offset; |
433 | 107 |
fsm->mode = mode; |
108 |
} |
|
109 |
||
110 |
/*****************************************************************************/ |
|
111 |
||
112 |
/** |
|
113 |
Initializes the SII write state machine. |
|
114 |
*/ |
|
115 |
||
116 |
void ec_fsm_sii_write(ec_fsm_sii_t *fsm, /**< finite state machine */ |
|
117 |
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
|
118 |
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
|
119 |
const uint16_t *value, /**< pointer to 2 bytes of data */ |
433 | 120 |
ec_fsm_sii_addressing_t mode /**< addressing scheme */ |
121 |
) |
|
122 |
{ |
|
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
123 |
fsm->state = ec_fsm_sii_state_start_writing; |
433 | 124 |
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
|
125 |
fsm->word_offset = word_offset; |
433 | 126 |
fsm->mode = mode; |
127 |
memcpy(fsm->value, value, 2); |
|
128 |
} |
|
129 |
||
130 |
/*****************************************************************************/ |
|
131 |
||
132 |
/** |
|
133 |
Executes the SII state machine. |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
134 |
\return false, if the state machine has terminated |
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
135 |
*/ |
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 |
int ec_fsm_sii_exec(ec_fsm_sii_t *fsm /**< finite state machine */) |
433 | 138 |
{ |
139 |
fsm->state(fsm); |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
140 |
|
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
141 |
return fsm->state != ec_fsm_sii_state_end |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
142 |
&& fsm->state != ec_fsm_sii_state_error; |
433 | 143 |
} |
144 |
||
145 |
/*****************************************************************************/ |
|
146 |
||
147 |
/** |
|
148 |
Returns, if the master startup state machine terminated with success. |
|
149 |
\return non-zero if successful. |
|
150 |
*/ |
|
151 |
||
152 |
int ec_fsm_sii_success(ec_fsm_sii_t *fsm /**< Finite state machine */) |
|
153 |
{ |
|
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
154 |
return fsm->state == ec_fsm_sii_state_end; |
433 | 155 |
} |
156 |
||
157 |
/****************************************************************************** |
|
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
158 |
* state functions |
433 | 159 |
*****************************************************************************/ |
160 |
||
161 |
/** |
|
162 |
SII state: START READING. |
|
163 |
Starts reading the slave information interface. |
|
164 |
*/ |
|
165 |
||
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
166 |
void ec_fsm_sii_state_start_reading( |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
167 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
168 |
) |
433 | 169 |
{ |
170 |
ec_datagram_t *datagram = fsm->datagram; |
|
171 |
||
172 |
// initiate read operation |
|
173 |
switch (fsm->mode) { |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
174 |
case EC_FSM_SII_USE_INCREMENT_ADDRESS: |
433 | 175 |
ec_datagram_apwr(datagram, fsm->slave->ring_position, 0x502, 4); |
176 |
break; |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
177 |
case EC_FSM_SII_USE_CONFIGURED_ADDRESS: |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
178 |
ec_datagram_fpwr(datagram, fsm->slave->station_address, 0x502, 4); |
433 | 179 |
break; |
180 |
} |
|
181 |
||
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
182 |
EC_WRITE_U8 (datagram->data, 0x80); // two address octets |
433 | 183 |
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
|
184 |
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
|
185 |
|
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
186 |
#ifdef SII_DEBUG |
1957
b481ccf21272
Minor: Improved SII debugging.
Florian Pose <fp@igh-essen.com>
parents:
1951
diff
changeset
|
187 |
EC_SLAVE_DBG(fsm->slave, 0, "reading SII data, word %u:\n", |
b481ccf21272
Minor: Improved SII debugging.
Florian Pose <fp@igh-essen.com>
parents:
1951
diff
changeset
|
188 |
fsm->word_offset); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
189 |
ec_print_data(datagram->data, 4); |
755
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( |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
204 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
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; |
1921 | 214 |
EC_SLAVE_ERR(fsm->slave, "Failed to receive SII read datagram: "); |
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1599
diff
changeset
|
215 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
216 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
217 |
} |
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 |
if (datagram->working_counter != 1) { |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
220 |
fsm->state = ec_fsm_sii_state_error; |
1921 | 221 |
EC_SLAVE_ERR(fsm->slave, "Reception of SII read datagram failed: "); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
222 |
ec_datagram_print_wc_error(datagram); |
433 | 223 |
return; |
224 |
} |
|
225 |
||
1039
2881a83d084f
Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
226 |
fsm->jiffies_start = datagram->jiffies_sent; |
433 | 227 |
fsm->check_once_more = 1; |
228 |
||
229 |
// issue check/fetch datagram |
|
230 |
switch (fsm->mode) { |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
231 |
case EC_FSM_SII_USE_INCREMENT_ADDRESS: |
433 | 232 |
ec_datagram_aprd(datagram, fsm->slave->ring_position, 0x502, 10); |
233 |
break; |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
234 |
case EC_FSM_SII_USE_CONFIGURED_ADDRESS: |
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
235 |
ec_datagram_fprd(datagram, fsm->slave->station_address, 0x502, 10); |
433 | 236 |
break; |
237 |
} |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
600
diff
changeset
|
238 |
|
1225
4d5b739edcb5
Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents:
1123
diff
changeset
|
239 |
ec_datagram_zero(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
240 |
fsm->retries = EC_FSM_RETRIES; |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
241 |
fsm->state = ec_fsm_sii_state_read_fetch; |
433 | 242 |
} |
243 |
||
244 |
/*****************************************************************************/ |
|
245 |
||
246 |
/** |
|
247 |
SII state: READ FETCH. |
|
248 |
Fetches the result of an SII-read datagram. |
|
249 |
*/ |
|
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
250 |
void ec_fsm_sii_state_read_fetch( |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
251 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
252 |
) |
433 | 253 |
{ |
254 |
ec_datagram_t *datagram = fsm->datagram; |
|
255 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
600
diff
changeset
|
256 |
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
|
257 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
258 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
259 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
260 |
fsm->state = ec_fsm_sii_state_error; |
1921 | 261 |
EC_SLAVE_ERR(fsm->slave, |
262 |
"Failed to receive SII check/fetch datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1599
diff
changeset
|
263 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
264 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
265 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
266 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
267 |
if (datagram->working_counter != 1) { |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
268 |
fsm->state = ec_fsm_sii_state_error; |
1921 | 269 |
EC_SLAVE_ERR(fsm->slave, |
270 |
"Reception of SII check/fetch datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
271 |
ec_datagram_print_wc_error(datagram); |
433 | 272 |
return; |
273 |
} |
|
274 |
||
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
275 |
#ifdef SII_DEBUG |
1921 | 276 |
EC_SLAVE_DBG(fsm->slave, 0, "checking SII read state:\n"); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
277 |
ec_print_data(datagram->data, 10); |
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
278 |
#endif |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
279 |
|
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
280 |
if (EC_READ_U8(datagram->data + 1) & 0x20) { |
1951 | 281 |
EC_SLAVE_ERR(fsm->slave, "Error on last command while" |
282 |
" reading from SII word 0x%04x.\n", fsm->word_offset); |
|
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
283 |
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
|
284 |
return; |
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 |
|
433 | 287 |
// check "busy bit" |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
288 |
if (EC_READ_U8(datagram->data + 1) & 0x81) { /* busy bit or |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
289 |
read operation busy */ |
433 | 290 |
// still busy... timeout? |
1039
2881a83d084f
Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
291 |
unsigned long diff_ms = |
2881a83d084f
Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
292 |
(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
|
293 |
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
|
294 |
if (fsm->check_once_more) { |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
295 |
fsm->check_once_more = 0; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
296 |
} else { |
1921 | 297 |
EC_SLAVE_ERR(fsm->slave, "SII: Read timeout.\n"); |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
298 |
fsm->state = ec_fsm_sii_state_error; |
433 | 299 |
return; |
300 |
} |
|
301 |
} |
|
302 |
||
303 |
// issue check/fetch datagram again |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
304 |
fsm->retries = EC_FSM_RETRIES; |
433 | 305 |
return; |
306 |
} |
|
307 |
||
308 |
// SII value received. |
|
309 |
memcpy(fsm->value, datagram->data + 6, 4); |
|
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
310 |
fsm->state = ec_fsm_sii_state_end; |
433 | 311 |
} |
312 |
||
313 |
/*****************************************************************************/ |
|
314 |
||
315 |
/** |
|
316 |
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
|
317 |
Starts writing a word through the slave information interface. |
433 | 318 |
*/ |
319 |
||
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
320 |
void ec_fsm_sii_state_start_writing( |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
321 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
322 |
) |
433 | 323 |
{ |
324 |
ec_datagram_t *datagram = fsm->datagram; |
|
325 |
||
326 |
// initiate write operation |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
327 |
ec_datagram_fpwr(datagram, fsm->slave->station_address, 0x502, 8); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
328 |
EC_WRITE_U8 (datagram->data, 0x81); /* two address octets |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
329 |
+ enable write access */ |
433 | 330 |
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
|
331 |
EC_WRITE_U16(datagram->data + 2, fsm->word_offset); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
332 |
memset(datagram->data + 4, 0x00, 2); |
433 | 333 |
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
|
334 |
|
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
335 |
#ifdef SII_DEBUG |
1921 | 336 |
EC_SLAVE_DBG(fsm->slave, 0, "writing SII data:\n"); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
337 |
ec_print_data(datagram->data, 8); |
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
338 |
#endif |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
339 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
340 |
fsm->retries = EC_FSM_RETRIES; |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
341 |
fsm->state = ec_fsm_sii_state_write_check; |
433 | 342 |
} |
343 |
||
344 |
/*****************************************************************************/ |
|
345 |
||
346 |
/** |
|
347 |
SII state: WRITE CHECK. |
|
348 |
*/ |
|
349 |
||
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
350 |
void ec_fsm_sii_state_write_check( |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
351 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
352 |
) |
433 | 353 |
{ |
354 |
ec_datagram_t *datagram = fsm->datagram; |
|
355 |
||
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
600
diff
changeset
|
356 |
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
|
357 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
358 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
359 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
360 |
fsm->state = ec_fsm_sii_state_error; |
1921 | 361 |
EC_SLAVE_ERR(fsm->slave, "Failed to receive SII write datagram: "); |
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1599
diff
changeset
|
362 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
363 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
364 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
365 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
366 |
if (datagram->working_counter != 1) { |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
367 |
fsm->state = ec_fsm_sii_state_error; |
1921 | 368 |
EC_SLAVE_ERR(fsm->slave, "Reception of SII write datagram failed: "); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
369 |
ec_datagram_print_wc_error(datagram); |
433 | 370 |
return; |
371 |
} |
|
372 |
||
1039
2881a83d084f
Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
373 |
fsm->jiffies_start = datagram->jiffies_sent; |
433 | 374 |
fsm->check_once_more = 1; |
375 |
||
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
376 |
// issue check datagram |
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
377 |
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
|
378 |
ec_datagram_zero(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
379 |
fsm->retries = EC_FSM_RETRIES; |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
380 |
fsm->state = ec_fsm_sii_state_write_check2; |
433 | 381 |
} |
382 |
||
383 |
/*****************************************************************************/ |
|
384 |
||
385 |
/** |
|
386 |
SII state: WRITE CHECK 2. |
|
387 |
*/ |
|
388 |
||
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
389 |
void ec_fsm_sii_state_write_check2( |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
390 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
391 |
) |
433 | 392 |
{ |
393 |
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
|
394 |
unsigned long diff_ms; |
433 | 395 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
600
diff
changeset
|
396 |
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
|
397 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
398 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
399 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
400 |
fsm->state = ec_fsm_sii_state_error; |
1921 | 401 |
EC_SLAVE_ERR(fsm->slave, |
402 |
"Failed to receive SII write check datagram: "); |
|
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1599
diff
changeset
|
403 |
ec_datagram_print_state(datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
404 |
return; |
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 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
407 |
if (datagram->working_counter != 1) { |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
408 |
fsm->state = ec_fsm_sii_state_error; |
1921 | 409 |
EC_SLAVE_ERR(fsm->slave, |
410 |
"Reception of SII write check datagram failed: "); |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
411 |
ec_datagram_print_wc_error(datagram); |
433 | 412 |
return; |
413 |
} |
|
414 |
||
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
415 |
#ifdef SII_DEBUG |
1921 | 416 |
EC_SLAVE_DBG(fsm->slave, 0, "checking SII write state:\n"); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
417 |
ec_print_data(datagram->data, 2); |
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
418 |
#endif |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
419 |
|
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
420 |
if (EC_READ_U8(datagram->data + 1) & 0x20) { |
1921 | 421 |
EC_SLAVE_ERR(fsm->slave, "SII: Error on last SII command!\n"); |
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
422 |
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
|
423 |
return; |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
424 |
} |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
425 |
|
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
426 |
/* FIXME: some slaves never answer with the busy flag set... |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
427 |
* 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
|
428 |
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
|
429 |
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
|
430 |
#ifdef SII_DEBUG |
1921 | 431 |
EC_SLAVE_DBG(fsm->slave, 0, "too early.\n"); |
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
432 |
#endif |
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
433 |
// 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
|
434 |
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
|
435 |
return; |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
436 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
437 |
|
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
438 |
if (EC_READ_U8(datagram->data + 1) & 0x82) { /* busy bit or |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
439 |
write operation busy bit */ |
433 | 440 |
// still busy... timeout? |
1039
2881a83d084f
Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
441 |
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
|
442 |
if (fsm->check_once_more) { |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
443 |
fsm->check_once_more = 0; |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
444 |
} else { |
1921 | 445 |
EC_SLAVE_ERR(fsm->slave, "SII: Write timeout.\n"); |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
446 |
fsm->state = ec_fsm_sii_state_error; |
433 | 447 |
return; |
448 |
} |
|
449 |
} |
|
450 |
||
755
178353fc47e5
SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
451 |
// issue check datagram again |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
452 |
fsm->retries = EC_FSM_RETRIES; |
433 | 453 |
return; |
454 |
} |
|
455 |
||
456 |
if (EC_READ_U8(datagram->data + 1) & 0x40) { |
|
1921 | 457 |
EC_SLAVE_ERR(fsm->slave, "SII: Write operation failed!\n"); |
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
458 |
fsm->state = ec_fsm_sii_state_error; |
433 | 459 |
return; |
460 |
} |
|
461 |
||
462 |
// success |
|
753
7ba5f9cd8f7e
Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
463 |
fsm->state = ec_fsm_sii_state_end; |
433 | 464 |
} |
465 |
||
466 |
/*****************************************************************************/ |
|
467 |
||
468 |
/** |
|
469 |
State: ERROR. |
|
470 |
*/ |
|
471 |
||
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
472 |
void ec_fsm_sii_state_error( |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
473 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
474 |
) |
433 | 475 |
{ |
476 |
} |
|
477 |
||
478 |
/*****************************************************************************/ |
|
479 |
||
480 |
/** |
|
481 |
State: END. |
|
482 |
*/ |
|
483 |
||
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
753
diff
changeset
|
484 |
void ec_fsm_sii_state_end( |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
485 |
ec_fsm_sii_t *fsm /**< finite state machine */ |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
486 |
) |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
487 |
{ |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
488 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
489 |
|
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
490 |
/*****************************************************************************/ |