]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
ds2401 silicon serial id chip driver including a basic 1-wire bust master implementation
authorsallai <sallai>
Fri, 31 Oct 2008 17:02:55 +0000 (17:02 +0000)
committersallai <sallai>
Fri, 31 Oct 2008 17:02:55 +0000 (17:02 +0000)
tos/chips/ds2401/CachedIeeeEui64P.nc [new file with mode: 0644]
tos/chips/ds2401/Ds2401.h [new file with mode: 0644]
tos/chips/ds2401/Ds2401ToIeeeEui64C.nc [new file with mode: 0644]
tos/chips/ds2401/HplDs2401.nc [new file with mode: 0644]
tos/chips/ds2401/HplDs2401C.nc [new file with mode: 0644]
tos/chips/ds2401/OneWireMaster.nc [new file with mode: 0644]
tos/chips/ds2401/OneWireMasterC.nc [new file with mode: 0644]

diff --git a/tos/chips/ds2401/CachedIeeeEui64P.nc b/tos/chips/ds2401/CachedIeeeEui64P.nc
new file mode 100644 (file)
index 0000000..4a3ab1d
--- /dev/null
@@ -0,0 +1,47 @@
+// $Id$
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Author: Janos Sallai
+ */
+
+/**
+ * Cache an EUI 64 at initialization time and return the cached value for
+ * subsequent queries.
+ */
+module CachedIeeeEui64P {
+  uses interface LocalIeeeEui64 as SubIeeeEui64;
+  provides {
+    interface LocalIeeeEui64;
+    interface Init;
+  }
+} implementation {
+
+  ieee_eui64_t eui;
+
+  command error_t Init.init() {
+    atomic eui = call SubIeeeEui64.getId();
+    return SUCCESS;
+  }
+
+  command ieee_eui64_t LocalIeeeEui64.getId() {
+    return eui;
+  }
+}
diff --git a/tos/chips/ds2401/Ds2401.h b/tos/chips/ds2401/Ds2401.h
new file mode 100644 (file)
index 0000000..6b80485
--- /dev/null
@@ -0,0 +1,42 @@
+// $Id$
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Author: Janos Sallai
+ */
+
+#ifndef DS2401_H
+#define DS2401_H
+
+enum {
+  DS2401_SERIAL_LENGTH = 6,
+  DS2401_DATA_LENGTH = 8
+};
+
+typedef union ds2401_serial_t {
+  uint8_t data[DS2401_DATA_LENGTH];
+  struct {
+     uint8_t family_code;
+     uint8_t serial[DS2401_SERIAL_LENGTH];
+     uint8_t crc;
+  };
+} ds2401_serial_t;
+
+#endif // DS2401_H
diff --git a/tos/chips/ds2401/Ds2401ToIeeeEui64C.nc b/tos/chips/ds2401/Ds2401ToIeeeEui64C.nc
new file mode 100644 (file)
index 0000000..5720263
--- /dev/null
@@ -0,0 +1,63 @@
+// $Id$
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Author: Janos Sallai
+ */
+
+#include "Ds2401.h"
+#include "IeeeEui64.h"
+#include "PlatformIeeeEui64.h"
+
+/**
+ * Convert silicon serial ID to IEEE EUI 64, according to Application Note
+ * 186 - Creating Global Identifiers Using 1-Wire Devices from Dallas/Maxim.
+ */
+module Ds2401ToIeeeEui64C {
+  uses interface HplDs2401 as Hpl;
+  provides interface LocalIeeeEui64;
+} implementation {
+
+  command ieee_eui64_t LocalIeeeEui64.getId() {
+    ds2401_serial_t rom;
+    ieee_eui64_t eui;
+    
+    atomic {
+      call Hpl.read(&rom);
+    }
+
+    // company ID
+    eui.data[0] = IEEE_EUI64_COMPANY_ID_0;
+    eui.data[1] = IEEE_EUI64_COMPANY_ID_1;
+    eui.data[2] = IEEE_EUI64_COMPANY_ID_2;
+
+    // 16 bits of the ID is generated by software
+    // could be used for hardware model id and revision, for example
+    eui.data[3] = IEEE_EUI64_SERIAL_ID_0;
+    eui.data[4] = IEEE_EUI64_SERIAL_ID_1;
+
+    // 24 least significant bits of the serial ID read from the DS2401
+    eui.data[5] = rom.data[3];
+    eui.data[6] = rom.data[2];
+    eui.data[7] = rom.data[1];
+
+    return eui;
+  }
+}
diff --git a/tos/chips/ds2401/HplDs2401.nc b/tos/chips/ds2401/HplDs2401.nc
new file mode 100644 (file)
index 0000000..ba45390
--- /dev/null
@@ -0,0 +1,38 @@
+// $Id$
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Author: Janos Sallai
+ */
+
+#include "Ds2401.h"
+
+/**
+ * Interface to read the 64-bit hardware ID from the DS2401 chip.
+ */
+interface HplDs2401 {
+
+/**
+ * Read the 64-bit hardware ID (family id, serial, crc) from the DS2401 chip.
+ * @param rom Pointer to a ds2401_serial_t struct, defined in ds2401.h.
+ * @returns SUCCESS on success, an error code otherwise.
+ */
+  async command error_t read(ds2401_serial_t* rom);
+}
diff --git a/tos/chips/ds2401/HplDs2401C.nc b/tos/chips/ds2401/HplDs2401C.nc
new file mode 100644 (file)
index 0000000..deb677b
--- /dev/null
@@ -0,0 +1,66 @@
+// $Id$
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ * 
+ * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Author: Janos Sallai
+ */
+
+#include "Ds2401.h"
+
+/**
+ * HPL for the DS2401 hardware ID chip.
+ */
+module HplDs2401C {
+  provides interface HplDs2401 as Hpl;
+  uses interface OneWireMaster as OneWire;
+}
+implementation {
+  bool busy = FALSE;
+
+  async command error_t Hpl.read(ds2401_serial_t* rom) {
+    uint8_t i;
+
+    if(busy) {
+      return EBUSY;
+    }
+
+    busy = TRUE;
+
+    call OneWire.init();
+
+    if(call OneWire.reset() != SUCCESS) {
+      call OneWire.release();
+      busy = FALSE;
+      return EOFF;
+    }
+
+    call OneWire.writeByte(0x33);
+
+    for(i=0;i<DS2401_DATA_LENGTH;i++) {
+      rom->data[i] = call OneWire.readByte();
+    }
+
+    // TODO: crc check
+
+    call OneWire.release();
+    busy = FALSE;
+    return SUCCESS;
+  }
+}
diff --git a/tos/chips/ds2401/OneWireMaster.nc b/tos/chips/ds2401/OneWireMaster.nc
new file mode 100644 (file)
index 0000000..2a01ae9
--- /dev/null
@@ -0,0 +1,69 @@
+// $Id$
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Author: Janos Sallai
+ */
+
+/**
+ * Interface to interact with 1-wire bus devices, as a master on the 1-wire
+ * bus.
+ */
+interface OneWireMaster {
+  /**
+   * Initialize bus (pin is input with pullup).
+   */
+  async command void idle();
+  /**
+   * Initialize bus, start sourcing current (pin is input with pullup).
+   */
+  async command void init();
+  /**
+   * Release bus, stop sourcing current (pin is three-stated input).
+   */
+  async command void release();
+  /**
+   * Generate reset signal.
+   * @returns SUCCESS if a client is present, an error_t error value otherwise.
+   */
+  async command error_t reset();
+  /**
+   * Write bit 1 to the bus.
+   */
+  async command void writeOne();
+  /**
+   * Write bit 0 to the bus.
+   */
+  async command void writeZero();
+  /**
+   * Write 8 bits to the bus, LSB first.
+   * @param b the byte to write.
+   */
+  async command void writeByte(uint8_t b);
+  /**
+   * Read a bit from the bus.
+   */
+  async command bool readBit();
+  /**
+   * Read 8 bits from the bus, LSB first.
+   * @returns the byte read.
+   */
+  async command uint8_t readByte();
+}
diff --git a/tos/chips/ds2401/OneWireMasterC.nc b/tos/chips/ds2401/OneWireMasterC.nc
new file mode 100644 (file)
index 0000000..2d81ae8
--- /dev/null
@@ -0,0 +1,128 @@
+// $Id$
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ * 
+ * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Author: Janos Sallai
+ */
+
+/**
+ * This module is the implementation of an 1-wire bus master.
+ *
+ */
+module OneWireMasterC {
+  uses interface GeneralIO as Pin;
+  uses interface BusyWait<TMicro, uint16_t> as BusyWaitMicro;
+  provides interface OneWireMaster as OneWire;
+
+}
+implementation {
+
+  async command void OneWire.idle() {
+    call Pin.makeInput();
+    call Pin.set(); // start sourcing current
+  }
+
+  async command void OneWire.init() {
+    call OneWire.idle();
+    call BusyWaitMicro.wait(500); // wait at least 500us after bootup
+  }
+
+  async command void OneWire.release() {
+    call Pin.makeInput();
+    call Pin.clr(); // stop sourcing current
+  }
+
+  async command error_t OneWire.reset() {
+    bool clientPresent;
+
+    // it is assumed that the bus is in idle state here
+
+    // transmit reset pulse
+    call Pin.makeOutput(); // output low
+    call Pin.clr();
+    call BusyWaitMicro.wait(500); // must be at least 480us
+    call OneWire.idle(); // input with pullup set
+
+    // test for present pulse
+    call BusyWaitMicro.wait(80); // presence pulse is sent 18-60us after reset
+    clientPresent = call Pin.get(); // test for presence pulse
+    call BusyWaitMicro.wait(400); // presence pulse is 60-240us long
+
+    if (clientPresent == 0) {
+      return SUCCESS;
+    } else {
+      return EOFF;
+    }
+  }
+
+  async command void OneWire.writeOne() {
+    call Pin.makeOutput(); // output low
+    call Pin.clr();
+    call BusyWaitMicro.wait(8); // must be 1-15us
+    call OneWire.idle(); // input with pullup set
+    call BusyWaitMicro.wait(72); // low time plus idle time must 60-120us
+  }
+
+  async command void OneWire.writeZero() {
+    call Pin.makeOutput(); // output low
+    call Pin.clr();
+    call BusyWaitMicro.wait(72); // must be 60-120us
+    call OneWire.idle(); // input with pullup set
+    call BusyWaitMicro.wait(8); // low time plus idle time must 60-120us
+  }
+
+  async command void OneWire.writeByte(uint8_t b) {
+    uint8_t i;
+
+    // send out bits, LSB first
+    for(i=0;i<8;i++) {
+      if(b & 0x01) {
+        call OneWire.writeOne();
+      } else {
+        call OneWire.writeZero();
+      }
+      b >>= 1;
+    }
+  }
+
+  async command bool OneWire.readBit() {
+    bool b;
+    call Pin.makeOutput(); // output low
+    call Pin.clr();
+    call BusyWaitMicro.wait(1);
+    call OneWire.idle(); // input with pullup set
+    call BusyWaitMicro.wait(8); // must be 1-15us
+    b = call Pin.get(); // read pin
+    call BusyWaitMicro.wait(71); // timeslot length must be 60-120us
+    return b;
+  }
+
+  async command uint8_t OneWire.readByte() {
+    uint8_t i,b=0;
+
+    // read bits, LSB first
+    for(i=0;i<8;i++) {
+      b >>= 1;
+      b |= call OneWire.readBit() << 7;
+    }
+    return b;
+  }
+
+}