Mercurial > ~darius > hgwebdir.cgi > tempctrl
comparison testavr.c @ 47:13a68734348b
Add watchdog timer.
author | darius@Inchoate |
---|---|
date | Mon, 20 Oct 2008 22:22:15 +1030 |
parents | 5898fba6593c |
children | cb184206344d |
comparison
equal
deleted
inserted
replaced
46:fb272cb82bcb | 47:13a68734348b |
---|---|
32 #include <stdio.h> | 32 #include <stdio.h> |
33 #include <string.h> | 33 #include <string.h> |
34 #include <ctype.h> | 34 #include <ctype.h> |
35 #include <stdlib.h> | 35 #include <stdlib.h> |
36 #include <util/delay.h> | 36 #include <util/delay.h> |
37 #include <avr/wdt.h> | |
37 | 38 |
38 #include "cons.h" | 39 #include "cons.h" |
39 #include "1wire.h" | 40 #include "1wire.h" |
40 #ifdef WITHUSB | 41 #ifdef WITHUSB |
41 #include "usb.h" | 42 #include "usb.h" |
42 #endif | 43 #endif |
43 #include "tempctrl.h" | 44 #include "tempctrl.h" |
44 | 45 |
46 /* | |
47 * Mirror of the MCUCSR register, taken early during startup. | |
48 */ | |
49 uint8_t mcucsr __attribute__((section(".noinit"))); | |
50 | |
45 void process_cmd(void); | 51 void process_cmd(void); |
52 | |
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) { | |
60 mcucsr = MCUCSR; | |
61 MCUCSR = 0; | |
62 } | |
46 | 63 |
47 int | 64 int |
48 main(void) { | 65 main(void) { |
49 /* Disable interrupts while we frob stuff */ | 66 /* Disable interrupts while we frob stuff */ |
50 cli(); | 67 cli(); |
82 cons_init(); | 99 cons_init(); |
83 | 100 |
84 printf_P(PSTR("\r\n\r\n===============\r\n" | 101 printf_P(PSTR("\r\n\r\n===============\r\n" |
85 "Inited!\r\n\r\n")); | 102 "Inited!\r\n\r\n")); |
86 | 103 |
104 if ((mcucsr & _BV(PORF)) == _BV(PORF)) | |
105 printf_P(PSTR("Power on reset\r\n")); | |
106 | |
107 if ((mcucsr & _BV(EXTRF)) == _BV(EXTRF)) | |
108 printf_P(PSTR("External reset\r\n")); | |
109 | |
110 if ((mcucsr & _BV(BORF)) == _BV(BORF)) | |
111 printf_P(PSTR("Brown-out reset\r\n")); | |
112 | |
113 if ((mcucsr & _BV(WDRF)) == _BV(WDRF)) | |
114 printf_P(PSTR("Watchdog reset\r\n")); | |
115 | |
116 if ((mcucsr & _BV(JTRF)) == _BV(JTRF)) | |
117 printf_P(PSTR("JTAG reset\r\n")); | |
118 | |
87 tempctrl_init(); | 119 tempctrl_init(); |
88 | 120 |
89 /* Ready to go! */ | 121 /* Ready to go! */ |
90 sei(); | 122 sei(); |
91 | 123 |
92 #if 0 | 124 /* |
93 DDRA = 0xff; | 125 * Enable the watchdog with the largest prescaler. Will cause a |
94 DDRC = 0xff; | 126 * watchdog reset after approximately 2 s @ Vcc = 5 V |
95 while (1) { | 127 * |
96 printf_P(PSTR("1\r\n")); | 128 * Gets reset in the loop below and in the tempctrl.c timer IRQ |
97 PORTA = 0xff; | 129 */ |
98 printf_P(PSTR("2\r\n")); | 130 wdt_enable(WDTO_2S); |
99 PORTC = 0x00; | 131 |
100 printf_P(PSTR("3\r\n")); | |
101 _delay_us(1); | |
102 printf_P(PSTR("4\r\n")); | |
103 PORTA = 0x80; | |
104 printf_P(PSTR("5\r\n")); | |
105 PORTC = 0xff; | |
106 printf_P(PSTR("6\r\n")); | |
107 } | |
108 #endif | |
109 | |
110 #ifdef WITHUSB | 132 #ifdef WITHUSB |
111 printf_P(PSTR("Calling usb_init\r\n")); | 133 printf_P(PSTR("Calling usb_init\r\n")); |
112 usb_init(); | 134 usb_init(); |
113 printf_P(PSTR("done\r\n")); | 135 printf_P(PSTR("done\r\n")); |
114 _delay_us(1000); | 136 _delay_us(1000); |
116 printf_P(PSTR("> ")); | 138 printf_P(PSTR("> ")); |
117 cmd.state = 0; | 139 cmd.state = 0; |
118 | 140 |
119 /* Wait for user input or an "interrupt" */ | 141 /* Wait for user input or an "interrupt" */ |
120 while (1) { | 142 while (1) { |
143 wdt_reset(); | |
144 | |
121 tempctrl_update(); | 145 tempctrl_update(); |
122 | 146 |
123 if (cmd.state == 255) { | 147 if (cmd.state == 255) { |
124 process_cmd(); | 148 process_cmd(); |
125 printf_P(PSTR("> ")); | 149 printf_P(PSTR("> ")); |