Home | History | Annotate | Line # | Download | only in ic
      1  1.10   matt /*	$NetBSD: ds.h,v 1.10 2012/02/12 16:34:11 matt Exp $	*/
      2   1.1     is 
      3   1.1     is /*-
      4   1.3     is  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5   1.2     is  * All rights reserved.
      6   1.2     is  *
      7   1.2     is  * This code is derived from software contributed to The NetBSD Foundation
      8   1.2     is  * by Ignatios Souvatzis.
      9   1.1     is  *
     10   1.1     is  * Redistribution and use in source and binary forms, with or without
     11   1.1     is  * modification, are permitted provided that the following conditions
     12   1.1     is  * are met:
     13   1.1     is  * 1. Redistributions of source code must retain the above copyright
     14   1.1     is  *    notice, this list of conditions and the following disclaimer.
     15   1.1     is  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1     is  *    notice, this list of conditions and the following disclaimer in the
     17   1.1     is  *    documentation and/or other materials provided with the distribution.
     18   1.1     is  *
     19   1.2     is  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.2     is  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.2     is  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.2     is  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.2     is  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.2     is  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.2     is  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.2     is  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.2     is  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.2     is  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.2     is  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1     is  */
     31   1.1     is 
     32   1.1     is /*
     33   1.6  perry  * Definitions for access to Dallas Semiconductor chips which attach to
     34   1.1     is  * the same 1-wire bus as the DS2404 RTC.
     35   1.1     is  */
     36   1.1     is 
     37   1.1     is #ifndef DALLAS_SEMI_CHIPS_H
     38   1.1     is #define DALLAS_SEMI_CHIPS_H
     39   1.1     is 
     40   1.1     is /* Family codes (low byte of the ROM) */
     41   1.1     is 
     42   1.4  bjh21 #define DS_FAMILY_2401	0x01	/* DS2401 Silicon Serial Number */
     43   1.1     is #define DS_FAMILY_2404	0x04	/* DS2404 Econoram Time Chip */
     44   1.1     is 
     45   1.1     is /*
     46   1.1     is  * ROM access codes. These are only available from the 1-wire bus, and one
     47   1.1     is  * of them MUST be used before a memory access code is called. If you want
     48   1.1     is  * to detect which devices are on the bus, you have to issue the ROM search
     49   1.1     is  * function (see data sheet).
     50   1.1     is  * If only one device is on the BUS, and you don't want any ROM function,
     51   1.1     is  * issue the SKIP function.
     52   1.1     is  * READ ROM works only if only one device is on the bus.
     53   1.1     is  */
     54   1.1     is 
     55   1.1     is #define DS_ROM_MATCH		0x55	/* 55 8-bytes-of-ROM-to-select */
     56   1.1     is #define DS_ROM_SEARCH		0xf0	/* see data sheet */
     57   1.1     is #define DS_ROM_SKIP		0xCC	/* don't do ROM function */
     58   1.1     is #define DS_ROM_READ		0x33	/* 33 -> 8 bytes of ROM */
     59   1.1     is 
     60   1.1     is /*
     61   1.1     is  * Memory access codes. These are available from the 1- or 3-wire bus, and
     62   1.6  perry  * but you must use one of the ROM access codes first, if using the 1-wire
     63   1.1     is  * bus.
     64   1.1     is  *
     65   1.1     is  * You can read from any starting address up to the end of the chip, or
     66   1.1     is  * abort the read with a reset pulse.
     67   1.1     is  * You first write 2-32 bytes beginning some address to the scratchpad.
     68   1.6  perry  * Starting address and final byte stream length are remembered by the
     69   1.1     is  * chip. After reading data and address/length back from the scratchpad,
     70   1.1     is  * and verifying the information, you can issue the copy scratchpad command
     71   1.1     is  * to copy the written parts of the scratchpad to the corresponding parts
     72   1.1     is  * of the implied (in the address) memory page.
     73   1.1     is  */
     74   1.1     is 
     75   1.1     is #define DS_MEM_WRITE_SCRATCH	0x0f	/* 0F low-ads high-ads data ... */
     76   1.6  perry #define DS_MEM_READ_SCRATCH	0xaa	/* AA -> low-ads high-ads end-ofs
     77   1.1     is 					 * data ... */
     78   1.1     is #define DS_MEM_COPY_SCRATCH	0x55	/* 55 low-ads high-ads end-ofs */
     79   1.1     is #define DS_MEM_READ_MEMORY	0xf0	/* F0 low-ads high-ads -> data ...*/
     80   1.1     is 
     81   1.1     is /*
     82   1.1     is  * Hardware handle for access functions
     83   1.1     is  */
     84   1.1     is 
     85   1.1     is struct ds_handle {
     86   1.5  perry 	int (*ds_read_bit)(void *);
     87   1.5  perry 	void (*ds_write_bit)(void *, int);
     88   1.5  perry 	void (*ds_reset)(void *);
     89   1.1     is 	void *ds_hw_handle;
     90   1.1     is };
     91   1.1     is 
     92   1.1     is /*
     93   1.6  perry  * Functions for access to Dallas Semiconductor chips which attach to
     94   1.1     is  * the same 1-wire bus as the DS2404 RTC.
     95   1.1     is  */
     96   1.1     is 
     97   1.5  perry static u_int8_t ds_read_byte(struct ds_handle *);
     98   1.5  perry static void ds_write_byte(struct ds_handle *, unsigned int);
     99   1.1     is 
    100   1.8  perry static __inline u_int8_t
    101  1.10   matt ds_read_byte(struct ds_handle *dsh)
    102   1.1     is {
    103   1.1     is 	u_int8_t buf;
    104   1.1     is 	int i;
    105   1.1     is 
    106   1.1     is 	for (i=buf=0; i<8; ++i)
    107   1.1     is 		buf |= (dsh->ds_read_bit)(dsh->ds_hw_handle) << i;
    108   1.1     is 
    109   1.1     is 	return buf;
    110   1.1     is }
    111   1.1     is 
    112   1.8  perry static __inline void
    113  1.10   matt ds_write_byte(struct ds_handle *dsh, unsigned int b)
    114   1.1     is {
    115   1.1     is 	int i;
    116   1.1     is 
    117   1.1     is 	for (i=0; i<8; ++i) {
    118   1.1     is 		(dsh->ds_write_bit)(dsh->ds_hw_handle, b & 1);
    119   1.1     is 		b >>= 1;
    120   1.1     is 	}
    121   1.1     is }
    122   1.1     is 
    123   1.1     is #endif /* DALLAS_SEMI_CHIPS_H */
    124