Mercurial > templog
comparison main.c @ 346:d6219df77c41
main.c:
- get rid of some debugging
- separate uart_enabled flag
ts.py:
- remember next wake time, not the interval
log.py:
- comments for sqlite
templog.py
- use cgi
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 23 Jun 2012 22:10:23 +0800 |
parents | ccab04e2f601 |
children | 1701457e6007 |
comparison
equal
deleted
inserted
replaced
345:a3473b5ea50e | 346:d6219df77c41 |
---|---|
1 /* Name: main.c | |
2 * Author: <insert your name here> | |
3 * Copyright: <insert your copyright message here> | |
4 * License: <insert your license reference here> | |
5 */ | |
6 | |
7 #include <stdio.h> | 1 #include <stdio.h> |
8 #include <string.h> | 2 #include <string.h> |
9 #include <stddef.h> | 3 #include <stddef.h> |
10 #include <avr/io.h> | 4 #include <avr/io.h> |
11 #include <avr/interrupt.h> | 5 #include <avr/interrupt.h> |
83 static uint32_t last_measurement_clock; | 77 static uint32_t last_measurement_clock; |
84 | 78 |
85 // boolean flags | 79 // boolean flags |
86 static uint8_t need_measurement; | 80 static uint8_t need_measurement; |
87 static uint8_t need_comms; | 81 static uint8_t need_comms; |
82 static uint8_t uart_enabled; | |
88 | 83 |
89 // counts down from WAKE_SECS to 0, goes to deep sleep when hits 0 | 84 // counts down from WAKE_SECS to 0, goes to deep sleep when hits 0 |
90 static uint8_t comms_timeout; | 85 static uint8_t comms_timeout; |
91 | 86 |
92 static uint8_t readpos; | 87 static uint8_t readpos; |
182 // set 2x clock, improves accuracy of UBRR | 177 // set 2x clock, improves accuracy of UBRR |
183 UCSR0A |= _BV(U2X0); | 178 UCSR0A |= _BV(U2X0); |
184 UCSR0B = _BV(RXCIE0) | _BV(RXEN0) | _BV(TXEN0); | 179 UCSR0B = _BV(RXCIE0) | _BV(RXEN0) | _BV(TXEN0); |
185 //8N1 | 180 //8N1 |
186 UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); | 181 UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); |
182 uart_enabled = 1; | |
187 } | 183 } |
188 | 184 |
189 static void | 185 static void |
190 uart_off() | 186 uart_off() |
191 { | 187 { |
192 #if 0 | |
193 // Turn of interrupts and disable tx/rx | 188 // Turn of interrupts and disable tx/rx |
194 UCSR0B = 0; | 189 UCSR0B = 0; |
190 uart_enabled = 0; | |
195 | 191 |
196 // Power reduction register | 192 // Power reduction register |
197 //PRR |= _BV(PRUSART0); | 193 //PRR |= _BV(PRUSART0); |
198 #endif | |
199 } | 194 } |
200 | 195 |
201 int | 196 int |
202 uart_putchar(char c, FILE *stream) | 197 uart_putchar(char c, FILE *stream) |
203 { | 198 { |
199 if (!uart_enabled) | |
200 { | |
201 return EOF; | |
202 } | |
204 // XXX could perhaps sleep in the loop for power. | 203 // XXX could perhaps sleep in the loop for power. |
205 if (c == '\n') | 204 if (c == '\n') |
206 { | 205 { |
207 loop_until_bit_is_set(UCSR0A, UDRE0); | 206 loop_until_bit_is_set(UCSR0A, UDRE0); |
208 UDR0 = '\r'; | 207 UDR0 = '\r'; |
220 if (stream == crc_stdout) | 219 if (stream == crc_stdout) |
221 { | 220 { |
222 crc_out = _crc_ccitt_update(crc_out, '\n'); | 221 crc_out = _crc_ccitt_update(crc_out, '\n'); |
223 } | 222 } |
224 } | 223 } |
225 return 0; | 224 return (unsigned char)c; |
226 } | 225 } |
227 | 226 |
228 static void | 227 static void |
229 cmd_fetch() | 228 cmd_fetch() |
230 { | 229 { |
751 sei(); | 750 sei(); |
752 | 751 |
753 need_comms = 1; | 752 need_comms = 1; |
754 need_measurement = 1; | 753 need_measurement = 1; |
755 | 754 |
756 #if 0 | |
757 for (;;) | |
758 { | |
759 do_comms(); | |
760 } | |
761 #endif | |
762 | |
763 for(;;) | 755 for(;;) |
764 { | 756 { |
765 if (need_measurement) | 757 if (need_measurement) |
766 { | 758 { |
767 need_measurement = 0; | 759 need_measurement = 0; |
776 continue; | 768 continue; |
777 } | 769 } |
778 | 770 |
779 deep_sleep(); | 771 deep_sleep(); |
780 blink(); | 772 blink(); |
781 printf("."); | |
782 } | 773 } |
783 | 774 |
784 return 0; /* never reached */ | 775 return 0; /* never reached */ |
785 } | 776 } |