0
|
1 #include <stdio.h> |
|
2 #include <string.h> |
|
3 #include <stddef.h> |
|
4 #include <stdbool.h> |
|
5 #include <stdlib.h> |
|
6 #include <avr/io.h> |
|
7 #include <avr/interrupt.h> |
|
8 #include <avr/sleep.h> |
|
9 #include <util/delay.h> |
|
10 #include <avr/pgmspace.h> |
|
11 #include <avr/eeprom.h> |
|
12 #include <avr/wdt.h> |
|
13 #include <util/atomic.h> |
|
14 #include <util/crc16.h> |
|
15 |
1
|
16 //#include "simple_ds18b20.h" |
|
17 //#include "onewire.h" |
0
|
18 |
|
19 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) |
|
20 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) |
|
21 |
|
22 // TICK should be 8 or less (8 untested). all timers need |
|
23 // to be a multiple. |
|
24 |
1
|
25 #define TICK 1 |
0
|
26 // we have 1024 prescaler, 32768 crystal. |
|
27 #define SLEEP_COMPARE (32*TICK-1) |
|
28 |
1
|
29 #define KEYLEN 20 |
|
30 |
0
|
31 #define VALUE_NOSENSOR 0x07D0 // 125 degrees |
|
32 #define VALUE_BROKEN 0x07D1 // 125.0625 |
|
33 |
|
34 #define OVERSHOOT_MAX_DIV 1800.0 // 30 mins |
|
35 #define WORT_INVALID_TIME 900 // 15 mins |
|
36 // fridge min/max are only used if the wort sensor is invalid |
|
37 #define FRIDGE_AIR_MIN_RANGE 40 // 4º |
|
38 #define FRIDGE_AIR_MAX_RANGE 40 // 4º |
|
39 |
|
40 #define BAUD 19200 |
|
41 #define UBRR ((F_CPU)/8/(BAUD)-1) |
|
42 |
|
43 #define PORT_LED PORTC |
|
44 #define DDR_LED DDRC |
|
45 #define PIN_LED PC4 |
|
46 |
|
47 #define PORT_SHDN PORTD |
|
48 #define DDR_SHDN DDRD |
|
49 #define PIN_SHDN PD7 |
|
50 |
|
51 #define PORT_FRIDGE PORTD |
|
52 #define DDR_FRIDGE DDRD |
|
53 #define PIN_FRIDGE PD6 |
|
54 |
|
55 // total amount of 16bit values available for measurements. |
|
56 // adjust emperically, be sure to allow enough stack space too |
|
57 #define TOTAL_MEASUREMENTS 800 |
|
58 |
|
59 // each sensor slot uses 8 bytes |
|
60 #define MAX_SENSORS 6 |
|
61 |
|
62 // fixed at 8, have a shorter name |
|
63 #define ID_LEN OW_ROMCODE_SIZE |
|
64 |
|
65 // #define HAVE_UART_ECHO |
|
66 |
|
67 // stores a value of clock_epoch combined with the remainder of TCNT2, |
|
68 // for 1/32 second accuracy |
|
69 struct epoch_ticks |
|
70 { |
|
71 uint32_t ticks; |
|
72 // remainder |
|
73 uint8_t rem; |
|
74 }; |
|
75 |
1
|
76 // eeprom-settable parameters, default values defined here. |
|
77 // all timeouts should be a multiple of TICK |
|
78 static uint32_t watchdog_long_limit = 60*60*24; |
|
79 static uint32_t watchdog_short_limit = 0; |
|
80 static uint32_t newboot_limit = 60*10; |
0
|
81 |
1
|
82 // avr proves itself |
|
83 static uint8_t avr_keys[NKEYS][KEYLEN] = {0}; |
|
84 |
0
|
85 |
|
86 // ---- Atomic guards required accessing these variables |
|
87 // clock_epoch in seconds |
|
88 static uint32_t clock_epoch; |
1
|
89 // watchdog counts up |
|
90 static uint32_t watchdog_long_count; |
|
91 static uint32_t watchdog_short_count; |
|
92 // newboot counts down - it's a one-shot |
|
93 static uint32_t newboot_count; |
0
|
94 // ---- End atomic guards required |
|
95 |
|
96 // boolean flags |
1
|
97 static uint8_t watchdog_long_hit; |
|
98 static uint8_t watchdog_short_hit; |
|
99 static uint8_t newboot_hit; |
0
|
100 |
|
101 static uint8_t readpos; |
1
|
102 static char readbuf[50]; |
0
|
103 static uint8_t have_cmd; |
|
104 |
|
105 int uart_putchar(char c, FILE *stream); |
|
106 static void long_delay(int ms); |
|
107 static void blink(); |
|
108 static uint16_t adc_vcc(); |
|
109 |
|
110 static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, |
|
111 _FDEV_SETUP_WRITE); |
|
112 |
|
113 // thanks to http://projectgus.com/2010/07/eeprom-access-with-arduino/ |
|
114 #define eeprom_read_to(dst_p, eeprom_field, dst_size) eeprom_read_block((dst_p), (void *)offsetof(struct __eeprom_data, eeprom_field), (dst_size)) |
|
115 #define eeprom_read(dst, eeprom_field) eeprom_read_to((&dst), eeprom_field, sizeof(dst)) |
|
116 #define eeprom_write_from(src_p, eeprom_field, src_size) eeprom_write_block((src_p), (void *)offsetof(struct __eeprom_data, eeprom_field), (src_size)) |
|
117 #define eeprom_write(src, eeprom_field) { eeprom_write_from(&src, eeprom_field, sizeof(src)); } |
|
118 |
1
|
119 #define EXPECT_MAGIC 0xdf83 |
0
|
120 |
|
121 struct __attribute__ ((__packed__)) __eeprom_data { |
1
|
122 uint32_t watchdog_long_limit; |
|
123 uint32_t watchdog_short_limit; |
|
124 uint32_t newboot_limit; |
0
|
125 |
1
|
126 uint8_t avr_key[NKEYS][KEYLEN]; |
0
|
127 |
|
128 uint16_t magic; |
|
129 }; |
|
130 |
|
131 static void deep_sleep(); |
|
132 |
|
133 // Very first setup |
|
134 static void |
|
135 setup_chip() |
|
136 { |
|
137 cli(); |
|
138 |
|
139 // stop watchdog timer (might have been used to cause a reset) |
|
140 wdt_reset(); |
|
141 MCUSR &= ~_BV(WDRF); |
|
142 WDTCSR |= _BV(WDCE) | _BV(WDE); |
|
143 WDTCSR = 0; |
|
144 |
1
|
145 // set to 8S, in case sha1 is slow etc. |
|
146 wdt_enable(WDTO_8S); |
|
147 |
0
|
148 // Set clock to 2mhz |
|
149 CLKPR = _BV(CLKPCE); |
|
150 // divide by 4 |
|
151 CLKPR = _BV(CLKPS1); |
|
152 |
|
153 // enable pullups |
1
|
154 // XXX matt pihelp |
0
|
155 PORTB = 0xff; // XXX change when using SPI |
|
156 PORTD = 0xff; |
|
157 PORTC = 0xff; |
|
158 |
|
159 // 3.3v power for bluetooth and SD |
|
160 DDR_LED |= _BV(PIN_LED); |
|
161 |
|
162 // set pullup |
|
163 PORTD |= _BV(PD2); |
|
164 // INT0 setup |
|
165 EICRA = (1<<ISC01); // falling edge - data sheet says it won't work? |
|
166 EIMSK = _BV(INT0); |
|
167 |
|
168 // comparator disable |
|
169 ACSR = _BV(ACD); |
|
170 |
|
171 // disable adc pin input buffers |
|
172 DIDR0 = 0x3F; // acd0-adc5 |
|
173 DIDR1 = (1<<AIN1D)|(1<<AIN0D); // ain0/ain1 |
|
174 |
|
175 sei(); |
|
176 } |
|
177 |
|
178 static void |
|
179 get_epoch_ticks(struct epoch_ticks *t) |
|
180 { |
|
181 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) |
|
182 { |
|
183 t->ticks = clock_epoch; |
|
184 t->rem = TCNT2; |
|
185 } |
|
186 } |
|
187 |
|
188 static void |
|
189 setup_tick_counter() |
|
190 { |
|
191 // set up counter2. |
|
192 // COM21 COM20 Set OC2 on Compare Match (p116) |
|
193 // WGM21 Clear counter on compare |
|
194 //TCCR2A = _BV(COM2A1) | _BV(COM2A0) | _BV(WGM21); |
|
195 // toggle on match |
|
196 TCCR2A = _BV(COM2A0); |
|
197 // CS22 CS21 CS20 clk/1024 |
|
198 TCCR2B = _BV(CS22) | _BV(CS21) | _BV(CS20); |
|
199 // set async mode |
|
200 ASSR |= _BV(AS2); |
|
201 TCNT2 = 0; |
|
202 OCR2A = SLEEP_COMPARE; |
|
203 // interrupt |
|
204 TIMSK2 = _BV(OCIE2A); |
|
205 } |
|
206 |
|
207 static void |
|
208 uart_on() |
|
209 { |
|
210 // Power reduction register |
|
211 PRR &= ~_BV(PRUSART0); |
|
212 |
|
213 // All of this needs to be done each time after turning off the PRR |
|
214 // baud rate |
|
215 UBRR0H = (unsigned char)(UBRR >> 8); |
|
216 UBRR0L = (unsigned char)UBRR; |
|
217 // set 2x clock, improves accuracy of UBRR |
|
218 UCSR0A |= _BV(U2X0); |
|
219 UCSR0B = _BV(RXCIE0) | _BV(RXEN0) | _BV(TXEN0); |
|
220 //8N1 |
|
221 UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); |
|
222 uart_enabled = 1; |
|
223 } |
|
224 |
|
225 static void |
|
226 uart_off() |
|
227 { |
|
228 // Turn off interrupts and disable tx/rx |
|
229 UCSR0B = 0; |
|
230 uart_enabled = 0; |
|
231 |
|
232 // Power reduction register |
|
233 PRR |= _BV(PRUSART0); |
|
234 } |
|
235 |
|
236 int |
|
237 uart_putchar(char c, FILE *stream) |
|
238 { |
|
239 if (!uart_enabled) |
|
240 { |
|
241 return EOF; |
|
242 } |
|
243 // XXX could perhaps sleep in the loop for power. |
|
244 if (c == '\n') |
|
245 { |
|
246 loop_until_bit_is_set(UCSR0A, UDRE0); |
|
247 UDR0 = '\r'; |
|
248 } |
|
249 loop_until_bit_is_set(UCSR0A, UDRE0); |
|
250 UDR0 = c; |
|
251 if (stream == crc_stdout) |
|
252 { |
|
253 crc_out = _crc_ccitt_update(crc_out, c); |
|
254 } |
|
255 if (c == '\r') |
|
256 { |
|
257 loop_until_bit_is_set(UCSR0A, UDRE0); |
|
258 UDR0 = '\n'; |
|
259 if (stream == crc_stdout) |
|
260 { |
|
261 crc_out = _crc_ccitt_update(crc_out, '\n'); |
|
262 } |
|
263 } |
|
264 return (unsigned char)c; |
|
265 } |
|
266 |
|
267 static void |
|
268 cmd_reset() |
|
269 { |
|
270 printf_P(PSTR("reset\n")); |
|
271 _delay_ms(100); |
|
272 cli(); // disable interrupts |
|
273 wdt_enable(WDTO_15MS); // enable watchdog |
|
274 while(1); // wait for watchdog to reset processor |
|
275 } |
|
276 |
1
|
277 |
0
|
278 |
|
279 static void |
1
|
280 cmd_get_params() |
0
|
281 { |
1
|
282 uint32_t cur_watchdog_long, cur_watchdog_short, cur_newboot; |
|
283 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) |
|
284 { |
|
285 cur_watchdog_long = watchdot_long_count; |
|
286 cur_watchdog_short = watchdot_short_count; |
|
287 cur_newboot = newboot_limit_count; |
|
288 } |
|
289 |
|
290 printf_P(PSTR("limit (count) : watchdog_long %lu (%lu) watchdog_short %lu (%lu) newboot %lu (%lu)\n"), |
|
291 watchdog_long_limit, |
|
292 watchdog_long_count, |
|
293 watchdog_short_limit, |
|
294 watchdog_short_count, |
|
295 newboot_limit, |
|
296 newboot_count); |
0
|
297 } |
|
298 |
|
299 static void |
1
|
300 cmd_set_params(const char *params) |
0
|
301 { |
1
|
302 uint32_t new_watchdog_long_limit; |
|
303 uint32_t new_watchdog_short_limit; |
|
304 uint32_t new_newboot_limit; |
|
305 |
|
306 int ret = sscanf_P(params, PSTR("%lu %lu %lu"), |
|
307 &new_watchdog_long_limit, |
|
308 &new_watchdog_short_limit, |
|
309 &new_newboot_limit); |
|
310 |
|
311 |
|
312 if (ret != 3) |
0
|
313 { |
1
|
314 printf_P(PSTR("Bad values\n")); |
|
315 } |
|
316 else |
|
317 { |
|
318 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) |
|
319 { |
|
320 eeprom_write(new_watchdog_long_limit, watchdog_long_limit); |
|
321 eeprom_write(new_watchdog_short_limit, watchdog_short_limit); |
|
322 eeprom_write(new_newboot_limit, newboot_limit); |
|
323 uint16_t magic = EXPECT_MAGIC; |
|
324 eeprom_write(magic, magic); |
0
|
325 } |
1
|
326 printf_P(PSTR("set_params for next boot\n")); |
|
327 printf_P(PSTR("watchdog_long %lu watchdog_short %lu newboot %lu\n"), |
|
328 new_watchdog_long_limit, |
|
329 new_watchdog_short_limit, |
|
330 new_newboot_limit); |
|
331 |
|
332 } |
|
333 } |
0
|
334 |
1
|
335 uint8_t from_hex(char c) |
|
336 { |
|
337 if (c >= '0' && c <= '9') { |
|
338 return c-'0'; |
|
339 } |
|
340 if (c >= 'a' && c <= 'f') { |
|
341 return c-'a' + 0xa; |
|
342 } |
|
343 if (c >= 'A' && c <= 'F') { |
|
344 return c-'A' + 0xa; |
|
345 } |
|
346 return 0; |
|
347 } |
|
348 |
|
349 static void |
|
350 cmd_set_avr_key(const char *params) |
|
351 { |
|
352 // "N HEXKEY" |
|
353 if (strlen(params)) != KEYLEN*2+2) { |
|
354 printf_P(PSTR("Wrong length key\n")); |
|
355 return; |
0
|
356 } |
|
357 |
1
|
358 uint8_t new_key[KEYLEN]; |
|
359 for (int i = 0, p = 0; i < KEYLEN; i++, p += 2) |
|
360 { |
|
361 new_key[i] = (fromhex(params[p]) << 4) | fromhex(params[p+1]); |
|
362 } |
0
|
363 } |
|
364 |
|
365 static void |
|
366 load_params() |
|
367 { |
|
368 uint16_t magic; |
|
369 eeprom_read(magic, magic); |
|
370 if (magic == EXPECT_MAGIC) |
|
371 { |
1
|
372 eeprom_read(watchdog_long_limit, watchdog_long_limit); |
|
373 eeprom_read(watchdog_short_limit, watchdog_short_limit); |
|
374 eeprom_read(netboot_limit); |
|
375 eeprom_read(avr_key); |
|
376 } |
0
|
377 } |
|
378 |
|
379 // returns true if eeprom was written |
|
380 static bool |
|
381 set_initial_eeprom() |
|
382 { |
|
383 uint16_t magic; |
|
384 eeprom_read(magic, magic); |
|
385 if (magic == EXPECT_MAGIC) |
|
386 { |
|
387 return false; |
|
388 } |
|
389 |
|
390 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) |
|
391 { |
|
392 eeprom_write(measure_wake, measure_wake); |
|
393 eeprom_write(comms_wake, comms_wake); |
|
394 eeprom_write(wake_secs, wake_secs); |
|
395 eeprom_write(fridge_setpoint, fridge_setpoint); |
|
396 eeprom_write(fridge_difference, fridge_difference); |
|
397 eeprom_write(fridge_delay, fridge_delay); |
|
398 eeprom_write(overshoot_delay, overshoot_delay); |
|
399 eeprom_write(overshoot_factor, overshoot_factor); |
|
400 magic = EXPECT_MAGIC; |
|
401 eeprom_write(magic, magic); |
|
402 } |
|
403 |
|
404 return true; |
|
405 } |
|
406 |
|
407 static void |
|
408 read_handler() |
|
409 { |
|
410 if (strcmp_P(readbuf, PSTR("fetch")) == 0) |
|
411 { |
|
412 cmd_fetch(); |
|
413 } |
|
414 else if (strcmp_P(readbuf, PSTR("clear")) == 0) |
|
415 { |
|
416 cmd_clear(); |
|
417 } |
|
418 else if (strcmp_P(readbuf, PSTR("btoff")) == 0) |
|
419 { |
|
420 cmd_btoff(); |
|
421 } |
|
422 else if (strcmp_P(readbuf, PSTR("measure")) == 0) |
|
423 { |
|
424 cmd_measure(); |
|
425 } |
|
426 else if (strcmp_P(readbuf, PSTR("sensors")) == 0) |
|
427 { |
|
428 cmd_sensors(); |
|
429 } |
|
430 else if (strcmp_P(readbuf, PSTR("get_params")) == 0) |
|
431 { |
|
432 cmd_get_params(); |
|
433 } |
|
434 else if (strncmp_P(readbuf, PSTR("set_params "), 11) == 0) |
|
435 { |
|
436 cmd_set_params(&readbuf[11]); |
|
437 } |
|
438 else if (strcmp_P(readbuf, PSTR("awake")) == 0) |
|
439 { |
|
440 cmd_awake(); |
|
441 } |
|
442 else if (strncmp_P(readbuf, PSTR("fridge_setpoint "), 16) == 0) |
|
443 { |
|
444 cmd_set_fridge_setpoint(&readbuf[16]); |
|
445 } |
|
446 else if (strncmp_P(readbuf, PSTR("fridge_diff "), 12) == 0) |
|
447 { |
|
448 cmd_set_fridge_difference(&readbuf[12]); |
|
449 } |
|
450 else if (strncmp_P(readbuf, PSTR("fridge_delay "), 13) == 0) |
|
451 { |
|
452 cmd_set_fridge_delay(&readbuf[13]); |
|
453 } |
|
454 else if (strncmp_P(readbuf, PSTR("overshoot_delay "), 16) == 0) |
|
455 { |
|
456 cmd_set_overshoot_delay(&readbuf[16]); |
|
457 } |
|
458 else if (strncmp_P(readbuf, PSTR("overshoot_factor "), 17) == 0) |
|
459 { |
|
460 cmd_set_overshoot_factor(&readbuf[17]); |
|
461 } |
|
462 else if (strcmp_P(readbuf, PSTR("reset")) == 0) |
|
463 { |
|
464 cmd_reset(); |
|
465 } |
|
466 else |
|
467 { |
|
468 printf_P(PSTR("Bad command '%s'\n"), readbuf); |
|
469 } |
|
470 } |
|
471 |
|
472 ISR(INT0_vect) |
|
473 { |
|
474 button_pressed = 1; |
|
475 blink(); |
|
476 _delay_ms(100); |
|
477 blink(); |
|
478 } |
|
479 |
|
480 |
|
481 ISR(USART_RX_vect) |
|
482 { |
|
483 char c = UDR0; |
|
484 #ifdef HAVE_UART_ECHO |
|
485 uart_putchar(c, NULL); |
|
486 #endif |
|
487 if (c == '\r' || c == '\n') |
|
488 { |
|
489 if (readpos > 0) |
|
490 { |
|
491 readbuf[readpos] = '\0'; |
|
492 have_cmd = 1; |
|
493 readpos = 0; |
|
494 } |
|
495 } |
|
496 else |
|
497 { |
|
498 readbuf[readpos] = c; |
|
499 readpos++; |
|
500 if (readpos >= sizeof(readbuf)) |
|
501 { |
|
502 readpos = 0; |
|
503 } |
|
504 } |
|
505 } |
|
506 |
|
507 ISR(TIMER2_COMPA_vect) |
|
508 { |
|
509 TCNT2 = 0; |
|
510 |
|
511 clock_epoch += TICK; |
|
512 |
1
|
513 // watchdogs count up, continuous |
|
514 if (watchdog_long_limit > 0) { |
|
515 watchdog_count += TICK; |
|
516 if (watchdog_long_count >= watchdog_long_limit) |
|
517 { |
|
518 watchdog_long_count = 0; |
|
519 watchdog_long_hit = 1; |
|
520 } |
0
|
521 } |
|
522 |
1
|
523 if (watchdog_short_limit > 0) { |
|
524 watchdog_count += TICK; |
|
525 if (watchdog_short_count >= watchdog_short_limit) |
|
526 { |
|
527 watchdog_short_count = 0; |
|
528 watchdog_short_hit = 1; |
|
529 } |
0
|
530 } |
|
531 |
1
|
532 // newboot counts down, oneshot. |
|
533 if (newboot_count > 0) |
0
|
534 { |
1
|
535 newboot_count--; |
|
536 if (newboot_count == 0) |
|
537 { |
|
538 newboot_hit = 1; |
|
539 } |
0
|
540 } |
1
|
541 |
0
|
542 } |
|
543 |
|
544 static void |
|
545 deep_sleep() |
|
546 { |
|
547 // p119 of manual |
|
548 OCR2A = SLEEP_COMPARE; |
|
549 loop_until_bit_is_clear(ASSR, OCR2AUB); |
|
550 |
|
551 set_sleep_mode(SLEEP_MODE_PWR_SAVE); |
|
552 sleep_mode(); |
|
553 } |
|
554 |
|
555 static void |
|
556 idle_sleep() |
|
557 { |
|
558 set_sleep_mode(SLEEP_MODE_IDLE); |
|
559 sleep_mode(); |
|
560 } |
|
561 |
|
562 static uint16_t |
|
563 adc_vcc() |
|
564 { |
|
565 PRR &= ~_BV(PRADC); |
|
566 |
|
567 // /16 prescaler |
|
568 ADCSRA = _BV(ADEN) | _BV(ADPS2); |
|
569 |
|
570 // set to measure 1.1 reference |
|
571 ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); |
|
572 // average a number of samples |
|
573 uint16_t sum = 0; |
|
574 uint8_t num = 0; |
|
575 for (uint8_t n = 0; n < 20; n++) |
|
576 { |
|
577 ADCSRA |= _BV(ADSC); |
|
578 loop_until_bit_is_clear(ADCSRA, ADSC); |
|
579 |
|
580 uint8_t low_11 = ADCL; |
|
581 uint8_t high_11 = ADCH; |
|
582 uint16_t val = low_11 + (high_11 << 8); |
|
583 |
|
584 if (n >= 4) |
|
585 { |
|
586 sum += val; |
|
587 num++; |
|
588 } |
|
589 } |
|
590 ADCSRA = 0; |
|
591 PRR |= _BV(PRADC); |
|
592 |
|
593 //float res_volts = 1.1 * 1024 * num / sum; |
|
594 //return 1000 * res_volts; |
|
595 return ((uint32_t)1100*1024*num) / sum; |
|
596 } |
|
597 |
|
598 static void |
|
599 do_comms() |
|
600 { |
|
601 // avoid receiving rubbish, perhaps |
|
602 uart_on(); |
|
603 |
|
604 // write sd card here? same 3.3v regulator... |
|
605 |
1
|
606 while (1) |
0
|
607 { |
1
|
608 wdt_reset(); |
0
|
609 if (have_cmd) |
|
610 { |
|
611 have_cmd = 0; |
|
612 read_handler(); |
|
613 continue; |
|
614 } |
|
615 |
|
616 // wait for commands from the master |
|
617 idle_sleep(); |
|
618 } |
|
619 } |
|
620 |
|
621 static void |
|
622 blink() |
|
623 { |
|
624 PORT_LED &= ~_BV(PIN_LED); |
|
625 _delay_ms(1); |
|
626 PORT_LED |= _BV(PIN_LED); |
|
627 } |
|
628 |
|
629 static void |
|
630 long_delay(int ms) |
|
631 { |
|
632 int iter = ms / 100; |
|
633 |
|
634 for (int i = 0; i < iter; i++) |
|
635 { |
|
636 _delay_ms(100); |
|
637 } |
|
638 } |
|
639 |
|
640 ISR(BADISR_vect) |
|
641 { |
|
642 //uart_on(); |
|
643 printf_P(PSTR("Bad interrupt\n")); |
|
644 } |
|
645 |
|
646 int main(void) |
|
647 { |
|
648 setup_chip(); |
|
649 blink(); |
|
650 |
|
651 stdout = &mystdout; |
|
652 uart_on(); |
|
653 |
|
654 printf(PSTR("Started.\n")); |
|
655 |
|
656 load_params(); |
|
657 |
|
658 setup_tick_counter(); |
|
659 |
|
660 sei(); |
|
661 |
1
|
662 // doesn't return |
|
663 do_comms(); |
0
|
664 |
|
665 return 0; /* never reached */ |
|
666 } |