3 #include "dev/clock-avr.h"
4 #include "sys/etimer.h"
7 #include <avr/interrupt.h>
9 /* RADIOSTATS should be also be defined in the radio driver and webserver */
10 #if RF230BB && WEBSERVER
14 static volatile clock_time_t count
, scount
, rcount
;
15 volatile unsigned long seconds
,radioontime
;
16 extern uint8_t RF230_receive_on
;
18 static volatile clock_time_t count
, scount
;
19 volatile unsigned long seconds
;
22 /*---------------------------------------------------------------------------*/
23 //SIGNAL(SIG_OUTPUT_COMPARE0)
24 ISR(AVR_OUTPUT_COMPARE_INT
)
27 if(++scount
== CLOCK_SECOND
) {
32 if (RF230_receive_on
) {
33 if (++rcount
== CLOCK_SECOND
) {
39 if(etimer_pending()) {
40 etimer_request_poll();
44 /* External clock source does not work ? */
50 TIMSK
&= ((unsigned char)~(1 << (TOIE0
)));
51 TIMSK
&= ((unsigned char)~(1 << (OCIE0
)));
52 /* Disable TC0 interrupt */
55 * set Timer/Counter0 to be asynchronous
56 * from the CPU clock with a second external
57 * clock(32,768kHz)driving it
60 TCCR0
= _BV (CS02
) | _BV (CS01
) | _BV (WGM1
);
65 TIMSK
|= (1 << (OCIE0
));
66 TIMSK
|= (1 << (TOIE0
));
71 /*---------------------------------------------------------------------------*/
81 * Counts the number of ticks. Since clock_time_t is an unsigned
82 * 16 bit data type, time intervals of up to 524 seconds can be
90 /*---------------------------------------------------------------------------*/
97 } while(tmp
!= count
);
100 /*---------------------------------------------------------------------------*/
102 * Delay the CPU for a multiple of TODO
105 clock_delay(unsigned int i
)
107 for (; i
> 0; i
--) { /* Needs fixing XXX */
109 for (j
= 50; j
> 0; j
--)
114 /*---------------------------------------------------------------------------*/
116 * Wait for a multiple of 1 / 125 sec = 0.008 ms.
124 start
= clock_time();
125 while(clock_time() - start
< (clock_time_t
)i
);
127 /*---------------------------------------------------------------------------*/
129 clock_set_seconds(unsigned long sec
)
140 } while(tmp
!= seconds
);