hw_timer.h
2.06 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
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
#ifndef _HW_TIMER_H
#define _HW_TIMER_H
#include <xtensa/config/core.h>
#include <xtensa/config/specreg.h>
//#include "xtensa_timer.h"
//#define XT_TICK_PER_SEC 50
//#define OS_TIMER0_TICK_MS 50
//#define OS_TIMER0_TICK_MS (1000/XT_TICK_PER_SEC)
/*
* timer related functions
*/
void timer_delayus( U32 xus );
void timer_delayms( U32 xms );
typedef struct {
int sysTick;
U32 sysCnt;
U32 sysCmp;
} TIME;
void timer_get( TIME *time, int hiPrecise );
U32 timer_calUs( TIME *start, TIME *stop );
#define _XTSTR(x) # x
#define XTSTR(x) _XTSTR(x)
//static __inline__ int read_ccount()
static __inline__ unsigned int read_ccount()
{
unsigned int ccount;
__asm__ __volatile__ (
"rsr %0, "XTSTR(CCOUNT)
: "=a" (ccount)
);
return ccount;
}
//static __inline__ int read_ccompare0()
static __inline__ unsigned int read_ccompare0()
{
unsigned int ccompare0;
__asm__ __volatile__ (
"rsr %0, "XTSTR(CCOMPARE_0)
: "=a" (ccompare0)
);
return ccompare0;
}
static __inline__ int read_ccompare1()
{
unsigned int ccompare1;
__asm__ __volatile__ (
"rsr %0, "XTSTR(CCOMPARE_1)
: "=a" (ccompare1)
);
return ccompare1;
}
static __inline__ unsigned int read_intenable()
{
unsigned int intenable;
__asm__ __volatile__ (
"rsr %0, "XTSTR(INTENABLE)
: "=a" (intenable)
);
return intenable;
}
static __inline__ void set_ccompare1(int val)
{
__asm__ __volatile__ (
"wsr %0, "XTSTR(CCOMPARE_1)"\n\t"
"isync\n\t"
:
: "a" (val)
);
}
static __inline__ void set_ccompare2(int val)
{
__asm__ __volatile__ (
"wsr %0, "XTSTR(CCOMPARE_2)"\n\t"
"isync\n\t"
:
: "a" (val)
);
}
static __inline__ void set_ccompare0(int val)
{
__asm__ __volatile__ (
"wsr %0, "XTSTR(CCOMPARE_0)"\n\t"
"isync\n\t"
:
: "a" (val)
);
}
U8 timer_checkTimeout(U32 StartTime, U32 xus);
U32 timer_getCurtime(void);
#endif //_HW_TIMER_H