-
Notifications
You must be signed in to change notification settings - Fork 8
/
omap_PWT.c
executable file
·84 lines (62 loc) · 1.6 KB
/
omap_PWT.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
//(c) uARM project https://github.com/uARM-Palm/uARM [email protected]
#include "omap_PWT.h"
#include <string.h>
#include <stdlib.h>
#include "util.h"
#include "mem.h"
#define OMAP_PWT_BASE 0xFFFB6000UL
#define OMAP_PWT_SIZE 12
struct OmapPwt {
uint8_t freq, vol, ctrl;
};
static bool omapPwtPrvMemAccessF(void* userData, uint32_t pa, uint_fast8_t size, bool write, void* buf)
{
struct OmapPwt *pwt = (struct OmapPwt*)userData;
uint32_t val = 0;
if ((size != 2 && size != 4) || (pa & 3)) {
fprintf(stderr, "%s: Unexpected %s of %u bytes to 0x%08lx\n", __func__, write ? "write" : "read", size, (unsigned long)pa);
return false;
}
pa = (pa - OMAP_PWT_BASE) >> 2;
if (write)
val = (size == 2) ? *(uint16_t*)buf : *(uint32_t*)buf;
switch (pa) {
case 0x00 / 4:
if (write)
pwt->freq = val & 0x3f;
else
val = pwt->freq;
break;
case 0x04 / 4:
if (write)
pwt->vol = val & 0x7f;
else
val = pwt->vol;
break;
case 0x08 / 4:
if (write)
pwt->ctrl = val & 0x03;
else
val = pwt->ctrl;
break;
default:
return false;
}
if (!write) {
if (size == 2)
*(uint16_t*)buf = val;
else
*(uint32_t*)buf = val;
}
return true;
}
struct OmapPwt* omapPwtInit(struct ArmMem *physMem)
{
struct OmapPwt *pwt = (struct OmapPwt*)malloc(sizeof(*pwt));
if (!pwt)
ERR("cannot alloc PWT");
memset(pwt, 0, sizeof (*pwt));
if (!memRegionAdd(physMem, OMAP_PWT_BASE, OMAP_PWT_SIZE, omapPwtPrvMemAccessF, pwt))
ERR("cannot add PWT to MEM\n");
return pwt;
}