File tree Expand file tree Collapse file tree 3 files changed +24
-12
lines changed Expand file tree Collapse file tree 3 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -12,18 +12,6 @@ inline void delayMicroseconds(unsigned int us)
1212 _delay_us (us );
1313}
1414
15- extern "C" uint32_t micros_raw ();
16- inline uint32_t micros ()
17- {
18- /*
19- register uint32_t micros_ asm("r22");
20- asm ("call micros_raw" : "=r" (micros_) );
21- return micros_;
22- */
23- // asm volatile ("call micros_raw");
24- return micros_raw () * 4 ;
25- }
26-
2715extern "C" uint32_t millis_raw ();
2816inline uint32_t millis ()
2917{
Original file line number Diff line number Diff line change @@ -8,6 +8,14 @@ struct {
88 uint8_t ovfl_pad ;
99} t0_millis ;
1010
11+ extern uint32_t micros_raw ();
12+ uint32_t micros ()
13+ {
14+ register uint32_t u asm("r22" );
15+ asm ("%~call %x1" : "=r" (u ) : "i" (micros_raw ) : "r30" , "r31" );
16+ return u * 4 ;
17+ }
18+
1119// portability macros for mega8
1220#ifndef TCCR0B
1321#define TCCR0B TCCR0
Original file line number Diff line number Diff line change 44#include <Arduino.h>
55#include <util/delay.h>
66
7+ /*
78__attribute ((noinline))
89void delay(unsigned long ms)
910{
1011 do {
1112 _delay_us(999); // leave 1us for loop overhead
1213 } while (--ms);
1314}
15+ */
16+
17+ void delay (unsigned long ms )
18+ {
19+ // lower 16-bits of micros is enough considering wraparound
20+ uint16_t start = micros ();
21+
22+ while (ms > 0 ) {
23+ yield ();
24+ while (ms > 0 && ((uint16_t )micros () - start ) >= 1000 ) {
25+ ms -- ;
26+ start += 1000 ;
27+ }
28+ }
29+ }
1430
1531// avr-libc math.h does not declare gcc log2 builtin
1632double log2 (double );
You can’t perform that action at this time.
0 commit comments