/*************************************************************************** * Copyright (C) 01/2019 by Olaf Rempel * * razzor@kopf-tisch.de * * * * This program 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; version 2 of the License, * * * * 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., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include #include "event.h" #include "timer.h" /* *********************************************************************** */ #define TIMER_TIM_INIT() { \ TCCR0A = 0x00; \ TCCR0B = 0x00; \ TIMSK0 = (1< 0) { m_timers[i]--; if (m_timers[i] == 0) { event_queue(EVENT_TYPE_TIMER_ELAPSED, i, 0); } else { timer_needed = 1; } } } /* stop timer */ if (timer_needed == 0) { TIMER_TIM_DISABLE(); } return 1; } return 0; } /* timer_check */ void timer_event_handler(event_entry_t * p_event) { if ((p_event->type == EVENT_TYPE_TIMER_SET) && (p_event->num < TIMER_COUNT) ) { m_timers[p_event->num] = p_event->value; /* start timer if needed */ if (!TIMER_TIM_RUNNING()) { TIMER_TIM_RELOAD(TIMER_MSEC2TICKS(TIMER_IRQFREQ_MS)); TIMER_TIM_ENABLE(); } } } /* timer_event_handler */ uint8_t timer_need_hw_clock(void) { return !!TIMER_TIM_RUNNING(); } /* timer_need_hw_clock */ void timer_init(void) { TIMER_TIM_INIT(); TIMER_TIM_RELOAD(TIMER_MSEC2TICKS(TIMER_IRQFREQ_MS)); TIMER_TIM_ENABLE(); } /* timer_init */