]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/drivers/delayloop.cpp
update
[l4.git] / kernel / fiasco / src / drivers / delayloop.cpp
1 INTERFACE:
2
3 #include "std_macros.h"
4 #include "initcalls.h"
5
6 class Delay
7 {
8 private:
9   static unsigned count;
10
11 public:
12   static void init() FIASCO_INIT;
13 };
14
15 IMPLEMENTATION:
16
17 #include "kip.h"
18 #include "processor.h"
19 #include "timer.h"
20
21 unsigned Delay::count;
22
23 IMPLEMENT void
24 Delay::init()
25 {
26   Cpu_time t1;
27   count = 0;
28
29   Kip *k = Kip::k();
30   Cpu_time t = Kip::k()->clock;
31   Timer::update_timer(t + 1000); // 1ms
32   while (t == (t1 = k->clock))
33     Proc::pause();
34   Timer::update_timer(k->clock + 1000); // 1ms
35   while (t1 == k->clock)
36     {
37       ++count;
38       Proc::pause();
39     }
40 }
41
42 /**
43  * Hint: ms is actually the timer granularity, which
44  *       currently happens to be milliseconds
45  */
46 PUBLIC static void
47 Delay::delay(unsigned ms)
48 {
49   Kip *k = Kip::k();
50   while (ms--)
51     {
52       unsigned c = count;
53       while (c--)
54         {
55           (void)k->clock;
56           Proc::pause();
57         }
58     }
59 }