-
Notifications
You must be signed in to change notification settings - Fork 29
/
pxa255_TIMR.c
executable file
·123 lines (95 loc) · 2.25 KB
/
pxa255_TIMR.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
#include "pxa255_TIMR.h"
#include "mem.h"
static void pxa255timrPrvRaiseLowerInts(Pxa255timr* timr){
pxa255icInt(timr->ic, PXA255_I_TIMR0, (timr->OSSR & 1) != 0);
pxa255icInt(timr->ic, PXA255_I_TIMR1, (timr->OSSR & 2) != 0);
pxa255icInt(timr->ic, PXA255_I_TIMR2, (timr->OSSR & 4) != 0);
pxa255icInt(timr->ic, PXA255_I_TIMR3, (timr->OSSR & 8) != 0);
}
static void pxa255timrPrvCheckMatch(Pxa255timr* timr, UInt8 idx){
UInt8 v = 1UL << idx;
if((timr->OSCR == timr->OSMR[idx]) && (timr->OIER & v)){
timr->OSSR |= v;
}
}
static void pxa255timrPrvUpdate(Pxa255timr* timr){
pxa255timrPrvCheckMatch(timr, 0);
pxa255timrPrvCheckMatch(timr, 1);
pxa255timrPrvCheckMatch(timr, 2);
pxa255timrPrvCheckMatch(timr, 3);
}
static Boolean pxa255timrPrvMemAccessF(void* userData, UInt32 pa, UInt8 size, Boolean write, void* buf){
Pxa255timr* timr = userData;
UInt32 val = 0;
if(size != 4) {
err_str(__FILE__ ": Unexpected ");
// err_str(write ? "write" : "read");
// err_str(" of ");
// err_dec(size);
// err_str(" bytes to 0x");
// err_hex(pa);
// err_str("\r\n");
return true; //we do not support non-word accesses
}
pa = (pa - PXA255_TIMR_BASE) >> 2;
if(write){
val = *(UInt32*)buf;
switch(pa){
case 0:
case 1:
case 2:
case 3:
timr->OSMR[pa] = val;
break;
case 4:
timr->OSCR = val;
break;
case 5:
timr->OSSR = timr->OSSR &~ val;
pxa255timrPrvRaiseLowerInts(timr);
break;
case 6:
timr->OWER = val;
break;
case 7:
timr->OIER = val;
pxa255timrPrvUpdate(timr);
pxa255timrPrvRaiseLowerInts(timr);
break;
}
}
else{
switch(pa){
case 0:
case 1:
case 2:
case 3:
val = timr->OSMR[pa];
break;
case 4:
val = timr->OSCR;
break;
case 5:
val = timr->OSSR;
break;
case 6:
val = timr->OWER;
break;
case 7:
val = timr->OIER;
break;
}
*(UInt32*)buf = val;
}
return true;
}
Boolean pxa255timrInit(Pxa255timr* timr, ArmMem* physMem, Pxa255ic* ic){
__mem_zero(timr, sizeof(Pxa255timr));
timr->ic = ic;
return memRegionAdd(physMem, PXA255_TIMR_BASE, PXA255_TIMR_SIZE, pxa255timrPrvMemAccessF, timr);
}
void pxa255timrTick(Pxa255timr* timr){
timr->OSCR++;
pxa255timrPrvUpdate(timr);
pxa255timrPrvRaiseLowerInts(timr);
}