From 55498b4999066ab6c085e06157345280add9dcba Mon Sep 17 00:00:00 2001 From: Tom Barthe Date: Wed, 30 Dec 2020 02:09:54 +0100 Subject: [PATCH] Move avr.h functions to avr.c To avoid multiple definitions of the ISR. --- .gitignore | 1 + lib/c/avr.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/c/avr.h | 30 ++++------------------------ 3 files changed, 62 insertions(+), 26 deletions(-) create mode 100644 lib/c/avr.c diff --git a/.gitignore b/.gitignore index 74ad10a..31d7ea2 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ config.status auto autom4te.cache !/lib/c/*.h +!/lib/c/*.c diff --git a/lib/c/avr.c b/lib/c/avr.c new file mode 100644 index 0000000..610a194 --- /dev/null +++ b/lib/c/avr.c @@ -0,0 +1,57 @@ +/***********************************************************************/ +/* */ +/* Heptagon */ +/* */ +/* Gwenael Delaval, LIG/INRIA, UJF */ +/* Leonard Gerard, Parkas, ENS */ +/* Adrien Guatto, Parkas, ENS */ +/* Cedric Pasteur, Parkas, ENS */ +/* Marc Pouzet, Parkas, ENS */ +/* */ +/* Copyright 2012 ENS, INRIA, UJF */ +/* */ +/* This file is part of the Heptagon compiler. */ +/* */ +/* Heptagon is free software: you can redistribute it and/or modify it */ +/* under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation, either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* Heptagon is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with Heptagon. If not, see */ +/* */ +/***********************************************************************/ + +#include +#include +#include +#include "avr.h" + +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(); +} + +void atomic_memcpy(void *dest, const void *src, size_t size) { + ATOMIC_BLOCK(ATOMIC_FORCEON) { + memcpy(dest, src, size); + } +} + diff --git a/lib/c/avr.h b/lib/c/avr.h index e3eadce..573f4d0 100644 --- a/lib/c/avr.h +++ b/lib/c/avr.h @@ -27,14 +27,11 @@ /* */ /***********************************************************************/ -/* Pervasives module for the Heptagon compiler */ - #ifndef DECADES_AVR_H #define DECADES_AVR_H #ifdef __AVR__ -#include -#include -#include +#include +#include #ifndef F_CPU #error "F_CPU must be defined" @@ -42,28 +39,9 @@ void run_timers(); -ISR(TIMER0_OVF_vect) { - run_timers(); -} +void init_timer1(); -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); - } -} +void atomic_memcpy(void *dest, const void *src, size_t size); #endif #endif