1 // --------------------------------------------------------------------------
2 INTERFACE [arm && integrator]:
4 #include "mmio_register_block.h"
6 EXTENSION class Timer : private Mmio_register_block
9 static unsigned irq() { return 6; }
22 TIMER_CTRL_IE = 1 << 5,
23 TIMER_CTRL_PERIODIC = 1 << 6,
24 TIMER_CTRL_ENABLE = 1 << 7,
27 static Static_object<Timer> _timer;
30 // ----------------------------------------------------------------------
31 IMPLEMENTATION [arm && integrator]:
36 #include "mem_layout.h"
38 Static_object<Timer> Timer::_timer;
41 Timer::Timer(Address base) : Mmio_register_block(base)
43 /* Switch all timers off */
44 write(0, TIMER0_BASE + TIMER_CTRL);
45 write(0, TIMER1_BASE + TIMER_CTRL);
46 write(0, TIMER2_BASE + TIMER_CTRL);
48 unsigned timer_ctrl = TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC;
49 unsigned timer_reload = 1000000 / Config::Scheduler_granularity;
51 write(timer_reload, TIMER1_BASE + TIMER_LOAD);
52 write(timer_reload, TIMER1_BASE + TIMER_VALUE);
53 write(timer_ctrl | TIMER_CTRL_IE, TIMER1_BASE + TIMER_CTRL);
57 void Timer::init(Cpu_number)
58 { _timer.construct(Kmem::mmio_remap(Mem_layout::Timer_phys_base)); }
64 _timer->write(1, TIMER1_BASE + TIMER_INTCLR);
69 Timer::update_one_shot(Unsigned64 wakeup)
74 IMPLEMENT inline NEEDS["kip.h"]
78 if (Config::Scheduler_one_shot)
81 return Kip::k()->clock;