-
Notifications
You must be signed in to change notification settings - Fork 1
/
demoTimer.c
219 lines (178 loc) · 5.11 KB
/
demoTimer.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
* \file demoTimer.c
*
* \brief This file contains Timer related functions.
*
*/
/* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
* ALL RIGHTS RESERVED
*/
#include "demoTimer.h"
#include "soc_AM335x.h"
#include "evmAM335x.h"
#include "interrupt.h"
#include "dmtimer.h"
/*******************************************************************************
** INTERNAL MACRO DEFINITIONS
*******************************************************************************/
#define TIMER_INITIAL_COUNT (0xFFE00000u)
#define TIMER_RLD_COUNT (0xFFE00000u)
#define TMR_STEP_CNT (7u)
/* 1 count at 32.768 KHz takes 31.25us */
/* 0x1900 counts takes 200ms */
#define TIMER_200MS_DELAY (0xFFFFE6FF)
/*******************************************************************************
** INTERNAL FUNCTION PROTOTYPES
*******************************************************************************/
static void Timer2Isr(void);
static void Timer4Isr(void);
/*******************************************************************************
** INTERNAL VARIABLE DEFINITIONS
*******************************************************************************/
volatile unsigned int tmrFlag = FALSE;
unsigned int tmrClick = FALSE;
volatile unsigned int tmr4Flag = FALSE;
unsigned int timerCount[10] =
{
0xFFF00000u,
0xFFE00000u,
0xFFC00000u,
0xFFA00000u,
0xFF800000u,
0xFF600000u,
0xFF400000u,
0xFF200000u,
0xFF000000u,
0xFD000000u,
};
/*******************************************************************************
** FUNCTION DEFINITIONS
*******************************************************************************/
/*
** Registers the Timer2 ISR.
*/
void Timer2IntRegister(void)
{
IntRegister(SYS_INT_TINT2, Timer2Isr);
}
/*
** Configures the Timer2 for 32 bit
*/
void Timer2Config(void)
{
/* Load the counter with the initial count value */
DMTimerCounterSet(SOC_DMTIMER_2_REGS, TIMER_INITIAL_COUNT);
/* Load the load register with the reload count value */
//DMTimerReloadSet(SOC_DMTIMER_2_REGS, TIMER_RLD_COUNT);
/* Configure the DMTimer for one shot mode */
DMTimerModeConfigure(SOC_DMTIMER_2_REGS, DMTIMER_ONESHOT_NOCMP_ENABLE);
tmrFlag = FALSE;
Timer2Stop();
}
/*
** Enables the Timer2 Interrupts
*/
void Timer2IntEnable(void)
{
/* Enable the DMTimer interrupts */
DMTimerIntEnable(SOC_DMTIMER_2_REGS, DMTIMER_INT_OVF_EN_FLAG);
}
/*
** Starts the Timer
*/
void Timer2Start(void)
{
/* Start the DMTimer */
DMTimerEnable(SOC_DMTIMER_2_REGS);
}
/*
** Stops the Timer. The Timer Counter is Reset.
*/
void Timer2Stop(void)
{
DMTimerDisable(SOC_DMTIMER_2_REGS);
//DMTimerCounterSet(SOC_DMTIMER_2_REGS, 0);
}
/*
** Timer 2 Interrupt Service Routine
*/
static void Timer2Isr(void)
{
static unsigned int index = 0;
/* Clear the status of the interrupt flags */
DMTimerIntStatusClear(SOC_DMTIMER_2_REGS, DMTIMER_INT_OVF_EN_FLAG);
/* Notify end of interrupt */
DMTimerEndOfInterrupt(SOC_DMTIMER_2_REGS);
if(TRUE == tmrClick)
{
tmrFlag = TRUE;
}
else
{
tmrFlag = FALSE;
}
DMTimerCounterSet(SOC_DMTIMER_2_REGS, timerCount[index++%10]);
DMTimerEnable(SOC_DMTIMER_2_REGS);
}
/*******************************************************************************
** FUNCTION DEFINITIONS TIMER4
*******************************************************************************/
/*
** Registers the Timer4 ISR.
*/
void Timer4IntRegister(void)
{
IntRegister(SYS_INT_TINT4, Timer4Isr);
/* Set the priority */
IntPrioritySet(SYS_INT_TINT4, 0, AINTC_HOSTINT_ROUTE_IRQ);
/* Enable the system interrupt */
IntSystemEnable(SYS_INT_TINT4);
}
/*
** Configures the Timer4 for 32 bit
*/
void Timer4Config(void)
{
/* Load the counter with the initial count value */
DMTimerCounterSet(SOC_DMTIMER_4_REGS, TIMER_INITIAL_COUNT);
/* Load the load register with the reload count value */
DMTimerReloadSet(SOC_DMTIMER_4_REGS, TIMER_200MS_DELAY);
/* Configure the DMTimer for one shot mode */
DMTimerModeConfigure(SOC_DMTIMER_4_REGS, DMTIMER_AUTORLD_NOCMP_ENABLE);
Timer4Stop();
}
/*
** Enables the Timer4 Interrupts
*/
void Timer4IntEnable(void)
{
/* Enable the DMTimer interrupts */
DMTimerIntEnable(SOC_DMTIMER_4_REGS, DMTIMER_INT_OVF_EN_FLAG);
}
/*
** Starts the Timer
*/
void Timer4Start(void)
{
/* Start the DMTimer */
DMTimerEnable(SOC_DMTIMER_4_REGS);
}
/*
** Stops the Timer. The Timer Counter is Reset.
*/
void Timer4Stop(void)
{
DMTimerDisable(SOC_DMTIMER_4_REGS);
//DMTimerCounterSet(SOC_DMTIMER_4_REGS, 0);
}
/*
** Timer 4 Interrupt Service Routine
*/
static void Timer4Isr(void)
{
/* Clear the status of the interrupt flags */
DMTimerIntStatusClear(SOC_DMTIMER_4_REGS, DMTIMER_INT_OVF_EN_FLAG);
tmr4Flag = TRUE;
//DMTimerEnable(SOC_DMTIMER_4_REGS);
}
/******************************** End of file **********************************/