fixed defs and to compile for atmega32 also - has no TCNT3

This commit is contained in:
joxe 2007-12-11 17:21:14 +00:00
parent 486ea95b4f
commit f997ec6231
3 changed files with 24 additions and 3 deletions

View File

@ -26,12 +26,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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 #ifndef AVRDEF_H
#define AVRDEF_H #define AVRDEF_H
/* SREG is defined in this file */
#include <avr/io.h>
#include <avr/interrupt.h>
#ifdef HAVE_STDINT_H #ifdef HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#else #else

View File

@ -28,14 +28,16 @@
* *
* This file is part of the Contiki operating system. * 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 * \file
* AVR-specific rtimer code * AVR-specific rtimer code
* Currently only works on ATMEGAs that have Timer 3.
* \author * \author
* Fredrik Osterlind <fros@sics.se> * Fredrik Osterlind <fros@sics.se>
* Joakim Eriksson <joakime@sics.se>
*/ */
/* OBS: 8 seconds maximum time! */ /* OBS: 8 seconds maximum time! */
@ -48,6 +50,7 @@
#include "rtimer-arch.h" #include "rtimer-arch.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#ifdef TCNT3
SIGNAL (SIG_OUTPUT_COMPARE3A) { SIGNAL (SIG_OUTPUT_COMPARE3A) {
ENERGEST_ON(ENERGEST_TYPE_IRQ); ENERGEST_ON(ENERGEST_TYPE_IRQ);
@ -59,6 +62,7 @@ SIGNAL (SIG_OUTPUT_COMPARE3A) {
ENERGEST_OFF(ENERGEST_TYPE_IRQ); ENERGEST_OFF(ENERGEST_TYPE_IRQ);
} }
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
rtimer_arch_init(void) rtimer_arch_init(void)
@ -68,6 +72,8 @@ rtimer_arch_init(void)
sreg = SREG; sreg = SREG;
cli (); cli ();
#ifdef TCNT3
ETIMSK &= ~((1 << OCIE3A) | (1 << OCIE3B) | (1 << TOIE3) | ETIMSK &= ~((1 << OCIE3A) | (1 << OCIE3B) | (1 << TOIE3) |
(1 << TICIE3) | (1 << OCIE3C)); (1 << TICIE3) | (1 << OCIE3C));
ETIFR |= (1 << ICF3) | (1 << OCF3A) | (1 << OCF3B) | (1 << TOV3) | ETIFR |= (1 << ICF3) | (1 << OCF3A) | (1 << OCF3B) | (1 << TOV3) |
@ -84,6 +90,8 @@ rtimer_arch_init(void)
/* Maximum prescaler */ /* Maximum prescaler */
TCCR3B |= 5; TCCR3B |= 5;
#endif
/* Restore interrupt state */ /* Restore interrupt state */
SREG = sreg; SREG = sreg;
} }
@ -96,12 +104,15 @@ rtimer_arch_schedule(rtimer_clock_t t)
sreg = SREG; sreg = SREG;
cli (); cli ();
#ifdef TCNT3
/* Set compare register */ /* Set compare register */
OCR3A = t; OCR3A = t;
ETIFR |= (1 << ICF3) | (1 << OCF3A) | (1 << OCF3B) | (1 << TOV3) | ETIFR |= (1 << ICF3) | (1 << OCF3A) | (1 << OCF3B) | (1 << TOV3) |
(1 << OCF3C); (1 << OCF3C);
ETIMSK |= (1 << OCIE3A); ETIMSK |= (1 << OCIE3A);
#endif
/* Restore interrupt state */ /* Restore interrupt state */
SREG = sreg; SREG = sreg;
} }

View File

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * 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__ #ifndef __RTIMER_ARCH_H__
@ -38,6 +38,12 @@
#define RTIMER_ARCH_SECOND (8192) #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) #define rtimer_arch_now() (TCNT3)
#else
#define rtimer_arch_now() (0)
#endif
#endif /* __RTIMER_ARCH_H__ */ #endif /* __RTIMER_ARCH_H__ */