genode/repos/base-hw/src/core/spec/riscv/timer.cc
Martin Stein 4d3d4ecca0 hw core: merge Kernel::Clock and Kernel::Timer
With this, we get rid of platform specific timer interfaces. The new
Timer class does the same as the old Clock class and has a generic
interface. The old Timer class was merely used by the old Clock class.
Also, we get rid of having only one timer instance which we tell with
each method call for which CPU it shall be done. Instead now each Cpu
object has its own Timer member that knows the CPU it works for.

Also, rename all "tics" to "ticks".

Fixes #2347
2017-05-31 13:16:10 +02:00

58 lines
1.1 KiB
C++

/*
* \brief Timer driver for core
* \author Sebastian Sumpf
* \date 2015-08-22
*/
/*
* Copyright (C) 2015-2017 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.
*/
/* Core includes */
#include <kernel/timer.h>
#include <machine_call.h>
using namespace Genode;
using namespace Kernel;
Timer_driver::Timer_driver(unsigned)
{
/* enable timer interrupt */
enum { STIE = 0x20 };
asm volatile ("csrs sie, %0" : : "r"(STIE));
}
void Timer::_start_one_shot(time_t const ticks, unsigned const)
{
_driver.timeout = _driver.stime() + ticks;
Machine::set_sys_timer(_driver.timeout);
}
time_t Timer::_ticks_to_us(time_t const ticks) const {
return (ticks / Driver::TICS_PER_MS) * 1000; }
time_t Timer::us_to_ticks(time_t const us) const {
return (us / 1000) * Driver::TICS_PER_MS; }
time_t Timer::_max_value() {
return (addr_t)~0; }
time_t Timer::_value(unsigned const)
{
addr_t time = _driver.stime();
return time < _driver.timeout ? _driver.timeout - time : 0;
}
unsigned Timer::interrupt_id() const {
return 1; }