X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/fnordlicht-mini/blobdiff_plain/24562c8a748c379de491019607921e5959459464..745723e4d1fee18fc31d79172fe8357a75628eea:/firmware/fnordlicht-controller/timer.c?ds=sidebyside diff --git a/firmware/fnordlicht-controller/timer.c b/firmware/fnordlicht-controller/timer.c deleted file mode 100644 index 8bd5263..0000000 --- a/firmware/fnordlicht-controller/timer.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * unzap firmware - * - * (c) by Alexander Neumann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * For more information on the GPL, please go to: - * http://www.gnu.org/copyleft/gpl.html - */ - -#include -#include -#include "../common/io.h" -#include "timer.h" - -static volatile uint8_t internal_counter; - -void timer_init(void) -{ -#if defined(__AVR_ATmega8__) - /* initialize timer2, CTC at 10ms, prescaler 1024 */ - OCR2 = F_CPU/1024/100; - TCCR2 = _BV(WGM21) | _BV(CS22) | _BV(CS21) | _BV(CS20); - TIMSK |= _BV(OCIE2); -#elif defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) - /* initialize timer2, CTC at 10ms, prescaler 1024 */ - OCR2A = F_CPU/1024/100; - TCCR2A = _BV(WGM21); - TCCR2B = _BV(CS22) | _BV(CS21) | _BV(CS20); - TIMSK2 = _BV(OCIE2A); -#else -#error "unknown controller, unable to initialize timer2" -#endif -} - -void timer_set(timer_t *t, uint8_t timeout) -{ - t->current = internal_counter; - t->timeout = timeout; -} - -bool timer_expired(timer_t *t) -{ - if (t->timeout == 0) - return true; - - /* attention: this is not correct, if internal_counter is incremented by more than one - * between two calls of timer_expired()! */ - if (t->current != internal_counter) { - t->timeout--; - t->current = internal_counter; - } - - return false; -} - -/* timer interrupt function */ -#if defined(__AVR_ATmega8__) -ISR(TIMER2_COMP_vect, ISR_NOBLOCK) { - internal_counter++; -} -#elif defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) -ISR(TIMER2_COMPA_vect, ISR_NOBLOCK) { - internal_counter++; -} -#endif