annotate testavr.c @ 12:4b141cc7cbd4

- Reduce type widths where possible. - Add URL for Dallas OWPD kit. - Hide more stuff behind OW_DEBUG.
author darius
date Wed, 01 Sep 2004 17:45:24 +0930
parents ccc39c9f320b
children 2c03ec600dbc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
1 /*
9
7ed10c59ba06 Supply clock speed via the command line so 1wire-delay.h can use it.
darius
parents: 7
diff changeset
2 * Test various AVR bits and pieces
7ed10c59ba06 Supply clock speed via the command line so 1wire-delay.h can use it.
darius
parents: 7
diff changeset
3 *
7ed10c59ba06 Supply clock speed via the command line so 1wire-delay.h can use it.
darius
parents: 7
diff changeset
4 * $Id$
7ed10c59ba06 Supply clock speed via the command line so 1wire-delay.h can use it.
darius
parents: 7
diff changeset
5 *
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
6 * Copyright (c) 2004
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
7 * Daniel O'Connor <darius@dons.net.au>. All rights reserved.
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
8 *
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
9 * Redistribution and use in source and binary forms, with or without
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
10 * modification, are permitted provided that the following conditions
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
11 * are met:
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
12 * 1. Redistributions of source code must retain the above copyright
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer.
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
14 * 2. Redistributions in binary form must reproduce the above copyright
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
15 * notice, this list of conditions and the following disclaimer in the
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
16 * documentation and/or other materials provided with the distribution.
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
17 *
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
18 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
21 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
28 * SUCH DAMAGE.
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
29 */
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
30
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
31 #include <stdio.h>
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
32 #include <avr/io.h>
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
33 #include <avr/interrupt.h>
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
34 #include <avr/signal.h>
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
35 #include <avr/pgmspace.h>
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
36 #include <string.h>
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
37 #include <ctype.h>
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
38
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
39 #include "1wire.h"
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
40
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
41 #define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu)/((baudRate)*16l)-1)
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
42 #define UART_BAUD_RATE 19200
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
43
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
44 void uart_putsP(const char *addr);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
45 void uart_puts(const char *addr);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
46 int uart_putc(char c);
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
47 int uart_getc(void);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
48 int beginswith_P(const char *s1, const char *s2);
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
49
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
50 uint8_t PROGMEM ledvals[] = {0x01, 0x03, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0, 0xc0, 0x80};
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
51 static uint8_t dir = 0;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
52 static volatile uint8_t leds = 0;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
53 static uint8_t ledpos = 0;
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
54
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
55 INTERRUPT(SIG_OVERFLOW0) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
56 if (!leds)
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
57 return;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
58
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
59 /* Going up */
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
60 if (dir == 0) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
61 if (ledpos == 9) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
62 dir = 1;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
63 TCNT0 = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
64 goto doleds;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
65 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
66
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
67 ledpos++;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
68 } else {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
69 if (ledpos == 0) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
70 dir = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
71 TCNT0 = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
72 goto doleds;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
73 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
74
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
75 ledpos--;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
76 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
77
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
78 doleds:
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
79 TCNT0 = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
80
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
81 PORTA = pgm_read_byte(&ledvals[ledpos]);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
82 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
83
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
84 void
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
85 usleep(uint16_t usec) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
86 /* 4Mhz = 250ns per clock cycle */
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
87 usec /= 2;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
88 if (usec < 1)
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
89 return;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
90
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
91 while (usec--)
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
92 asm volatile (
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
93 ""
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
94 ::);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
95 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
96
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
97 int
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
98 main(void) {
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
99 uint8_t ROM[8];
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
100 char cmdbuf[40];
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
101 int i;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
102
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
103 cli();
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
104 outp(0xff, DDRA);
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
105
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
106 /* Timer Clock divisor - CK/1024 */
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
107 outp(BV(CS00) | BV(CS02), TCCR0);
11
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
108
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
109 outp(0xfc, DDRC);
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
110 outp(0x00, PORTC);
11
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
111
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
112 /* Init UART */
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
113 outp(UART_BAUD_SELECT(UART_BAUD_RATE,XTAL_CPU), UBRR);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
114
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
115 /* Enable receiver and transmitter. Turn on transmit interrupts */
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
116 outp(BV(RXEN) | BV(TXEN), UCR);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
117
11
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
118 #if 0
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
119 int was;
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
120 uint32_t count;
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
121
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
122 was = inp(PINC) & 0x02;
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
123
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
124 count = 0;
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
125 while (1) {
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
126 if (was) {
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
127 if (!(inp(PINC) & 0x02)) {
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
128 sprintf_P(cmdbuf, PSTR("high -> low, i = %d\n\r"), count);
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
129 uart_puts(cmdbuf);
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
130 count = 0;
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
131 was = 0x00;
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
132 }
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
133 } else {
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
134 if ((inp(PINC) & 0x02)) {
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
135 sprintf_P(cmdbuf, PSTR("low -> high, i = %d\n\r"), count);
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
136 uart_puts(cmdbuf);
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
137 count = 0;
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
138 was = 0x02;
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
139 }
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
140 }
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
141
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
142 count++;
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
143 }
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
144 #endif
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
145
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
146 uart_putsP(PSTR("\n\r\n\r===============\n\r"
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
147 "Inited!\n\r\n\r"));
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
148
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
149 while (1) {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
150 uart_putsP(PSTR("> "));
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
151 i = 0;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
152 while (1) {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
153 cmdbuf[i] = tolower(uart_getc());
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
154 if (cmdbuf[i] == '\n' || cmdbuf[i] == '\r')
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
155 break;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
156
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
157 /* Backspace */
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
158 if (cmdbuf[i] == 010) {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
159 if (i > 0) {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
160 uart_putsP(PSTR("\010\040\010"));
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
161 i--;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
162 }
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
163 continue;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
164 }
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
165
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
166 /* Anything unprintable just ignore it */
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
167 if (!isprint(cmdbuf[i]))
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
168 continue;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
169
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
170 uart_putc(cmdbuf[i]);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
171 i++;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
172 if (i == sizeof(cmdbuf)) {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
173 uart_putsP(PSTR("\n\rLine too long\n\r"));
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
174 i = 0;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
175 continue;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
176 }
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
177 }
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
178 cmdbuf[i + 1] = '\0';
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
179 uart_putsP(PSTR("\n\r"));
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
180 if (i == 0)
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
181 continue;
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
182
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
183 if (cmdbuf[0] == '?') {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
184 uart_putsP(PSTR("rs Reset and check for presence\n\r"
7
a940431af6f5 Add usage for sr command.
darius
parents: 4
diff changeset
185 "sr Search the bus for ROMs\n\r"
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
186 "re Read a bit\n\r"
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
187 "rb Read a byte\n\r"
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
188 "wr bit Write a bit\n\r"
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
189 "wb byte Write a byte (hex)\n\r"
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
190 "wc cmd [ROMID] Write command\n\r"
11
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
191 "te ROMID Read the temperature from a DS1820\n\r"
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
192 "le Turn pretty LED cycling on\n\r"));
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
193
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
194 continue;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
195 }
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
196
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
197 if (i < 2)
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
198 goto badcmd;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
199
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
200 if (cmdbuf[0] == 'r' && cmdbuf[1] == 's') {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
201 uart_putsP(PSTR("Resetting... "));
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
202
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
203 if (OWTouchReset() == 1)
10
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
204 uart_putsP(PSTR("No presense pulse found\n\r"));
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
205 else
10
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
206 uart_putsP(PSTR("Presense pulse found\n\r"));
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
207 } else if (cmdbuf[0] == 'r' && cmdbuf[1] == 'e') {
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
208 if (OWReadBit())
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
209 uart_putsP(PSTR("Read a 1\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
210 else
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
211 uart_putsP(PSTR("Read a 0\n\r"));
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
212 } else if (cmdbuf[0] == 'r' && cmdbuf[1] == 'b') {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
213 sprintf_P(cmdbuf, PSTR("Read a 0x%02x\n\r"), OWReadByte());
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
214 uart_puts(cmdbuf);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
215 } else if (cmdbuf[0] == 'w' && cmdbuf[1] == 'r') {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
216 int arg;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
217
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
218 if (sscanf_P(cmdbuf + 3, PSTR("%d"), &arg) != 1) {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
219 uart_putsP(PSTR("Unable to parse wr command\n\r"));
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
220 continue;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
221 }
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
222
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
223 OWWriteBit(arg);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
224 sprintf_P(cmdbuf, PSTR("Wrote a %d\n\r"), arg);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
225 uart_puts(cmdbuf);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
226 } else if (cmdbuf[0] == 'w' && cmdbuf[1] == 'b') {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
227 int arg;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
228
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
229 if (sscanf_P(cmdbuf + 3, PSTR("%2x"), &arg) != 1) {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
230 uart_putsP(PSTR("Unable to parse wb command\n\r"));
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
231 continue;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
232 }
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
233
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
234 OWWriteByte(arg);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
235 sprintf_P(cmdbuf, PSTR("Wrote a 0x%02x\n\r"), arg);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
236 uart_puts(cmdbuf);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
237 } else if (cmdbuf[0] == 'w' && cmdbuf[1] == 'c') {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
238 int arg;
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
239
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
240 switch (sscanf_P(cmdbuf + 3, PSTR("%x %x:%x:%x:%x:%x:%x:%x:%x:%x"), &arg,
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
241 &ROM[0], &ROM[1], &ROM[2], &ROM[3],
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
242 &ROM[4], &ROM[5], &ROM[6], &ROM[7])) {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
243 break;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
244
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
245 case 1:
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
246 OWSendCmd(NULL, arg);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
247 sprintf_P(cmdbuf, PSTR("Sent 0x%02x to all ROMS\n\r"), arg);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
248 uart_puts(cmdbuf);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
249 break;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
250
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
251 case 9:
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
252 OWSendCmd(ROM, arg);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
253 sprintf_P(cmdbuf, PSTR("Sent 0x%02x to ROM %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n\r"),
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
254 arg, ROM[0], ROM[1], ROM[2], ROM[3],
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
255 ROM[4], ROM[5], ROM[6], ROM[7]);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
256 uart_puts(cmdbuf);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
257
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
258 break;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
259
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
260 case 0:
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
261 default:
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
262 uart_putsP(PSTR("Unable to parse wc command\n\r"));
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
263 break;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
264 }
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
265
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
266 OWWriteByte(arg);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
267 sprintf_P(cmdbuf, PSTR("Wrote a 0x%02x\n\r"), arg);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
268 uart_puts(cmdbuf);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
269 } else if (cmdbuf[0] == 't' && cmdbuf[1] == 'e') {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
270 uint8_t crc;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
271 uint16_t temp;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
272 uint8_t buf[9];
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
273
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
274 if (sscanf_P(cmdbuf + 3, PSTR("%x:%x:%x:%x:%x:%x:%x:%x:%x"),
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
275 &ROM[0], &ROM[1], &ROM[2], &ROM[3],
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
276 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
277 uart_putsP(PSTR("Unable to parse ROM ID\n\r"));
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
278 continue;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
279 }
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
280
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
281 if (ROM[0] != OW_FAMILY_TEMP) {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
282 uart_putsP(PSTR("ROM specified isn't a temperature sensor\n\r"));
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
283 continue;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
284 }
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
285
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
286 OWSendCmd(ROM, OW_CONVERTT_CMD);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
287 #if OW_DEBUG
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
288 uart_putsP(PSTR("Command sent, waiting\n\r"));
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
289 #endif
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
290 i = 0;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
291 while (OWReadBit() == 0) {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
292 i++;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
293 }
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
294 #if OW_DEBUG
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
295 sprintf_P(cmdbuf, PSTR("Temp comversion took %d cycles\n\r"), i);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
296 uart_puts(cmdbuf);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
297 #endif
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
298 OWSendCmd(ROM, OW_RD_SCR_CMD);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
299 crc = 0;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
300 for (i = 0; i < 9; i++) {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
301 buf[i] = OWReadByte();
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
302 if (i < 8)
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
303 OWCRC(buf[i], &crc);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
304 }
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
305
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
306 temp = buf[0];
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
307 temp |= (uint16_t)buf[1] << 8;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
308 temp <<= 3;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
309
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
310 if (crc != buf[8]) {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
311 sprintf_P(cmdbuf, PSTR("CRC mismatch got %d vs calcd %d\n\r"), buf[8], crc);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
312 uart_puts(cmdbuf);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
313 continue;
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
314 }
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
315
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
316 sprintf_P(cmdbuf, PSTR("temperature %d.%01d\n\r"),
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
317 temp >> 4, (temp << 12) / 6553);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
318 uart_puts(cmdbuf);
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
319 } else if (cmdbuf[0] == 's' && cmdbuf[1] == 'r') {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
320 memset(ROM, 0, 8);
10
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
321
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
322 i = OWFirst(ROM, 1, 0);
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
323 do {
10
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
324 switch (i) {
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
325 case OW_BADWIRE:
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
326 uart_putsP(PSTR("Presense pulse, but no module found, bad module/cabling?\n\r"));
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
327 break;
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
328
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
329 case OW_NOPRESENCE:
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
330 uart_putsP(PSTR("No presense pulse found\n\r"));
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
331 break;
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
332
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
333 case OW_BADCRC:
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
334 uart_putsP(PSTR("Bad CRC\n\r"));
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
335 break;
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
336
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
337 case OW_NOMODULES:
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
338 case OW_FOUND:
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
339 break;
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
340
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
341 default:
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
342 uart_putsP(PSTR("Unknown error from 1 wire library\n\r"));
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
343 break;
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
344 }
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
345
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
346 if (i != OW_FOUND)
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
347 break;
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
348
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
349 sprintf_P(cmdbuf, PSTR("%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n\r"),
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
350 ROM[0],
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
351 ROM[1],
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
352 ROM[2],
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
353 ROM[3],
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
354 ROM[4],
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
355 ROM[5],
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
356 ROM[6],
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
357 ROM[7]);
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
358 uart_puts(cmdbuf);
10
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
359
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
360 i = OWNext(ROM, 1, 0);
eb1faf51968e - Add some useful return values to search functions.
darius
parents: 9
diff changeset
361 } while (1);
11
ccc39c9f320b Enable pretty LED command.
darius
parents: 10
diff changeset
362 } else if (cmdbuf[0] == 'l' && cmdbuf[1] == 'e') {
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
363 if (leds == 0) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
364 leds = 1;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
365 ledpos = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
366 outp(0, TCNT0);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
367 sbi(TIMSK, TOIE0);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
368 sei();
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
369 uart_putsP(PSTR("Starting\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
370 } else {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
371 leds = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
372 ledpos = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
373 PORTA = 0x00;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
374 cbi(TIMSK, TOIE0);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
375 cli();
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
376 uart_putsP(PSTR("Stopping\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
377 }
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
378 } else {
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
379 badcmd:
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
380 uart_putsP(PSTR("Unknown command, ? for a list\n\r"));
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
381 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
382
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
383 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
384
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
385 return(0);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
386 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
387
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
388 int
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
389 uart_putc(char c) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
390 loop_until_bit_is_set(USR, UDRE);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
391 outp(c, UDR);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
392
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
393 return(0);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
394 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
395
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
396 void
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
397 uart_putsP(const char *addr) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
398 char c;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
399
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
400 while ((c = PRG_RDB((unsigned short)addr++)))
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
401 uart_putc(c);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
402 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
403
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
404 void
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
405 uart_puts(const char *addr) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
406 while (*addr)
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
407 uart_putc(*addr++);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
408 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
409
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
410 int
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
411 uart_getc(void) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
412 while (!(inp(USR) & 0x80))
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
413 ;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
414
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
415 return (inp(UDR));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
416 }
4
81e2f85e02ce Implement a command driven 1 wire bus tool.
darius
parents: 0
diff changeset
417