The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/ic/ds.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: 571463e5c81758a7692283ffb82fe5d6


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.