-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlab5timerimpl.c
120 lines (101 loc) · 2.12 KB
/
lab5timerimpl.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
#include "mytimer.h"
void MYTIMER_init()
{
// we don't have to do anything.
}
void MYTIMER_enable()
{
MYTIMER->control |= MYTIMER_ENABLE_MASK;
}
void MYTIMER_disable()
{
MYTIMER->control &= ~MYTIMER_ENABLE_MASK;
}
void MYTIMER_setOverflowVal(uint32_t value)
{
// Yes it's inefficient, but it's written this way to
// show you the C to assembly mapping.
uint32_t * timerAddr = (uint32_t*)(MYTIMER);
*timerAddr = value; // overflowReg is at offset 0x0
}
uint32_t MYTIMER_getCounterVal()
{
// Yes it's inefficient, but it's written this way to
// show you the C to assembly mapping.
uint32_t * timerAddr = (uint32_t*)(MYTIMER);
return *(timerAddr+1); // counterReg is at offset 0x4
}
/*********************************************************************/
/**
* Enable all interrupts
*/
void MYTIMER_enable_allInterrupts() {
MYTIMER->control |= ALLINT_ENABLE_MASK;
}
/**
* Disable all interrupts
*/
void MYTIMER_disable_allInterrupts(){
MYTIMER->control &= ~ALLINT_ENABLE_MASK;
}
/**
* Enable compare interrupt
*/
void MYTIMER_enable_compareInt(){
MYTIMER->control |= CMPINT_ENABLE_MASK;
}
/**
* Disable compare interrupt
*/
void MYTIMER_disable_compareInt(){
MYTIMER->control &= ~CMPINT_ENABLE_MASK;
}
/**
* Set Compare value
*/
void MYTIMER_setCompareVal(uint32_t compare){
if(compare < MYTIMER->overflow)
MYTIMER->compare = compare;
}
/**
* Enable overflow interrupt
*/
void MYTIMER_enable_overflowInt(){
MYTIMER->control |= OVERFLOWINT_ENABLE_MASK;
}
/**
* Disable overflow interrupt
*/
void MYTIMER_disable_overflowInt(){
MYTIMER->control &= ~OVERFLOWINT_ENABLE_MASK;
}
/**
* Interrupt status
*/
uint32_t MYTIMER_getInterrupt_status(){
return MYTIMER->status;
}
/**
* Enable Capture
*/
void MYTIMER_enable_capture() {
MYTIMER->control |= CAPTUREINT_ENABLE_MASK;
}
/**
* Disable Capture
*/
void MYTIMER_disable_capture(){
MYTIMER->control &= ~CAPTUREINT_ENABLE_MASK;
}
/**
* Read the synchronous capture value
*/
uint32_t MYTIMER_get_sync_capture() {
return MYTIMER->sync;
}
/**
* Read the asynchronous capture value
*/
uint32_t MYTIMER_get_async_capture() {
return MYTIMER->async;
}