[Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/ds2401 CachedIeeeEui64P.nc, NONE, 1.1 Ds2401.h, NONE, 1.1 Ds2401ToIeeeEui64C.nc, NONE, 1.1 HplDs2401.nc, NONE, 1.1 HplDs2401C.nc, NONE, 1.1 OneWireMaster.nc, NONE, 1.1 OneWireMasterC.nc, NONE, 1.1

Janos Sallai sallai at users.sourceforge.net
Fri Oct 31 10:02:57 PDT 2008


Update of /cvsroot/tinyos/tinyos-2.x/tos/chips/ds2401
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv13065

Added Files:
	CachedIeeeEui64P.nc Ds2401.h Ds2401ToIeeeEui64C.nc 
	HplDs2401.nc HplDs2401C.nc OneWireMaster.nc OneWireMasterC.nc 
Log Message:
ds2401 silicon serial id chip driver including a basic 1-wire bust master implementation

--- NEW FILE: CachedIeeeEui64P.nc ---
// $Id: CachedIeeeEui64P.nc,v 1.1 2008/10/31 17:02:55 sallai Exp $
/*
 * 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;
  }
}

--- NEW FILE: Ds2401.h ---
// $Id: Ds2401.h,v 1.1 2008/10/31 17:02:55 sallai Exp $
/*
 * 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

--- NEW FILE: Ds2401ToIeeeEui64C.nc ---
// $Id: Ds2401ToIeeeEui64C.nc,v 1.1 2008/10/31 17:02:55 sallai Exp $
/*
 * 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;
  }
}

--- NEW FILE: HplDs2401.nc ---
// $Id: HplDs2401.nc,v 1.1 2008/10/31 17:02:55 sallai Exp $
/*
 * 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);
}

--- NEW FILE: HplDs2401C.nc ---
// $Id: HplDs2401C.nc,v 1.1 2008/10/31 17:02:55 sallai Exp $
/*
 * 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;
  }
}

--- NEW FILE: OneWireMaster.nc ---
// $Id: OneWireMaster.nc,v 1.1 2008/10/31 17:02:55 sallai Exp $
/*
 * 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();
}

--- NEW FILE: OneWireMasterC.nc ---
// $Id: OneWireMasterC.nc,v 1.1 2008/10/31 17:02:55 sallai Exp $
/*
 * 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;
  }

}



More information about the Tinyos-2-commits mailing list