-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathspecial_regs.h
343 lines (306 loc) · 7.3 KB
/
special_regs.h
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/**
* @file include/axis/special_regs.h
*
* @author Hiroyuki Chishiro
*/
#ifndef __MCUBE_AXIS_SPECIAL_REGS_H__
#define __MCUBE_AXIS_SPECIAL_REGS_H__
#ifndef __ASSEMBLY__
/**
* @def NR_SOFTWARE_INTERRUPTS
* @brief Number of software interrupts.
*/
#define NR_SOFTWARE_INTERRUPTS 8
/**
* @def SOFTWARE_INTERRUPT_OFFSET
* @brief Offset of software interrupt.
*/
#define SOFTWARE_INTERRUPT_OFFSET 8
/**
* @fn static inline unsigned long get_cpu_id(void)
* @brief get CPU ID (including serialized cluster ID).
*
* @return CPU ID.
*/
static inline unsigned long get_cpu_id(void)
{
unsigned long data;
unsigned long cluster;
asm volatile("mfs %0, $1" : "=r"(data));
cluster = data >> 16;
return (cluster << 3) + (data & 0x7);
}
/**
* @fn static inline unsigned long get_cluster_id(void)
* @brief get cluster ID.
*
* @return Cluster ID.
*/
static inline unsigned long get_cluster_id(void)
{
unsigned long data;
asm volatile("mfs %0, $1" : "=r"(data));
return data >> 16;
}
/**
* @fn static inline unsigned long get_cluster_and_cpu_ids(void)
* @brief get cluster and CPU IDs.
*
* @return Cluster and CPU IDs.
*/
static inline unsigned long get_cluster_and_cpu_ids(void)
{
unsigned long data;
asm volatile("mfs %0, $1" : "=r"(data));
return data;
}
/**
* @fn static inline unsigned long get_interrupt_vector_base_address(void)
* @brief get interrupt vector base address.
*
* @return Interrupt vector base address.
*/
static inline unsigned long get_interrupt_vector_base_address(void)
{
unsigned long addr;
asm volatile("mfs %0, $2" : "=r"(addr));
return addr;
}
/**
* @fn static inline void set_interrupt_vector_base_address(unsigned long addr)
* @brief set interrupt vector base address.
*
* @param addr Address.
*/
static inline void set_interrupt_vector_base_address(unsigned long addr)
{
asm volatile("mts $2, %0" :: "r"(addr));
}
/**
* @fn static inline unsigned long get_interrupt_program_counter(void)
* @brief get interrupt program counter.
*
* @return Interrupt program counter.
*/
static inline unsigned long get_interrupt_program_counter(void)
{
unsigned long addr;
asm volatile("mfs %0, $3" : "=r"(addr));
return addr;
}
/**
* @fn static inline void set_interrupt_program_counter(unsigned long addr)
* @brief set interrupt program counter.
*
* @param addr Address.
*/
static inline void set_interrupt_program_counter(unsigned long addr)
{
asm volatile("mts $3, %0" :: "r"(addr));
}
/**
* @fn static inline unsigned long get_interrupt_status(void)
* @brief get interrupt status.
*
* @return Interrupt status.
*/
static inline unsigned long get_interrupt_status(void)
{
unsigned long status;
asm volatile("mfs %0, $4" : "=r"(status));
return status;
}
/**
* @fn static inline void enable_timer_interrupt(void)
* @brief enable timer interrupt.
*/
static inline void enable_timer_interrupt(void)
{
unsigned long data;
asm volatile("mfs %0, $5" : "=r"(data));
data |= (0x1 << 0);
asm volatile("mts $5, %0" :: "r"(data));
}
/**
* @fn static inline void disable_timer_interrupt(void)
* @brief disable timer interrupt.
*/
static inline void disable_timer_interrupt(void)
{
unsigned long data;
asm volatile("mfs %0, $5" : "=r"(data));
data &= ~(0x1 << 0);
asm volatile("mts $5, %0" :: "r"(data));
}
/**
* @fn static inline void enable_dmac_interrupt(void)
* @brief enable DMAC interrupt.
*/
static inline void enable_dmac_interrupt(void)
{
unsigned long data;
asm volatile("mfs %0, $5" : "=r"(data));
data |= (0x1 << 1);
asm volatile("mts $5, %0" :: "r"(data));
}
/**
* @fn static inline void disable_dmac_interrupt(void)
* @brief disable DMAC interrupt.
*/
static inline void disable_dmac_interrupt(void)
{
unsigned long data;
asm volatile("mfs %0, $5" : "=r"(data));
data &= ~(0x1 << 1);
asm volatile("mts $5, %0" :: "r"(data));
}
/**
* @fn static inline void enable_software_interrupt(unsigned long id)
* @brief enable software interrupt.
*
* @param id ID.
*/
static inline void enable_software_interrupt(unsigned long id)
{
unsigned long data;
if (id > NR_SOFTWARE_INTERRUPTS) {
printk("Error: cpu id %lu exceeds %lu\n", id, NR_SOFTWARE_INTERRUPTS);
return;
}
asm volatile("mfs %0, $5" : "=r"(data));
data |= (0x1 << (id + SOFTWARE_INTERRUPT_OFFSET));
asm volatile("mts $5, %0" :: "r"(data));
}
/**
* @fn static inline void disable_software_interrupt(unsigned long id)
* @brief disable software interrupt.
*
* @param id ID.
*/
static inline void disable_software_interrupt(unsigned long id)
{
unsigned long data;
if (id > NR_SOFTWARE_INTERRUPTS) {
printk("Error: cpu id %lu exceeds %lu\n", id, NR_SOFTWARE_INTERRUPTS);
return;
}
asm volatile("mfs %0, $5" : "=r"(data));
data &= ~(0x1 << (id + SOFTWARE_INTERRUPT_OFFSET));
asm volatile("mts $5, %0" :: "r"(data));
}
/**
* @fn static inline unsigned long get_time_stamp_counter(void)
* @brief get time stamp counter.
*
* @return Time stamp counter.
*/
static inline unsigned long get_time_stamp_counter(void)
{
unsigned long data;
asm volatile("mfs %0, $6" : "=r"(data));
return data;
}
/**
* @fn static inline void set_time_stamp_counter(unsigned long data)
* @brief set time stamp counter.
*
* @param data Data.
*/
static inline void set_time_stamp_counter(unsigned long data)
{
asm volatile("mts $6, %0":: "r"(data));
}
/**
* @fn static inline unsigned long get_current_cpu_time(void)
* @brief get current CPU time.
*
* @return Current CPU time.
*/
static inline unsigned long get_current_cpu_time(void)
{
return get_time_stamp_counter();
}
/**
* @fn static inline void enable_timer(void)
* @brief enable timer.
*/
static inline void enable_timer(void)
{
asm volatile("mts $8, %0" :: "r"(1));
}
/**
* @fn static inline void disable_timer(void)
* @brief disable timer.
*/
static inline void disable_timer(void)
{
asm volatile("mts $8, %0" :: "r"(0));
}
/**
* @fn static inline unsigned long get_timer_count(void)
* @brief get timer count.
*
* @return Timer count.
*/
static inline unsigned long get_timer_count(void)
{
unsigned long data;
asm volatile("mfs %0, $9" : "=r"(data));
return data;
}
/**
* @fn static inline void set_timer_count(unsigned long data)
* @brief set timer count.
*
* @param data Data.
*/
static inline void set_timer_count(unsigned long data)
{
asm volatile("mts $9, %0" :: "r"(data));
}
/**
* @fn static inline unsigned long get_timer_period(void)
* @brief get timer period.
*
* @return Timer period.
*/
static inline unsigned long get_timer_period(void)
{
unsigned long data;
asm volatile("mfs %0, $10" : "=r"(data));
return data;
}
/**
* @fn static inline void set_timer_period(unsigned long data)
* @brief set timer period.
*
* @param data Data.
*/
static inline void set_timer_period(unsigned long data)
{
asm volatile("mts $10, %0" :: "r"(data));
}
/**
* @fn static inline unsigned long get_timer_status(void)
* @brief get timer status.
*
* @return Timer status.
*/
static inline unsigned long get_timer_status(void)
{
unsigned long data;
asm volatile("mfs %0, $11" : "=r"(data));
return data;
}
/**
* @fn static inline void set_timer_status(unsigned long data)
* @brief set timer status.
*
* @param data Data.
*/
static inline void set_timer_status(unsigned long data)
{
asm volatile("mts $11, %0" :: "r"(data));
}
#endif /* !__ASSEMBLY__ */
#endif /* __MCUBE_AXIS_SPECIAL_REGS__ */