1 |
581 |
jeremybenn |
//*****************************************************************************
|
2 |
|
|
//
|
3 |
|
|
// timer.c - Driver for the timer module.
|
4 |
|
|
//
|
5 |
|
|
// Copyright (c) 2005,2006 Luminary Micro, Inc. All rights reserved.
|
6 |
|
|
//
|
7 |
|
|
// Software License Agreement
|
8 |
|
|
//
|
9 |
|
|
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
|
10 |
|
|
// exclusively on LMI's Stellaris Family of microcontroller products.
|
11 |
|
|
//
|
12 |
|
|
// The software is owned by LMI and/or its suppliers, and is protected under
|
13 |
|
|
// applicable copyright laws. All rights are reserved. Any use in violation
|
14 |
|
|
// of the foregoing restrictions may subject the user to criminal sanctions
|
15 |
|
|
// under applicable laws, as well as to civil liability for the breach of the
|
16 |
|
|
// terms and conditions of this license.
|
17 |
|
|
//
|
18 |
|
|
// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
|
19 |
|
|
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
|
20 |
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
|
21 |
|
|
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
|
22 |
|
|
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
|
23 |
|
|
//
|
24 |
|
|
// This is part of revision 991 of the Stellaris Driver Library.
|
25 |
|
|
//
|
26 |
|
|
//*****************************************************************************
|
27 |
|
|
|
28 |
|
|
//*****************************************************************************
|
29 |
|
|
//
|
30 |
|
|
//! \addtogroup timer_api
|
31 |
|
|
//! @{
|
32 |
|
|
//
|
33 |
|
|
//*****************************************************************************
|
34 |
|
|
|
35 |
|
|
#include "../hw_ints.h"
|
36 |
|
|
#include "../hw_memmap.h"
|
37 |
|
|
#include "../hw_timer.h"
|
38 |
|
|
#include "../hw_types.h"
|
39 |
|
|
#include "debug.h"
|
40 |
|
|
#include "interrupt.h"
|
41 |
|
|
#include "timer.h"
|
42 |
|
|
|
43 |
|
|
//*****************************************************************************
|
44 |
|
|
//
|
45 |
|
|
//! Enables the timer(s).
|
46 |
|
|
//!
|
47 |
|
|
//! \param ulBase is the base address of the timer module.
|
48 |
|
|
//! \param ulTimer specifies the timer(s) to enable; must be one of \b TIMER_A,
|
49 |
|
|
//! \b TIMER_B, or \b TIMER_BOTH.
|
50 |
|
|
//!
|
51 |
|
|
//! This will enable operation of the timer module. The timer must be
|
52 |
|
|
//! configured before it is enabled.
|
53 |
|
|
//!
|
54 |
|
|
//! \return None.
|
55 |
|
|
//
|
56 |
|
|
//*****************************************************************************
|
57 |
|
|
#if defined(GROUP_enable) || defined(BUILD_ALL) || defined(DOXYGEN)
|
58 |
|
|
void
|
59 |
|
|
TimerEnable(unsigned long ulBase, unsigned long ulTimer)
|
60 |
|
|
{
|
61 |
|
|
//
|
62 |
|
|
// Check the arguments.
|
63 |
|
|
//
|
64 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
65 |
|
|
(ulBase == TIMER2_BASE));
|
66 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
|
67 |
|
|
(ulTimer == TIMER_BOTH));
|
68 |
|
|
|
69 |
|
|
//
|
70 |
|
|
// Enable the timer(s) module.
|
71 |
|
|
//
|
72 |
|
|
HWREG(ulBase + TIMER_O_CTL) |= ulTimer & (TIMER_CTL_TAEN | TIMER_CTL_TBEN);
|
73 |
|
|
}
|
74 |
|
|
#endif
|
75 |
|
|
|
76 |
|
|
//*****************************************************************************
|
77 |
|
|
//
|
78 |
|
|
//! Disables the timer(s).
|
79 |
|
|
//!
|
80 |
|
|
//! \param ulBase is the base address of the timer module.
|
81 |
|
|
//! \param ulTimer specifies the timer(s) to disable; must be one of
|
82 |
|
|
//! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
|
83 |
|
|
//!
|
84 |
|
|
//! This will disable operation of the timer module.
|
85 |
|
|
//!
|
86 |
|
|
//! \return None.
|
87 |
|
|
//
|
88 |
|
|
//*****************************************************************************
|
89 |
|
|
#if defined(GROUP_disable) || defined(BUILD_ALL) || defined(DOXYGEN)
|
90 |
|
|
void
|
91 |
|
|
TimerDisable(unsigned long ulBase, unsigned long ulTimer)
|
92 |
|
|
{
|
93 |
|
|
//
|
94 |
|
|
// Check the arguments.
|
95 |
|
|
//
|
96 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
97 |
|
|
(ulBase == TIMER2_BASE));
|
98 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
|
99 |
|
|
(ulTimer == TIMER_BOTH));
|
100 |
|
|
|
101 |
|
|
//
|
102 |
|
|
// Disable the timer module.
|
103 |
|
|
//
|
104 |
|
|
HWREG(ulBase + TIMER_O_CTL) &= ~(ulTimer &
|
105 |
|
|
(TIMER_CTL_TAEN | TIMER_CTL_TBEN));
|
106 |
|
|
}
|
107 |
|
|
#endif
|
108 |
|
|
|
109 |
|
|
//*****************************************************************************
|
110 |
|
|
//
|
111 |
|
|
//! Configures the timer(s).
|
112 |
|
|
//!
|
113 |
|
|
//! \param ulBase is the base address of the timer module.
|
114 |
|
|
//! \param ulConfig is the configuration for the timer.
|
115 |
|
|
//!
|
116 |
|
|
//! This function configures the operating mode of the timer(s). The timer
|
117 |
|
|
//! module is disabled before being configured, and is left in the disabled
|
118 |
|
|
//! state. The configuration is specified in \e ulConfig as one of the
|
119 |
|
|
//! following values:
|
120 |
|
|
//!
|
121 |
|
|
//! - \b TIMER_CFG_32_BIT_OS - 32-bit one shot timer
|
122 |
|
|
//! - \b TIMER_CFG_32_BIT_PER - 32-bit periodic timer
|
123 |
|
|
//! - \b TIMER_CFG_32_RTC - 32-bit real time clock timer
|
124 |
|
|
//! - \b TIMER_CFG_16_BIT_PAIR - Two 16-bit timers
|
125 |
|
|
//!
|
126 |
|
|
//! When configured for a pair of 16-bit timers, each timer is separately
|
127 |
|
|
//! configured. The first timer is configured by setting \e ulConfig to
|
128 |
|
|
//! the result of a logical OR operation between one of the following values
|
129 |
|
|
//! and \e ulConfig:
|
130 |
|
|
//!
|
131 |
|
|
//! - \b TIMER_CFG_A_ONE_SHOT - 16-bit one shot timer
|
132 |
|
|
//! - \b TIMER_CFG_A_PERIODIC - 16-bit periodic timer
|
133 |
|
|
//! - \b TIMER_CFG_A_CAP_COUNT - 16-bit edge count capture
|
134 |
|
|
//! - \b TIMER_CFG_A_CAP_TIME - 16-bit edge time capture
|
135 |
|
|
//! - \b TIMER_CFG_A_PWM - 16-bit PWM output
|
136 |
|
|
//!
|
137 |
|
|
//! Similarly, the second timer is configured by setting \e ulConfig to
|
138 |
|
|
//! the result of a logical OR operation between one of the corresponding
|
139 |
|
|
//! \b TIMER_CFG_B_* values and \e ulConfig.
|
140 |
|
|
//!
|
141 |
|
|
//! \return None.
|
142 |
|
|
//
|
143 |
|
|
//*****************************************************************************
|
144 |
|
|
#if defined(GROUP_configure) || defined(BUILD_ALL) || defined(DOXYGEN)
|
145 |
|
|
void
|
146 |
|
|
TimerConfigure(unsigned long ulBase, unsigned long ulConfig)
|
147 |
|
|
{
|
148 |
|
|
//
|
149 |
|
|
// Check the arguments.
|
150 |
|
|
//
|
151 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
152 |
|
|
(ulBase == TIMER2_BASE));
|
153 |
|
|
ASSERT((ulConfig == TIMER_CFG_32_BIT_OS) ||
|
154 |
|
|
(ulConfig == TIMER_CFG_32_BIT_PER) ||
|
155 |
|
|
(ulConfig == TIMER_CFG_32_RTC) ||
|
156 |
|
|
((ulConfig & 0xff000000) == TIMER_CFG_16_BIT_PAIR));
|
157 |
|
|
ASSERT(((ulConfig & 0xff000000) != TIMER_CFG_16_BIT_PAIR) ||
|
158 |
|
|
((((ulConfig & 0x000000ff) == TIMER_CFG_A_ONE_SHOT) ||
|
159 |
|
|
((ulConfig & 0x000000ff) == TIMER_CFG_A_PERIODIC) ||
|
160 |
|
|
((ulConfig & 0x000000ff) == TIMER_CFG_A_CAP_COUNT) ||
|
161 |
|
|
((ulConfig & 0x000000ff) == TIMER_CFG_A_CAP_TIME) ||
|
162 |
|
|
((ulConfig & 0x000000ff) == TIMER_CFG_A_PWM)) &&
|
163 |
|
|
(((ulConfig & 0x0000ff00) == TIMER_CFG_B_ONE_SHOT) ||
|
164 |
|
|
((ulConfig & 0x0000ff00) == TIMER_CFG_B_PERIODIC) ||
|
165 |
|
|
((ulConfig & 0x0000ff00) == TIMER_CFG_B_CAP_COUNT) ||
|
166 |
|
|
((ulConfig & 0x0000ff00) == TIMER_CFG_B_CAP_TIME) ||
|
167 |
|
|
((ulConfig & 0x0000ff00) == TIMER_CFG_B_PWM))));
|
168 |
|
|
|
169 |
|
|
//
|
170 |
|
|
// Disable the timers.
|
171 |
|
|
//
|
172 |
|
|
HWREG(ulBase + TIMER_O_CTL) &= ~(TIMER_CTL_TAEN | TIMER_CTL_TBEN);
|
173 |
|
|
|
174 |
|
|
//
|
175 |
|
|
// Set the global timer configuration.
|
176 |
|
|
//
|
177 |
|
|
HWREG(ulBase + TIMER_O_CFG) = ulConfig >> 24;
|
178 |
|
|
|
179 |
|
|
//
|
180 |
|
|
// Set the configuration of the A and B timers. Note that the B timer
|
181 |
|
|
// configuration is ignored by the hardware in 32-bit modes.
|
182 |
|
|
//
|
183 |
|
|
HWREG(ulBase + TIMER_O_TAMR) = ulConfig & 255;
|
184 |
|
|
HWREG(ulBase + TIMER_O_TBMR) = (ulConfig >> 8) & 255;
|
185 |
|
|
}
|
186 |
|
|
#endif
|
187 |
|
|
|
188 |
|
|
//*****************************************************************************
|
189 |
|
|
//
|
190 |
|
|
//! Controls the output level.
|
191 |
|
|
//!
|
192 |
|
|
//! \param ulBase is the base address of the timer module.
|
193 |
|
|
//! \param ulTimer specifies the timer(s) to adjust; must be one of \b TIMER_A,
|
194 |
|
|
//! \b TIMER_B, or \b TIMER_BOTH.
|
195 |
|
|
//! \param bInvert specifies the output level.
|
196 |
|
|
//!
|
197 |
|
|
//! This function sets the PWM output level for the specified timer. If the
|
198 |
|
|
//! parameter \e bInvert is \b true, then the timer's output will be made
|
199 |
|
|
//! active low; otherwise, it will be made active high.
|
200 |
|
|
//!
|
201 |
|
|
//! \return None.
|
202 |
|
|
//
|
203 |
|
|
//*****************************************************************************
|
204 |
|
|
#if defined(GROUP_controllevel) || defined(BUILD_ALL) || defined(DOXYGEN)
|
205 |
|
|
void
|
206 |
|
|
TimerControlLevel(unsigned long ulBase, unsigned long ulTimer,
|
207 |
|
|
tBoolean bInvert)
|
208 |
|
|
{
|
209 |
|
|
//
|
210 |
|
|
// Check the arguments.
|
211 |
|
|
//
|
212 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
213 |
|
|
(ulBase == TIMER2_BASE));
|
214 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
|
215 |
|
|
(ulTimer == TIMER_BOTH));
|
216 |
|
|
|
217 |
|
|
//
|
218 |
|
|
// Set the output levels as requested.
|
219 |
|
|
//
|
220 |
|
|
ulTimer &= TIMER_CTL_TAPWML | TIMER_CTL_TBPWML;
|
221 |
|
|
HWREG(ulBase + TIMER_O_CTL) = (bInvert ?
|
222 |
|
|
(HWREG(ulBase + TIMER_O_CTL) | ulTimer) :
|
223 |
|
|
(HWREG(ulBase + TIMER_O_CTL) & ~(ulTimer)));
|
224 |
|
|
}
|
225 |
|
|
#endif
|
226 |
|
|
|
227 |
|
|
//*****************************************************************************
|
228 |
|
|
//
|
229 |
|
|
//! Enables or disables the trigger output.
|
230 |
|
|
//!
|
231 |
|
|
//! \param ulBase is the base address of the timer module.
|
232 |
|
|
//! \param ulTimer specifies the timer to adjust; must be one of \b TIMER_A,
|
233 |
|
|
//! \b TIMER_B, or \b TIMER_BOTH.
|
234 |
|
|
//! \param bEnable specifies the desired trigger state.
|
235 |
|
|
//!
|
236 |
|
|
//! This function controls the trigger output for the specified timer. If the
|
237 |
|
|
//! parameter \e bEnable is \b true, then the timer's output trigger is
|
238 |
|
|
//! enabled; otherwise it is disabled.
|
239 |
|
|
//!
|
240 |
|
|
//! \return None.
|
241 |
|
|
//
|
242 |
|
|
//*****************************************************************************
|
243 |
|
|
#if defined(GROUP_controltrigger) || defined(BUILD_ALL) || defined(DOXYGEN)
|
244 |
|
|
void
|
245 |
|
|
TimerControlTrigger(unsigned long ulBase, unsigned long ulTimer,
|
246 |
|
|
tBoolean bEnable)
|
247 |
|
|
{
|
248 |
|
|
//
|
249 |
|
|
// Check the arguments.
|
250 |
|
|
//
|
251 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
252 |
|
|
(ulBase == TIMER2_BASE));
|
253 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
|
254 |
|
|
(ulTimer == TIMER_BOTH));
|
255 |
|
|
|
256 |
|
|
//
|
257 |
|
|
// Set the trigger output as requested.
|
258 |
|
|
//
|
259 |
|
|
ulTimer &= TIMER_CTL_TAOTE | TIMER_CTL_TBOTE;
|
260 |
|
|
HWREG(ulBase + TIMER_O_CTL) = (bEnable ?
|
261 |
|
|
(HWREG(ulBase + TIMER_O_CTL) | ulTimer) :
|
262 |
|
|
(HWREG(ulBase + TIMER_O_CTL) & ~(ulTimer)));
|
263 |
|
|
}
|
264 |
|
|
#endif
|
265 |
|
|
|
266 |
|
|
//*****************************************************************************
|
267 |
|
|
//
|
268 |
|
|
//! Controls the event type.
|
269 |
|
|
//!
|
270 |
|
|
//! \param ulBase is the base address of the timer module.
|
271 |
|
|
//! \param ulTimer specifies the timer(s) to be adjusted; must be one of
|
272 |
|
|
//! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
|
273 |
|
|
//! \param ulEvent specifies the type of event; must be one of
|
274 |
|
|
//! \b TIMER_EVENT_POS_EDGE, \b TIMER_EVENT_NEG_EDGE, or
|
275 |
|
|
//! \b TIMER_EVENT_BOTH_EDGES.
|
276 |
|
|
//!
|
277 |
|
|
//! This function sets the signal edge(s) that will trigger the timer when in
|
278 |
|
|
//! capture mode.
|
279 |
|
|
//!
|
280 |
|
|
//! \return None.
|
281 |
|
|
//
|
282 |
|
|
//*****************************************************************************
|
283 |
|
|
#if defined(GROUP_controlevent) || defined(BUILD_ALL) || defined(DOXYGEN)
|
284 |
|
|
void
|
285 |
|
|
TimerControlEvent(unsigned long ulBase, unsigned long ulTimer,
|
286 |
|
|
unsigned long ulEvent)
|
287 |
|
|
{
|
288 |
|
|
//
|
289 |
|
|
// Check the arguments.
|
290 |
|
|
//
|
291 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
292 |
|
|
(ulBase == TIMER2_BASE));
|
293 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
|
294 |
|
|
(ulTimer == TIMER_BOTH));
|
295 |
|
|
|
296 |
|
|
//
|
297 |
|
|
// Set the event type.
|
298 |
|
|
//
|
299 |
|
|
ulEvent &= ulTimer & (TIMER_CTL_TAEVENT_MSK | TIMER_CTL_TBEVENT_MSK);
|
300 |
|
|
HWREG(ulBase + TIMER_O_CTL) = ((HWREG(ulBase + TIMER_O_CTL) &
|
301 |
|
|
~(TIMER_CTL_TAEVENT_MSK |
|
302 |
|
|
TIMER_CTL_TBEVENT_MSK)) | ulEvent);
|
303 |
|
|
}
|
304 |
|
|
#endif
|
305 |
|
|
|
306 |
|
|
//*****************************************************************************
|
307 |
|
|
//
|
308 |
|
|
//! Controls the stall handling.
|
309 |
|
|
//!
|
310 |
|
|
//! \param ulBase is the base address of the timer module.
|
311 |
|
|
//! \param ulTimer specifies the timer(s) to be adjusted; must be one of
|
312 |
|
|
//! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
|
313 |
|
|
//! \param bStall specifies the response to a stall signal.
|
314 |
|
|
//!
|
315 |
|
|
//! This function controls the stall response for the specified timer. If the
|
316 |
|
|
//! parameter \e bStall is \b true, then the timer will stop counting if the
|
317 |
|
|
//! processor enters debug mode; otherwise the timer will keep running while in
|
318 |
|
|
//! debug mode.
|
319 |
|
|
//!
|
320 |
|
|
//! \return None.
|
321 |
|
|
//
|
322 |
|
|
//*****************************************************************************
|
323 |
|
|
#if defined(GROUP_controlstall) || defined(BUILD_ALL) || defined(DOXYGEN)
|
324 |
|
|
void
|
325 |
|
|
TimerControlStall(unsigned long ulBase, unsigned long ulTimer,
|
326 |
|
|
tBoolean bStall)
|
327 |
|
|
{
|
328 |
|
|
//
|
329 |
|
|
// Check the arguments.
|
330 |
|
|
//
|
331 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
332 |
|
|
(ulBase == TIMER2_BASE));
|
333 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
|
334 |
|
|
(ulTimer == TIMER_BOTH));
|
335 |
|
|
|
336 |
|
|
//
|
337 |
|
|
// Set the stall mode.
|
338 |
|
|
//
|
339 |
|
|
ulTimer &= TIMER_CTL_TASTALL | TIMER_CTL_TBSTALL;
|
340 |
|
|
HWREG(ulBase + TIMER_O_CTL) = (bStall ?
|
341 |
|
|
(HWREG(ulBase + TIMER_O_CTL) | ulTimer) :
|
342 |
|
|
(HWREG(ulBase + TIMER_O_CTL) & ~(ulTimer)));
|
343 |
|
|
}
|
344 |
|
|
#endif
|
345 |
|
|
|
346 |
|
|
//*****************************************************************************
|
347 |
|
|
//
|
348 |
|
|
//! Enable RTC counting.
|
349 |
|
|
//!
|
350 |
|
|
//! \param ulBase is the base address of the timer module.
|
351 |
|
|
//!
|
352 |
|
|
//! This function causes the timer to start counting when in RTC mode. If not
|
353 |
|
|
//! configured for RTC mode, this will do nothing.
|
354 |
|
|
//!
|
355 |
|
|
//! \return None.
|
356 |
|
|
//
|
357 |
|
|
//*****************************************************************************
|
358 |
|
|
#if defined(GROUP_rtcenable) || defined(BUILD_ALL) || defined(DOXYGEN)
|
359 |
|
|
void
|
360 |
|
|
TimerRTCEnable(unsigned long ulBase)
|
361 |
|
|
{
|
362 |
|
|
//
|
363 |
|
|
// Check the arguments.
|
364 |
|
|
//
|
365 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
366 |
|
|
(ulBase == TIMER2_BASE));
|
367 |
|
|
|
368 |
|
|
//
|
369 |
|
|
// Enable RTC counting.
|
370 |
|
|
//
|
371 |
|
|
HWREG(ulBase + TIMER_O_CTL) |= TIMER_CTL_RTCEN;
|
372 |
|
|
}
|
373 |
|
|
#endif
|
374 |
|
|
|
375 |
|
|
//*****************************************************************************
|
376 |
|
|
//
|
377 |
|
|
//! Disable RTC counting.
|
378 |
|
|
//!
|
379 |
|
|
//! \param ulBase is the base address of the timer module.
|
380 |
|
|
//!
|
381 |
|
|
//! This function causes the timer to stop counting when in RTC mode.
|
382 |
|
|
//!
|
383 |
|
|
//! \return None.
|
384 |
|
|
//
|
385 |
|
|
//*****************************************************************************
|
386 |
|
|
#if defined(GROUP_rtcdisable) || defined(BUILD_ALL) || defined(DOXYGEN)
|
387 |
|
|
void
|
388 |
|
|
TimerRTCDisable(unsigned long ulBase)
|
389 |
|
|
{
|
390 |
|
|
//
|
391 |
|
|
// Check the arguments.
|
392 |
|
|
//
|
393 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
394 |
|
|
(ulBase == TIMER2_BASE));
|
395 |
|
|
|
396 |
|
|
//
|
397 |
|
|
// Disable RTC counting.
|
398 |
|
|
//
|
399 |
|
|
HWREG(ulBase + TIMER_O_CTL) &= ~(TIMER_CTL_RTCEN);
|
400 |
|
|
}
|
401 |
|
|
#endif
|
402 |
|
|
|
403 |
|
|
//*****************************************************************************
|
404 |
|
|
//
|
405 |
|
|
//! Set the timer prescale value.
|
406 |
|
|
//!
|
407 |
|
|
//! \param ulBase is the base address of the timer module.
|
408 |
|
|
//! \param ulTimer specifies the timer(s) to adjust; must be one of \b TIMER_A,
|
409 |
|
|
//! \b TIMER_B, or \b TIMER_BOTH.
|
410 |
|
|
//! \param ulValue is the timer prescale value; must be between 0 and 255,
|
411 |
|
|
//! inclusive.
|
412 |
|
|
//!
|
413 |
|
|
//! This function sets the value of the input clock prescaler. The prescaler
|
414 |
|
|
//! is only operational when in 16-bit mode and is used to extend the range of
|
415 |
|
|
//! the 16-bit timer modes.
|
416 |
|
|
//!
|
417 |
|
|
//! \return None.
|
418 |
|
|
//
|
419 |
|
|
//*****************************************************************************
|
420 |
|
|
#if defined(GROUP_prescaleset) || defined(BUILD_ALL) || defined(DOXYGEN)
|
421 |
|
|
void
|
422 |
|
|
TimerPrescaleSet(unsigned long ulBase, unsigned long ulTimer,
|
423 |
|
|
unsigned long ulValue)
|
424 |
|
|
{
|
425 |
|
|
//
|
426 |
|
|
// Check the arguments.
|
427 |
|
|
//
|
428 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
429 |
|
|
(ulBase == TIMER2_BASE));
|
430 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
|
431 |
|
|
(ulTimer == TIMER_BOTH));
|
432 |
|
|
ASSERT(ulValue < 256);
|
433 |
|
|
|
434 |
|
|
//
|
435 |
|
|
// Set the timer A prescaler if requested.
|
436 |
|
|
//
|
437 |
|
|
if(ulTimer & TIMER_A)
|
438 |
|
|
{
|
439 |
|
|
HWREG(ulBase + TIMER_O_TAPR) = ulValue;
|
440 |
|
|
}
|
441 |
|
|
|
442 |
|
|
//
|
443 |
|
|
// Set the timer B prescaler if requested.
|
444 |
|
|
//
|
445 |
|
|
if(ulTimer & TIMER_B)
|
446 |
|
|
{
|
447 |
|
|
HWREG(ulBase + TIMER_O_TBPR) = ulValue;
|
448 |
|
|
}
|
449 |
|
|
}
|
450 |
|
|
#endif
|
451 |
|
|
|
452 |
|
|
//*****************************************************************************
|
453 |
|
|
//
|
454 |
|
|
//! Get the timer prescale value.
|
455 |
|
|
//!
|
456 |
|
|
//! \param ulBase is the base address of the timer module.
|
457 |
|
|
//! \param ulTimer specifies the timer; must be one of \b TIMER_A or
|
458 |
|
|
//! \b TIMER_B.
|
459 |
|
|
//!
|
460 |
|
|
//! This function gets the value of the input clock prescaler. The prescaler
|
461 |
|
|
//! is only operational when in 16-bit mode and is used to extend the range of
|
462 |
|
|
//! the 16-bit timer modes.
|
463 |
|
|
//!
|
464 |
|
|
//! \return The value of the timer prescaler.
|
465 |
|
|
//
|
466 |
|
|
//*****************************************************************************
|
467 |
|
|
#if defined(GROUP_prescaleget) || defined(BUILD_ALL) || defined(DOXYGEN)
|
468 |
|
|
unsigned long
|
469 |
|
|
TimerPrescaleGet(unsigned long ulBase, unsigned long ulTimer)
|
470 |
|
|
{
|
471 |
|
|
//
|
472 |
|
|
// Check the arguments.
|
473 |
|
|
//
|
474 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
475 |
|
|
(ulBase == TIMER2_BASE));
|
476 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
|
477 |
|
|
(ulTimer == TIMER_BOTH));
|
478 |
|
|
|
479 |
|
|
//
|
480 |
|
|
// Return the appropriate prescale value.
|
481 |
|
|
//
|
482 |
|
|
return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAPR) :
|
483 |
|
|
HWREG(ulBase + TIMER_O_TBPR));
|
484 |
|
|
}
|
485 |
|
|
#endif
|
486 |
|
|
|
487 |
|
|
//*****************************************************************************
|
488 |
|
|
//
|
489 |
|
|
//! Set the timer prescale match value.
|
490 |
|
|
//!
|
491 |
|
|
//! \param ulBase is the base address of the timer module.
|
492 |
|
|
//! \param ulTimer specifies the timer(s) to adjust; must be one of \b TIMER_A,
|
493 |
|
|
//! \b TIMER_B, or \b TIMER_BOTH.
|
494 |
|
|
//! \param ulValue is the timer prescale match value; must be between 0 and
|
495 |
|
|
//! 255, inclusive.
|
496 |
|
|
//!
|
497 |
|
|
//! This function sets the value of the input clock prescaler match value.
|
498 |
|
|
//! When in a 16-bit mode that uses the counter match (edge count or PWM), the
|
499 |
|
|
//! prescale match effectively extends the range of the counter to 24-bits.
|
500 |
|
|
//!
|
501 |
|
|
//! \return None.
|
502 |
|
|
//
|
503 |
|
|
//*****************************************************************************
|
504 |
|
|
#if defined(GROUP_prescalematchset) || defined(BUILD_ALL) || defined(DOXYGEN)
|
505 |
|
|
void
|
506 |
|
|
TimerPrescaleMatchSet(unsigned long ulBase, unsigned long ulTimer,
|
507 |
|
|
unsigned long ulValue)
|
508 |
|
|
{
|
509 |
|
|
//
|
510 |
|
|
// Check the arguments.
|
511 |
|
|
//
|
512 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
513 |
|
|
(ulBase == TIMER2_BASE));
|
514 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
|
515 |
|
|
(ulTimer == TIMER_BOTH));
|
516 |
|
|
ASSERT(ulValue < 256);
|
517 |
|
|
|
518 |
|
|
//
|
519 |
|
|
// Set the timer A prescale match if requested.
|
520 |
|
|
//
|
521 |
|
|
if(ulTimer & TIMER_A)
|
522 |
|
|
{
|
523 |
|
|
HWREG(ulBase + TIMER_O_TAPMR) = ulValue;
|
524 |
|
|
}
|
525 |
|
|
|
526 |
|
|
//
|
527 |
|
|
// Set the timer B prescale match if requested.
|
528 |
|
|
//
|
529 |
|
|
if(ulTimer & TIMER_B)
|
530 |
|
|
{
|
531 |
|
|
HWREG(ulBase + TIMER_O_TBPMR) = ulValue;
|
532 |
|
|
}
|
533 |
|
|
}
|
534 |
|
|
#endif
|
535 |
|
|
|
536 |
|
|
//*****************************************************************************
|
537 |
|
|
//
|
538 |
|
|
//! Get the timer prescale match value.
|
539 |
|
|
//!
|
540 |
|
|
//! \param ulBase is the base address of the timer module.
|
541 |
|
|
//! \param ulTimer specifies the timer; must be one of \b TIMER_A or
|
542 |
|
|
//! \b TIMER_B.
|
543 |
|
|
//!
|
544 |
|
|
//! This function gets the value of the input clock prescaler match value.
|
545 |
|
|
//! When in a 16-bit mode that uses the counter match (edge count or PWM), the
|
546 |
|
|
//! prescale match effectively extends the range of the counter to 24-bits.
|
547 |
|
|
//!
|
548 |
|
|
//! \return The value of the timer prescale match.
|
549 |
|
|
//
|
550 |
|
|
//*****************************************************************************
|
551 |
|
|
#if defined(GROUP_prescalematchget) || defined(BUILD_ALL) || defined(DOXYGEN)
|
552 |
|
|
unsigned long
|
553 |
|
|
TimerPrescaleMatchGet(unsigned long ulBase, unsigned long ulTimer)
|
554 |
|
|
{
|
555 |
|
|
//
|
556 |
|
|
// Check the arguments.
|
557 |
|
|
//
|
558 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
559 |
|
|
(ulBase == TIMER2_BASE));
|
560 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
|
561 |
|
|
(ulTimer == TIMER_BOTH));
|
562 |
|
|
|
563 |
|
|
//
|
564 |
|
|
// Return the appropriate prescale match value.
|
565 |
|
|
//
|
566 |
|
|
return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAPMR) :
|
567 |
|
|
HWREG(ulBase + TIMER_O_TBPMR));
|
568 |
|
|
}
|
569 |
|
|
#endif
|
570 |
|
|
|
571 |
|
|
//*****************************************************************************
|
572 |
|
|
//
|
573 |
|
|
//! Sets the timer load value.
|
574 |
|
|
//!
|
575 |
|
|
//! \param ulBase is the base address of the timer module.
|
576 |
|
|
//! \param ulTimer specifies the timer(s) to adjust; must be one of \b TIMER_A,
|
577 |
|
|
//! \b TIMER_B, or \b TIMER_BOTH. Only \b TIMER_A should be used when the
|
578 |
|
|
//! timer is configured for 32-bit operation.
|
579 |
|
|
//! \param ulValue is the load value.
|
580 |
|
|
//!
|
581 |
|
|
//! This function sets the timer load value; if the timer is running then the
|
582 |
|
|
//! value will be immediately loaded into the timer.
|
583 |
|
|
//!
|
584 |
|
|
//! \return None.
|
585 |
|
|
//
|
586 |
|
|
//*****************************************************************************
|
587 |
|
|
#if defined(GROUP_loadset) || defined(BUILD_ALL) || defined(DOXYGEN)
|
588 |
|
|
void
|
589 |
|
|
TimerLoadSet(unsigned long ulBase, unsigned long ulTimer,
|
590 |
|
|
unsigned long ulValue)
|
591 |
|
|
{
|
592 |
|
|
//
|
593 |
|
|
// Check the arguments.
|
594 |
|
|
//
|
595 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
596 |
|
|
(ulBase == TIMER2_BASE));
|
597 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
|
598 |
|
|
(ulTimer == TIMER_BOTH));
|
599 |
|
|
|
600 |
|
|
//
|
601 |
|
|
// Set the timer A load value if requested.
|
602 |
|
|
//
|
603 |
|
|
if(ulTimer & TIMER_A)
|
604 |
|
|
{
|
605 |
|
|
HWREG(ulBase + TIMER_O_TAILR) = ulValue;
|
606 |
|
|
}
|
607 |
|
|
|
608 |
|
|
//
|
609 |
|
|
// Set the timer B load value if requested.
|
610 |
|
|
//
|
611 |
|
|
if(ulTimer & TIMER_B)
|
612 |
|
|
{
|
613 |
|
|
HWREG(ulBase + TIMER_O_TBILR) = ulValue;
|
614 |
|
|
}
|
615 |
|
|
}
|
616 |
|
|
#endif
|
617 |
|
|
|
618 |
|
|
//*****************************************************************************
|
619 |
|
|
//
|
620 |
|
|
//! Gets the timer load value.
|
621 |
|
|
//!
|
622 |
|
|
//! \param ulBase is the base address of the timer module.
|
623 |
|
|
//! \param ulTimer specifies the timer; must be one of \b TIMER_A or
|
624 |
|
|
//! \b TIMER_B. Only \b TIMER_A should be used when the timer is configured
|
625 |
|
|
//! for 32-bit operation.
|
626 |
|
|
//!
|
627 |
|
|
//! This function gets the currently programmed interval load value for the
|
628 |
|
|
//! specified timer.
|
629 |
|
|
//!
|
630 |
|
|
//! \return Returns the load value for the timer.
|
631 |
|
|
//
|
632 |
|
|
//*****************************************************************************
|
633 |
|
|
#if defined(GROUP_loadget) || defined(BUILD_ALL) || defined(DOXYGEN)
|
634 |
|
|
unsigned long
|
635 |
|
|
TimerLoadGet(unsigned long ulBase, unsigned long ulTimer)
|
636 |
|
|
{
|
637 |
|
|
//
|
638 |
|
|
// Check the arguments.
|
639 |
|
|
//
|
640 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
641 |
|
|
(ulBase == TIMER2_BASE));
|
642 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B));
|
643 |
|
|
|
644 |
|
|
//
|
645 |
|
|
// Return the appropriate load value.
|
646 |
|
|
//
|
647 |
|
|
return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAILR) :
|
648 |
|
|
HWREG(ulBase + TIMER_O_TBILR));
|
649 |
|
|
}
|
650 |
|
|
#endif
|
651 |
|
|
|
652 |
|
|
//*****************************************************************************
|
653 |
|
|
//
|
654 |
|
|
//! Gets the current timer value.
|
655 |
|
|
//!
|
656 |
|
|
//! \param ulBase is the base address of the timer module.
|
657 |
|
|
//! \param ulTimer specifies the timer; must be one of \b TIMER_A or
|
658 |
|
|
//! \b TIMER_B. Only \b TIMER_A should be used when the timer is configured
|
659 |
|
|
//! for 32-bit operation.
|
660 |
|
|
//!
|
661 |
|
|
//! This function reads the current value of the specified timer.
|
662 |
|
|
//!
|
663 |
|
|
//! \return Returns the current value of the timer.
|
664 |
|
|
//
|
665 |
|
|
//*****************************************************************************
|
666 |
|
|
#if defined(GROUP_valueget) || defined(BUILD_ALL) || defined(DOXYGEN)
|
667 |
|
|
unsigned long
|
668 |
|
|
TimerValueGet(unsigned long ulBase, unsigned long ulTimer)
|
669 |
|
|
{
|
670 |
|
|
//
|
671 |
|
|
// Check the arguments.
|
672 |
|
|
//
|
673 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
674 |
|
|
(ulBase == TIMER2_BASE));
|
675 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B));
|
676 |
|
|
|
677 |
|
|
//
|
678 |
|
|
// Return the appropriate timer value.
|
679 |
|
|
//
|
680 |
|
|
return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAR) :
|
681 |
|
|
HWREG(ulBase + TIMER_O_TBR));
|
682 |
|
|
}
|
683 |
|
|
#endif
|
684 |
|
|
|
685 |
|
|
//*****************************************************************************
|
686 |
|
|
//
|
687 |
|
|
//! Sets the timer match value.
|
688 |
|
|
//!
|
689 |
|
|
//! \param ulBase is the base address of the timer module.
|
690 |
|
|
//! \param ulTimer specifies the timer(s) to adjust; must be one of \b TIMER_A,
|
691 |
|
|
//! \b TIMER_B, or \b TIMER_BOTH. Only \b TIMER_A should be used when the
|
692 |
|
|
//! timer is configured for 32-bit operation.
|
693 |
|
|
//! \param ulValue is the match value.
|
694 |
|
|
//!
|
695 |
|
|
//! This function sets the match value for a timer. This is used in capture
|
696 |
|
|
//! count mode to determine when to interrupt the processor and in PWM mode to
|
697 |
|
|
//! determine the duty cycle of the output signal.
|
698 |
|
|
//!
|
699 |
|
|
//! \return None.
|
700 |
|
|
//
|
701 |
|
|
//*****************************************************************************
|
702 |
|
|
#if defined(GROUP_matchset) || defined(BUILD_ALL) || defined(DOXYGEN)
|
703 |
|
|
void
|
704 |
|
|
TimerMatchSet(unsigned long ulBase, unsigned long ulTimer,
|
705 |
|
|
unsigned long ulValue)
|
706 |
|
|
{
|
707 |
|
|
//
|
708 |
|
|
// Check the arguments.
|
709 |
|
|
//
|
710 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
711 |
|
|
(ulBase == TIMER2_BASE));
|
712 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
|
713 |
|
|
(ulTimer == TIMER_BOTH));
|
714 |
|
|
|
715 |
|
|
//
|
716 |
|
|
// Set the timer A match value if requested.
|
717 |
|
|
//
|
718 |
|
|
if(ulTimer & TIMER_A)
|
719 |
|
|
{
|
720 |
|
|
HWREG(ulBase + TIMER_O_TAMATCHR) = ulValue;
|
721 |
|
|
}
|
722 |
|
|
|
723 |
|
|
//
|
724 |
|
|
// Set the timer B match value if requested.
|
725 |
|
|
//
|
726 |
|
|
if(ulTimer & TIMER_B)
|
727 |
|
|
{
|
728 |
|
|
HWREG(ulBase + TIMER_O_TBMATCHR) = ulValue;
|
729 |
|
|
}
|
730 |
|
|
}
|
731 |
|
|
#endif
|
732 |
|
|
|
733 |
|
|
//*****************************************************************************
|
734 |
|
|
//
|
735 |
|
|
//! Gets the timer match value.
|
736 |
|
|
//!
|
737 |
|
|
//! \param ulBase is the base address of the timer module.
|
738 |
|
|
//! \param ulTimer specifies the timer; must be one of \b TIMER_A or
|
739 |
|
|
//! \b TIMER_B. Only \b TIMER_A should be used when the timer is configured
|
740 |
|
|
//! for 32-bit operation.
|
741 |
|
|
//!
|
742 |
|
|
//! This function gets the match value for the specified timer.
|
743 |
|
|
//!
|
744 |
|
|
//! \return Returns the match value for the timer.
|
745 |
|
|
//
|
746 |
|
|
//*****************************************************************************
|
747 |
|
|
#if defined(GROUP_matchget) || defined(BUILD_ALL) || defined(DOXYGEN)
|
748 |
|
|
unsigned long
|
749 |
|
|
TimerMatchGet(unsigned long ulBase, unsigned long ulTimer)
|
750 |
|
|
{
|
751 |
|
|
//
|
752 |
|
|
// Check the arguments.
|
753 |
|
|
//
|
754 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
755 |
|
|
(ulBase == TIMER2_BASE));
|
756 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B));
|
757 |
|
|
|
758 |
|
|
//
|
759 |
|
|
// Return the appropriate match value.
|
760 |
|
|
//
|
761 |
|
|
return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAMATCHR) :
|
762 |
|
|
HWREG(ulBase + TIMER_O_TBMATCHR));
|
763 |
|
|
}
|
764 |
|
|
#endif
|
765 |
|
|
|
766 |
|
|
//*****************************************************************************
|
767 |
|
|
//
|
768 |
|
|
//! Registers an interrupt handler for the timer interrupt.
|
769 |
|
|
//!
|
770 |
|
|
//! \param ulBase is the base address of the timer module.
|
771 |
|
|
//! \param ulTimer specifies the timer(s); must be one of \b TIMER_A,
|
772 |
|
|
//! \b TIMER_B, or \b TIMER_BOTH.
|
773 |
|
|
//! \param pfnHandler is a pointer to the function to be called when the timer
|
774 |
|
|
//! interrupt occurs.
|
775 |
|
|
//!
|
776 |
|
|
//! This sets the handler to be called when a timer interrupt occurs. This
|
777 |
|
|
//! will enable the global interrupt in the interrupt controller; specific
|
778 |
|
|
//! timer interrupts must be enabled via TimerIntEnable(). It is the interrupt
|
779 |
|
|
//! handler's responsibility to clear the interrupt source via TimerIntClear().
|
780 |
|
|
//!
|
781 |
|
|
//! \sa IntRegister() for important information about registering interrupt
|
782 |
|
|
//! handlers.
|
783 |
|
|
//!
|
784 |
|
|
//! \return None.
|
785 |
|
|
//
|
786 |
|
|
//*****************************************************************************
|
787 |
|
|
#if defined(GROUP_intregister) || defined(BUILD_ALL) || defined(DOXYGEN)
|
788 |
|
|
void
|
789 |
|
|
TimerIntRegister(unsigned long ulBase, unsigned long ulTimer,
|
790 |
|
|
void (*pfnHandler)(void))
|
791 |
|
|
{
|
792 |
|
|
//
|
793 |
|
|
// Check the arguments.
|
794 |
|
|
//
|
795 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
796 |
|
|
(ulBase == TIMER2_BASE));
|
797 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
|
798 |
|
|
(ulTimer == TIMER_BOTH));
|
799 |
|
|
|
800 |
|
|
//
|
801 |
|
|
// Get the interrupt number for this timer module.
|
802 |
|
|
//
|
803 |
|
|
ulBase = ((ulBase == TIMER0_BASE) ? INT_TIMER0A :
|
804 |
|
|
((ulBase == TIMER1_BASE) ? INT_TIMER1A : INT_TIMER2A));
|
805 |
|
|
|
806 |
|
|
//
|
807 |
|
|
// Register an interrupt handler for timer A if requested.
|
808 |
|
|
//
|
809 |
|
|
if(ulTimer & TIMER_A)
|
810 |
|
|
{
|
811 |
|
|
//
|
812 |
|
|
// Register the interrupt handler.
|
813 |
|
|
//
|
814 |
|
|
IntRegister(ulBase, pfnHandler);
|
815 |
|
|
|
816 |
|
|
//
|
817 |
|
|
// Enable the interrupt.
|
818 |
|
|
//
|
819 |
|
|
IntEnable(ulBase);
|
820 |
|
|
}
|
821 |
|
|
|
822 |
|
|
//
|
823 |
|
|
// Register an interrupt handler for timer B if requested.
|
824 |
|
|
//
|
825 |
|
|
if(ulTimer & TIMER_B)
|
826 |
|
|
{
|
827 |
|
|
//
|
828 |
|
|
// Register the interrupt handler.
|
829 |
|
|
//
|
830 |
|
|
IntRegister(ulBase + 1, pfnHandler);
|
831 |
|
|
|
832 |
|
|
//
|
833 |
|
|
// Enable the interrupt.
|
834 |
|
|
//
|
835 |
|
|
IntEnable(ulBase + 1);
|
836 |
|
|
}
|
837 |
|
|
}
|
838 |
|
|
#endif
|
839 |
|
|
|
840 |
|
|
//*****************************************************************************
|
841 |
|
|
//
|
842 |
|
|
//! Unregisters an interrupt handler for the timer interrupt.
|
843 |
|
|
//!
|
844 |
|
|
//! \param ulBase is the base address of the timer module.
|
845 |
|
|
//! \param ulTimer specifies the timer(s); must be one of \b TIMER_A,
|
846 |
|
|
//! \b TIMER_B, or \b TIMER_BOTH.
|
847 |
|
|
//!
|
848 |
|
|
//! This function will clear the handler to be called when a timer interrupt
|
849 |
|
|
//! occurs. This will also mask off the interrupt in the interrupt controller
|
850 |
|
|
//! so that the interrupt handler no longer is called.
|
851 |
|
|
//!
|
852 |
|
|
//! \sa IntRegister() for important information about registering interrupt
|
853 |
|
|
//! handlers.
|
854 |
|
|
//!
|
855 |
|
|
//! \return None.
|
856 |
|
|
//
|
857 |
|
|
//*****************************************************************************
|
858 |
|
|
#if defined(GROUP_intunregister) || defined(BUILD_ALL) || defined(DOXYGEN)
|
859 |
|
|
void
|
860 |
|
|
TimerIntUnregister(unsigned long ulBase, unsigned long ulTimer)
|
861 |
|
|
{
|
862 |
|
|
//
|
863 |
|
|
// Check the arguments.
|
864 |
|
|
//
|
865 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
866 |
|
|
(ulBase == TIMER2_BASE));
|
867 |
|
|
ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
|
868 |
|
|
(ulTimer == TIMER_BOTH));
|
869 |
|
|
|
870 |
|
|
//
|
871 |
|
|
// Get the interrupt number for this timer module.
|
872 |
|
|
//
|
873 |
|
|
ulBase = ((ulBase == TIMER0_BASE) ? INT_TIMER0A :
|
874 |
|
|
((ulBase == TIMER1_BASE) ? INT_TIMER1A : INT_TIMER2A));
|
875 |
|
|
|
876 |
|
|
//
|
877 |
|
|
// Unregister the interrupt handler for timer A if requested.
|
878 |
|
|
//
|
879 |
|
|
if(ulTimer & TIMER_A)
|
880 |
|
|
{
|
881 |
|
|
//
|
882 |
|
|
// Disable the interrupt.
|
883 |
|
|
//
|
884 |
|
|
IntDisable(ulBase);
|
885 |
|
|
|
886 |
|
|
//
|
887 |
|
|
// Unregister the interrupt handler.
|
888 |
|
|
//
|
889 |
|
|
IntUnregister(ulBase);
|
890 |
|
|
}
|
891 |
|
|
|
892 |
|
|
//
|
893 |
|
|
// Unregister the interrupt handler for timer B if requested.
|
894 |
|
|
//
|
895 |
|
|
if(ulTimer & TIMER_B)
|
896 |
|
|
{
|
897 |
|
|
//
|
898 |
|
|
// Disable the interrupt.
|
899 |
|
|
//
|
900 |
|
|
IntDisable(ulBase + 1);
|
901 |
|
|
|
902 |
|
|
//
|
903 |
|
|
// Unregister the interrupt handler.
|
904 |
|
|
//
|
905 |
|
|
IntUnregister(ulBase + 1);
|
906 |
|
|
}
|
907 |
|
|
}
|
908 |
|
|
#endif
|
909 |
|
|
|
910 |
|
|
//*****************************************************************************
|
911 |
|
|
//
|
912 |
|
|
//! Enables individual timer interrupt sources.
|
913 |
|
|
//!
|
914 |
|
|
//! \param ulBase is the base address of the timer module.
|
915 |
|
|
//! \param ulIntFlags is the bit mask of the interrupt sources to be enabled.
|
916 |
|
|
//!
|
917 |
|
|
//! Enables the indicated timer interrupt sources. Only the sources that are
|
918 |
|
|
//! enabled can be reflected to the processor interrupt; disabled sources have
|
919 |
|
|
//! no effect on the processor.
|
920 |
|
|
//!
|
921 |
|
|
//! The parameter \e ulIntFlags must be the logical OR of any combination of
|
922 |
|
|
//! the following:
|
923 |
|
|
//!
|
924 |
|
|
//! - TIMER_CAPB_EVENT - Capture B event interrupt
|
925 |
|
|
//! - TIMER_CAPB_MATCH - Capture B match interrupt
|
926 |
|
|
//! - TIMER_TIMB_TIMEOUT - Timer B timeout interrupt
|
927 |
|
|
//! - TIMER_RTC_MATCH - RTC interrupt mask
|
928 |
|
|
//! - TIMER_CAPA_EVENT - Capture A event interrupt
|
929 |
|
|
//! - TIMER_CAPA_MATCH - Capture A match interrupt
|
930 |
|
|
//! - TIMER_TIMA_TIMEOUT - Timer A timeout interrupt
|
931 |
|
|
//!
|
932 |
|
|
//! \return None.
|
933 |
|
|
//
|
934 |
|
|
//*****************************************************************************
|
935 |
|
|
#if defined(GROUP_intenable) || defined(BUILD_ALL) || defined(DOXYGEN)
|
936 |
|
|
void
|
937 |
|
|
TimerIntEnable(unsigned long ulBase, unsigned long ulIntFlags)
|
938 |
|
|
{
|
939 |
|
|
//
|
940 |
|
|
// Check the arguments.
|
941 |
|
|
//
|
942 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
943 |
|
|
(ulBase == TIMER2_BASE));
|
944 |
|
|
|
945 |
|
|
//
|
946 |
|
|
// Enable the specified interrupts.
|
947 |
|
|
//
|
948 |
|
|
HWREG(ulBase + TIMER_O_IMR) |= ulIntFlags;
|
949 |
|
|
}
|
950 |
|
|
#endif
|
951 |
|
|
|
952 |
|
|
//*****************************************************************************
|
953 |
|
|
//
|
954 |
|
|
//! Disables individual timer interrupt sources.
|
955 |
|
|
//!
|
956 |
|
|
//! \param ulBase is the base address of the timer module.
|
957 |
|
|
//! \param ulIntFlags is the bit mask of the interrupt sources to be disabled.
|
958 |
|
|
//!
|
959 |
|
|
//! Disables the indicated timer interrupt sources. Only the sources that are
|
960 |
|
|
//! enabled can be reflected to the processor interrupt; disabled sources have
|
961 |
|
|
//! no effect on the processor.
|
962 |
|
|
//!
|
963 |
|
|
//! The parameter \e ulIntFlags has the same definition as the \e ulIntFlags
|
964 |
|
|
//! parameter to TimerIntEnable().
|
965 |
|
|
//!
|
966 |
|
|
//! \return None.
|
967 |
|
|
//
|
968 |
|
|
//*****************************************************************************
|
969 |
|
|
#if defined(GROUP_intdisable) || defined(BUILD_ALL) || defined(DOXYGEN)
|
970 |
|
|
void
|
971 |
|
|
TimerIntDisable(unsigned long ulBase, unsigned long ulIntFlags)
|
972 |
|
|
{
|
973 |
|
|
//
|
974 |
|
|
// Check the arguments.
|
975 |
|
|
//
|
976 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
977 |
|
|
(ulBase == TIMER2_BASE));
|
978 |
|
|
|
979 |
|
|
//
|
980 |
|
|
// Disable the specified interrupts.
|
981 |
|
|
//
|
982 |
|
|
HWREG(ulBase + TIMER_O_IMR) &= ~(ulIntFlags);
|
983 |
|
|
}
|
984 |
|
|
#endif
|
985 |
|
|
|
986 |
|
|
//*****************************************************************************
|
987 |
|
|
//
|
988 |
|
|
//! Gets the current interrupt status.
|
989 |
|
|
//!
|
990 |
|
|
//! \param ulBase is the base address of the timer module.
|
991 |
|
|
//! \param bMasked is false if the raw interrupt status is required and true if
|
992 |
|
|
//! the masked interrupt status is required.
|
993 |
|
|
//!
|
994 |
|
|
//! This returns the interrupt status for the timer module. Either the raw
|
995 |
|
|
//! interrupt status or the status of interrupts that are allowed to reflect to
|
996 |
|
|
//! the processor can be returned.
|
997 |
|
|
//!
|
998 |
|
|
//! \return The current interrupt status, enumerated as a bit field of
|
999 |
|
|
//! values described in TimerIntEnable().
|
1000 |
|
|
//
|
1001 |
|
|
//*****************************************************************************
|
1002 |
|
|
#if defined(GROUP_intstatus) || defined(BUILD_ALL) || defined(DOXYGEN)
|
1003 |
|
|
unsigned long
|
1004 |
|
|
TimerIntStatus(unsigned long ulBase, tBoolean bMasked)
|
1005 |
|
|
{
|
1006 |
|
|
//
|
1007 |
|
|
// Check the arguments.
|
1008 |
|
|
//
|
1009 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
1010 |
|
|
(ulBase == TIMER2_BASE));
|
1011 |
|
|
|
1012 |
|
|
//
|
1013 |
|
|
// Return either the interrupt status or the raw interrupt status as
|
1014 |
|
|
// requested.
|
1015 |
|
|
//
|
1016 |
|
|
return(bMasked ? HWREG(ulBase + TIMER_O_MIS) :
|
1017 |
|
|
HWREG(ulBase + TIMER_O_RIS));
|
1018 |
|
|
}
|
1019 |
|
|
#endif
|
1020 |
|
|
|
1021 |
|
|
//*****************************************************************************
|
1022 |
|
|
//
|
1023 |
|
|
//! Clears timer interrupt sources.
|
1024 |
|
|
//!
|
1025 |
|
|
//! \param ulBase is the base address of the timer module.
|
1026 |
|
|
//! \param ulIntFlags is a bit mask of the interrupt sources to be cleared.
|
1027 |
|
|
//!
|
1028 |
|
|
//! The specified timer interrupt sources are cleared, so that they no longer
|
1029 |
|
|
//! assert. This must be done in the interrupt handler to keep it from being
|
1030 |
|
|
//! called again immediately upon exit.
|
1031 |
|
|
//!
|
1032 |
|
|
//! The parameter \e ulIntFlags has the same definition as the \e ulIntFlags
|
1033 |
|
|
//! parameter to TimerIntEnable().
|
1034 |
|
|
//!
|
1035 |
|
|
//! \return None.
|
1036 |
|
|
//
|
1037 |
|
|
//*****************************************************************************
|
1038 |
|
|
#if defined(GROUP_intclear) || defined(BUILD_ALL) || defined(DOXYGEN)
|
1039 |
|
|
void
|
1040 |
|
|
TimerIntClear(unsigned long ulBase, unsigned long ulIntFlags)
|
1041 |
|
|
{
|
1042 |
|
|
//
|
1043 |
|
|
// Check the arguments.
|
1044 |
|
|
//
|
1045 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
1046 |
|
|
(ulBase == TIMER2_BASE));
|
1047 |
|
|
|
1048 |
|
|
//
|
1049 |
|
|
// Clear the requested interrupt sources.
|
1050 |
|
|
//
|
1051 |
|
|
HWREG(ulBase + TIMER_O_ICR) = ulIntFlags;
|
1052 |
|
|
}
|
1053 |
|
|
#endif
|
1054 |
|
|
|
1055 |
|
|
//*****************************************************************************
|
1056 |
|
|
//
|
1057 |
|
|
//! Puts the timer into its reset state.
|
1058 |
|
|
//!
|
1059 |
|
|
//! \param ulBase is the base address of the timer module.
|
1060 |
|
|
//!
|
1061 |
|
|
//! The specified timer is disabled, and all its interrupts are disabled,
|
1062 |
|
|
//! cleared, and unregistered. Then the timer registers are set to their reset
|
1063 |
|
|
//! value.
|
1064 |
|
|
//!
|
1065 |
|
|
//! \return None.
|
1066 |
|
|
//
|
1067 |
|
|
//*****************************************************************************
|
1068 |
|
|
#if defined(GROUP_quiesce) || defined(BUILD_ALL) || defined(DOXYGEN)
|
1069 |
|
|
void
|
1070 |
|
|
TimerQuiesce(unsigned long ulBase)
|
1071 |
|
|
{
|
1072 |
|
|
//
|
1073 |
|
|
// Check the arguments.
|
1074 |
|
|
//
|
1075 |
|
|
ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
|
1076 |
|
|
(ulBase == TIMER2_BASE));
|
1077 |
|
|
|
1078 |
|
|
//
|
1079 |
|
|
// Disable the timer.
|
1080 |
|
|
//
|
1081 |
|
|
HWREG(ulBase + TIMER_O_CTL) = TIMER_RV_CTL;
|
1082 |
|
|
|
1083 |
|
|
//
|
1084 |
|
|
// Disable all the timer interrupts.
|
1085 |
|
|
//
|
1086 |
|
|
HWREG(ulBase + TIMER_O_IMR) = TIMER_RV_IMR;
|
1087 |
|
|
|
1088 |
|
|
//
|
1089 |
|
|
// Clear all the timer interrupts.
|
1090 |
|
|
//
|
1091 |
|
|
HWREG(ulBase + TIMER_O_ICR) = 0xFFFFFFFF;
|
1092 |
|
|
|
1093 |
|
|
//
|
1094 |
|
|
// Unregister the interrupt handler. This also disables interrupts to the
|
1095 |
|
|
// core.
|
1096 |
|
|
//
|
1097 |
|
|
TimerIntUnregister(ulBase, TIMER_BOTH);
|
1098 |
|
|
|
1099 |
|
|
//
|
1100 |
|
|
// Set all the registers to their reset value.
|
1101 |
|
|
//
|
1102 |
|
|
HWREG(ulBase + TIMER_O_CFG) = TIMER_RV_CFG;
|
1103 |
|
|
HWREG(ulBase + TIMER_O_TAMR) = TIMER_RV_TAMR;
|
1104 |
|
|
HWREG(ulBase + TIMER_O_TBMR) = TIMER_RV_TBMR;
|
1105 |
|
|
HWREG(ulBase + TIMER_O_RIS) = TIMER_RV_RIS;
|
1106 |
|
|
HWREG(ulBase + TIMER_O_MIS) = TIMER_RV_MIS;
|
1107 |
|
|
HWREG(ulBase + TIMER_O_TAILR) = TIMER_RV_TAILR;
|
1108 |
|
|
HWREG(ulBase + TIMER_O_TBILR) = TIMER_RV_TBILR;
|
1109 |
|
|
HWREG(ulBase + TIMER_O_TAMATCHR) = TIMER_RV_TAMATCHR;
|
1110 |
|
|
HWREG(ulBase + TIMER_O_TBMATCHR) = TIMER_RV_TBMATCHR;
|
1111 |
|
|
HWREG(ulBase + TIMER_O_TAPR) = TIMER_RV_TAPR;
|
1112 |
|
|
HWREG(ulBase + TIMER_O_TBPR) = TIMER_RV_TBPR;
|
1113 |
|
|
HWREG(ulBase + TIMER_O_TAPMR) = TIMER_RV_TAPMR;
|
1114 |
|
|
HWREG(ulBase + TIMER_O_TBPMR) = TIMER_RV_TBPMR;
|
1115 |
|
|
HWREG(ulBase + TIMER_O_TAR) = TIMER_RV_TAR;
|
1116 |
|
|
HWREG(ulBase + TIMER_O_TBR) = TIMER_RV_TBR;
|
1117 |
|
|
}
|
1118 |
|
|
#endif
|
1119 |
|
|
|
1120 |
|
|
//*****************************************************************************
|
1121 |
|
|
//
|
1122 |
|
|
// Close the Doxygen group.
|
1123 |
|
|
//! @}
|
1124 |
|
|
//
|
1125 |
|
|
//*****************************************************************************
|