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