File tree Expand file tree Collapse file tree 3 files changed +59
-34
lines changed Expand file tree Collapse file tree 3 files changed +59
-34
lines changed Original file line number Diff line number Diff line change 11// (c) Ralph Doncaster 2020
22// ArduinoShrink
33
4+ #if F_CPU != 16000000
5+ #error Only 16Mhz F_CPU supported
6+ #endif
7+
48#include <util/delay.h>
59
610inline void delayMicroseconds (unsigned int us )
711{
812 _delay_us (us );
913}
14+
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+ ; micros not supported
14+ . global micros
15+ micros:
16+
17+ . global millis
18+ millis:
19+ ldi ZL , lo8(t0_millis)
20+ ldi ZH , hi8(t0_millis)
21+ ld r22 , Z
22+ ldd r23 , Z + 1
23+ ldd r24 , Z + 2
24+ ldd r25 , Z + 3
25+ ld r0 , Z
26+ cp r0 , r22 ; has millis changed?
27+ brne millis
28+ ret
29+
30+ . global TIMER0_OVF_vect
31+ TIMER0_OVF_vect:
32+ push r16
33+ in r16 , SREG - 0x20
34+ push r16
35+ push ZL
36+ ldi ZL , lo8(t0_millis)
37+ push ZH
38+ ldi ZH , hi8(t0_millis)
39+ millis_inc:
40+ ld r16 , Z
41+ subi r16 , - 1
42+ st Z +, r16
43+ brcc millis_inc
44+ pop ZH
45+ pop ZL
46+ pop r16
47+ out SREG - 0x20 , r16
48+ pop r16
49+ reti
50+
Original file line number Diff line number Diff line change 44#include <Arduino.h>
55
66struct {
7- uint8_t fract_count ;
8- volatile uint32_t millis ;
7+ volatile uint32_t t0_ovfl ;
98 uint8_t ovfl_pad ;
109} t0_millis ;
1110
12- ISR (TIMER0_OVF_vect , ISR_NAKED )
13- {
14- asm (
15- "push r16 \t\n"
16- "in r16, __SREG__ \t\n"
17- "push r16 \t\n"
18- "push ZL \t\n"
19- "ldi ZL, lo8(t0_millis) \t\n"
20- "ldd r22, Z+0 \t\n"
21- "reti \t\n"
22- );
23- }
24-
25- __attribute((naked ))
26- uint32_t millis ()
27- {
28- asm (
29- "ldd r22, Z+0 \t\n"
30- "ldd r23, Z+1 \t\n"
31- "ldd r24, Z+2 \t\n"
32- "ldd r25, Z+3 \t\n"
33- "ldd r0, Z+0 \t\n"
34- "cp r0, r22 \t\n" // has millis changed?
35- "brne millis \t\n"
36- "ret \t\n"
37- :: "z" (& (t0_millis .millis ))
38- );
39- }
40-
4111// portability macros for mega8
4212#ifndef TCCR0B
4313#define TCCR0B TCCR0
4414#define TIMSK0 TIMSK
4515#endif
46- __attribute(( section (".init8" ), used ))
16+
17+ __attribute(( section (".init8" ), used , naked ))
4718void init_millis ()
4819{
49- TCCR0B = _BV (CS01 ); // div8 prescaler
20+ TCCR0B = _BV (CS01 ) | _BV ( CS00 ); // div64 prescaler
5021 TIMSK0 = _BV (TOIE0 ); // enable overflow interrupt
5122}
52-
You can’t perform that action at this time.
0 commit comments