67 #include "sys/clock.h"
68 #include "dev/clock-avr.h"
72 #include <avr/interrupt.h>
76 #if CLOCK_SECOND && (CLOCK_SECOND - 1)
77 #define TWO_COUNTERS 1
81 static volatile clock_time_t count;
84 static volatile uint8_t scount;
103 static volatile clock_time_t count;
105 static volatile uint8_t scount;
107 >>>>>>> 5e18239... Adjust sleep time by ticks instead of seconds, proposed by Ivan Delamer
108 volatile unsigned long seconds;
113 #if RF230BB && AVR_WEBSERVER
118 static volatile uint8_t rcount;
119 volatile unsigned long radioontime;
120 extern uint8_t RF230_receive_on;
128 #if RADIO_CONF_CALIBRATE_INTERVAL
129 extern volatile uint8_t rf230_calibrate;
130 static uint8_t calibrate_interval;
157 }
while(tmp != count);
172 }
while(tmp != seconds);
192 if (
sizeof(clock_time_t) == 1) {
193 while ((
signed char )(
clock_time() - endticks) < 0) {;}
194 }
else if (
sizeof(clock_time_t) == 2) {
195 while ((
signed short)(
clock_time() - endticks) < 0) {;}
197 while ((
signed long )(
clock_time() - endticks) < 0) {;}
207 static inline void my_delay_loop_2(uint16_t __count)
__attribute__((always_inline));
209 my_delay_loop_2(uint16_t __count)
212 "1: sbiw %0,1" "\n\t"
225 if(howlong<=(uint16_t)(279000000UL/F_CPU))
return;
226 howlong-=(uint16_t) (279000000UL/F_CPU);
227 my_delay_loop_2(((uint64_t)(howlong) * (uint64_t) F_CPU) / 4000000ULL);
230 #elif F_CPU>=16000000UL
231 if(howlong<1)
return;
232 my_delay_loop_2((howlong*(uint16_t)(F_CPU/3250000)));
233 #elif F_CPU >= 12000000UL
234 if(howlong<2)
return;
235 howlong-=(uint16_t) (3*12000000/F_CPU);
236 my_delay_loop_2((howlong*(uint16_t)(F_CPU/3250000)));
237 #elif F_CPU >= 8000000UL
238 if(howlong<4)
return;
239 howlong-=(uint16_t) (3*8000000/F_CPU);
240 my_delay_loop_2((howlong*(uint16_t)(F_CPU/2000000))/2);
241 #elif F_CPU >= 4000000UL
242 if(howlong<5)
return;
243 howlong-=(uint16_t) (4*4000000/F_CPU);
244 my_delay_loop_2((howlong*(uint16_t)(F_CPU/2000000))/2);
245 #elif F_CPU >= 2000000UL
246 if(howlong<11)
return;
247 howlong-=(uint16_t) (10*2000000/F_CPU);
248 my_delay_loop_2((howlong*(uint16_t)(F_CPU/1000000))/4);
249 #elif F_CPU >= 1000000UL
250 if(howlong<=17)
return;
251 howlong-=(uint16_t) (17*1000000/F_CPU);
252 my_delay_loop_2((howlong*(uint16_t)(F_CPU/1000000))/4);
255 if (howlong < 1)
return;
256 my_delay_loop_2(howlong);
269 if(howlong<2)
return;
304 >>>>>>> 5e18239... Adjust sleep time by ticks instead of seconds, proposed by Ivan Delamer
318 uint8_t sreg = SREG;cli();
328 void clock_adjust_seconds(uint8_t howmany) {
330 sleepseconds +=howmany;
332 >>>>>>> 5e18239... Adjust sleep time by ticks instead of seconds, proposed by Ivan Delamer
334 if (RF230_receive_on) radioontime += 1;
355 if (RF230_receive_on) radioontime += 1;
387 #if RADIO_CONF_CALIBRATE_INTERVAL
389 if (++calibrate_interval==0) {
398 if (RF230_receive_on) {
406 #if F_CPU == 0x800000 && USE_32K_CRYSTAL
416 #include "rtimer-arch.h"
418 volatile static uint8_t lockcount;
419 volatile static int16_t last_phase;
420 volatile static uint8_t osccalhigh,osccallow;
422 if(++lockcount >= 8192UL*128/RTIMER_ARCH_SECOND) {
424 rtimer_phase = TCNT3 & 0x0fff;
425 if (seconds < 2) OSCCAL=100;
426 if (last_phase > rtimer_phase) osccalhigh=++OSCCAL;
else osccallow=--OSCCAL;
427 last_phase = rtimer_phase;
430 uint8_t error = (TCNT3 - last_phase) & 0x3f;
432 }
else if (error<32) {
448 extern struct etimer *timerlist;
449 extern volatile unsigned char poll_requested;
451 #define PROCESS_STATE_NONE 0
452 #define PROCESS_STATE_RUNNING 1
453 #define PROCESS_STATE_CALLED 2
456 if(etimer_process.state == PROCESS_STATE_RUNNING || etimer_process.state == PROCESS_STATE_CALLED) {
457 etimer_process.needspoll = 1;
484 }
while(tmp != count);
497 for (j = 50; j > 0; j--)
513 while(
clock_time() - start < (clock_time_t)i);
522 >>>>>>> 5e18239... Adjust sleep time by ticks instead of seconds, proposed by Ivan Delamer
524 #ifdef HANDLE_UNSUPPORTED_INTERRUPTS
531 #ifdef HANG_ON_UNKNOWN_INTERRUPT
537 static volatile uint8_t x;
538 ISR( _VECTOR(0)) {
while (1) x++;}
539 ISR( _VECTOR(1)) {
while (1) x++;}
540 ISR( _VECTOR(2)) {
while (1) x++;}
541 ISR( _VECTOR(3)) {
while (1) x++;}
542 ISR( _VECTOR(4)) {
while (1) x++;}
543 ISR( _VECTOR(5)) {
while (1) x++;}
544 ISR( _VECTOR(6)) {
while (1) x++;}
545 ISR( _VECTOR(7)) {
while (1) x++;}
546 ISR( _VECTOR(8)) {
while (1) x++;}
547 ISR( _VECTOR(9)) {
while (1) x++;}
548 ISR( _VECTOR(10)) {
while (1) x++;}
549 ISR( _VECTOR(11)) {
while (1) x++;}
550 ISR( _VECTOR(12)) {
while (1) x++;}
551 ISR( _VECTOR(13)) {
while (1) x++;}
552 ISR( _VECTOR(14)) {
while (1) x++;}
553 ISR( _VECTOR(15)) {
while (1) x++;}
554 ISR( _VECTOR(16)) {
while (1) x++;}
555 ISR( _VECTOR(17)) {
while (1) x++;}
556 ISR( _VECTOR(18)) {
while (1) x++;}
557 ISR( _VECTOR(19)) {
while (1) x++;}
560 ISR( _VECTOR(22)) {
while (1) x++;}
561 ISR( _VECTOR(23)) {
while (1) x++;}
562 ISR( _VECTOR(24)) {
while (1) x++;}
564 ISR( _VECTOR(26)) {
while (1) x++;}
566 ISR( _VECTOR(28)) {
while (1) x++;}
567 ISR( _VECTOR(29)) {
while (1) x++;}
568 ISR( _VECTOR(30)) {
while (1) x++;}
569 ISR( _VECTOR(31)) {
while (1) x++;}
571 ISR( _VECTOR(33)) {
while (1) x++;}
572 ISR( _VECTOR(34)) {
while (1) x++;}
573 ISR( _VECTOR(35)) {
while (1) x++;}
575 ISR( _VECTOR(37)) {
while (1) x++;}
577 ISR( _VECTOR(39)) {
while (1) x++;}
578 ISR( _VECTOR(40)) {
while (1) x++;}
579 ISR( _VECTOR(41)) {
while (1) x++;}
580 ISR( _VECTOR(42)) {
while (1) x++;}
581 ISR( _VECTOR(43)) {
while (1) x++;}
582 ISR( _VECTOR(44)) {
while (1) x++;}
583 ISR( _VECTOR(45)) {
while (1) x++;}
584 ISR( _VECTOR(46)) {
while (1) x++;}
585 ISR( _VECTOR(47)) {
while (1) x++;}
586 ISR( _VECTOR(48)) {
while (1) x++;}
587 ISR( _VECTOR(49)) {
while (1) x++;}
588 ISR( _VECTOR(50)) {
while (1) x++;}
589 ISR( _VECTOR(51)) {
while (1) x++;}
590 ISR( _VECTOR(52)) {
while (1) x++;}
591 ISR( _VECTOR(53)) {
while (1) x++;}
592 ISR( _VECTOR(54)) {
while (1) x++;}
593 ISR( _VECTOR(55)) {
while (1) x++;}
594 ISR( _VECTOR(56)) {
while (1) x++;}
599 ISR( _VECTOR(61)) {
while (1) x++;}
600 ISR( _VECTOR(62)) {
while (1) x++;}
601 ISR( _VECTOR(63)) {
while (1) x++;}
602 ISR( _VECTOR(64)) {
while (1) x++;}
603 ISR( _VECTOR(65)) {
while (1) x++;}
604 ISR( _VECTOR(66)) {
while (1) x++;}
605 ISR( _VECTOR(67)) {
while (1) x++;}
606 ISR( _VECTOR(68)) {
while (1) x++;}
607 ISR( _VECTOR(69)) {
while (1) x++;}
608 ISR( _VECTOR(70)) {
while (1) x++;}
609 ISR( _VECTOR(71)) {
while (1) x++;}
610 ISR( _VECTOR(72)) {
while (1) x++;}
611 ISR( _VECTOR(73)) {
while (1) x++;}
612 ISR( _VECTOR(74)) {
while (1) x++;}
613 ISR( _VECTOR(75)) {
while (1) x++;}
614 ISR( _VECTOR(76)) {
while (1) x++;}
615 ISR( _VECTOR(77)) {
while (1) x++;}
616 ISR( _VECTOR(78)) {
while (1) x++;}
617 ISR( _VECTOR(79)) {
while (1) x++;}
624 >>>>>>> 5e18239... Adjust sleep time by ticks instead of seconds, proposed by Ivan Delamer