From d873e4ed7bc231daa6cb378b3a300b457ff0e0cf Mon Sep 17 00:00:00 2001 From: Fabio Utzig Date: Sat, 9 Apr 2016 13:57:38 +0000 Subject: [AVR] Fix timer usage for ATmega128 git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9263 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/AVR/hal_st_lld.c | 51 ++++++++++++++++++++++++++++++++----------- os/hal/ports/AVR/hal_st_lld.h | 18 +++++++++++---- 2 files changed, 52 insertions(+), 17 deletions(-) (limited to 'os/hal/ports') diff --git a/os/hal/ports/AVR/hal_st_lld.c b/os/hal/ports/AVR/hal_st_lld.c index 4d5b545e8..0a33f16ab 100644 --- a/os/hal/ports/AVR/hal_st_lld.c +++ b/os/hal/ports/AVR/hal_st_lld.c @@ -62,20 +62,45 @@ /* Find the most suitable prescaler setting for the desired OSAL_ST_FREQUENCY */ #if ((F_CPU / OSAL_ST_FREQUENCY) <= AVR_TIMER_COUNTER_MAX) + #define AVR_TIMER_PRESCALER 1 - #define AVR_TIMER_PRESCALER_BITS (0< + /*===========================================================================*/ /* Driver constants. */ /*===========================================================================*/ @@ -68,6 +70,14 @@ extern "C" { } #endif +#ifdef __AVR_ATmega128__ +#define TIFR_REG TIFR +#define TIMSK_REG TIMSK +#else +#define TIFR_REG TIFR1 +#define TIMSK_REG TIMSK1 +#endif + /*===========================================================================*/ /* Driver inline functions. */ /*===========================================================================*/ @@ -98,10 +108,10 @@ static inline void st_lld_start_alarm(systime_t time) { OCR1A = (uint16_t) time; /* Reset pending. */ - TIFR1 = _BV(OCF1A); + TIFR_REG = _BV(OCF1A); /* enable interrupt */ - TIMSK1 = _BV(OCIE1A); + TIMSK_REG = _BV(OCIE1A); } /** @@ -111,7 +121,7 @@ static inline void st_lld_start_alarm(systime_t time) { */ static inline void st_lld_stop_alarm(void) { - TIMSK1 = 0; + TIMSK_REG = 0; } /** @@ -149,7 +159,7 @@ static inline systime_t st_lld_get_alarm(void) { */ static inline bool st_lld_is_alarm_active(void) { - return (bool) ((TIMSK1 & _BV(OCIE1A)) != 0); + return (bool) ((TIMSK_REG & _BV(OCIE1A)) != 0); } #endif /* _ST_LLD_H_ */ -- cgit v1.2.3