annotate testavr.c @ 3:ee3c9a16099e

- Specify the part number. - Build with -Wall
author darius
date Mon, 12 Jul 2004 15:39:27 +0930
parents ffeab3c04e83
children 81e2f85e02ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
1 /*
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
2 * Copyright (c) 2004
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
3 * Daniel O'Connor <darius@dons.net.au>. All rights reserved.
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
4 *
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
6 * modification, are permitted provided that the following conditions
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
7 * are met:
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
13 *
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
14 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
17 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
24 * SUCH DAMAGE.
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
25 */
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
26
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
27 #include <stdio.h>
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
28 #include <avr/io.h>
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
29 #include <avr/interrupt.h>
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
30 #include <avr/signal.h>
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
31 #include <avr/pgmspace.h>
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
32 #include <string.h>
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
33
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
34 #include "1wire.h"
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
35
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
36 #define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu)/((baudRate)*16l)-1)
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
37 #define XTAL_CPU 4000000 /* 4Mhz */
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
38 #define UART_BAUD_RATE 9600 /* 9600 baud */
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
39
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
40 static uint8_t dir = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
41 static volatile uint8_t leds = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
42 static uint8_t ledpos = 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);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
47 uint8_t uart_getc(void);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
48
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
49 uint8_t PROGMEM ledvals[] = {0x01, 0x03, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0, 0xc0, 0x80};
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
50
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
51 INTERRUPT(SIG_OVERFLOW0) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
52 if (!leds)
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
53 return;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
54
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
55 /* Going up */
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
56 if (dir == 0) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
57 if (ledpos == 9) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
58 dir = 1;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
59 TCNT0 = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
60 goto doleds;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
61 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
62
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
63 ledpos++;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
64 } else {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
65 if (ledpos == 0) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
66 dir = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
67 TCNT0 = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
68 goto doleds;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
69 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
70
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
71 ledpos--;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
72 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
73
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
74 doleds:
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
75 TCNT0 = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
76
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
77 PORTA = pgm_read_byte(&ledvals[ledpos]);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
78 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
79
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
80 void
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
81 usleep(uint16_t usec) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
82 /* 4Mhz = 250ns per clock cycle */
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
83 usec /= 2;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
84 if (usec < 1)
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
85 return;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
86
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
87 while (usec--)
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
88 asm volatile (
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
89 ""
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
90 ::);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
91 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
92
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
93 int
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
94 main(void) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
95 uint8_t ROM[8], count;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
96 char foo[40];
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
97 int i;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
98
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
99 cli();
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
100 outp(0xff, DDRA);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
101 outp(0xfe, DDRC);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
102 outp(0x00, PORTC);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
103
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
104 /* Init UART */
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
105 outp(UART_BAUD_SELECT(UART_BAUD_RATE,XTAL_CPU), UBRR);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
106
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
107 /* Enable receiver and transmitter. Turn on transmit interrupts */
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
108 outp(BV(RXEN) | BV(TXEN), UCR);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
109
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
110 /* Timer Clock divisor - CK/1024 */
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
111 outp(BV(CS00) | BV(CS02), TCCR0);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
112
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
113 uart_putsP(PSTR("\n\r\n\r===============\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
114 uart_putsP(PSTR("Inited!\n\r\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
115 uart_putsP(PSTR("Test message 1\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
116
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
117 count = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
118 while (1) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
119 char cmd;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
120
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
121 cmd = uart_getc();
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
122 switch (cmd) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
123 case 'r':
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
124 uart_putsP(PSTR("Resetting... "));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
125
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
126 if (OWTouchReset() == 1)
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
127 uart_putsP(PSTR("No presense\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
128 else
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
129 uart_putsP(PSTR("Presense\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
130 break;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
131
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
132 case 'R':
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
133 if (OWReadBit())
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
134 uart_putsP(PSTR("Read a 1\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
135 else
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
136 uart_putsP(PSTR("Read a 0\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
137 break;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
138
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
139 case 'w':
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
140 OWWriteBit(0);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
141 uart_putsP(PSTR("Wote a 0\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
142 break;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
143
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
144 case 'W':
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
145 OWWriteBit(1);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
146 uart_putsP(PSTR("Wote a 1\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
147 break;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
148
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
149 case 'd':
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
150 bzero(ROM, 8);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
151 if (OWTouchReset()) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
152 uart_putsP(PSTR("No devices on bus\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
153 break;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
154 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
155 if (OWFirst(ROM, 1, 0) == 0) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
156 uart_putsP(PSTR("No module found\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
157 break;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
158 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
159 do {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
160 uart_putsP(PSTR("Found a module "));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
161 sprintf_P(foo, PSTR("%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x"),
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
162 ROM[0],
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
163 ROM[1],
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
164 ROM[2],
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
165 ROM[3],
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
166 ROM[4],
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
167 ROM[5],
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
168 ROM[6],
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
169 ROM[7]);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
170 uart_puts(foo);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
171 if (ROM[0] == OW_FAMILY_TEMP) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
172 uint8_t tempbuf[9];
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
173 uint8_t crc;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
174 uint16_t temp;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
175
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
176 uart_putsP(PSTR(" is a temp sensor\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
177 OWSendCmd(ROM, OW_CONVERTT_CMD);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
178 #if OW_DEBUG
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
179 uart_putsP(PSTR("Command sent, waiting\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
180 #endif
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
181 i = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
182 while (OWReadBit() == 0) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
183 i++;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
184 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
185 #if OW_DEBUG
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
186 sprintf_P(foo, PSTR("Temp comversion took %d cycles\n\r"), i);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
187 uart_puts(foo);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
188 #endif
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
189 OWSendCmd(ROM, OW_RD_SCR_CMD);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
190 crc = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
191 for (i = 0; i < 9; i++) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
192 tempbuf[i] = OWReadByte();
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
193 if (i < 8)
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
194 OWCRC(tempbuf[i], &crc);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
195 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
196
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
197 temp = tempbuf[0];
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
198 temp |= (uint16_t)tempbuf[1] << 8;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
199 temp <<= 3;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
200
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
201 if (crc != tempbuf[9]) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
202 sprintf_P(foo, PSTR("CRC mismatch got %d vs calcd %d\n\r"), tempbuf[9], crc);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
203 uart_puts(foo);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
204 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
205
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
206 sprintf_P(foo, PSTR("temperature %d.%01d\n\r"),
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
207 temp >> 4, (temp << 12) / 6553);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
208 uart_puts(foo);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
209 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
210
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
211 if (ROM[0] == OW_FAMILY_ROM) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
212 uart_putsP(PSTR(" is a ROM\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
213 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
214 } while (OWNext(ROM, 1, 0));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
215 break;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
216
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
217 case 'l':
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
218 if (leds == 0) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
219 leds = 1;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
220 ledpos = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
221 outp(0, TCNT0);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
222 sbi(TIMSK, TOIE0);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
223 sei();
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
224 uart_putsP(PSTR("Starting\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
225 } else {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
226 leds = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
227 ledpos = 0;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
228 PORTA = 0x00;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
229 cbi(TIMSK, TOIE0);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
230 cli();
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
231 uart_putsP(PSTR("Stopping\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
232 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
233
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
234 break;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
235
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
236 default:
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
237 uart_putsP(PSTR("Unknown command\n\r"));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
238 break;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
239 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
240
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
241 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
242
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
243 return(0);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
244 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
245
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
246 int
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
247 uart_putc(char c) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
248 loop_until_bit_is_set(USR, UDRE);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
249 outp(c, UDR);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
250
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
251 return(0);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
252 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
253
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
254 void
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
255 uart_putsP(const char *addr) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
256 char c;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
257
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
258 while ((c = PRG_RDB((unsigned short)addr++)))
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
259 uart_putc(c);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
260 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
261
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
262 void
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
263 uart_puts(const char *addr) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
264 while (*addr)
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
265 uart_putc(*addr++);
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
266 }
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
267
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
268 uint8_t
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
269 uart_getc(void) {
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
270 while (!(inp(USR) & 0x80))
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
271 ;
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
272
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
273 return (inp(UDR));
ffeab3c04e83 Initial revision
darius
parents:
diff changeset
274 }