// AVR timer interrupt scheduling code. // // Copyright (C) 2016 Kevin O'Connor // // This file may be distributed under the terms of the GNU GPLv3 license. #include // TCNT1 #include "autoconf.h" // CONFIG_AVR_CLKPR #include "board/misc.h" // timer_from_us #include "command.h" // shutdown #include "irq.h" // irq_save #include "sched.h" // sched_timer_kick /**************************************************************** * Low level timer code ****************************************************************/ DECL_CONSTANT(CLOCK_FREQ, F_CPU); // Return the number of clock ticks for a given number of microseconds uint32_t timer_from_us(uint32_t us) { return us * (F_CPU / 1000000); } static inline uint16_t timer_get(void) { return TCNT1; } static inline void timer_set(uint16_t next) { OCR1A = next; } static inline void timer_repeat_set(uint16_t next) { // Timer1B is used to limit the number of timers run from a timer1A irq OCR1B = next; TIFR1 = 1< TIMER_MIN_TRY_TICKS)) // Schedule next timer normally goto done; // Next timer in very near future - wait for it to be ready for (;;) { irq_enable(); if (unlikely(TIFR1 & (1<