Mercurial > pihelp
comparison main.c @ 16:8b1aeff120e9
add max/min sanity checks
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 13 Jun 2013 00:22:37 +0800 |
parents | 915be6f0ff13 |
children | 21717153e0f1 |
comparison
equal
deleted
inserted
replaced
15:915be6f0ff13 | 16:8b1aeff120e9 |
---|---|
62 }; | 62 }; |
63 | 63 |
64 // OCR1A ticks COUNTER_DIV(=4) times a second, we divide it down. | 64 // OCR1A ticks COUNTER_DIV(=4) times a second, we divide it down. |
65 static uint8_t counter_div = 0; | 65 static uint8_t counter_div = 0; |
66 | 66 |
67 #define WATCHDOG_LONG_MIN (60L*40) // 40 mins | |
68 #define WATCHDOG_LONG_MAX (60L*60*72) // 72 hours | |
69 #define WATCHDOG_LONG_DEFAULT (60L*60*6) // 6 hours | |
70 | |
71 #define WATCHDOG_SHORT_MIN (60L*15) // 15 mins | |
72 | |
73 #define NEWBOOT_DEFAULT (60*10) // 10 minutes | |
74 #define NEWBOOT_MIN (60*2) // 2 minutes | |
75 #define NEWBOOT_MAX (60*30) // 30 mins | |
76 | |
67 // eeprom-settable parameters, default values defined here. | 77 // eeprom-settable parameters, default values defined here. |
68 // all timeouts should be a multiple of TICK | 78 // all timeouts should be a multiple of TICK |
69 static uint32_t watchdog_long_limit = (60L*60*24); // 6 hours | 79 static uint32_t watchdog_long_limit = WATCHDOG_LONG_DEFAULT; |
70 static uint32_t watchdog_short_limit = 0; | 80 static uint32_t watchdog_short_limit = 0; |
71 static uint32_t newboot_limit = 60*10; // 10 minutes | 81 static uint32_t newboot_limit = NEWBOOT_DEFAULT; |
72 | 82 |
73 // avr proves itself | 83 // avr proves itself |
74 static uint8_t avr_keys[NKEYS][KEYLEN] = {{0}}; | 84 static uint8_t avr_keys[NKEYS][KEYLEN] = {{0}}; |
75 | 85 |
76 // ---- Atomic guards required accessing these variables | 86 // ---- Atomic guards required accessing these variables |
515 eeprom_read(watchdog_long_limit, watchdog_long_limit); | 525 eeprom_read(watchdog_long_limit, watchdog_long_limit); |
516 eeprom_read(watchdog_short_limit, watchdog_short_limit); | 526 eeprom_read(watchdog_short_limit, watchdog_short_limit); |
517 eeprom_read(newboot_limit, newboot_limit); | 527 eeprom_read(newboot_limit, newboot_limit); |
518 } | 528 } |
519 | 529 |
530 if (watchdog_long_limit < WATCHDOG_LONG_MIN | |
531 || watchdog_long_limit > WATCHDOG_LONG_MAX) | |
532 { | |
533 watchdog_long_limit = WATCHDOG_LONG_DEFAULT; | |
534 } | |
535 | |
536 if (watchdog_short_limit != 0 | |
537 && watchdog_short_limit < WATCHDOG_SHORT_MIN) | |
538 { | |
539 watchdog_short_limit = 0; | |
540 } | |
541 | |
542 if (newboot_limit < NEWBOOT_MIN || newboot_limit > NEWBOOT_MAX) | |
543 { | |
544 newboot_limit = NEWBOOT_DEFAULT; | |
545 } | |
546 | |
547 _Static_assert(NEWBOOT_MAX < WATCHDOG_LONG_MIN, "newboot max shorter than watchdog min"); | |
548 | |
520 eeprom_read(avr_keys, avr_keys); | 549 eeprom_read(avr_keys, avr_keys); |
521 } | 550 } |
522 | 551 |
523 static void | 552 static void |
524 cmd_alive() | 553 cmd_alive() |