/* * \brief Time source that uses the General Purpose Timer (Freescale) * \author Stefan Kalkowski * \date 2019-04-13 */ /* * Copyright (C) 2019 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU Affero General Public License version 3. */ /* local includes */ #include using namespace Genode; void Timer::Time_source::set_timeout(Genode::Microseconds duration, Timeout_handler &handler) { _handler = &handler; /* set to minimum ticks value to not miss a too short timeout */ uint32_t const ticks = max((uint32_t)1, (uint32_t)((duration.value * TICKS_PER_MS) / 1000)); /* clear interrupts */ if (read()) { write(0xffffffff); _timer_irq.ack_irq(); } /* set new timeout */ write(read() + ticks); } Duration Timer::Time_source::curr_time() { Cnt::access_t cur_cnt = read(); Genode::Microseconds us(timer_ticks_to_us(cur_cnt - _last_cnt, TICKS_PER_MS)); _last_cnt = cur_cnt; _curr_time.add(us); return _curr_time; } Microseconds Timer::Time_source::max_timeout() const { static unsigned long max = timer_ticks_to_us(0xffffffff, TICKS_PER_MS); return Genode::Microseconds(max); } void Timer::Time_source::_initialize() { _timer_irq.sigh(_signal_handler); write(0); write(0); write(0); write(0); write(0); write(0); write(0); write(Cr::Clk_src::HIGH_FREQ_REF_CLK); while (read()) ; write(0); write(1); write(1); write(1); write(1); }