diff options
| author | Selene ToyKeeper | 2017-09-26 16:47:44 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2017-09-26 16:47:44 -0600 |
| commit | 45e3a7758046536754f073c42ac27dc737e69fab (patch) | |
| tree | 189c6c5e42b34d89e80ca4d13d78af4680043fd1 /spaghetti-monster/fsm-misc.c | |
| parent | Fixed moon in lockout state. Was too low since the MCU wasn't underclocked. (diff) | |
| download | anduril-45e3a7758046536754f073c42ac27dc737e69fab.tar.gz anduril-45e3a7758046536754f073c42ac27dc737e69fab.tar.bz2 anduril-45e3a7758046536754f073c42ac27dc737e69fab.zip | |
Added dynamic underclocking to FSM, instead of doing it manually in Anduril.
Diffstat (limited to 'spaghetti-monster/fsm-misc.c')
| -rw-r--r-- | spaghetti-monster/fsm-misc.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/spaghetti-monster/fsm-misc.c b/spaghetti-monster/fsm-misc.c index 5d28002..1b8f864 100644 --- a/spaghetti-monster/fsm-misc.c +++ b/spaghetti-monster/fsm-misc.c @@ -20,6 +20,25 @@ #ifndef FSM_MISC_C #define FSM_MISC_C +#ifdef USE_DYNAMIC_UNDERCLOCKING +void auto_clock_speed() { + uint8_t level = actual_level; // volatile, avoid repeat access + if (level < QUARTERSPEED_LEVEL) { + // run at quarter speed + // note: this only works when executed as two consecutive instructions + // (don't try to combine them or put other stuff between) + CLKPR = 1<<CLKPCE; CLKPR = 2; + } + else if (level < HALFSPEED_LEVEL) { + // run at half speed + CLKPR = 1<<CLKPCE; CLKPR = 1; + } else { + // run at full speed + CLKPR = 1<<CLKPCE; CLKPR = 0; + } +} +#endif + #if defined(USE_BLINK_NUM) || defined(USE_BLINK_DIGIT) uint8_t blink_digit(uint8_t num) { //StatePtr old_state = current_state; |
