1 // ------------------------------------------------------------------------
2 INTERFACE [arm && (sa1100 || pxa)]:
9 static unsigned irq() { return 26; }
13 OSMR0 = Kmem::Timer_map_base + 0x00,
14 OSMR1 = Kmem::Timer_map_base + 0x04,
15 OSMR2 = Kmem::Timer_map_base + 0x08,
16 OSMR3 = Kmem::Timer_map_base + 0x0c,
17 OSCR = Kmem::Timer_map_base + 0x10,
18 OSSR = Kmem::Timer_map_base + 0x14,
19 OWER = Kmem::Timer_map_base + 0x18,
20 OIER = Kmem::Timer_map_base + 0x1c,
22 Timer_diff = (36864 * Config::Scheduler_granularity) / 10000, // 36864MHz*1ms
27 // -------------------------------------------------------------
28 IMPLEMENTATION [arm && (sa1100 || pxa)]:
36 void Timer::init(unsigned)
38 Io::write(1, OIER); // enable OSMR0
39 Io::write(0, OWER); // disable Watchdog
40 Io::write<Mword>(Timer_diff, OSMR0);
41 Io::write(0, OSCR); // set timer counter to zero
42 Io::write(~0U, OSSR); // clear all status bits
47 Timer::timer_to_us(Unsigned32 cr)
48 { return (((Unsigned64)cr) << 14) / 60398; }
52 Timer::us_to_timer(Unsigned64 us)
53 { return (us * 60398) >> 14; }
55 PUBLIC static inline NEEDS["io.h", "config.h", Timer::timer_to_us]
59 if (Config::Scheduler_one_shot)
61 Kip::k()->clock += timer_to_us(Io::read<Unsigned32>(OSCR));
62 //puts("Reset timer");
64 Io::write(0xffffffff, OSMR0);
68 Io::write(1, OSSR); // clear all status bits
74 IMPLEMENT inline NEEDS["kip.h", "io.h", Timer::timer_to_us, Timer::us_to_timer]
76 Timer::update_one_shot(Unsigned64 wakeup)
79 Kip::k()->clock += timer_to_us(Io::read<Unsigned32>(OSCR));
81 Unsigned64 now = Kip::k()->clock;
83 if (EXPECT_FALSE (wakeup <= now) )
88 apic = us_to_timer(wakeup - now);
89 if (EXPECT_FALSE(apic > 0x0ffffffff))
91 if (EXPECT_FALSE (apic < 1) )
96 //printf("%15lld: Set Timer to %lld [%08x]\n", now, wakeup, apic);
98 Io::write(apic, OSMR0);
99 Io::write(1, OSSR); // clear all status bits
102 IMPLEMENT inline NEEDS["config.h", "kip.h", "io.h", Timer::timer_to_us]
104 Timer::system_clock()
106 if (Config::Scheduler_one_shot)
107 return Kip::k()->clock + timer_to_us(Io::read<Unsigned32>(OSCR));
109 return Kip::k()->clock;