Mercurial > hg > Members > mitsuki > xv6_rpi2_port
comparison source/timer.c @ 0:ed10291ff195
first commit
author | mir3636 |
---|---|
date | Sun, 06 Jan 2019 19:27:03 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ed10291ff195 |
---|---|
1 /***************************************************************** | |
2 * timer.c | |
3 * by Zhiyi Huang, hzy@cs.otago.ac.nz | |
4 * University of Otago | |
5 * | |
6 ********************************************************************/ | |
7 | |
8 // The System Timer peripheral | |
9 | |
10 #include "types.h" | |
11 #include "defs.h" | |
12 #include "param.h" | |
13 #include "memlayout.h" | |
14 #include "proc.h" | |
15 #include "traps.h" | |
16 #include "arm.h" | |
17 #include "spinlock.h" | |
18 | |
19 #define TIMER_REGS_BASE (MMIO_VA+0x003000) | |
20 #define CONTROL_STATUS 0x0 // control/status | |
21 #define COUNTER_LO 0x4 // the time-stamp lower 32 bits | |
22 #define COUNTER_HI 0x8 // the time-stamp higher 32 bits | |
23 #define COMPARE0 0xc // compare 0 | |
24 #define COMPARE1 0x10 // compare 1 | |
25 #define COMPARE2 0x14 // compare 2 | |
26 #define COMPARE3 0x18 // compare 3 | |
27 | |
28 #define TIMER_FREQ 10000 // interrupt 100 times/sec. | |
29 | |
30 void | |
31 enabletimer3irq(void) | |
32 { | |
33 intctrlregs *ip; | |
34 | |
35 ip = (intctrlregs *)INT_REGS_BASE; | |
36 ip->gpuenable[0] |= 1 << IRQ_TIMER3; // enable the system timer3 irq | |
37 } | |
38 | |
39 | |
40 void | |
41 timer3init(void) | |
42 { | |
43 uint v; | |
44 | |
45 enabletimer3irq(); | |
46 | |
47 v = inw(TIMER_REGS_BASE+COUNTER_LO); | |
48 v += TIMER_FREQ; | |
49 | |
50 outw(TIMER_REGS_BASE+COMPARE3, v); | |
51 ticks = 0; | |
52 } | |
53 | |
54 void | |
55 timer3intr(void) | |
56 { | |
57 uint v; | |
58 //cprintf("timer3 interrupt: %x\n", inw(TIMER_REGS_BASE+CONTROL_STATUS)); | |
59 outw(TIMER_REGS_BASE+CONTROL_STATUS, (1 << IRQ_TIMER3)); // clear timer3 irq | |
60 | |
61 ticks++; | |
62 wakeup(&ticks); | |
63 | |
64 // reset the value of compare3 | |
65 v=inw(TIMER_REGS_BASE+COUNTER_LO); | |
66 v += TIMER_FREQ; | |
67 outw(TIMER_REGS_BASE+COMPARE3, v); | |
68 } | |
69 | |
70 void | |
71 delay(uint m) | |
72 { | |
73 unsigned long long t; | |
74 | |
75 if(m == 0) return; | |
76 | |
77 t = getsystemtime() + m; | |
78 while(t != getsystemtime()); | |
79 | |
80 return; | |
81 } |