genode/repos/os/src/drivers/timer/pistachio/time_source.cc

58 lines
1.2 KiB
C++
Raw Normal View History

2011-12-22 16:19:25 +01:00
/*
* \brief Time source that uses sleeping by the means of the kernel
2011-12-22 16:19:25 +01:00
* \author Julian Stecklina
* \author Martin Stein
2011-12-22 16:19:25 +01:00
* \date 2008-03-19
*/
/*
2013-01-10 21:44:47 +01:00
* Copyright (C) 2008-2013 Genode Labs GmbH
2011-12-22 16:19:25 +01:00
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
/* Genode includes */
#include <base/blocking.h>
/* Pistachio includes */
namespace Pistachio {
#include <l4/ipc.h>
}
/* local includes */
#include <time_source.h>
2011-12-22 16:19:25 +01:00
using namespace Genode;
using Microseconds = Genode::Time_source::Microseconds;
2011-12-22 16:19:25 +01:00
Microseconds Timer::Time_source::max_timeout() const
2011-12-22 16:19:25 +01:00
{
Lock::Guard lock_guard(_lock);
return Microseconds(1000 * 1000);
2011-12-22 16:19:25 +01:00
}
Microseconds Timer::Time_source::curr_time() const
2011-12-22 16:19:25 +01:00
{
Lock::Guard lock_guard(_lock);
return Microseconds(_curr_time_us);
2011-12-22 16:19:25 +01:00
}
void Timer::Time_source::_usleep(unsigned long us)
2011-12-22 16:19:25 +01:00
{
using namespace Pistachio;
enum { MAGIC_USER_DEFINED_HANDLE = 13 };
L4_Set_UserDefinedHandle(MAGIC_USER_DEFINED_HANDLE);
L4_Sleep(L4_TimePeriod(us));
_curr_time_us += us;
2011-12-22 16:19:25 +01:00
/* check if sleep was canceled */
if (L4_UserDefinedHandle() != MAGIC_USER_DEFINED_HANDLE)
throw Blocking_canceled();
2011-12-22 16:19:25 +01:00
}