67 #include "sys/clock.h"
68 #include "dev/clock-avr.h"
72 #include <avr/interrupt.h>
75 #if CLOCK_SECOND && (CLOCK_SECOND - 1)
76 #define TWO_COUNTERS 1
80 static volatile clock_time_t count;
83 static volatile uint8_t scount;
86 volatile unsigned long seconds;
91 #if RF230BB && AVR_WEBSERVER
96 static volatile uint8_t rcount;
97 volatile unsigned long radioontime;
98 extern uint8_t RF230_receive_on;
106 #if RADIO_CONF_CALIBRATE_INTERVAL
107 extern volatile uint8_t rf230_calibrate;
108 static uint8_t calibrate_interval;
134 }
while(tmp != count);
149 }
while(tmp != seconds);
169 if (
sizeof(clock_time_t) == 1) {
170 while ((
signed char )(
clock_time() - endticks) < 0) {;}
171 }
else if (
sizeof(clock_time_t) == 2) {
172 while ((
signed short)(
clock_time() - endticks) < 0) {;}
174 while ((
signed long )(
clock_time() - endticks) < 0) {;}
184 static inline void my_delay_loop_2(uint16_t __count)
__attribute__((always_inline));
186 my_delay_loop_2(uint16_t __count)
189 "1: sbiw %0,1" "\n\t"
202 if(howlong<=(uint16_t)(279000000UL/
F_CPU))
return;
203 howlong-=(uint16_t) (279000000UL/
F_CPU);
204 my_delay_loop_2(((uint64_t)(howlong) * (uint64_t)
F_CPU) / 4000000ULL);
207 #elif F_CPU>=16000000UL
208 if(howlong<1)
return;
209 my_delay_loop_2((howlong*(uint16_t)(F_CPU/3250000)));
210 #elif F_CPU >= 12000000UL
211 if(howlong<2)
return;
212 howlong-=(uint16_t) (3*12000000/F_CPU);
213 my_delay_loop_2((howlong*(uint16_t)(F_CPU/3250000)));
214 #elif F_CPU >= 8000000UL
215 if(howlong<4)
return;
216 howlong-=(uint16_t) (3*8000000/F_CPU);
217 my_delay_loop_2((howlong*(uint16_t)(F_CPU/2000000))/2);
218 #elif F_CPU >= 4000000UL
219 if(howlong<5)
return;
220 howlong-=(uint16_t) (4*4000000/F_CPU);
221 my_delay_loop_2((howlong*(uint16_t)(F_CPU/2000000))/2);
222 #elif F_CPU >= 2000000UL
223 if(howlong<11)
return;
224 howlong-=(uint16_t) (10*2000000/F_CPU);
225 my_delay_loop_2((howlong*(uint16_t)(F_CPU/1000000))/4);
226 #elif F_CPU >= 1000000UL
227 if(howlong<=17)
return;
228 howlong-=(uint16_t) (17*1000000/F_CPU);
229 my_delay_loop_2((howlong*(uint16_t)(F_CPU/1000000))/4);
232 if (howlong < 1)
return;
233 my_delay_loop_2(howlong);
246 if(howlong<2)
return;
291 uint8_t sreg = SREG;cli();
301 if (RF230_receive_on) radioontime += 1;
337 #if RADIO_CONF_CALIBRATE_INTERVAL
339 if (++calibrate_interval==0) {
348 if (RF230_receive_on) {
356 #if F_CPU == 0x800000 && USE_32K_CRYSTAL
366 #include "rtimer-arch.h"
368 volatile static uint8_t lockcount;
369 volatile static int16_t last_phase;
370 volatile static uint8_t osccalhigh,osccallow;
372 if(++lockcount >= 8192UL*128/RTIMER_ARCH_SECOND) {
374 rtimer_phase = TCNT3 & 0x0fff;
375 if (seconds < 2) OSCCAL=100;
376 if (last_phase > rtimer_phase) osccalhigh=++OSCCAL;
else osccallow=--OSCCAL;
377 last_phase = rtimer_phase;
380 uint8_t error = (TCNT3 - last_phase) & 0x3f;
382 }
else if (error<32) {
398 extern struct etimer *timerlist;
399 extern volatile unsigned char poll_requested;
401 #define PROCESS_STATE_NONE 0
402 #define PROCESS_STATE_RUNNING 1
403 #define PROCESS_STATE_CALLED 2
406 if(etimer_process.state == PROCESS_STATE_RUNNING || etimer_process.state == PROCESS_STATE_CALLED) {
407 etimer_process.needspoll = 1;
417 #ifdef HANDLE_UNSUPPORTED_INTERRUPTS
424 #ifdef HANG_ON_UNKNOWN_INTERRUPT
430 static volatile uint8_t x;
431 ISR( _VECTOR(0)) {
while (1) x++;}
432 ISR( _VECTOR(1)) {
while (1) x++;}
433 ISR( _VECTOR(2)) {
while (1) x++;}
434 ISR( _VECTOR(3)) {
while (1) x++;}
435 ISR( _VECTOR(4)) {
while (1) x++;}
436 ISR( _VECTOR(5)) {
while (1) x++;}
437 ISR( _VECTOR(6)) {
while (1) x++;}
438 ISR( _VECTOR(7)) {
while (1) x++;}
439 ISR( _VECTOR(8)) {
while (1) x++;}
440 ISR( _VECTOR(9)) {
while (1) x++;}
441 ISR( _VECTOR(10)) {
while (1) x++;}
442 ISR( _VECTOR(11)) {
while (1) x++;}
443 ISR( _VECTOR(12)) {
while (1) x++;}
444 ISR( _VECTOR(13)) {
while (1) x++;}
445 ISR( _VECTOR(14)) {
while (1) x++;}
446 ISR( _VECTOR(15)) {
while (1) x++;}
447 ISR( _VECTOR(16)) {
while (1) x++;}
448 ISR( _VECTOR(17)) {
while (1) x++;}
449 ISR( _VECTOR(18)) {
while (1) x++;}
450 ISR( _VECTOR(19)) {
while (1) x++;}
453 ISR( _VECTOR(22)) {
while (1) x++;}
454 ISR( _VECTOR(23)) {
while (1) x++;}
455 ISR( _VECTOR(24)) {
while (1) x++;}
457 ISR( _VECTOR(26)) {
while (1) x++;}
459 ISR( _VECTOR(28)) {
while (1) x++;}
460 ISR( _VECTOR(29)) {
while (1) x++;}
461 ISR( _VECTOR(30)) {
while (1) x++;}
462 ISR( _VECTOR(31)) {
while (1) x++;}
464 ISR( _VECTOR(33)) {
while (1) x++;}
465 ISR( _VECTOR(34)) {
while (1) x++;}
466 ISR( _VECTOR(35)) {
while (1) x++;}
468 ISR( _VECTOR(37)) {
while (1) x++;}
470 ISR( _VECTOR(39)) {
while (1) x++;}
471 ISR( _VECTOR(40)) {
while (1) x++;}
472 ISR( _VECTOR(41)) {
while (1) x++;}
473 ISR( _VECTOR(42)) {
while (1) x++;}
474 ISR( _VECTOR(43)) {
while (1) x++;}
475 ISR( _VECTOR(44)) {
while (1) x++;}
476 ISR( _VECTOR(45)) {
while (1) x++;}
477 ISR( _VECTOR(46)) {
while (1) x++;}
478 ISR( _VECTOR(47)) {
while (1) x++;}
479 ISR( _VECTOR(48)) {
while (1) x++;}
480 ISR( _VECTOR(49)) {
while (1) x++;}
481 ISR( _VECTOR(50)) {
while (1) x++;}
482 ISR( _VECTOR(51)) {
while (1) x++;}
483 ISR( _VECTOR(52)) {
while (1) x++;}
484 ISR( _VECTOR(53)) {
while (1) x++;}
485 ISR( _VECTOR(54)) {
while (1) x++;}
486 ISR( _VECTOR(55)) {
while (1) x++;}
487 ISR( _VECTOR(56)) {
while (1) x++;}
492 ISR( _VECTOR(61)) {
while (1) x++;}
493 ISR( _VECTOR(62)) {
while (1) x++;}
494 ISR( _VECTOR(63)) {
while (1) x++;}
495 ISR( _VECTOR(64)) {
while (1) x++;}
496 ISR( _VECTOR(65)) {
while (1) x++;}
497 ISR( _VECTOR(66)) {
while (1) x++;}
498 ISR( _VECTOR(67)) {
while (1) x++;}
499 ISR( _VECTOR(68)) {
while (1) x++;}
500 ISR( _VECTOR(69)) {
while (1) x++;}
501 ISR( _VECTOR(70)) {
while (1) x++;}
502 ISR( _VECTOR(71)) {
while (1) x++;}
503 ISR( _VECTOR(72)) {
while (1) x++;}
504 ISR( _VECTOR(73)) {
while (1) x++;}
505 ISR( _VECTOR(74)) {
while (1) x++;}
506 ISR( _VECTOR(75)) {
while (1) x++;}
507 ISR( _VECTOR(76)) {
while (1) x++;}
508 ISR( _VECTOR(77)) {
while (1) x++;}
509 ISR( _VECTOR(78)) {
while (1) x++;}
510 ISR( _VECTOR(79)) {
while (1) x++;}
#define F_CPU
CPU core frequency resulting from the chosen divisors and multipliers.
void clock_delay_usec(uint16_t dt)
Delay a given number of microseconds.
void __attribute__((interrupt))
This ISR handles most of the business interacting with the 1-wire bus.
void clock_delay_msec(uint16_t howlong)
Delay up to 65535 milliseconds.
void clock_init(void)
Initialize the clock library.
void AVR_OUTPUT_COMPARE_INT(void)
ISR for the TIMER0 or TIMER2 interrupt as defined in clock-avr.h for the particular MCU...
void clock_adjust_ticks(clock_time_t howmany)
Adjust the system current clock time.
CCIF clock_time_t clock_time(void)
Get the current clock time.
void etimer_request_poll(void)
Make the event timer aware that the clock has changed.
void clock_set_seconds(unsigned long sec)
Set the value of the platform seconds.
CCIF unsigned long clock_seconds(void)
Get the current value of the platform seconds.
int etimer_pending(void)
Check if there are any non-expired event timers.
void clock_delay(unsigned int delay)
Obsolete delay function but we implement it here since some code still uses it.
void clock_wait(clock_time_t t)
Wait for a given number of ticks.
#define CLOCK_SECOND
A second, measured in system clock time.