X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=drv%2Ftimer_avr.h;h=24db1bcf8102d33d68809b2f5c809a489d3a55a6;hb=3bb41294aab4b0d1ee4cf5bea166848180863b54;hp=acaeff6d5105ae04d96bffbe52f9e0b2c81eaf58;hpb=93f604197657bbeab793d2a345a347c32f01d2be;p=bertos.git diff --git a/drv/timer_avr.h b/drv/timer_avr.h index acaeff6d..24db1bcf 100755 --- a/drv/timer_avr.h +++ b/drv/timer_avr.h @@ -15,6 +15,27 @@ /* * $Log$ + * Revision 1.11 2004/08/03 15:53:17 aleph + * Fix spacing + * + * Revision 1.10 2004/08/02 20:20:29 aleph + * Merge from project_ks + * + * Revision 1.9 2004/07/22 02:01:14 bernie + * Use TIMER_PRESCALER consistently. + * + * Revision 1.8 2004/07/20 23:50:20 bernie + * Also define TIMER_PRESCALER. + * + * Revision 1.7 2004/07/20 23:49:40 bernie + * Compute value of OCR_DIVISOR from CLOCK_FREQ. + * + * Revision 1.6 2004/07/20 23:48:16 bernie + * Finally remove redundant protos. + * + * Revision 1.5 2004/07/18 22:16:35 bernie + * Add missing header; Prevent warning for project_ks-specific code. + * * Revision 1.4 2004/06/27 15:22:15 aleph * Fix spacing * @@ -33,19 +54,23 @@ #define DRV_TIMER_AVR_H #include +#include -#if (ARCH & ARCH_BOARD_KC) +#if defined(ARCH_BOARD_KC) && (ARCH & ARCH_BOARD_KC) #include #endif -#define timer_hw_irq() /* Not needed, IRQ timer flag cleared automatically */ +/* Not needed, IRQ timer flag cleared automatically */ +#define timer_hw_irq() do {} while (0) + +#define TIMER_PRESCALER 64 /*! * System timer: additional division after the prescaler * 12288000 / 64 / 192 (0..191) = 1 ms */ -#define OCR_DIVISOR 191 +#define OCR_DIVISOR (CLOCK_FREQ / TIMER_PRESCALER / TICKS_PER_SEC - 1) /* 191 */ /*! HW dependent timer initialization */ #if defined(CONFIG_TIMER_ON_TIMER0) @@ -62,10 +87,15 @@ TIFR = BV(OCF0) | BV(TOV0); /* Setup Timer/Counter interrupt */ - ASSR = 0x00; /* internal system clock */ - TCCR0 = BV(WGM01) | BV(CS02); /* Clear on Compare match & prescaler = 64. When changing - prescaler change TIMER_HW_HPTICKS_PER_SEC too */ - TCNT0 = 0x00; /* initialization of Timer/Counter */ + ASSR = 0x00; /* Internal system clock */ + TCCR0 = BV(WGM01) /* Clear on Compare match */ + #if TIMER_PRESCALER == 64 + | BV(CS02) + #else + #error Unsupported value of TIMER_PRESCALER + #endif + ; + TCNT0 = 0x00; /* Initialization of Timer/Counter */ OCR0 = OCR_DIVISOR; /* Timer/Counter Output Compare Register */ /* Enable timer interrupts: Timer/Counter2 Output Compare (OCIE2) */ @@ -76,9 +106,8 @@ } //! Frequency of the hardware high precision timer - #define TIMER_HW_HPTICKS_PER_SEC (CLOCK_FREQ / 64) + #define TIMER_HW_HPTICKS_PER_SEC (CLOCK_FREQ / TIMER_PRESCALER) - INLINE hptime_t timer_hw_hpread(void); INLINE hptime_t timer_hw_hpread(void) { return TCNT0; @@ -115,7 +144,6 @@ //! Frequency of the hardware high precision timer #define TIMER_HW_HPTICKS_PER_SEC (24000ul * 512) - INLINE hptime_t timer_hw_hpread(void); INLINE hptime_t timer_hw_hpread(void) { return TCNT1; @@ -135,7 +163,13 @@ TIFR = BV(OCF2) | BV(TOV2); /* Setup Timer/Counter interrupt */ - TCCR2 = BV(WGM21) | BV(CS21) | BV(CS20); + TCCR2 = BV(WGM21) + #if TIMER_PRESCALER == 64 + | BV(CS21) | BV(CS20) + #else + #error Unsupported value of TIMER_PRESCALER + #endif + ; /* Clear on Compare match & prescaler = 64, internal sys clock. When changing prescaler change TIMER_HW_HPTICKS_PER_SEC too */ TCNT2 = 0x00; /* initialization of Timer/Counter */ @@ -149,9 +183,8 @@ } //! Frequency of the hardware high precision timer - #define TIMER_HW_HPTICKS_PER_SEC (CLOCK_FREQ / 64) + #define TIMER_HW_HPTICKS_PER_SEC (CLOCK_FREQ / TIMER_PRESCALER) - INLINE hptime_t timer_hw_hpread(void); INLINE hptime_t timer_hw_hpread(void) { return TCNT2;