2016-11-07 18:00:24 +01:00
|
|
|
/*
|
2019-07-10 16:12:21 +02:00
|
|
|
* \brief Timer implementation specific to BCM2835 System Timer
|
2016-11-07 18:00:24 +01:00
|
|
|
* \author Norman Feske
|
|
|
|
* \author Stefan Kalkowski
|
2017-03-23 03:06:53 +01:00
|
|
|
* \author Martin Stein
|
2016-11-07 18:00:24 +01:00
|
|
|
* \date 2016-01-07
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2016-2017 Genode Labs GmbH
|
2016-11-07 18:00:24 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2016-11-07 18:00:24 +01:00
|
|
|
*/
|
|
|
|
|
2017-03-23 03:06:53 +01:00
|
|
|
/* core includes */
|
2019-07-10 16:12:21 +02:00
|
|
|
#include <board.h>
|
2016-11-07 18:00:24 +01:00
|
|
|
#include <platform.h>
|
2017-03-23 03:06:53 +01:00
|
|
|
#include <kernel/timer.h>
|
2016-11-07 18:00:24 +01:00
|
|
|
|
|
|
|
using namespace Genode;
|
2017-03-23 03:06:53 +01:00
|
|
|
using namespace Kernel;
|
2019-07-10 16:12:21 +02:00
|
|
|
using Device = Board::Timer;
|
2016-11-07 18:00:24 +01:00
|
|
|
|
|
|
|
|
2019-07-10 16:12:21 +02:00
|
|
|
Board::Timer::Timer(unsigned)
|
2016-11-07 18:00:24 +01:00
|
|
|
: Mmio(Platform::mmio_to_virt(Board::SYSTEM_TIMER_MMIO_BASE)) { }
|
|
|
|
|
|
|
|
|
2017-03-23 03:06:53 +01:00
|
|
|
void Timer::_start_one_shot(time_t const ticks)
|
2016-11-07 18:00:24 +01:00
|
|
|
{
|
2019-07-10 16:12:21 +02:00
|
|
|
_device.write<Device::Cs::M1>(1);
|
|
|
|
_device.read<Device::Cs>();
|
|
|
|
_device.write<Device::Cmp>(_device.read<Device::Clo>()
|
2019-02-21 17:23:10 +01:00
|
|
|
+ (ticks < 2 ? 2 : ticks));
|
2016-11-07 18:00:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-10 16:12:21 +02:00
|
|
|
enum { TICS_PER_US = Board::SYSTEM_TIMER_CLOCK / 1000 / 1000 };
|
|
|
|
|
|
|
|
|
2019-02-21 17:23:10 +01:00
|
|
|
time_t Timer::ticks_to_us(time_t const ticks) const {
|
2019-07-10 16:12:21 +02:00
|
|
|
return ticks / TICS_PER_US; }
|
2016-11-07 18:00:24 +01:00
|
|
|
|
|
|
|
|
2017-03-23 03:06:53 +01:00
|
|
|
time_t Timer::us_to_ticks(time_t const us) const {
|
2019-07-10 16:12:21 +02:00
|
|
|
return us * TICS_PER_US; }
|
2016-11-07 18:00:24 +01:00
|
|
|
|
|
|
|
|
2017-03-23 03:06:53 +01:00
|
|
|
time_t Timer::_max_value() const {
|
2019-02-21 17:23:10 +01:00
|
|
|
return 0xffffffff; }
|
2016-11-07 18:00:24 +01:00
|
|
|
|
|
|
|
|
2019-02-21 17:23:10 +01:00
|
|
|
time_t Timer::_duration() const
|
2016-11-07 18:00:24 +01:00
|
|
|
{
|
2019-07-10 16:12:21 +02:00
|
|
|
Device::Clo::access_t const clo = _device.read<Device::Clo>();
|
|
|
|
Device::Cmp::access_t const cmp = _device.read<Device::Cmp>();
|
|
|
|
Device::Cs::access_t const irq = _device.read<Device::Cs::M1>();
|
2019-02-21 17:23:10 +01:00
|
|
|
uint32_t d = (irq) ? (uint32_t)_last_timeout_duration + (clo - cmp)
|
|
|
|
: clo - (cmp - _last_timeout_duration);
|
|
|
|
return d;
|
2016-11-07 18:00:24 +01:00
|
|
|
}
|
2017-03-23 03:06:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
unsigned Timer::interrupt_id() const { return Board::SYSTEM_TIMER_IRQ; }
|