# HG changeset patch # User darius # Date 1134392260 -37800 # Node ID bd792ebf813d4ddd6888ef3098139236b168169e # Parent e82d15fa9a1a1f55c7de6f7e4792c745a028d9c9 Report the bus being held low back to the caller from OWFirst/Next. diff -r e82d15fa9a1a -r bd792ebf813d 1wire.c --- a/1wire.c Mon Dec 12 23:01:00 2005 +1030 +++ b/1wire.c Mon Dec 12 23:27:40 2005 +1030 @@ -54,14 +54,19 @@ } /*----------------------------------------------------------------------------- - * Generate a 1-Wire reset, return 0 if presence pulse was found, - * return 1 otherwise. + * Generate a 1-Wire reset, return 0 if presence pulse was found, 1 if it + * wasn't, or 2 if the line appears to be being held low. + * * * (NOTE: Does not handle alarm presence from DS2404/DS1994) */ uint8_t OWTouchReset(void) { DELAY_G; + + if (!(OWIREINPORT & _BV(OWIREINPIN))) + return 2; + OWIREOUTPORT &= ~(_BV(OWIREOUTPIN)); OWIREDDR |= _BV(OWIREOUTPIN); DELAY_H; @@ -239,14 +244,30 @@ #if OW_DEBUG uart_putsP(PSTR("Resetting\n\r")); #endif - if (OWTouchReset()) { - /* reset the search */ - OW_LastDiscrepancy = 0; - OW_LastFamilyDiscrepancy = 0; + switch (OWTouchReset()) { + case 0: + break; + + case 1: + /* reset the search */ + OW_LastDiscrepancy = 0; + OW_LastFamilyDiscrepancy = 0; #if OW_DEBUG - uart_putsP(PSTR("No devices on bus\n\r")); + uart_putsP(PSTR("No devices on bus\n\r")); #endif - return OW_NOPRESENCE; + return OW_NOPRESENCE; + break; + + case 2: + /* reset the search */ + OW_LastDiscrepancy = 0; + OW_LastFamilyDiscrepancy = 0; +#if OW_DEBUG + uart_putsP(PSTR("Bus appears to be being held low\n\r")); +#endif + return OW_BADWIRE; + break; + } }