Mercurial > ~darius > hgwebdir.cgi > tempctrl
annotate testavr.c @ 58:1afc710266bd
Ignore non-source files.
author | darius@Inchoate |
---|---|
date | Thu, 30 Oct 2008 11:43:16 +1030 |
parents | 09f8d879afb9 |
children | 50fca9562310 |
rev | line source |
---|---|
0 | 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 * |
41 | 4 * Copyright (c) 2008 |
0 | 5 * Daniel O'Connor <darius@dons.net.au>. All rights reserved. |
6 * | |
7 * Redistribution and use in source and binary forms, with or without | |
8 * modification, are permitted provided that the following conditions | |
9 * are met: | |
10 * 1. Redistributions of source code must retain the above copyright | |
11 * notice, this list of conditions and the following disclaimer. | |
12 * 2. Redistributions in binary form must reproduce the above copyright | |
13 * notice, this list of conditions and the following disclaimer in the | |
14 * documentation and/or other materials provided with the distribution. | |
15 * | |
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE | |
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 * SUCH DAMAGE. | |
27 */ | |
28 | |
29 #include <avr/io.h> | |
30 #include <avr/interrupt.h> | |
31 #include <avr/pgmspace.h> | |
41 | 32 #include <stdio.h> |
0 | 33 #include <string.h> |
4 | 34 #include <ctype.h> |
13 | 35 #include <stdlib.h> |
24 | 36 #include <util/delay.h> |
47 | 37 #include <avr/wdt.h> |
0 | 38 |
41 | 39 #include "cons.h" |
0 | 40 #include "1wire.h" |
37 | 41 #ifdef WITHUSB |
24 | 42 #include "usb.h" |
37 | 43 #endif |
41 | 44 #include "tempctrl.h" |
24 | 45 |
47 | 46 /* |
47 * Mirror of the MCUCSR register, taken early during startup. | |
48 */ | |
49 uint8_t mcucsr __attribute__((section(".noinit"))); | |
50 | |
24 | 51 void process_cmd(void); |
0 | 52 |
47 | 53 /* |
54 * Read out and reset MCUCSR early during startup. | |
55 */ | |
56 void handle_mcucsr(void) | |
57 __attribute__((section(".init3"))) | |
58 __attribute__((naked)); | |
59 void handle_mcucsr(void) { | |
53
98b5a43fc748
Disable WDT in reset just in case we take too long (eg after reset when the
darius@Inchoate
parents:
52
diff
changeset
|
60 wdt_disable(); |
47 | 61 mcucsr = MCUCSR; |
62 MCUCSR = 0; | |
63 } | |
64 | |
24 | 65 int |
66 main(void) { | |
67 /* Disable interrupts while we frob stuff */ | |
68 cli(); | |
69 | |
41 | 70 #if 0 |
24 | 71 /* Disable JTAG (yes twice) */ |
72 MCUCSR |= _BV(JTD); | |
73 MCUCSR |= _BV(JTD); | |
37 | 74 #endif |
75 | |
76 #ifdef WITHUSB | |
24 | 77 /* USB data bus (7:0) */ |
78 DDRA = 0x00; | |
79 PORTA = 0x00; | |
80 | |
37 | 81 /* USB control (4:0) */ |
82 DDRB = 0x0d; | |
24 | 83 PORTB = 0x00; |
37 | 84 #else |
85 DDRA = 0xff; | |
86 PORTA = 0x00; | |
54
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
87 |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
88 DDRB = 0x00; |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
89 PORTB = 0x00; |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
90 |
37 | 91 #endif |
24 | 92 /* GPIO (0:7) */ |
93 DDRC = 0xff; | |
94 PORTC = 0x00; | |
95 | |
37 | 96 /* USART (0:1), IDBus (2:5), 485 (6:6), GPIO (7:7) */ |
97 DDRD = 0xf7; | |
98 PORTD = 0xf7; | |
99 | |
54
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
100 #ifndef WITHUSB |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
101 /* Beep |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
102 * |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
103 * Fpwm = Fclk / (N * 510) |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
104 * = 16e6 / (8 * 510) |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
105 * = 3921Hz |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
106 * |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
107 * Behind ifndef because PB3 is A0 on PDI chip |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
108 * |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
109 * Phase correct PWM, non-inverted output, divide by 8 */ |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
110 TCCR0 = _BV(WGM00) | _BV(WGM11) | _BV(COM00) | _BV(COM01) | _BV(CS01); |
56 | 111 OCR0 = 128; |
54
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
112 #endif |
58f1ec46bff6
Add a beeper when the data is stale (only when USB is disabled as they share
darius@Inchoate
parents:
53
diff
changeset
|
113 |
37 | 114 /* Set up the one wire stuff */ |
115 OWInit(); | |
24 | 116 |
117 /* Init UART */ | |
41 | 118 cons_init(); |
24 | 119 |
41 | 120 printf_P(PSTR("\r\n\r\n===============\r\n" |
121 "Inited!\r\n\r\n")); | |
24 | 122 |
47 | 123 if ((mcucsr & _BV(PORF)) == _BV(PORF)) |
124 printf_P(PSTR("Power on reset\r\n")); | |
125 | |
126 if ((mcucsr & _BV(EXTRF)) == _BV(EXTRF)) | |
127 printf_P(PSTR("External reset\r\n")); | |
128 | |
129 if ((mcucsr & _BV(BORF)) == _BV(BORF)) | |
130 printf_P(PSTR("Brown-out reset\r\n")); | |
131 | |
132 if ((mcucsr & _BV(WDRF)) == _BV(WDRF)) | |
133 printf_P(PSTR("Watchdog reset\r\n")); | |
134 | |
135 if ((mcucsr & _BV(JTRF)) == _BV(JTRF)) | |
136 printf_P(PSTR("JTAG reset\r\n")); | |
137 | |
41 | 138 tempctrl_init(); |
139 | |
24 | 140 /* Ready to go! */ |
141 sei(); | |
142 | |
47 | 143 /* |
144 * Enable the watchdog with the largest prescaler. Will cause a | |
145 * watchdog reset after approximately 2 s @ Vcc = 5 V | |
146 * | |
147 * Gets reset in the loop below and in the tempctrl.c timer IRQ | |
148 */ | |
149 wdt_enable(WDTO_2S); | |
150 | |
37 | 151 #ifdef WITHUSB |
41 | 152 printf_P(PSTR("Calling usb_init\r\n")); |
24 | 153 usb_init(); |
41 | 154 printf_P(PSTR("done\r\n")); |
155 _delay_us(1000); | |
37 | 156 #endif |
41 | 157 printf_P(PSTR("> ")); |
24 | 158 cmd.state = 0; |
159 | |
160 /* Wait for user input or an "interrupt" */ | |
161 while (1) { | |
47 | 162 wdt_reset(); |
163 | |
41 | 164 tempctrl_update(); |
165 | |
24 | 166 if (cmd.state == 255) { |
167 process_cmd(); | |
41 | 168 printf_P(PSTR("> ")); |
24 | 169 /* Allow new characters to be processed */ |
170 cmd.state = 0; | |
171 } | |
172 | |
37 | 173 #ifdef WITHUSB |
174 if (!(PDICTL & _BV(PDIINT))) | |
24 | 175 usb_intr(); |
37 | 176 #endif |
24 | 177 } |
178 } | |
179 | |
180 void | |
181 process_cmd(void) { | |
52
3217e93b28a3
Missed variable declaration changes from previous commit.
darius@Inchoate
parents:
51
diff
changeset
|
182 uint8_t ROM[8], crc, buf[9], temp; |
24 | 183 int8_t i, arg; |
52
3217e93b28a3
Missed variable declaration changes from previous commit.
darius@Inchoate
parents:
51
diff
changeset
|
184 int16_t t; |
0 | 185 |
24 | 186 /* User just pressed enter */ |
187 if (cmd.len == 0) | |
188 return; | |
189 | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
190 if (!strcasecmp_P((char *)cmd.buf, PSTR("?")) || |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
191 !strcasecmp_P((char *)cmd.buf, PSTR("help"))) { |
41 | 192 printf_P(PSTR("rs Reset and check for presence\r\n" |
193 "sr Search the bus for ROMs\r\n" | |
194 "re Read a bit\r\n" | |
195 "rb Read a byte\r\n" | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
196 "wr bit Write a bit\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
197 "wb byte Write a byte (hex)\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
198 "wc cmd [ROMID] Write command\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
199 "te ROMID Read the temperature from a DS1820\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
200 "in port Read from a port\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
201 "ou port val Write to a port (val in hex)\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
202 "dd port [val] Read/write DDR for a port (val in hex)\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
203 "rt ROMID Read DS2502 status page\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
204 "we ROMID adr val Write data into a DS2502 PROM (adr & val in hex)\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
205 "rr ROMID Read DS2502 PROM\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
206 "zz Reset MCU\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
207 #ifdef WITHUSB |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
208 "us Generate USB data\r\n" |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
209 #endif |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
210 "tc ... Temperature control related (tc help for more)\r\n")); |
41 | 211 |
24 | 212 return; |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
213 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("zz"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
214 cli(); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
215 wdt_enable(WDTO_15MS); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
216 for (;;) |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
217 ; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
218 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("rs"), 2)) { |
41 | 219 printf_P(PSTR("Resetting... ")); |
4 | 220 |
24 | 221 if (OWTouchReset() == 1) |
41 | 222 printf_P(PSTR("No presence pulse found\r\n")); |
24 | 223 else |
41 | 224 printf_P(PSTR("Presence pulse found\r\n")); |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
225 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("re"), 2)) { |
24 | 226 if (OWReadBit()) |
41 | 227 printf_P(PSTR("Read a 1\r\n")); |
24 | 228 else |
41 | 229 printf_P(PSTR("Read a 0\r\n")); |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
230 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("rb"), 2)) { |
41 | 231 printf_P(PSTR("Read a 0x%02x\r\n"), OWReadByte()); |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
232 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("wr"), 2)) { |
24 | 233 arg = strtol((char *)cmd.buf + 3, (char **)NULL, 10); |
234 OWWriteBit(arg); | |
41 | 235 printf_P(PSTR("Wrote a %c\r\n"), arg ? '1' : '0'); |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
236 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("wb"), 2)) { |
24 | 237 arg = (int)strtol((char *)cmd.buf + 3, (char **)NULL, 16); |
238 OWWriteByte(arg); | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
239 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("rt"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
240 if (sscanf_P((char *)cmd.buf, PSTR("rt %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"), |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
241 &ROM[0], &ROM[1], &ROM[2], &ROM[3], |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
242 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) { |
41 | 243 printf_P(PSTR("Unable to parse ROM ID\r\n")); |
37 | 244 return; |
245 } | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
246 |
37 | 247 if (ROM[0] != OW_FAMILY_ROM) { |
41 | 248 printf_P(PSTR("ROM specified isn't a DS2502\r\n")); |
37 | 249 return; |
250 } | |
251 | |
252 if (OWTouchReset() != 0) { | |
41 | 253 printf_P(PSTR("No presence\r\n")); |
37 | 254 return; |
255 } | |
256 | |
257 crc = 0; | |
258 | |
259 OWCRC(OW_READ_STATUS, &crc); | |
260 OWSendCmd(ROM, OW_READ_STATUS); | |
261 | |
262 OWWriteByte(0x00); | |
263 OWCRC(0x00, &crc); | |
264 | |
265 OWWriteByte(0x00); | |
266 OWCRC(0x00, &crc); | |
267 | |
268 if (crc != OWReadByte()) { | |
41 | 269 printf_P(PSTR("CRC mismatch on command & address\r\n")); |
37 | 270 return; |
271 } | |
272 | |
273 crc = 0; | |
274 for (i = 0; i < 8; i++) { | |
275 temp = OWReadByte(); | |
41 | 276 printf_P(PSTR("%02x "), temp); |
37 | 277 OWCRC(temp, &crc); |
278 } | |
41 | 279 printf_P(PSTR("\r\n")); |
37 | 280 if (crc != OWReadByte()) { |
41 | 281 printf_P(PSTR("CRC mismatch on data\r\n")); |
37 | 282 return; |
283 } | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
284 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("we"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
285 uint8_t adr, data; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
286 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
287 if (sscanf_P((char *)cmd.buf, PSTR("we %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hhx %hhx"), |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
288 &ROM[0], &ROM[1], &ROM[2], &ROM[3], |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
289 &ROM[4], &ROM[5], &ROM[6], &ROM[7], |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
290 &adr, &data) != 10) { |
41 | 291 printf_P(PSTR("Unable to parse ROM ID\r\n")); |
37 | 292 return; |
293 } | |
294 | |
295 if (ROM[0] != OW_FAMILY_ROM) { | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
296 printf_P(PSTR("ID specified isn't a ROM\r\n")); |
37 | 297 return; |
298 } | |
299 | |
300 if (OWTouchReset() != 0) { | |
41 | 301 printf_P(PSTR("No presence\r\n")); |
37 | 302 return; |
303 } | |
304 | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
305 printf_P(PSTR("OWProgROM returned %S\r\n"), OWProgROM_Status[OWProgROM(ROM, buf[0], 2, &buf[1], 0, 0)]); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
306 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("rr"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
307 if (sscanf_P((char *)cmd.buf, PSTR("rr %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"), |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
308 &ROM[0], &ROM[1], &ROM[2], &ROM[3], |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
309 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) { |
41 | 310 printf_P(PSTR("Unable to parse ROM ID\r\n")); |
37 | 311 return; |
312 } | |
313 | |
314 if (ROM[0] != OW_FAMILY_ROM) { | |
41 | 315 printf_P(PSTR("ROM specified isn't a ROM\r\n")); |
37 | 316 return; |
317 } | |
318 | |
319 crc = 0; | |
320 OWSendCmd(ROM, OW_READ_MEMORY); | |
321 OWCRC(OW_READ_MEMORY, &crc); | |
322 | |
323 OWWriteByte(0x00); | |
324 OWCRC(0x00, &crc); | |
325 | |
326 OWWriteByte(0x00); | |
327 OWCRC(0x00, &crc); | |
328 | |
329 if (crc != OWReadByte()) { | |
41 | 330 printf_P(PSTR("CRC mismatch on command & address\r\n")); |
37 | 331 return; |
332 } | |
333 | |
334 crc = 0; | |
335 for (buf[0] = 0; buf[0] < 128; buf[0]++) { | |
336 buf[1] = OWReadByte(); | |
337 if (buf[0] > 0) { | |
338 if (buf[0] % 16 != 0) | |
41 | 339 printf_P(PSTR(" ")); |
37 | 340 else |
41 | 341 printf_P(PSTR("\r\n")); |
37 | 342 } |
343 | |
41 | 344 printf_P(PSTR("%02x"), buf[1]); |
37 | 345 OWCRC(buf[1], &crc); |
346 } | |
41 | 347 printf_P(PSTR("\r\n")); |
37 | 348 if (crc != OWReadByte()) { |
41 | 349 printf_P(PSTR("CRC mismatch on data\r\n")); |
37 | 350 return; |
351 } | |
352 | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
353 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("wc"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
354 uint8_t c; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
355 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
356 i = sscanf_P((char *)cmd.buf, PSTR("wc %hhx %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"), |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
357 &ROM[0], &ROM[1], &ROM[2], &ROM[3], |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
358 &ROM[4], &ROM[5], &ROM[6], &ROM[7], |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
359 &c); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
360 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
361 if (i != 1 && i != 9) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
362 printf_P(PSTR("Incorrect usage\r\n")); |
24 | 363 return; |
364 } | |
365 | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
366 if (i == 1) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
367 OWSendCmd(i == 1 ? NULL : ROM, c); |
24 | 368 return; |
369 } | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
370 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("te"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
371 if (sscanf_P((char *)cmd.buf, PSTR("te %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"), |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
372 &ROM[0], &ROM[1], &ROM[2], &ROM[3], |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
373 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) { |
41 | 374 printf_P(PSTR("Unable to parse ROM ID\r\n")); |
24 | 375 return; |
376 } | |
377 | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
378 t = OWGetTemp(ROM); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
379 switch (t) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
380 case OW_TEMP_WRONG_FAM: |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
381 printf_P(PSTR("ROM specified isn't a temperature sensor\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
382 break; |
24 | 383 |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
384 case OW_TEMP_CRC_ERR: |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
385 printf_P(PSTR("CRC mismatch\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
386 break; |
41 | 387 |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
388 case OW_TEMP_NO_ROM: |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
389 printf_P(PSTR("No ROM found\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
390 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
391 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
392 default: |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
393 printf_P(PSTR("%d.%02d\r\n"), GETWHOLE(t), GETFRAC(t)); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
394 break; |
24 | 395 } |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
396 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("sr"), 2)) { |
24 | 397 memset(ROM, 0, 8); |
10 | 398 |
24 | 399 i = OWFirst(ROM, 1, 0); |
400 do { | |
401 switch (i) { | |
10 | 402 case OW_BADWIRE: |
41 | 403 printf_P(PSTR("Presence pulse, but no module found, bad module/cabling?\r\n")); |
10 | 404 break; |
405 | |
406 case OW_NOPRESENCE: | |
41 | 407 printf_P(PSTR("No presence pulse found\r\n")); |
10 | 408 break; |
409 | |
410 case OW_BADCRC: | |
41 | 411 printf_P(PSTR("Bad CRC\r\n")); |
10 | 412 break; |
413 | |
414 case OW_NOMODULES: | |
415 case OW_FOUND: | |
416 break; | |
417 | |
418 default: | |
41 | 419 printf_P(PSTR("Unknown error from 1 wire library\r\n")); |
10 | 420 break; |
24 | 421 } |
10 | 422 |
24 | 423 if (i != OW_FOUND) |
424 break; | |
13 | 425 |
41 | 426 for (i = 0; i < 8; i++) |
427 printf_P(PSTR("%02x%S"), ROM[i], i == 7 ? PSTR("\r\n") : PSTR(":")); | |
10 | 428 |
24 | 429 i = OWNext(ROM, 1, 0); |
430 } while (1); | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
431 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("in"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
432 uint8_t inp; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
433 |
24 | 434 switch (tolower(cmd.buf[3])) { |
435 case 'a': | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
436 inp = PINA; |
24 | 437 break; |
438 | |
439 case 'b': | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
440 inp = PINB; |
24 | 441 break; |
442 | |
443 case 'c': | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
444 inp = PINC; |
24 | 445 break; |
446 | |
447 case 'd': | |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
448 inp = PIND; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
449 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
450 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
451 default: |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
452 printf_P(PSTR("Unknown port\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
453 return; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
454 } |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
455 printf_P(PSTR("0x%02x\r\n"), inp); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
456 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("ou"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
457 char port; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
458 int val; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
459 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
460 if (sscanf_P((char *)cmd.buf, PSTR("ou %c %x"), &port, &val) != 2) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
461 printf_P(PSTR("Unable to parse ou arguments\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
462 return; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
463 } |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
464 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
465 switch (port) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
466 case 'a': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
467 PORTA = val & 0xff; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
468 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
469 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
470 case 'b': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
471 PORTB = val & 0xff; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
472 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
473 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
474 case 'c': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
475 PORTC = val & 0xff; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
476 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
477 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
478 case 'd': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
479 PORTD = val & 0xff; |
24 | 480 break; |
481 | |
482 default: | |
41 | 483 printf_P(PSTR("Unknown port\r\n")); |
24 | 484 return; |
0 | 485 } |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
486 printf_P(PSTR("PORT%c <= 0x%02x\r\n"), toupper(port), val); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
487 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("dd"), 2)) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
488 char port; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
489 uint8_t val; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
490 int num; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
491 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
492 num = sscanf_P((char *)cmd.buf, PSTR("dd %c %x"), &port, &val); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
493 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
494 if (num != 2 && num != 3) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
495 printf_P(PSTR("Unable to parse dd arguments\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
496 return; |
24 | 497 } |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
498 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
499 if (num == 2) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
500 switch (port) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
501 case 'a': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
502 val = DDRA; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
503 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
504 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
505 case 'b': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
506 val = DDRB; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
507 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
508 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
509 case 'c': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
510 val = DDRC; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
511 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
512 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
513 case 'd': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
514 val = DDRD; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
515 break; |
37 | 516 |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
517 default: |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
518 printf_P(PSTR("Unknown port\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
519 return; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
520 } |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
521 printf_P(PSTR("DDR%c => 0x%02x\r\n"), toupper(port), val); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
522 } else { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
523 switch (port) { |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
524 case 'a': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
525 DDRA = val & 0xff; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
526 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
527 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
528 case 'b': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
529 DDRB = val & 0xff; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
530 break; |
37 | 531 |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
532 case 'c': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
533 DDRC = val & 0xff; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
534 break; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
535 |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
536 case 'd': |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
537 DDRD = val & 0xff; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
538 break; |
37 | 539 |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
540 default: |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
541 printf_P(PSTR("Unknown port\r\n")); |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
542 return; |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
543 } |
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
544 printf_P(PSTR("DDR%c <= 0x%02x\r\n"), toupper(port), val); |
37 | 545 } |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
546 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("tc"), 2)) { |
41 | 547 tempctrl_cmd((char *)cmd.buf); |
37 | 548 #ifdef WITHUSB |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
549 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("us"), 2)) { |
24 | 550 usb_gendata(); |
37 | 551 #endif |
24 | 552 } else { |
51
cb184206344d
Rejig command parsing and assume the compiler isn't dumb (eg it can reuse
darius@Inchoate
parents:
47
diff
changeset
|
553 printf_P(PSTR("Unknown command, help for a list\r\n")); |
0 | 554 } |
24 | 555 } |
0 | 556 |
557 |