]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/alphapc/clock.c
etheriwl: implement 4965 firmware bootstrap (untested)
[plan9front.git] / sys / src / 9 / alphapc / clock.c
1 #include        "u.h"
2 #include        "../port/lib.h"
3 #include        "mem.h"
4 #include        "dat.h"
5 #include        "fns.h"
6 #include        "io.h"
7 #include        "axp.h"
8 #include        "ureg.h"
9
10 void
11 clockinit(void)
12 {
13 }
14
15 uvlong
16 cycletimer(void)
17 {
18         ulong pcc;
19         vlong delta;
20
21         pcc = rpcc(nil) & 0xFFFFFFFF;
22         if(m->cpuhz == 0){
23                 /*
24                  * pcclast is needed to detect wraparound of
25                  * the cycle timer which is only 32-bits.
26                  * m->cpuhz is set from the info passed from
27                  * the firmware.
28                  * This could be in clockinit if can
29                  * guarantee no wraparound between then and now.
30                  *
31                  * All the clock stuff needs work.
32                  */
33                 m->cpuhz = hwrpb->cfreq;
34                 m->pcclast = pcc;
35         }
36         delta = pcc - m->pcclast;
37         if(delta < 0)
38                 delta += 0x100000000LL;
39         m->pcclast = pcc;
40         m->fastclock += delta;
41
42         return MACHP(0)->fastclock;
43 }
44
45 uvlong
46 fastticks(uvlong* hz)
47 {
48         uvlong ticks;
49         int x;
50
51         x = splhi();
52         ticks = cycletimer();
53         splx(x);
54
55         if(hz)
56                 *hz = m->cpuhz;
57
58         return ticks;
59 }
60
61 ulong
62 µs(void)
63 {
64         return fastticks2us(cycletimer());
65 }
66
67 /*  
68  *  performance measurement ticks.  must be low overhead.
69  *  doesn't have to count over a second.
70  */
71 ulong
72 perfticks(void)
73 {
74         return rpcc(nil);
75 }
76
77 void
78 timerset(Tval)
79 {
80 }
81
82 void
83 microdelay(int us)
84 {
85         uvlong eot;
86
87         eot = fastticks(nil) + (m->cpuhz/1000000)*us;
88         while(fastticks(nil) < eot)
89                 ;
90 }
91
92 void
93 delay(int millisecs)
94 {
95         microdelay(millisecs*1000);
96 }
97
98 void
99 clock(Ureg *ureg)
100 {
101         static int count;
102
103         cycletimer();
104
105         /* HZ == 100, timer == 1024Hz.  error < 1ms */
106         count += 100;
107         if (count < 1024)
108                 return;
109         count -= 1024;
110
111         timerintr(ureg, 0);
112 }