From f997ec62313cc6c31a9b18ee726a8ecf62051e26 Mon Sep 17 00:00:00 2001 From: joxe Date: Tue, 11 Dec 2007 17:21:14 +0000 Subject: [PATCH] fixed defs and to compile for atmega32 also - has no TCNT3 --- cpu/avr/avrdef.h | 6 +++++- cpu/avr/rtimer-arch.c | 13 ++++++++++++- cpu/avr/rtimer-arch.h | 8 +++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/cpu/avr/avrdef.h b/cpu/avr/avrdef.h index dd4f99336..4cb3eaa01 100644 --- a/cpu/avr/avrdef.h +++ b/cpu/avr/avrdef.h @@ -26,12 +26,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)$Id: avrdef.h,v 1.1 2007/08/16 13:20:09 bg- Exp $ + * @(#)$Id: avrdef.h,v 1.2 2007/12/11 17:21:14 joxe Exp $ */ #ifndef AVRDEF_H #define AVRDEF_H +/* SREG is defined in this file */ +#include +#include + #ifdef HAVE_STDINT_H #include #else diff --git a/cpu/avr/rtimer-arch.c b/cpu/avr/rtimer-arch.c index fd03878e3..dce3407e5 100644 --- a/cpu/avr/rtimer-arch.c +++ b/cpu/avr/rtimer-arch.c @@ -28,14 +28,16 @@ * * This file is part of the Contiki operating system. * - * $Id: rtimer-arch.c,v 1.1 2007/11/29 02:44:05 fros4943 Exp $ + * $Id: rtimer-arch.c,v 1.2 2007/12/11 17:21:14 joxe Exp $ */ /** * \file * AVR-specific rtimer code + * Currently only works on ATMEGAs that have Timer 3. * \author * Fredrik Osterlind + * Joakim Eriksson */ /* OBS: 8 seconds maximum time! */ @@ -48,6 +50,7 @@ #include "rtimer-arch.h" /*---------------------------------------------------------------------------*/ +#ifdef TCNT3 SIGNAL (SIG_OUTPUT_COMPARE3A) { ENERGEST_ON(ENERGEST_TYPE_IRQ); @@ -59,6 +62,7 @@ SIGNAL (SIG_OUTPUT_COMPARE3A) { ENERGEST_OFF(ENERGEST_TYPE_IRQ); } +#endif /*---------------------------------------------------------------------------*/ void rtimer_arch_init(void) @@ -68,6 +72,8 @@ rtimer_arch_init(void) sreg = SREG; cli (); +#ifdef TCNT3 + ETIMSK &= ~((1 << OCIE3A) | (1 << OCIE3B) | (1 << TOIE3) | (1 << TICIE3) | (1 << OCIE3C)); ETIFR |= (1 << ICF3) | (1 << OCF3A) | (1 << OCF3B) | (1 << TOV3) | @@ -84,6 +90,8 @@ rtimer_arch_init(void) /* Maximum prescaler */ TCCR3B |= 5; +#endif + /* Restore interrupt state */ SREG = sreg; } @@ -96,12 +104,15 @@ rtimer_arch_schedule(rtimer_clock_t t) sreg = SREG; cli (); +#ifdef TCNT3 /* Set compare register */ OCR3A = t; ETIFR |= (1 << ICF3) | (1 << OCF3A) | (1 << OCF3B) | (1 << TOV3) | (1 << OCF3C); ETIMSK |= (1 << OCIE3A); +#endif + /* Restore interrupt state */ SREG = sreg; } diff --git a/cpu/avr/rtimer-arch.h b/cpu/avr/rtimer-arch.h index 6f8886b17..93319edf4 100644 --- a/cpu/avr/rtimer-arch.h +++ b/cpu/avr/rtimer-arch.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: rtimer-arch.h,v 1.3 2007/11/29 02:44:05 fros4943 Exp $ + * $Id: rtimer-arch.h,v 1.4 2007/12/11 17:21:14 joxe Exp $ */ #ifndef __RTIMER_ARCH_H__ @@ -38,6 +38,12 @@ #define RTIMER_ARCH_SECOND (8192) +/* Handle that not all AVRs have TCNT3 - this should be configuratble + in contiki-conf later! */ +#ifdef TCNT3 #define rtimer_arch_now() (TCNT3) +#else +#define rtimer_arch_now() (0) +#endif #endif /* __RTIMER_ARCH_H__ */