timer/util: generic TIMER_MIN_TICKS_PER_MS

Ref #2400
This commit is contained in:
Martin Stein 2017-08-24 13:36:24 +02:00 committed by Christian Helmuth
parent ffaf99ae86
commit d9073a1848
4 changed files with 10 additions and 5 deletions

View File

@ -26,7 +26,8 @@ using namespace Kernel;
Timer_driver::Timer_driver(unsigned)
: Mmio(Platform::mmio_to_virt(Board::Cpu_mmio::PRIVATE_TIMER_MMIO_BASE))
{
static_assert(TICS_PER_MS >= 1000, "Bad TICS_PER_MS value");
static_assert(TICS_PER_MS >= (unsigned)TIMER_MIN_TICKS_PER_MS,
"Bad TICS_PER_MS value");
write<Control::Timer_enable>(0);
}

View File

@ -67,7 +67,7 @@ Timer_driver::Timer_driver(unsigned)
/* Calculate timer frequency */
ticks_per_ms = pit_calc_timer_freq();
assert(ticks_per_ms >= 1000);
assert(ticks_per_ms >= TIMER_MIN_TICKS_PER_MS);
}

View File

@ -16,6 +16,8 @@
namespace Genode {
enum { TIMER_MIN_TICKS_PER_MS = 1000ULL };
/*
* Translate timer ticks to microseconds without losing precicision
*
@ -28,8 +30,9 @@ namespace Genode {
* shifting the values to their optimal bit position. Afterwards, the
* results are shifted back and merged together again.
*
* Please ensure that the assertion "ticks_per_ms >= 1000" is true
* when calling this method!
* Please ensure that the assertion
* "ticks_per_ms >= TIMER_MIN_TICKS_PER_MS" is true when calling this
* method!
*/
template <typename RESULT_T, typename TICS_PER_MS_T>
RESULT_T timer_ticks_to_us(RESULT_T const ticks,

View File

@ -92,7 +92,8 @@ Duration Timer::Time_source::curr_time()
ticks = PIT_MAX_COUNT + 1 - curr_counter;
}
static_assert(PIT_TICKS_PER_MSEC >= 1000, "Bad TICS_PER_MS value");
static_assert(PIT_TICKS_PER_MSEC >= (unsigned)TIMER_MIN_TICKS_PER_MS,
"Bad TICS_PER_MS value");
_curr_time_us += timer_ticks_to_us(ticks, PIT_TICKS_PER_MSEC);
/* use current counter as the reference for the next update */