2 * Copyright (c) 2007, Swedish Institute of Computer Science.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * This file is part of the Contiki operating system.
31 * $Id: rtimer-arch.c,v 1.7 2010/02/18 17:21:44 dak664 Exp $
36 * AVR-specific rtimer code
37 * Currently only works on ATMEGAs that have Timer 3.
39 * Fredrik Osterlind <fros@sics.se>
40 * Joakim Eriksson <joakime@sics.se>
43 /* OBS: 8 seconds maximum time! */
46 #include <avr/interrupt.h>
49 #include "sys/energest.h"
50 #include "sys/rtimer.h"
51 #include "rtimer-arch.h"
53 #if defined(__AVR_ATmega1281__) || defined(__AVR_ATmega1284P__)
54 //#error FTH081029 test timer 3
59 //Has no 'C', so we just set it to B. The code doesn't really use C so this
60 //is safe to do but lets it compile
61 #warning No OCIE3C in architecture, hopefully it will not be needed
66 #if defined(__AVR_AT90USB1287__)
67 #warning AT90USB1287 rtimers not tested
73 /*---------------------------------------------------------------------------*/
75 ISR (TIMER3_COMPA_vect
) {
76 ENERGEST_ON(ENERGEST_TYPE_IRQ
);
78 ETIMSK
&= ~((1 << OCIE3A
) | (1 << OCIE3B
) | (1 << TOIE3
) |
79 (1 << TICIE3
) | (1 << OCIE3C
));
81 /* Call rtimer callback */
84 ENERGEST_OFF(ENERGEST_TYPE_IRQ
);
88 #error "No Timer3 in rtimer-arch.c"
91 /*---------------------------------------------------------------------------*/
93 rtimer_arch_init(void)
95 /* Disable interrupts (store old state) */
103 ETIMSK
&= ~((1 << OCIE3A
) | (1 << OCIE3B
) | (1 << TOIE3
) |
104 (1 << TICIE3
) | (1 << OCIE3C
));
105 ETIFR
|= (1 << ICF3
) | (1 << OCF3A
) | (1 << OCF3B
) | (1 << TOV3
) |
108 /* Default timer behaviour */
116 /* Maximum prescaler */
120 #error "No Timer3 in rtimer-arch.c"
124 /* Restore interrupt state */
127 /*---------------------------------------------------------------------------*/
129 rtimer_arch_schedule(rtimer_clock_t t
)
131 /* Disable interrupts (store old state) */
138 /* Set compare register */
140 ETIFR
|= (1 << ICF3
) | (1 << OCF3A
) | (1 << OCF3B
) | (1 << TOV3
) |
142 ETIMSK
|= (1 << OCIE3A
);
145 #error "No Timer3 in rtimer-arch.c"
149 /* Restore interrupt state */