diff options
author | Fabio Utzig <utzig@utzig.org> | 2016-04-09 13:57:38 +0000 |
---|---|---|
committer | Fabio Utzig <utzig@utzig.org> | 2016-04-09 13:57:38 +0000 |
commit | d873e4ed7bc231daa6cb378b3a300b457ff0e0cf (patch) | |
tree | 3c5e1cc07e5de902c7adcb55e8837f49e961d881 /os/hal/ports/AVR/hal_st_lld.c | |
parent | aa91fa657699d253a915fc392e4e8af9e54c6c93 (diff) | |
download | ChibiOS-d873e4ed7bc231daa6cb378b3a300b457ff0e0cf.tar.gz ChibiOS-d873e4ed7bc231daa6cb378b3a300b457ff0e0cf.tar.bz2 ChibiOS-d873e4ed7bc231daa6cb378b3a300b457ff0e0cf.zip |
[AVR] Fix timer usage for ATmega128
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9263 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/ports/AVR/hal_st_lld.c')
-rw-r--r-- | os/hal/ports/AVR/hal_st_lld.c | 51 |
1 files changed, 38 insertions, 13 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 */
|