comparison main.c @ 73:56165caf744b

Missed some USB related crud + copyright updates.
author darius@Inchoate
date Wed, 21 Jan 2009 18:01:17 +1030
parents 13f8e6eb5c01
children
comparison
equal deleted inserted replaced
72:13f8e6eb5c01 73:56165caf744b
1 /* 1 /*
2 * Test various AVR bits and pieces 2 * Monitor fermenter temperature and control it by switching cooler & heater.
3 * 3 *
4 * Copyright (c) 2008 4 * Copyright (c) 2009
5 * Daniel O'Connor <darius@dons.net.au>. All rights reserved. 5 * Daniel O'Connor <darius@dons.net.au>. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
36 #include <util/delay.h> 36 #include <util/delay.h>
37 #include <avr/wdt.h> 37 #include <avr/wdt.h>
38 38
39 #include "cons.h" 39 #include "cons.h"
40 #include "1wire.h" 40 #include "1wire.h"
41 #ifdef WITHUSB
42 #include "usb.h"
43 #endif
44 #include "tempctrl.h" 41 #include "tempctrl.h"
45 #include "ds1307.h" 42 #include "ds1307.h"
46 43
47 /* 44 /*
48 * Mirror of the MCUCSR register, taken early during startup. 45 * Mirror of the MCUCSR register, taken early during startup.
72 /* Disable JTAG (yes twice) */ 69 /* Disable JTAG (yes twice) */
73 MCUCSR |= _BV(JTD); 70 MCUCSR |= _BV(JTD);
74 MCUCSR |= _BV(JTD); 71 MCUCSR |= _BV(JTD);
75 #endif 72 #endif
76 73
77 #ifdef WITHUSB
78 /* USB data bus (7:0) */
79 DDRA = 0x00;
80 PORTA = 0x00;
81
82 /* USB control (4:0) */
83 DDRB = 0x0d;
84 PORTB = 0x00;
85 #else
86 DDRA = 0xff; 74 DDRA = 0xff;
87 PORTA = 0x00; 75 PORTA = 0x00;
88 76
89 DDRB = 0x00; 77 DDRB = 0x00;
90 PORTB = 0x00; 78 PORTB = 0x00;
91 79
92 #endif
93 /* GPIO (0:7) */ 80 /* GPIO (0:7) */
94 DDRC = 0xff; 81 DDRC = 0xff;
95 PORTC = 0x00; 82 PORTC = 0x00;
96 83
97 /* USART (0:1), IDBus (2:5), 485 (6:6), GPIO (7:7) */ 84 /* USART (0:1), IDBus (2:5), 485 (6:6), GPIO (7:7) */
98 DDRD = 0xf7; 85 DDRD = 0xf7;
99 PORTD = 0xf7; 86 PORTD = 0xf7;
100 87
101 #ifndef WITHUSB
102 /* Beep 88 /* Beep
103 * 89 *
104 * Fpwm = Fclk / (N * 510) 90 * Fpwm = Fclk / (N * 510)
105 * = 16e6 / (8 * 510) 91 * = 16e6 / (8 * 510)
106 * = 3921Hz 92 * = 3921Hz
108 * Behind ifndef because PB3 is A0 on PDI chip 94 * Behind ifndef because PB3 is A0 on PDI chip
109 * 95 *
110 * Phase correct PWM, non-inverted output, divide by 8 */ 96 * Phase correct PWM, non-inverted output, divide by 8 */
111 TCCR0 = _BV(WGM00) | _BV(WGM11) | _BV(COM00) | _BV(COM01) | _BV(CS01); 97 TCCR0 = _BV(WGM00) | _BV(WGM11) | _BV(COM00) | _BV(COM01) | _BV(CS01);
112 OCR0 = 128; 98 OCR0 = 128;
113 #endif
114 99
115 /* Set up the one wire stuff */ 100 /* Set up the one wire stuff */
116 OWInit(); 101 OWInit();
117 102
118 /* Setup IIC */ 103 /* Setup IIC */
151 * 136 *
152 * Gets reset in the loop below and in the tempctrl.c timer IRQ 137 * Gets reset in the loop below and in the tempctrl.c timer IRQ
153 */ 138 */
154 wdt_enable(WDTO_2S); 139 wdt_enable(WDTO_2S);
155 140
156 #ifdef WITHUSB
157 printf_P(PSTR("Calling usb_init\r\n"));
158 usb_init();
159 printf_P(PSTR("done\r\n"));
160 _delay_us(1000);
161 #endif
162 printf_P(PSTR("> ")); 141 printf_P(PSTR("> "));
163 cmd.state = 0; 142 cmd.state = 0;
164 143
165 /* Wait for user input or an "interrupt" */ 144 /* Wait for user input or an "interrupt" */
166 while (1) { 145 while (1) {
172 process_cmd(); 151 process_cmd();
173 printf_P(PSTR("> ")); 152 printf_P(PSTR("> "));
174 /* Allow new characters to be processed */ 153 /* Allow new characters to be processed */
175 cmd.state = 0; 154 cmd.state = 0;
176 } 155 }
177
178 #ifdef WITHUSB
179 if (!(PDICTL & _BV(PDIINT)))
180 usb_intr();
181 #endif
182 } 156 }
183 } 157 }
184 158
185 void 159 void
186 process_cmd(void) { 160 process_cmd(void) {
209 "we ROMID adr val Write data into a DS2502 PROM (adr & val in hex)\r\n" 183 "we ROMID adr val Write data into a DS2502 PROM (adr & val in hex)\r\n"
210 "rr ROMID Read DS2502 PROM\r\n" 184 "rr ROMID Read DS2502 PROM\r\n"
211 "zz Reset MCU\r\n" 185 "zz Reset MCU\r\n"
212 "gc Get time of day\r\n" 186 "gc Get time of day\r\n"
213 "sc time Set time of day (time is YYYY/MM/DD HH:MM:SS)\r\n" 187 "sc time Set time of day (time is YYYY/MM/DD HH:MM:SS)\r\n"
214 #ifdef WITHUSB
215 "us Generate USB data\r\n"
216 #endif
217 "tc ... Temperature control related (tc help for more)\r\n")); 188 "tc ... Temperature control related (tc help for more)\r\n"));
218 189
219 return; 190 return;
220 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("zz"), 2)) { 191 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("zz"), 2)) {
221 cli(); 192 cli();
550 } 521 }
551 printf_P(PSTR("DDR%c <= 0x%02x\r\n"), toupper(port), val); 522 printf_P(PSTR("DDR%c <= 0x%02x\r\n"), toupper(port), val);
552 } 523 }
553 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("tc"), 2)) { 524 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("tc"), 2)) {
554 tempctrl_cmd((char *)cmd.buf); 525 tempctrl_cmd((char *)cmd.buf);
555 #ifdef WITHUSB
556 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("us"), 2)) {
557 usb_gendata();
558 #endif
559 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("gc"), 2)) { 526 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("gc"), 2)) {
560 ds1307_printtime(PSTR(""), PSTR("\r\n")); 527 ds1307_printtime(PSTR(""), PSTR("\r\n"));
561 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("sc"), 2)) { 528 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("sc"), 2)) {
562 if (cmd.len < 17) { 529 if (cmd.len < 17) {
563 printf_P(PSTR("Command not long enough\r\n")); 530 printf_P(PSTR("Command not long enough\r\n"));