summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-03-11 14:33:16 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-03-11 14:33:16 +0000
commit94c4724420218c678151b610da096773dca9a49c (patch)
tree378e0665ade5ee73e3b03cc46b685f58e91684d7 /firmware
parent89a38d4273a9ef6f7e2d46876ddfe5ce8cee10da (diff)
Fix a late error that only let it read at default CPU frequency. Disable interrupts during ds2411 read since it's timing sensitive.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12724 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/target/coldfire/iaudio/x5/ds2411-x5.c70
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)
*/
int ds2411_read_id(struct ds2411_id *id)
{
+ int level = set_irq_level(DISABLE_INTERRUPTS); /* Timing sensitive */
int i;
unsigned char crc;
/* Initialize delay factor based on loop time: 3*(uS-1) + 3 */
- ds2411_delay_factor = MIN(cpu_frequency / (1000000*3), 1);
+ ds2411_delay_factor = MAX(cpu_frequency / (1000000*3), 1);
/* Init GPIO 1 wire bus for bit banging with a pullup resistor where
* 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)
/* Read presence pulse - line should be pulled low at proper time by the
slave device */
- if (GPIO_READ & DS2411_BIT)
+ if ((GPIO_READ & DS2411_BIT) == 0)
{
- logf("ds2411: no presence pulse");
- return DS2411_NO_PRESENCE;
- }
+ /* Trsth + 1 - 66 = Tpdhmax + Tpdlmax + Trecmin + 1 - 66 */
+ DELAY(240);
- /* Trsth + 1 - 66 = Tpdhmax + Tpdlmax + Trecmin + 1 - 66 */
- DELAY(240);
+ /* ds2411 should be ready for data transfer */
- /* ds2411 should be ready for data transfer */
+ /* Send Read ROM command */
+ ds2411_write_byte(0x33);
- /* Send Read ROM command */
- ds2411_write_byte(0x33);
+ /* Read ROM serial number and CRC */
+ i = 0, crc = 0;
- /* Read ROM serial number and CRC */
- i = 0, crc = 0;
+ do
+ {
+ unsigned char byte = ds2411_read_byte();
+ ((unsigned char *)id)[i] = byte;
+ crc = ds2411_calc_crc(crc ^ byte);
+ }
+ while (++i < 8);
- do
- {
- unsigned char byte = ds2411_read_byte();
- ((unsigned char *)id)[i] = byte;
- crc = ds2411_calc_crc(crc ^ byte);
+ /* Check that family code is ok */
+ if (id->family_code != 0x01)
+ {
+ logf("ds2411: invalid family code=%02X", (unsigned)id->family_code);
+ i = DS2411_INVALID_FAMILY_CODE;
+ }
+ /* Check that CRC was ok */
+ else if (crc != 0) /* Because last loop eors the CRC with the resulting CRC */
+ {
+ logf("ds2411: invalid CRC=%02X", (unsigned)id->crc);
+ i = DS2411_INVALID_CRC;
+ }
+ else
+ {
+ /* Good ID read */
+ i = DS2411_OK;
+ }
}
- while (++i < 8);
-
- /* Check that family code is ok */
- if (id->family_code != 0x01)
+ else
{
- logf("ds2411: invalid family code=%02X", (unsigned)id->family_code);
- return DS2411_INVALID_FAMILY_CODE;
+ logf("ds2411: no presence pulse");
+ i = DS2411_NO_PRESENCE;
}
- /* Check that CRC was ok */
- if (crc != 0) /* Because last loop eors the CRC with the resulting CRC */
- {
- logf("ds2411: invalid CRC=%02X", (unsigned)id->crc);
- return DS2411_INVALID_CRC;
- }
+ set_irq_level(level);
- /* Good ID read */
- return DS2411_OK;
+ return i;
} /* ds2411_read_id */