|
|
|
@ -34,6 +34,11 @@
|
|
|
|
|
#ifdef __AVR__
|
|
|
|
|
#include <util/atomic.h>
|
|
|
|
|
#include <avr/interrupt.h>
|
|
|
|
|
#include <avr/io.h>
|
|
|
|
|
|
|
|
|
|
#ifndef F_CPU
|
|
|
|
|
#error "F_CPU must be defined"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void run_timers();
|
|
|
|
|
|
|
|
|
@ -41,6 +46,19 @@ ISR(TIMER0_OVF_vect) {
|
|
|
|
|
run_timers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void set_ocr1a(uint16_t value) {
|
|
|
|
|
OCR1AH = value >> 8;
|
|
|
|
|
OCR1AL = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Source: https://adnbr.co.uk/articles/counting-milliseconds */
|
|
|
|
|
void init_timer1() {
|
|
|
|
|
TCCR1B |= _BV(WGM12) | _BV(CS11);
|
|
|
|
|
set_ocr1a((F_CPU / 1000) / 8);
|
|
|
|
|
TIMSK1 |= _BV(OCIE1A);
|
|
|
|
|
sei();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void atomic_memcpy(void *dest, const void *src, size_t size) {
|
|
|
|
|
ATOMIC_BLOCK(ATOMIC_FORCEON) {
|
|
|
|
|
memcpy(dest, src, size);
|
|
|
|
|