forked from len0rd/rockbox
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
This commit is contained in:
parent
89a38d4273
commit
94c4724420
1 changed files with 45 additions and 37 deletions
|
@ -134,11 +134,12 @@ static unsigned char ds2411_read_byte(void)
|
||||||
*/
|
*/
|
||||||
int ds2411_read_id(struct ds2411_id *id)
|
int ds2411_read_id(struct ds2411_id *id)
|
||||||
{
|
{
|
||||||
|
int level = set_irq_level(DISABLE_INTERRUPTS); /* Timing sensitive */
|
||||||
int i;
|
int i;
|
||||||
unsigned char crc;
|
unsigned char crc;
|
||||||
|
|
||||||
/* Initialize delay factor based on loop time: 3*(uS-1) + 3 */
|
/* 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
|
/* 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.
|
* it is set low as output and switched between input and output mode.
|
||||||
|
@ -162,12 +163,8 @@ int ds2411_read_id(struct ds2411_id *id)
|
||||||
|
|
||||||
/* Read presence pulse - line should be pulled low at proper time by the
|
/* Read presence pulse - line should be pulled low at proper time by the
|
||||||
slave device */
|
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 */
|
/* Trsth + 1 - 66 = Tpdhmax + Tpdlmax + Trecmin + 1 - 66 */
|
||||||
DELAY(240);
|
DELAY(240);
|
||||||
|
|
||||||
|
@ -191,16 +188,27 @@ int ds2411_read_id(struct ds2411_id *id)
|
||||||
if (id->family_code != 0x01)
|
if (id->family_code != 0x01)
|
||||||
{
|
{
|
||||||
logf("ds2411: invalid family code=%02X", (unsigned)id->family_code);
|
logf("ds2411: invalid family code=%02X", (unsigned)id->family_code);
|
||||||
return DS2411_INVALID_FAMILY_CODE;
|
i = DS2411_INVALID_FAMILY_CODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check that CRC was ok */
|
/* Check that CRC was ok */
|
||||||
if (crc != 0) /* Because last loop eors the CRC with the resulting CRC */
|
else if (crc != 0) /* Because last loop eors the CRC with the resulting CRC */
|
||||||
{
|
{
|
||||||
logf("ds2411: invalid CRC=%02X", (unsigned)id->crc);
|
logf("ds2411: invalid CRC=%02X", (unsigned)id->crc);
|
||||||
return DS2411_INVALID_CRC;
|
i = DS2411_INVALID_CRC;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Good ID read */
|
||||||
|
i = DS2411_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logf("ds2411: no presence pulse");
|
||||||
|
i = DS2411_NO_PRESENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Good ID read */
|
set_irq_level(level);
|
||||||
return DS2411_OK;
|
|
||||||
|
return i;
|
||||||
} /* ds2411_read_id */
|
} /* ds2411_read_id */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue