Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/onewire calculate extended precision as per DS1920/D...



details:   https://anonhg.NetBSD.org/src/rev/6d593676b1ca
branches:  trunk
changeset: 795951:6d593676b1ca
user:      kardel <kardel%NetBSD.org@localhost>
date:      Wed May 14 08:14:56 2014 +0000

description:
calculate extended precision as per DS1920/DS1820 data sheets

diffstat:

 sys/dev/onewire/owtemp.c |  25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)

diffs (51 lines):

diff -r 60720b1998d7 -r 6d593676b1ca sys/dev/onewire/owtemp.c
--- a/sys/dev/onewire/owtemp.c  Wed May 14 06:38:09 2014 +0000
+++ b/sys/dev/onewire/owtemp.c  Wed May 14 08:14:56 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: owtemp.c,v 1.16 2011/06/20 17:24:16 pgoyette Exp $ */
+/*     $NetBSD: owtemp.c,v 1.17 2014/05/14 08:14:56 kardel Exp $ */
 /*     $OpenBSD: owtemp.c,v 1.1 2006/03/04 16:27:03 grange Exp $       */
 
 /*
@@ -22,7 +22,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: owtemp.c,v 1.16 2011/06/20 17:24:16 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: owtemp.c,v 1.17 2014/05/14 08:14:56 kardel Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -64,7 +64,7 @@
 extern struct cfdriver owtemp_cd;
 
 static const struct onewire_matchfam owtemp_fams[] = {
-       { ONEWIRE_FAMILY_DS1920 },
+       { ONEWIRE_FAMILY_DS1920 }, /* also DS1820 */
        { ONEWIRE_FAMILY_DS18B20 },
        { ONEWIRE_FAMILY_DS1822 },
 };
@@ -235,6 +235,21 @@
        temp = (int8_t)buf[1];
        temp = (temp << 8) | buf[0];
 
-       /* Convert to uK */
-       return (temp * 500000 + 273150000);
+       if (buf[7] != 0) {
+               /*
+                * interpolate for higher precision using the count registers
+                *
+                * buf[7]: COUNT_PER_C(elsius)
+                * buf[6]: COUNT_REMAIN
+                *
+                * T = TEMP - 0.25 + (COUNT_PER_C - COUNT_REMAIN) / COUNT_PER_C
+                */
+               temp &= ~1;
+               temp += 500000 * temp + (500000 * (buf[7] - buf[6])) / buf[7] - 250000;
+       } else {
+               temp *= 500000;
+       }
+
+       /* convert to uK */
+       return (temp + 273150000);
 }



Home | Main Index | Thread Index | Old Index