This repository has been archived by the owner on Jan 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
timer.c
153 lines (127 loc) · 2.89 KB
/
timer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "basic.h"
#include "type.h"
#include "timer.h"
#include "debug.h"
#define TIMER_CLOCK_FREQ 12500000
void ptimer_init( void )
{
UW ip;
ip = TIMER_CLOCK_FREQ;
Asm("mcr p15, 0, %0, c14, c0, 0":: "r"(ip));
}
UD ptimer_get_value( void ){
UW t1,t2;
UD ret;
Asm("ISB");
Asm("mrrc p15, 0, %0, %1, c14":"=r"(t1),"=r"(t2));
ret = t2;
ret <<= 32;
ret += t1;
return ret;
}
UD vtimer_get_value( void ){
UW t1,t2;
UD ret;
Asm("ISB");
Asm("mrrc p15, 1, %0, %1, c14":"=r"(t1),"=r"(t2));
ret = t2;
ret <<= 32;
ret += t1;
return ret;
}
void ptimer_set_value( UD next_time ){
UW t1,t2;
t1 = next_time;
t2 = next_time >> 32;
Asm("mcrr p15, 2, %0, %1, c14"::"r"(t1),"r"(t2));
UW ip = 0x5;
Asm("mcr p15, 0, %0, c14, c2, 1":: "r"(ip));
}
void ptimer_set( UW status, UD next_time ){
UW t1,t2;
t1 = next_time & 0xffffffffLL;
t2 = next_time >> 32;
Asm("mcrr p15, 2, %0, %1, c14"::"r"(t1),"r"(t2));
Asm("mcr p15, 0, %0, c14, c2, 1":: "r"(status));
}
void vtimer_set( UW status, UD next_time ){
UW t1,t2;
t1 = next_time & 0xffffffffLL;
t2 = next_time >> 32;
Asm("mcrr p15, 3, %0, %1, c14"::"r"(t1),"r"(t2));
Asm("mcr p15, 0, %0, c14, c3, 1":: "r"(status));
}
void ptimer_clear( void ){
UW t1 = 0xffffffff, t2 = 0xffffffff;
Asm("mcrr p15, 2, %0, %1, c14"::"r"(t1),"r"(t2));
UW ip = 0x2;
Asm("mcr p15, 0, %0, c14, c2, 1":: "r"(ip));
}
UW ptimer_get_status( void ){
UW r0;
Asm("mrc p15, 0, %0, c14, c2, 1":"=r"(r0));
return r0;
}
UW vtimer_get_status( void ){
UW r0;
Asm("mrc p15, 0, %0, c14, c3, 1":"=r"(r0));
return r0;
}
UD ptimer_get_cmp_value( void ){
UW r0,r1;
Asm("ISB");
Asm("mrrc p15, 2, %0, %1, c14":"=r"(r0),"=r"(r1));
UD ret = r1;
ret <<= 32;
ret += r0;
return ret;
}
UD vtimer_get_cmp_value( void ){
UW r0,r1;
Asm("ISB");
Asm("mrrc p15, 3, %0, %1, c14":"=r"(r0),"=r"(r1));
UD ret = r1;
ret <<= 32;
ret += r0;
return ret;
}
UD vtimer_get_offset( void ){
UW r0, r1;
Asm("mrrc p15, 4, %0, %1, c14":"=r"(r0), "=r"(r1));
UD ret = r1;
ret <<= 32;
ret += r0;
return ret;
}
void vtimer_set_offset( UD offset ){
UW r0 = offset&0xffffffff, r1 = offset >> 32;
Asm("mcrr p15, 4, %0, %1, c14"::"r"(r0), "r"(r1));
}
UD htimer_get_cmp_value( void ) {
UW r0,r1;
Asm("ISB");
Asm("mrrc p15, 6, %0, %1, c14":"=r"(r0),"=r"(r1));
UD ret = r1;
ret <<= 32;
ret += r0;
return ret;
}
void htimer_set_value( UD next_time ){
UW t1,t2;
t1 = next_time;
t2 = next_time >> 32;
Asm("mcrr p15, 6, %0, %1, c14"::"r"(t1),"r"(t2));
UW ip = 0x5;
Asm("mcr p15, 4, %0, c14, c2, 1":: "r"(ip));
}
void htimer_clear( void ){
UW t1 = 0xffffffff, t2 = 0xffffffff;
Asm("mcrr p15, 6, %0, %1, c14":"=r"(t1),"=r"(t2));
UW ip = 0x2;
Asm("mcr p15, 4, %0, c14, c2, 1":: "r"(ip));
}
bool htimer_is_enable( void ){
UW ip;
Asm("mrc p15, 4, %0, c14, c2, 1":"=r"(ip));
return ip!=0x2;
}