WIP: Add a TIMER1 configuration routine in avr.h
The function hasn't been tested on real hardware.
This commit is contained in:
parent
e23fce0285
commit
4827bdd9fe
1 changed files with 18 additions and 0 deletions
18
lib/c/avr.h
18
lib/c/avr.h
|
@ -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…
Reference in a new issue