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