diff options
Diffstat (limited to 'firmware/target/coldfire')
-rw-r--r-- | firmware/target/coldfire/iaudio/x5/ds2411-x5.c | 70 |
1 files changed, 39 insertions, 31 deletions
diff --git a/firmware/target/coldfire/iaudio/x5/ds2411-x5.c b/firmware/target/coldfire/iaudio/x5/ds2411-x5.c index a8b2ae705c..bb85c8e00e 100644 --- a/firmware/target/coldfire/iaudio/x5/ds2411-x5.c +++ b/firmware/target/coldfire/iaudio/x5/ds2411-x5.c | |||
@@ -134,11 +134,12 @@ static unsigned char ds2411_read_byte(void) | |||
134 | */ | 134 | */ |
135 | int ds2411_read_id(struct ds2411_id *id) | 135 | int ds2411_read_id(struct ds2411_id *id) |
136 | { | 136 | { |
137 | int level = set_irq_level(DISABLE_INTERRUPTS); /* Timing sensitive */ | ||
137 | int i; | 138 | int i; |
138 | unsigned char crc; | 139 | unsigned char crc; |
139 | 140 | ||
140 | /* Initialize delay factor based on loop time: 3*(uS-1) + 3 */ | 141 | /* Initialize delay factor based on loop time: 3*(uS-1) + 3 */ |
141 | ds2411_delay_factor = MIN(cpu_frequency / (1000000*3), 1); | 142 | ds2411_delay_factor = MAX(cpu_frequency / (1000000*3), 1); |
142 | 143 | ||
143 | /* Init GPIO 1 wire bus for bit banging with a pullup resistor where | 144 | /* Init GPIO 1 wire bus for bit banging with a pullup resistor where |
144 | * it is set low as output and switched between input and output mode. | 145 | * it is set low as output and switched between input and output mode. |
@@ -162,45 +163,52 @@ int ds2411_read_id(struct ds2411_id *id) | |||
162 | 163 | ||
163 | /* Read presence pulse - line should be pulled low at proper time by the | 164 | /* Read presence pulse - line should be pulled low at proper time by the |
164 | slave device */ | 165 | slave device */ |
165 | if (GPIO_READ & DS2411_BIT) | 166 | if ((GPIO_READ & DS2411_BIT) == 0) |
166 | { | 167 | { |
167 | logf("ds2411: no presence pulse"); | 168 | /* Trsth + 1 - 66 = Tpdhmax + Tpdlmax + Trecmin + 1 - 66 */ |
168 | return DS2411_NO_PRESENCE; | 169 | DELAY(240); |
169 | } | ||
170 | 170 | ||
171 | /* Trsth + 1 - 66 = Tpdhmax + Tpdlmax + Trecmin + 1 - 66 */ | 171 | /* ds2411 should be ready for data transfer */ |
172 | DELAY(240); | ||
173 | 172 | ||
174 | /* ds2411 should be ready for data transfer */ | 173 | /* Send Read ROM command */ |
174 | ds2411_write_byte(0x33); | ||
175 | 175 | ||
176 | /* Send Read ROM command */ | 176 | /* Read ROM serial number and CRC */ |
177 | ds2411_write_byte(0x33); | 177 | i = 0, crc = 0; |
178 | 178 | ||
179 | /* Read ROM serial number and CRC */ | 179 | do |
180 | i = 0, crc = 0; | 180 | { |
181 | unsigned char byte = ds2411_read_byte(); | ||
182 | ((unsigned char *)id)[i] = byte; | ||
183 | crc = ds2411_calc_crc(crc ^ byte); | ||
184 | } | ||
185 | while (++i < 8); | ||
181 | 186 | ||
182 | do | 187 | /* Check that family code is ok */ |
183 | { | 188 | if (id->family_code != 0x01) |
184 | unsigned char byte = ds2411_read_byte(); | 189 | { |
185 | ((unsigned char *)id)[i] = byte; | 190 | logf("ds2411: invalid family code=%02X", (unsigned)id->family_code); |
186 | crc = ds2411_calc_crc(crc ^ byte); | 191 | i = DS2411_INVALID_FAMILY_CODE; |
192 | } | ||
193 | /* Check that CRC was ok */ | ||
194 | else if (crc != 0) /* Because last loop eors the CRC with the resulting CRC */ | ||
195 | { | ||
196 | logf("ds2411: invalid CRC=%02X", (unsigned)id->crc); | ||
197 | i = DS2411_INVALID_CRC; | ||
198 | } | ||
199 | else | ||
200 | { | ||
201 | /* Good ID read */ | ||
202 | i = DS2411_OK; | ||
203 | } | ||
187 | } | 204 | } |
188 | while (++i < 8); | 205 | else |
189 | |||
190 | /* Check that family code is ok */ | ||
191 | if (id->family_code != 0x01) | ||
192 | { | 206 | { |
193 | logf("ds2411: invalid family code=%02X", (unsigned)id->family_code); | 207 | logf("ds2411: no presence pulse"); |
194 | return DS2411_INVALID_FAMILY_CODE; | 208 | i = DS2411_NO_PRESENCE; |
195 | } | 209 | } |
196 | 210 | ||
197 | /* Check that CRC was ok */ | 211 | set_irq_level(level); |
198 | if (crc != 0) /* Because last loop eors the CRC with the resulting CRC */ | ||
199 | { | ||
200 | logf("ds2411: invalid CRC=%02X", (unsigned)id->crc); | ||
201 | return DS2411_INVALID_CRC; | ||
202 | } | ||
203 | 212 | ||
204 | /* Good ID read */ | 213 | return i; |
205 | return DS2411_OK; | ||
206 | } /* ds2411_read_id */ | 214 | } /* ds2411_read_id */ |