3 #include "dev/clock-avr.h"
4 #include "sys/etimer.h"
7 #include <avr/interrupt.h>
9 static volatile clock_time_t count
;
10 static volatile uint8_t scount
;
11 volatile unsigned long seconds
;
13 /* Set RADIOSTATS to monitor radio on time (must also be set in the radio driver) */
14 #if RF230BB && WEBSERVER
18 static volatile uint8_t rcount
;
19 volatile unsigned long radioontime
;
20 extern uint8_t RF230_receive_on
;
24 CLOCK_SECOND is the number of ticks per second.
25 It is defined through CONF_CLOCK_SECOND in the contiki-conf.h for each platform.
26 The usual AVR default is ~125 ticks per second, counting a prescaler the CPU clock
27 using the 8 bit timer0.
29 As clock_time_t is an unsigned 16 bit data type, intervals up to 524 seconds
30 can be measured with 8 millisecond precision.
31 For longer intervals a 32 bit global is incremented every second.
33 clock-avr.h contains the specific setup code for each mcu.
35 /*---------------------------------------------------------------------------*/
36 //SIGNAL(SIG_OUTPUT_COMPARE0)
37 ISR(AVR_OUTPUT_COMPARE_INT
)
40 if(++scount
== CLOCK_SECOND
) {
45 if (RF230_receive_on
) {
46 if (++rcount
== CLOCK_SECOND
) {
52 if(etimer_pending()) {
53 etimer_request_poll();
57 /*---------------------------------------------------------------------------*/
67 /*---------------------------------------------------------------------------*/
74 } while(tmp
!= count
);
77 /*---------------------------------------------------------------------------*/
79 * Delay the CPU for a multiple of TODO
82 clock_delay(unsigned int i
)
84 for (; i
> 0; i
--) { /* Needs fixing XXX */
86 for (j
= 50; j
> 0; j
--)
91 /*---------------------------------------------------------------------------*/
93 * Wait for a multiple of 1 / 125 sec = 0.008 ms.
101 start
= clock_time();
102 while(clock_time() - start
< (clock_time_t
)i
);
104 /*---------------------------------------------------------------------------*/
106 clock_set_seconds(unsigned long sec
)
117 } while(tmp
!= seconds
);