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