]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/arm/bsp/integrator/timer-arm-integrator.cpp
update
[l4.git] / kernel / fiasco / src / kern / arm / bsp / integrator / timer-arm-integrator.cpp
1 // --------------------------------------------------------------------------
2 INTERFACE [arm && integrator]:
3
4 #include "mmio_register_block.h"
5
6 EXTENSION class Timer : private Mmio_register_block
7 {
8 public:
9   static unsigned irq() { return 6; }
10
11 private:
12   enum {
13     TIMER0_BASE = 0x000,
14     TIMER1_BASE = 0x100,
15     TIMER2_BASE = 0x200,
16
17     TIMER_LOAD   = 0x00,
18     TIMER_VALUE  = 0x04,
19     TIMER_CTRL   = 0x08,
20     TIMER_INTCLR = 0x0c,
21
22     TIMER_CTRL_IE       = 1 << 5,
23     TIMER_CTRL_PERIODIC = 1 << 6,
24     TIMER_CTRL_ENABLE   = 1 << 7,
25   };
26
27   static Static_object<Timer> _timer;
28 };
29
30 // ----------------------------------------------------------------------
31 IMPLEMENTATION [arm && integrator]:
32
33 #include "config.h"
34 #include "kip.h"
35 #include "kmem.h"
36 #include "mem_layout.h"
37
38 Static_object<Timer> Timer::_timer;
39
40 PUBLIC
41 Timer::Timer(Address base) : Mmio_register_block(base)
42 {
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);
47
48   unsigned timer_ctrl = TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC;
49   unsigned timer_reload = 1000000 / Config::Scheduler_granularity;
50
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);
54 }
55
56 IMPLEMENT
57 void Timer::init(Cpu_number)
58 { _timer.construct(Kmem::mmio_remap(Mem_layout::Timer_phys_base)); }
59
60 PUBLIC static inline
61 void
62 Timer::acknowledge()
63 {
64   _timer->write(1, TIMER1_BASE + TIMER_INTCLR);
65 }
66
67 IMPLEMENT inline
68 void
69 Timer::update_one_shot(Unsigned64 wakeup)
70 {
71   (void)wakeup;
72 }
73
74 IMPLEMENT inline NEEDS["kip.h"]
75 Unsigned64
76 Timer::system_clock()
77 {
78   if (Config::Scheduler_one_shot)
79     return 0;
80   else
81     return Kip::k()->clock;
82 }
83