Skip to content

Commit e6f1594

Browse files
committed
v0.3.0
1 parent d3b4d2a commit e6f1594

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ This library replaces Arduino AVR Core functions with smaller and faster version
33
For example, the Blink example sketch built for the Uno takes 924 bytes of flash, but only needs 196 bytes with ArduinoShrink.
44

55
## Usage
6-
Download [a release](https://github.com/nerdralph/ArduinoShrink/releases), and extract the files into your Arduino/libraries folder. Select ArduinoShrink from the Sketch, Include Library menu. This will replace pinMode, digitalWrite, and digitalRead with much smaller and faster versions. The Arduino pin number must be known at compile time if you are using this library.
6+
Download [a release](https://github.com/nerdralph/ArduinoShrink/releases), and extract the files into your Arduino/libraries folder. Select ArduinoShrink from the Sketch, Include Library menu. This will replace several Arduino functions with smaller and faster versions. The Arduino pin number must be known at compile time if you are using this library.
77

88
## Limitations
9-
ArduinoShrink implements a simple millis timer, but does not implement micros.
9+
ArduinoShrink supports only ATmegax8 MCUs running at 16Mhz
1010

1111
## Development plans
12-
Future versions will include support for 8Mhz clock rate.
12+
Future versions will support 8Mhz.

src/micros.S

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
; uint8_t ovfl_pad;
1111
;} t0_millis;
1212

13-
; ensure timer ISR is brought in by linker
14-
.global t0_ovfl_inc
13+
14+
;.global lsl4_r22_r30
1515

1616
.global micros
1717
micros:
@@ -24,5 +24,7 @@ micros:
2424
ldd r25, Z+2
2525
in r0, TCNT0
2626
sub r0, r22 ; TCNT0 overflow?
27-
brne 1b
27+
brcs 1b
28+
ldi r30, 2 ; multiply by micros/tick
29+
rcall lsl4_r22_r30
2830
ret

src/millis.S

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
; uint8_t ovfl_pad;
99
;} t0_millis;
1010

11-
; ensure timer ISR is brought in by linker
12-
.global t0_ovfl_inc
11+
; to force t0_isr to get linked in
12+
.global lsl4_r22_r20
1313

1414
.global millis
1515
millis:
@@ -22,4 +22,25 @@ millis:
2222
ld r0, Z
2323
cp r0, r22 ; has millis changed?
2424
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
2546
ret

src/t0_ovfl_isr.S

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
; uint8_t ovfl_pad;
99
;} t0_millis;
1010

11-
; so timer ISR is brought in by linker when needed
12-
.global t0_ovfl_inc
13-
1411
.global TIMER0_OVF_vect
1512
TIMER0_OVF_vect:
1613
push r16
@@ -32,3 +29,13 @@ t0_ovfl_inc:
3229
pop r16
3330
reti
3431

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)