X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=cpu%2Favr%2Fdrv%2Ftimer_avr.h;fp=cpu%2Favr%2Fdrv%2Ftimer_avr.h;h=74414263123c9dbcdd838f6a460ea6b2e8d0ec24;hb=3110ae0831fa4ba081c9206663390e21c7a4f78a;hp=5d0eba36eb8e632738a9b1be21c72caca8a68aa1;hpb=d9f99c9f43f39c988c2df5bab952818105f5cb58;p=bertos.git diff --git a/cpu/avr/drv/timer_avr.h b/cpu/avr/drv/timer_avr.h index 5d0eba36..74414263 100644 --- a/cpu/avr/drv/timer_avr.h +++ b/cpu/avr/drv/timer_avr.h @@ -88,6 +88,7 @@ #include /* CONFIG_TIMER */ #include /* uint8_t */ +#include /* DIV_ROUND */ #include /* CLOCK_FREQ */ /** @@ -127,7 +128,7 @@ /** This value is the maximum in overflow based timers. */ #define TIMER_HW_CNT (1 << TIMER_HW_BITS) #define DEFINE_TIMER_ISR SIGNAL(SIG_OVERFLOW1) - #define TIMER_TICKS_PER_SEC ((TIMER_HW_HPTICKS_PER_SEC + TIMER_HW_CNT / 2) / TIMER_HW_CNT) + #define TIMER_TICKS_PER_SEC DIV_ROUND(TIMER_HW_HPTICKS_PER_SEC, TIMER_HW_CNT) /// Type of time expressed in ticks of the hardware high precision timer typedef uint16_t hptime_t; @@ -156,7 +157,7 @@ /** This value is the maximum in overflow based timers. */ #define TIMER_HW_CNT (1 << TIMER_HW_BITS) #define DEFINE_TIMER_ISR SIGNAL(SIG_OVERFLOW3) - #define TIMER_TICKS_PER_SEC ((TIMER_HW_HPTICKS_PER_SEC + TIMER_HW_CNT / 2) / TIMER_HW_CNT) + #define TIMER_TICKS_PER_SEC DIV_ROUND(TIMER_HW_HPTICKS_PER_SEC, TIMER_HW_CNT) /// Type of time expressed in ticks of the hardware high precision timer typedef uint16_t hptime_t; @@ -167,13 +168,13 @@ /** Frequency of the hardware high precision timer. */ -#define TIMER_HW_HPTICKS_PER_SEC ((CLOCK_FREQ + TIMER_PRESCALER / 2) / TIMER_PRESCALER) +#define TIMER_HW_HPTICKS_PER_SEC DIV_ROUND(CLOCK_FREQ, TIMER_PRESCALER) /** * System timer: additional division after the prescaler * 12288000 / 64 / 192 (0..191) = 1 ms */ -#define OCR_DIVISOR (((CLOCK_FREQ + TIMER_PRESCALER / 2) / TIMER_PRESCALER + TIMER_TICKS_PER_SEC / 2) / TIMER_TICKS_PER_SEC - 1) +#define OCR_DIVISOR (DIV_ROUND(DIV_ROUND(CLOCK_FREQ, TIMER_PRESCALER), TIMER_TICKS_PER_SEC) - 1) /** Not needed, IRQ timer flag cleared automatically */ #define timer_hw_irq() do {} while (0)