diff 1wire.c @ 12:4b141cc7cbd4

- Reduce type widths where possible. - Add URL for Dallas OWPD kit. - Hide more stuff behind OW_DEBUG.
author darius
date Wed, 01 Sep 2004 17:45:24 +0930
parents eb1faf51968e
children 026dc24d85e0
line wrap: on
line diff
--- a/1wire.c	Fri Jul 16 23:39:58 2004 +0930
+++ b/1wire.c	Wed Sep 01 17:45:24 2004 +0930
@@ -1,6 +1,7 @@
 /*
  * Various 1 wire routines
- * Search routine is copied from the Dallas owpd library with mods.
+ * Search routine is copied from the Dallas owpd library with mods
+ * available from here http://www.ibutton.com/software/1wire/wirekit.html
  *
  * $Id$
  *
@@ -36,10 +37,12 @@
 #include "1wire.h"
 #include "1wire-delay.h"
 
+#if OW_DEBUG
 void		uart_putsP(const char *addr);
 void		uart_puts(const char *addr);
 void		uart_getc();
 int		uart_putc(char c);
+#endif
 
 static uint8_t OW_LastDevice = 0;
 static uint8_t OW_LastDiscrepancy = 0;
@@ -51,11 +54,11 @@
 }
 
 /*-----------------------------------------------------------------------------
- * Generate a 1-Wire reset, return 1 if no presence detect was found,
- * return 0 otherwise.
+ * Generate a 1-Wire reset, return 0 if presence pulse was found,
+ * return 1 otherwise.
  * (NOTE: Does not handle alarm presence from DS2404/DS1994)
  */
-int
+uint8_t
 OWTouchReset(void) {
     DELAY_G;
     OWIREOUTPORT &= ~(_BV(OWIREOUTPIN));
@@ -71,7 +74,7 @@
  * Send a 1-wire write bit.
  */
 void
-OWWriteBit(int bit) {
+OWWriteBit(uint8_t bit) {
     OWdelay();
     if (bit) {
 	OWIREOUTPORT &= ~(_BV(OWIREOUTPIN));
@@ -91,7 +94,7 @@
 /*-----------------------------------------------------------------------------
  * Read a bit from the 1-wire bus and return it.
  */
-int
+uint8_t
 OWReadBit(void) {
     OWdelay();
 
@@ -108,7 +111,7 @@
  */
 void
 OWWriteByte(uint8_t data) {
-    int i;
+    uint8_t i;
     
     /* Send LSB first */
     for (i = 0; i < 8; i++) {
@@ -120,7 +123,7 @@
 /*-----------------------------------------------------------------------------
  * Read a byte from the 1-wire bus
  */
-int
+uint8_t
 OWReadByte(void) {
     int i, result = 0;
     
@@ -135,9 +138,9 @@
 /*-----------------------------------------------------------------------------
  * Write a 1-wire data byte and return the sampled result.
  */
-int
+uint8_t
 OWTouchByte(uint8_t data) {
-    int i, result = 0;
+    uint8_t i, result = 0;
     
     for (i = 0; i < 8; i++) {
 	result >>= 1;
@@ -173,7 +176,7 @@
  */
 void
 OWSendCmd(uint8_t *ROM, uint8_t cmd) {
-    int		i;
+    uint8_t	i;
 
     OWTouchReset();
     
@@ -198,7 +201,7 @@
  *         -2 if bad CRC,
  *         -3 if bad wiring.
  */
-int
+uint8_t
 OWFirst(uint8_t *ROM, uint8_t do_reset, uint8_t alarm_only) {
     /* Reset state */
     OW_LastDiscrepancy = 0;
@@ -210,13 +213,12 @@
 }
 
 /* Returns 1 when something is found, 0 if nothing left */
-int
+uint8_t
 OWNext(uint8_t *ROM, uint8_t do_reset, uint8_t alarm_only) {
     uint8_t	bit_test, search_direction, bit_number;
     uint8_t	last_zero, rom_byte_number, rom_byte_mask;
     uint8_t	lastcrc8, crcaccum;
-    int		next_result;
-    char	errstr[30];
+    int8_t	next_result;
 
     /* Init for search */
    bit_number = 1;
@@ -330,8 +332,10 @@
       /* if the search was successful then */
       if (!(bit_number < 65) || lastcrc8) {
 	  if (lastcrc8) {
+#if OW_DEBUG
 	      sprintf_P(errstr, PSTR("Bad CRC (%d)\n\r"), lastcrc8);
 	      uart_puts(errstr);
+#endif
 	      next_result = OW_BADCRC;
 	  } else {
 	      /*  search successful so set LastDiscrepancy,LastDevice,next_result */