-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmytimer.h
127 lines (100 loc) · 2.71 KB
/
mytimer.h
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
124
125
126
127
#ifndef MYTIMER_H_
#define MYTIMER_H_
#include "CMSIS/a2fxxxm3.h"
#define MYTIMER_BASE 0x40050000
#define MYTIMER_BASE2 0X40050200
// The technique of using a structure declaration
// to describe the device register layout and names is
// very common practice. Notice that there aren't actually
// any objects of that type defined, so the declaration
// simply indicates the structure without using up any store.
typedef struct
{
uint32_t overflow; // Offset 0x00
uint32_t counter; // Offset 0x04
uint32_t control; // Offset 0x08
uint32_t compare; // Offset 0x0C
uint32_t interrupt_status; // Offset 0x10
uint32_t sync_capture; // Offset 0x14
uint32_t async_capture; // Offset 0x18
} mytimer_t;
#define MYTIMER_ENABLE_MASK 0x00000001UL
// Using the mytimer_t structure we can make the
// compiler do the offset mapping for us.
// To access the device registers, an appropriately
// cast constant is used as if it were pointing to
// such a structure, but of course it points to memory addresses instead.
// Look at at mytimer.c
// Look at the the functions's disassembly
// in .lst file under the Debug folder
#define MYTIMER ((mytimer_t *) MYTIMER_BASE)
#define MYTIMER2 ((mytimer_t *) MYTIMER_BASE2)
/**
* Initialize the MYTIMER
*/
void MYTIMER_init(int timerNo);
/**
* Start MYTIMER
*/
void MYTIMER_enable(int timerNo);
/**
* Stop MYTIMER
*/
void MYTIMER_disable(int timerNo);
/**
* Set the limit to which the timer counts.
*/
void MYTIMER_setOverflowVal(int timerNo, uint32_t value);
/**
* Read the counter value of the timer.
*/
uint32_t MYTIMER_getCounterVal(int timerNo);
/**
* Enable all interrupts
*/
void MYTIMER_enable_allInterrupts(int timerNo);
/**
* Disable all interrupts
*/
void MYTIMER_disable_allInterrupts(int timerNo);
/**
* Enable compare interrupt
*/
void MYTIMER_enable_compareInt(int timerNo);
/**
* Disable compare interrupt
*/
void MYTIMER_disable_compareInt(int timerNo);
/**
* Set Compare value
*/
void MYTIMER_setCompareVal(int timerNo, uint32_t compare);
/**
* Enable overflow interrupt
*/
void MYTIMER_enable_overflowInt(int timerNo);
/**
* Disable overflow interrupt
*/
void MYTIMER_disable_overflowInt(int timerNo);
/**
* Interrupt status
*/
uint32_t MYTIMER_getInterrupt_status(int timerNo);
/**
* Enable Capture
*/
void MYTIMER_enable_capture(int timerNo);
/**
* Disable Capture
*/
void MYTIMER_disable_capture(int timerNo);
/**
* Read the synchronous capture value
*/
uint32_t MYTIMER_get_sync_capture(int timerNo);
/**
* Read the asynchronous capture value
*/
uint32_t MYTIMER_get_async_capture(int timerNo);
#endif /* MYTIMER_H_ */