ds.h revision 1.2 1 1.2 is /* $NetBSD: ds.h,v 1.2 1999/02/16 22:46:57 is Exp $ */
2 1.1 is
3 1.1 is /*-
4 1.2 is * Copyright (c) 1999 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.1 is * 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.1 is #define DS_FAMILY_2404 0x04 /* DS2404 Econoram Time Chip */
50 1.1 is
51 1.1 is /*
52 1.1 is * ROM access codes. These are only available from the 1-wire bus, and one
53 1.1 is * of them MUST be used before a memory access code is called. If you want
54 1.1 is * to detect which devices are on the bus, you have to issue the ROM search
55 1.1 is * function (see data sheet).
56 1.1 is * If only one device is on the BUS, and you don't want any ROM function,
57 1.1 is * issue the SKIP function.
58 1.1 is * READ ROM works only if only one device is on the bus.
59 1.1 is */
60 1.1 is
61 1.1 is #define DS_ROM_MATCH 0x55 /* 55 8-bytes-of-ROM-to-select */
62 1.1 is #define DS_ROM_SEARCH 0xf0 /* see data sheet */
63 1.1 is #define DS_ROM_SKIP 0xCC /* don't do ROM function */
64 1.1 is #define DS_ROM_READ 0x33 /* 33 -> 8 bytes of ROM */
65 1.1 is
66 1.1 is /*
67 1.1 is * Memory access codes. These are available from the 1- or 3-wire bus, and
68 1.1 is * but you must use one of the ROM access codes first, if using the 1-wire
69 1.1 is * bus.
70 1.1 is *
71 1.1 is * You can read from any starting address up to the end of the chip, or
72 1.1 is * abort the read with a reset pulse.
73 1.1 is * You first write 2-32 bytes beginning some address to the scratchpad.
74 1.1 is * Starting address and final byte stream length are remembered by the
75 1.1 is * chip. After reading data and address/length back from the scratchpad,
76 1.1 is * and verifying the information, you can issue the copy scratchpad command
77 1.1 is * to copy the written parts of the scratchpad to the corresponding parts
78 1.1 is * of the implied (in the address) memory page.
79 1.1 is */
80 1.1 is
81 1.1 is #define DS_MEM_WRITE_SCRATCH 0x0f /* 0F low-ads high-ads data ... */
82 1.1 is #define DS_MEM_READ_SCRATCH 0xaa /* AA -> low-ads high-ads end-ofs
83 1.1 is * data ... */
84 1.1 is #define DS_MEM_COPY_SCRATCH 0x55 /* 55 low-ads high-ads end-ofs */
85 1.1 is #define DS_MEM_READ_MEMORY 0xf0 /* F0 low-ads high-ads -> data ...*/
86 1.1 is
87 1.1 is /*
88 1.1 is * Hardware handle for access functions
89 1.1 is */
90 1.1 is
91 1.1 is struct ds_handle {
92 1.1 is int (*ds_read_bit) __P((void *));
93 1.1 is void (*ds_write_bit) __P((void *, int));
94 1.1 is void (*ds_reset) __P((void *));
95 1.1 is void *ds_hw_handle;
96 1.1 is };
97 1.1 is
98 1.1 is /*
99 1.1 is * Functions for access to Dallas Semiconductor chips which attach to
100 1.1 is * the same 1-wire bus as the DS2404 RTC.
101 1.1 is */
102 1.1 is
103 1.1 is static u_int8_t ds_read_byte __P((struct ds_handle *));
104 1.1 is static void ds_write_byte __P((struct ds_handle *, unsigned int));
105 1.1 is
106 1.1 is static inline u_int8_t
107 1.1 is ds_read_byte(dsh)
108 1.1 is struct ds_handle *dsh;
109 1.1 is {
110 1.1 is u_int8_t buf;
111 1.1 is int i;
112 1.1 is
113 1.1 is for (i=buf=0; i<8; ++i)
114 1.1 is buf |= (dsh->ds_read_bit)(dsh->ds_hw_handle) << i;
115 1.1 is
116 1.1 is return buf;
117 1.1 is }
118 1.1 is
119 1.1 is static inline void
120 1.1 is ds_write_byte(dsh, b)
121 1.1 is struct ds_handle *dsh;
122 1.1 is unsigned int b;
123 1.1 is {
124 1.1 is int i;
125 1.1 is
126 1.1 is for (i=0; i<8; ++i) {
127 1.1 is (dsh->ds_write_bit)(dsh->ds_hw_handle, b & 1);
128 1.1 is b >>= 1;
129 1.1 is }
130 1.1 is }
131 1.1 is
132 1.1 is #endif /* DALLAS_SEMI_CHIPS_H */
133