46 #include <avr/interrupt.h> 
   51 #include "rtimer-arch.h" 
   53 #if defined(__AVR_ATmega1284P__) 
   67 #if defined(__AVR_ATmega1281__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega128RFA1__) 
   73 #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega644__) 
   81 extern uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE];
 
   82 #define DEBUGFLOW(c) if (debugflowsize<(DEBUGFLOWSIZE-1)) debugflow[debugflowsize++]=c 
   88 #if defined(TCNT3) && RTIMER_ARCH_PRESCALER 
   89 ISR (TIMER3_COMPA_vect) {
 
   91   ENERGEST_ON(ENERGEST_TYPE_IRQ);
 
   94   ETIMSK &= ~((1 << OCIE3A) | (1 << OCIE3B) | (1 << TOIE3) |
 
   95       (1 << TICIE3) | (1 << OCIE3C));
 
   97 #if RTIMER_CONF_NESTED_INTERRUPTS 
  106   ENERGEST_OFF(ENERGEST_TYPE_IRQ);
 
  110 #elif RTIMER_ARCH_PRESCALER 
  111 #warning "No Timer3 in rtimer-arch.c - using Timer1 instead" 
  112 ISR (TIMER1_COMPA_vect) {
 
  114   TIMSK &= ~((1<<TICIE1)|(1<<OCIE1A)|(1<<OCIE1B)|(1<<TOIE1));
 
  125 #if RTIMER_ARCH_PRESCALER 
  133   ETIMSK &= ~((1 << OCIE3A) | (1 << OCIE3B) | (1 << TOIE3) |
 
  134       (1 << TICIE3) | (1 << OCIE3C));
 
  136   ETIFR |= (1 << ICF3) | (1 << OCF3A) | (1 << OCF3B) | (1 << TOV3) |
 
  147 #if RTIMER_ARCH_PRESCALER==1024 
  149 #elif RTIMER_ARCH_PRESCALER==256 
  151 #elif RTIMER_ARCH_PRESCALER==64 
  153 #elif RTIMER_ARCH_PRESCALER==8 
  155 #elif RTIMER_ARCH_PRESCALER==1 
  158 #error Timer3 PRESCALER factor not supported. 
  161 #elif RTIMER_ARCH_PRESCALER 
  165   TIMSK &= ~((1<<TICIE1)|(1<<OCIE1A)|(1<<OCIE1B)|(1<<TOIE1));
 
  166   TIFR |= (1 << ICF1) | (1 << OCF1A) | (1 << OCF1B) | (1 << TOV1);
 
  176 #if RTIMER_ARCH_PRESCALER==1024 
  178 #elif RTIMER_ARCH_PRESCALER==256 
  180 #elif RTIMER_ARCH_PRESCALER==64 
  182 #elif RTIMER_ARCH_PRESCALER==8 
  184 #elif RTIMER_ARCH_PRESCALER==1 
  187 #error Timer1 PRESCALER factor not supported. 
  200 #if RTIMER_ARCH_PRESCALER 
  210   ETIFR |= (1 << ICF3) | (1 << OCF3A) | (1 << OCF3B) | (1 << TOV3) |
 
  213   ETIMSK |= (1 << OCIE3A);
 
  215 #elif RTIMER_ARCH_PRESCALER 
  218   TIFR |= (1 << ICF1) | (1 << OCF1A) | (1 << OCF1B) | (1 << TOV1);
 
  219   TIMSK |= (1 << OCIE1A);
 
  228 #if RDC_CONF_MCU_SLEEP 
  231 rtimer_arch_sleep(rtimer_clock_t howlong)
 
  240 #include <avr/sleep.h> 
  241 #include <dev/watchdog.h> 
  242 uint32_t longhowlong;
 
  243 #if AVR_CONF_USE32KCRYSTAL 
  245     uint8_t savedTCNT2=TCNT2, savedTCCR2A=TCCR2A, savedTCCR2B = TCCR2B, savedOCR2A = OCR2A;
 
  249         set_sleep_mode(SLEEP_MODE_PWR_SAVE);
 
  255 #if 0    //Prescale by 1024 -   32 ticks/sec, 8 seconds max sleep 
  256     TCCR2B =((1<<CS22)|(1<<CS21)|(1<<CS20));
 
  257         longhowlong=howlong*32UL; 
 
  258 #elif 0  // Prescale by 256 -  128 ticks/sec, 2 seconds max sleep 
  259         TCCR2B =((1<<CS22)|(1<<CS21)|(0<<CS20));
 
  260         longhowlong=howlong*128UL;
 
  261 #elif 0  // Prescale by 128 -  256 ticks/sec, 1 seconds max sleep 
  262         TCCR2B =((1<<CS22)|(0<<CS21)|(1<<CS20));
 
  263         longhowlong=howlong*256UL;
 
  264 #elif 0  // Prescale by  64 -  512 ticks/sec, 500 msec max sleep 
  265         TCCR2B =((1<<CS22)|(0<<CS21)|(0<<CS20));
 
  266         longhowlong=howlong*512UL;
 
  267 #elif 1  // Prescale by  32 - 1024 ticks/sec, 250 msec max sleep 
  268         TCCR2B =((0<<CS22)|(1<<CS21)|(1<<CS20));
 
  269         longhowlong=howlong*1024UL;
 
  270 #elif 0  // Prescale by   8 - 4096 ticks/sec, 62.5 msec max sleep 
  271         TCCR2B =((0<<CS22)|(1<<CS21)|(0<<CS20));
 
  272         longhowlong=howlong*4096UL;
 
  273 #else    // No Prescale -    32768 ticks/sec, 7.8 msec max sleep 
  274         TCCR2B =((0<<CS22)|(0<<CS21)|(1<<CS20));
 
  275         longhowlong=howlong*32768UL;
 
  277         OCR2A = longhowlong/RTIMER_ARCH_SECOND;
 
  281     while(ASSR & (1 << TCN2UB));
 
  284     TIMSK2 |= (1 << OCIE2A);
 
  287         ENERGEST_OFF(ENERGEST_TYPE_CPU);
 
  288         if (OCR2A) sleep_mode();
 
  295 #if RTIMER_ARCH_PRESCALER 
  302         ENERGEST_ON(ENERGEST_TYPE_CPU);
 
  304 #if AVR_CONF_USE32KCRYSTAL 
  307     TCCR2A = savedTCCR2A;
 
  308     TCCR2B = savedTCCR2B;
 
  314     TIMSK2 &= ~(1 << OCIE2A);
 
  319         longhowlong=CLOCK_CONF_SECOND;
 
  320         longhowlong*=howlong;
 
  324 #if !AVR_CONF_USE32KCRYSTAL 
  328 ISR(TIMER2_COMPA_vect)
 
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval. 
void rtimer_arch_init(void)
We don't need to explicitly initialise anything but this routine is required by the API...
    Header file for the energy estimation mechanism  
void clock_adjust_ticks(clock_time_t howmany)
Adjust the system current clock time. 
void watchdog_stop(void)
In watchdog mode, the WDT can not be stopped. 
    Header file for the real-time timer module. 
void rtimer_arch_schedule(rtimer_clock_t t)
Schedules an rtimer task to be triggered at time t. 
void rtimer_run_next(void)
Execute the next real-time task and schedule the next task, if any.