From e88f60feee8b3ab6c24ce7027916826d4924c088 Mon Sep 17 00:00:00 2001 From: Ralf Schlatterbeck Date: Sat, 31 May 2014 16:17:07 +0200 Subject: [PATCH] Make HW timer for contiki rtimer configurable ... and configure osd platform to use timer 5. With the new configuration we can use timer 3 for generating hardware PWM. --- cpu/avr/rtimer-arch.c | 142 +++++++++--------------- cpu/avr/rtimer-arch.h | 39 ++++++- platform/osd-merkur/Makefile.osd-merkur | 2 +- 3 files changed, 86 insertions(+), 97 deletions(-) diff --git a/cpu/avr/rtimer-arch.c b/cpu/avr/rtimer-arch.c index d1d97af7e..fe978a24c 100644 --- a/cpu/avr/rtimer-arch.c +++ b/cpu/avr/rtimer-arch.c @@ -51,29 +51,24 @@ #include "rtimer-arch.h" #if defined(__AVR_ATmega1284P__) -#define ETIMSK TIMSK3 -#define ETIFR TIFR3 -#define TICIE3 ICIE3 - //Has no 'C', so we just set it to B. The code doesn't really use C so this //is safe to do but lets it compile. Probably should enable the warning if //it is ever used on other platforms. //#warning no OCIE3C in timer3 architecture, hopefully it won't be needed! - #define OCIE3C OCIE3B #define OCF3C OCF3B +#define PLAT_TCCRC PLAT_TCCRB #endif #if defined(__AVR_ATmega1281__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega128RFA1__) -#define ETIMSK TIMSK3 -#define ETIFR TIFR3 -#define TICIE3 ICIE3 #endif #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega644__) -#define TIMSK TIMSK1 -#define TICIE1 ICIE1 -#define TIFR TIFR1 +//Has no 'C', so we just set it to B. The code doesn't really use C so this +//is safe to do but lets it compile. +#define OCIE1C OCIE1B +#define OCF1C OCF1B +#define PLAT_TCCRC PLAT_TCCRB #endif /* Track flow through rtimer interrupts*/ @@ -85,14 +80,19 @@ extern uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE]; #endif /*---------------------------------------------------------------------------*/ -#if defined(TCNT3) && RTIMER_ARCH_PRESCALER -ISR (TIMER3_COMPA_vect) { +#if RTIMER_ARCH_PRESCALER +ISR (PLAT_VECT) { DEBUGFLOW('/'); ENERGEST_ON(ENERGEST_TYPE_IRQ); /* Disable rtimer interrupts */ - ETIMSK &= ~((1 << OCIE3A) | (1 << OCIE3B) | (1 << TOIE3) | - (1 << TICIE3) | (1 << OCIE3C)); + PLAT_TIMSK &= + ~( (1 << PLAT_OCIEA) + | (1 << PLAT_OCIEB) + | (1 << PLAT_OCIEC) + | (1 << PLAT_TOIE) + | (1 << PLAT_ICIE) + ); #if RTIMER_CONF_NESTED_INTERRUPTS /* Enable nested interrupts. Allows radio interrupt during rtimer interrupt. */ @@ -106,17 +106,6 @@ ISR (TIMER3_COMPA_vect) { ENERGEST_OFF(ENERGEST_TYPE_IRQ); DEBUGFLOW('\\'); } - -#elif RTIMER_ARCH_PRESCALER -#warning "No Timer3 in rtimer-arch.c - using Timer1 instead" -ISR (TIMER1_COMPA_vect) { - DEBUGFLOW('/'); - TIMSK &= ~((1<