diff options
Diffstat (limited to 'os/hal/ports/AVR')
-rw-r--r-- | os/hal/ports/AVR/hal_st_lld.c | 51 | ||||
-rw-r--r-- | os/hal/ports/AVR/hal_st_lld.h | 18 |
2 files changed, 52 insertions, 17 deletions
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<<CS02)|(0<<CS01)|(1<<CS00); /* CLK */
+ #define AVR_TIMER_PRESCALER_BITS ((0<<CS02)|(0<<CS01)|(1<<CS00)) /* CLK */
+
#elif ((F_CPU / OSAL_ST_FREQUENCY / 8) <= AVR_TIMER_COUNTER_MAX)
+
#define AVR_TIMER_PRESCALER 8
- #define AVR_TIMER_PRESCALER_BITS (0<<CS02)|(1<<CS01)|(0<<CS00); /* CLK/8 */
+ #define AVR_TIMER_PRESCALER_BITS ((0<<CS02)|(1<<CS01)|(0<<CS00)) /* CLK/8 */
+
#elif ((F_CPU / OSAL_ST_FREQUENCY / 64) <= AVR_TIMER_COUNTER_MAX)
+
#define AVR_TIMER_PRESCALER 64
- #define AVR_TIMER_PRESCALER_BITS (0<<CS02)|(1<<CS01)|(1<<CS00); /* CLK/64 */
+
+ #ifdef __AVR_ATmega128__
+ #define AVR_TIMER_PRESCALER_BITS ((1<<CS02)|(0<<CS01)|(0<<CS00)) /* CLK/64 */
+ #else
+ #define AVR_TIMER_PRESCALER_BITS ((0<<CS02)|(1<<CS01)|(1<<CS00)) /* CLK/64 */
+ #endif
+
#elif ((F_CPU / OSAL_ST_FREQUENCY / 256) <= AVR_TIMER_COUNTER_MAX)
+
#define AVR_TIMER_PRESCALER 256
- #define AVR_TIMER_PRESCALER_BITS (1<<CS02)|(0<<CS01)|(0<<CS00); /* CLK/256 */
+
+ #ifdef __AVR_ATmega128__
+ #define AVR_TIMER_PRESCALER_BITS ((1<<CS02)|(1<<CS01)|(0<<CS00)) /* CLK/256 */
+ #else
+ #define AVR_TIMER_PRESCALER_BITS ((1<<CS02)|(0<<CS01)|(0<<CS00)) /* CLK/256 */
+ #endif
+
#elif ((F_CPU / OSAL_ST_FREQUENCY / 1024) <= AVR_TIMER_COUNTER_MAX)
+
#define AVR_TIMER_PRESCALER 1024
- #define AVR_TIMER_PRESCALER_BITS (1<<CS02)|(0<<CS01)|(1<<CS00); /* CLK/1024 */
+
+ #ifdef __AVR_ATmega128__
+ #define AVR_TIMER_PRESCALER_BITS (1<<CS02)|(1<<CS01)|(1<<CS00); /* CLK/1024 */
+ #else
+ #define AVR_TIMER_PRESCALER_BITS (1<<CS02)|(0<<CS01)|(1<<CS00); /* CLK/1024 */
+ #endif
+
#else
#error "Frequency too low for timer, please set OSAL_ST_FREQUENCY to a higher value"
#endif
@@ -165,16 +190,16 @@ void st_lld_init(void) { */
/* CTC mode, no clock source */
- TCCR1A = 0;
- TCCR1B = _BV(WGM12);
+ TCCR1A = 0;
+ TCCR1B = _BV(WGM12);
/* start disabled */
- TCCR1C = 0;
- OCR1A = 0;
- TCNT1 = 0;
- TIFR1 = _BV(OCF1A); /* Reset pending. */
- TIMSK1 = 0;
- TCCR1B = PRESCALER;
+ TCCR1C = 0;
+ OCR1A = 0;
+ TCNT1 = 0;
+ TIFR_REG = _BV(OCF1A); /* Reset pending. */
+ TIMSK_REG = 0;
+ TCCR1B = PRESCALER;
#endif /* OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING */
diff --git a/os/hal/ports/AVR/hal_st_lld.h b/os/hal/ports/AVR/hal_st_lld.h index 96b0169e3..223a6ed37 100644 --- a/os/hal/ports/AVR/hal_st_lld.h +++ b/os/hal/ports/AVR/hal_st_lld.h @@ -27,6 +27,8 @@ #ifndef _ST_LLD_H_
#define _ST_LLD_H_
+#include <avr/io.h>
+
/*===========================================================================*/
/* 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_ */
|