File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ ; (c) Ralph Doncaster 2020
2+ ; ArduinoShrink
3+
4+ ; all used io registers are < 0x3F
5+ #define __SFR_OFFSET 0
6+ #include <avr/io.h>
7+
8+ ;struct {
9+ ; uint32_t t0_ovfl;
10+ ; uint8_t ovfl_pad;
11+ ;} t0_millis;
12+
13+ ; ensure timer ISR is brought in by linker
14+ .global t0_ovfl_inc
15+
16+ .global micros
17+ micros:
18+ ldi ZL, lo8(t0_millis)
19+ ldi ZH, hi8(t0_millis)
20+ 1:
21+ in r22, TCNT0
22+ ld r23, Z
23+ ldd r24, Z+1
24+ ldd r25, Z+2
25+ in r0, TCNT0
26+ sub r0, r22 ; TCNT0 overflow?
27+ brne 1b
28+ ret
Original file line number Diff line number Diff line change 1+ ; (c) Ralph Doncaster 2020
2+ ; ArduinoShrink
3+
4+ #include <avr/io.h>
5+
6+ ;struct {
7+ ; uint32_t t0_ovfl;
8+ ; uint8_t ovfl_pad;
9+ ;} t0_millis;
10+
11+ ; so timer ISR is brought in by linker when needed
12+ . global t0_ovfl_inc
13+
14+ . global TIMER0_OVF_vect
15+ TIMER0_OVF_vect:
16+ push r16
17+ in r16 , SREG - 0x20
18+ push r16
19+ push ZL
20+ ldi ZL , lo8(t0_millis)
21+ push ZH
22+ ldi ZH , hi8(t0_millis)
23+ t0_ovfl_inc:
24+ ld r16 , Z
25+ subi r16 , - 1
26+ st Z +, r16
27+ brcc t0_ovfl_inc
28+ pop ZH
29+ pop ZL
30+ pop r16
31+ out SREG - 0x20 , r16
32+ pop r16
33+ reti
34+
You can’t perform that action at this time.
0 commit comments