Skip to content

Commit aaf8a32

Browse files
committed
v0.4.0rc0
1 parent c939a30 commit aaf8a32

File tree

6 files changed

+38
-42
lines changed

6 files changed

+38
-42
lines changed

src/ArduinoShrink.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,21 @@ 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+
27+
extern "C" uint32_t millis_raw();
28+
inline uint32_t millis()
29+
{
30+
uint32_t m = millis_raw();
31+
return m + ((m * 1573) >> 16);
32+
}

src/macros.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
.macro GLABEL name
3+
.global \name
4+
\name:
5+
.endm

src/micros.S

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
;} t0_millis;
1212

1313

14-
;.global lsl4_r22_r30
14+
; to force t0_isr to get linked in
15+
.global t0_ovfl_isr
1516

16-
.global micros
17-
micros:
17+
.global micros_raw
18+
micros_raw:
1819
ldi ZL, lo8(t0_millis)
1920
ldi ZH, hi8(t0_millis)
2021
1:
@@ -25,6 +26,4 @@ micros:
2526
in r0, TCNT0
2627
sub r0, r22 ; TCNT0 overflow?
2728
brcs 1b
28-
ldi r30, 2 ; multiply by micros/tick
29-
rcall lsl4_r22_r30
3029
ret

src/millis.S

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,18 @@
99
;} t0_millis;
1010

1111
; to force t0_isr to get linked in
12-
.global lsl4_r22_r20
12+
.global t0_ovfl_isr
1313

14-
.global millis
15-
millis:
14+
.global millis_raw
15+
millis_raw:
1616
ldi ZL, lo8(t0_millis)
1717
ldi ZH, hi8(t0_millis)
18+
1:
1819
ld r22, Z
1920
ldd r23, Z+1
2021
ldd r24, Z+2
2122
ldd r25, Z+3
2223
ld r0, Z
2324
cp r0, r22 ; has millis changed?
24-
brne millis
25-
; millis = t0_ovfl * 1.024 , so multiply by fractional addition
26-
movw r18, r22
27-
movw r20, r24
28-
rcall shift_add ; adds t0_ovfl / 128
29-
rcall shift_add ; adds t0_ovfl / 64
30-
; rcall 1f
31-
; todo: add t0_ovfl / 2048
32-
1: add r18, r24 ; adds t0_ovfl / 16384
33-
adc r19, r25
34-
adc r20, r1
35-
movw r22, r18
36-
movw r24, r20
37-
ret
38-
39-
shift_add:
40-
ldi r30, 1
41-
rcall lsl4_r22_r30
42-
add r18, r23
43-
adc r19, r24
44-
adc r20, r25
45-
adc r21, r1
25+
brne 1b
4626
ret

src/millis.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ void init_millis()
2020
TCCR0B = _BV(CS01) | _BV(CS00); // div64 prescaler
2121
TIMSK0 = _BV(TOIE0); // enable overflow interrupt
2222
}
23+

src/t0_ovfl_isr.S

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
; ArduinoShrink
33

44
#include <avr/io.h>
5+
#include "macros.inc"
56

67
;struct {
78
; uint32_t t0_ovfl;
89
; uint8_t ovfl_pad;
910
;} t0_millis;
1011

11-
.global TIMER0_OVF_vect
12-
TIMER0_OVF_vect:
12+
; to help with linking
13+
GLABEL t0_ovfl_isr
14+
15+
GLABEL TIMER0_OVF_vect
1316
push r16
1417
in r16, SREG-0x20
1518
push r16
@@ -29,13 +32,3 @@ t0_ovfl_inc:
2932
pop r16
3033
reti
3134

32-
; shift left r22-r25 (ulong), arg in r30
33-
.global lsl4_r22_r30
34-
lsl4_r22_r30:
35-
lsl r22
36-
rol r23
37-
rol r24
38-
rol r25
39-
dec r30
40-
brne lsl4_r22_r30
41-
ret

0 commit comments

Comments
 (0)