changeset 22:bd792ebf813d

Report the bus being held low back to the caller from OWFirst/Next.
author darius
date Mon, 12 Dec 2005 23:27:40 +1030
parents e82d15fa9a1a
children 845934a4e7fe
files 1wire.c
diffstat 1 files changed, 29 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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;
+		    
 	    }
 	}