-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathperf_timer.c
More file actions
72 lines (54 loc) · 1.54 KB
/
perf_timer.c
File metadata and controls
72 lines (54 loc) · 1.54 KB
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
#include "perf_timer.h"
/* For delay calculation using global timer */
#define SCU_GLOBAL_TIMER_COUNT_L32 0xF8F00200
#define SCU_GLOBAL_TIMER_COUNT_U32 0xF8F00204
#define SCU_GLOBAL_TIMER_CONTROL 0xF8F00208
#define APU_FREQ 666666687
/* start timer */
void perf_start_clock(void)
{
*(volatile unsigned int*)SCU_GLOBAL_TIMER_CONTROL = ((1 << 0) | // Timer Enable
(1 << 3) | // Auto-increment
(0 << 8) // Pre-scale
);
}
/* Compute mask for given delay in miliseconds*/
unsigned int get_number_of_cycles_for_delay(unsigned int delay)
{
// GTC is always clocked at 1/2 of the CPU frequency (CPU_3x2x)
return (APU_FREQ*delay/(2*1000));
}
unsigned int get_delay_for_number_of_cycles(unsigned int number_of_cycles)
{
return ((2*1000)*number_of_cycles/APU_FREQ);
}
/* stop timer */
void perf_stop_clock(void)
{
*(volatile unsigned int*)SCU_GLOBAL_TIMER_CONTROL = 0;
}
/* stop timer and reset timer count regs */
void perf_reset_clock(void)
{
perf_stop_clock();
*(volatile unsigned int*)SCU_GLOBAL_TIMER_COUNT_L32 = 0;
*(volatile unsigned int*)SCU_GLOBAL_TIMER_COUNT_U32 = 0;
}
void perf_reset_and_start_clock()
{
perf_reset_clock();
perf_start_clock();
}
typedef struct timerLongStr {
unsigned int lo;
unsigned int hi;
};
volatile unsigned long long int get_clock() {
return *(volatile unsigned long long int*)SCU_GLOBAL_TIMER_COUNT_L32;
}
volatile unsigned int get_clock_L() {
return *(volatile unsigned int*)SCU_GLOBAL_TIMER_COUNT_L32;
}
volatile unsigned int get_clock_U() {
return *(volatile unsigned int*)SCU_GLOBAL_TIMER_COUNT_U32;
}