annotate 1wire-config.h @ 71:553c061fda7c default tip

Keep the newer GCC happy.
author darius@Inchoate
date Mon, 19 Jan 2009 22:54:19 +1030
parents 5898fba6593c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
1 /*
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
2 * 1 wire header
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
3 *
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
4 * This is the user servicable stuff - how to do delays and how to
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
5 * frob the IO pins.
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
6 *
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
7 * $Id$
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
8 *
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
9 * Copyright (c) 2004
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
10 * Daniel O'Connor <darius@dons.net.au>. All rights reserved.
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
11 *
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
12 * Redistribution and use in source and binary forms, with or without
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
13 * modification, are permitted provided that the following conditions
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
14 * are met:
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
15 * 1. Redistributions of source code must retain the above copyright
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
16 * notice, this list of conditions and the following disclaimer.
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
17 * 2. Redistributions in binary form must reproduce the above copyright
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
18 * notice, this list of conditions and the following disclaimer in the
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
19 * documentation and/or other materials provided with the distribution.
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
20 *
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
21 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
24 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
31 * SUCH DAMAGE.
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
32 */
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
33
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
34 /*
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
35 * Alter these for your configuration
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
36 */
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
37
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
38 /* Set DDR on the right pins */
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
39 #define OWBUSINIT() do { \
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
40 DDRD |= _BV(4); \
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
41 DDRD &= ~_BV(3); \
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
42 } while (0)
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
43
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
44 /* Read the 1-wire bus, non-inverting logic */
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
45 #define OWREADBUS() (PIND & _BV(3) ? 1 : 0)
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
46
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
47 /* Set the 1-wire bus to 0
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
48 * Turns a transistor on to pull it low
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
49 */
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
50 #define OWSETBUSLOW() PORTD |= _BV(4)
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
51
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
52 /* Set the 1-wire bus to 1
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
53 * Turn the transistor off to let the pullup do its job
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
54 */
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
55 #define OWSETBUSHIGH() PORTD &= ~_BV(4)
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
56
33
0aa6bf4b98ae - Don't wrap individual debug statements in ifdef, use a conditionally
darius
parents: 32
diff changeset
57 /* Turn Vpp on (ie put +12V on the bus
0aa6bf4b98ae - Don't wrap individual debug statements in ifdef, use a conditionally
darius
parents: 32
diff changeset
58 * This is optional, if it is undefined OWProgROM always fails */
0aa6bf4b98ae - Don't wrap individual debug statements in ifdef, use a conditionally
darius
parents: 32
diff changeset
59 #define OWSETVPPON() PORTD |= _BV(5)
0aa6bf4b98ae - Don't wrap individual debug statements in ifdef, use a conditionally
darius
parents: 32
diff changeset
60 #define OWSETVPPOFF() PORTD &= ~_BV(5)
0aa6bf4b98ae - Don't wrap individual debug statements in ifdef, use a conditionally
darius
parents: 32
diff changeset
61
32
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
62 /* _delay_us can only do a delay of 768/clock_freq */
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
63 #if F_CPU > 16000000
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
64 #error F_CPU > 16MHz, delays need adjusting
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
65 #endif
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
66
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
67 #define OWDELAY_A _delay_us(6) /* 6 usec */
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
68 #define OWDELAY_B do { _delay_us(48); _delay_us(16); } while (0) /* 64 usec */
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
69 #define OWDELAY_C do { _delay_us(48); _delay_us(12); } while (0) /* 60 usec */
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
70 #define OWDELAY_D _delay_us(10) /* 10 usec */
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
71 #define OWDELAY_E _delay_us(9) /* 9 usec */
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
72 #define OWDELAY_F do { _delay_us(55); } while (0) /* 55 usec */
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
73 #define OWDELAY_G /* 0 usec */
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
74 #define OWDELAY_H do { _delay_us(48); _delay_us(48); _delay_us(48); \
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
75 _delay_us(48); _delay_us(48); _delay_us(48); _delay_us(48); \
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
76 _delay_us(48);_delay_us(48); _delay_us(48); } while (0) /* 480 usec */
b0cb873c0206 Isolate the bus frobbing parts and the delays into a separate header.
darius
parents:
diff changeset
77 #define OWDELAY_I do { _delay_us(48); _delay_us(22); } while (0) /* 70 usec */
33
0aa6bf4b98ae - Don't wrap individual debug statements in ifdef, use a conditionally
darius
parents: 32
diff changeset
78
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 33
diff changeset
79 #ifdef OW_DEBUG
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 33
diff changeset
80 #define OWPUTS(x) puts_P(x)
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 33
diff changeset
81 #define OWPUTSP(x) puts_P(x)
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 33
diff changeset
82 #define OWPRINTFP(fmt, ...) printf_P(fmt, ## __VA_ARGS__)
33
0aa6bf4b98ae - Don't wrap individual debug statements in ifdef, use a conditionally
darius
parents: 32
diff changeset
83 #else
0aa6bf4b98ae - Don't wrap individual debug statements in ifdef, use a conditionally
darius
parents: 32
diff changeset
84 #define OWPUTS(x)
0aa6bf4b98ae - Don't wrap individual debug statements in ifdef, use a conditionally
darius
parents: 32
diff changeset
85 #define OWPUTSP(x)
41
5898fba6593c Add temperature control.
darius@inchoate.localdomain
parents: 33
diff changeset
86 #define OWPRINTFP(fmt, ...)
33
0aa6bf4b98ae - Don't wrap individual debug statements in ifdef, use a conditionally
darius
parents: 32
diff changeset
87 #endif
0aa6bf4b98ae - Don't wrap individual debug statements in ifdef, use a conditionally
darius
parents: 32
diff changeset
88