WIP: Add a TIMER1 configuration routine in avr.h

The function hasn't been tested on real hardware.
async
jeltz 3 years ago
parent e23fce0285
commit 4827bdd9fe
Signed by: jeltz
GPG Key ID: 800882B66C0C3326

@ -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);

Loading…
Cancel
Save