1 //*****************************************************************************
2 //
3 // timer.c - Driver for the timer module.
4 //
5 // Copyright (c) 2005-2012 Texas Instruments Incorporated. All rights reserved.
6 // Software License Agreement
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the
18 // distribution.
19 //
20 // Neither the name of Texas Instruments Incorporated nor the names of
21 // its contributors may be used to endorse or promote products derived
22 // from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // This is part of revision 9453 of the Stellaris Peripheral Driver Library.
37 //
38 //*****************************************************************************
39
40 //*****************************************************************************
41 //
42 //! \addtogroup timer_api
43 //! @{
44 //
45 //*****************************************************************************
46
47 #include "inc/hw_ints.h"
48 #include "inc/hw_memmap.h"
49 #include "inc/hw_timer.h"
50 #include "inc/hw_types.h"
51 #include "driverlib/debug.h"
52 #include "driverlib/interrupt.h"
53 #include "driverlib/timer.h"
54
55 //*****************************************************************************
56 //
57 // A mapping of timer base address to interrupt number.
58 //
59 //*****************************************************************************
60 static const unsigned long g_ppulTimerIntMap[][2] =
61 {
62 { TIMER0_BASE, INT_TIMER0A },
63 { TIMER1_BASE, INT_TIMER1A },
64 { TIMER2_BASE, INT_TIMER2A },
65 { TIMER3_BASE, INT_TIMER3A },
66 { TIMER4_BASE, INT_TIMER4A },
67 { TIMER5_BASE, INT_TIMER5A },
68 { WTIMER0_BASE, INT_WTIMER0A },
69 { WTIMER1_BASE, INT_WTIMER1A },
70 { WTIMER2_BASE, INT_WTIMER2A },
71 { WTIMER3_BASE, INT_WTIMER3A },
72 { WTIMER4_BASE, INT_WTIMER4A },
73 { WTIMER5_BASE, INT_WTIMER5A },
74 };
75
76 //*****************************************************************************
77 //
78 //! \internal
79 //! Checks a timer base address.
80 //!
81 //! \param ulBase is the base address of the timer module.
82 //!
83 //! This function determines if a timer module base address is valid.
84 //!
85 //! \return Returns \b true if the base address is valid and \b false
86 //! otherwise.
87 //
88 //*****************************************************************************
89 #ifdef DEBUG
90 static tBoolean
TimerBaseValid(unsigned long ulBase)91 TimerBaseValid(unsigned long ulBase)
92 {
93 return((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
94 (ulBase == TIMER2_BASE) || (ulBase == TIMER3_BASE) ||
95 (ulBase == TIMER4_BASE) || (ulBase == TIMER5_BASE) ||
96 (ulBase == WTIMER0_BASE) || (ulBase == WTIMER1_BASE) ||
97 (ulBase == WTIMER2_BASE) || (ulBase == WTIMER3_BASE) ||
98 (ulBase == WTIMER4_BASE) || (ulBase == WTIMER5_BASE));
99 }
100 #endif
101
102 //*****************************************************************************
103 //
104 //! \internal
105 //! Gets the timer interrupt number.
106 //!
107 //! \param ulBase is the base address of the timer module.
108 //!
109 //! Given a timer base address, this function returns the corresponding
110 //! interrupt number.
111 //!
112 //! \return Returns a timer interrupt number, or -1 if \e ulBase is invalid.
113 //
114 //*****************************************************************************
115 static long
TimerIntNumberGet(unsigned long ulBase)116 TimerIntNumberGet(unsigned long ulBase)
117 {
118 unsigned long ulIdx;
119
120 //
121 // Loop through the table that maps timer base addresses to interrupt
122 // numbers.
123 //
124 for(ulIdx = 0; ulIdx < (sizeof(g_ppulTimerIntMap) /
125 sizeof(g_ppulTimerIntMap[0])); ulIdx++)
126 {
127 //
128 // See if this base address matches.
129 //
130 if(g_ppulTimerIntMap[ulIdx][0] == ulBase)
131 {
132 //
133 // Return the corresponding interrupt number.
134 //
135 return(g_ppulTimerIntMap[ulIdx][1]);
136 }
137 }
138
139 //
140 // The base address could not be found, so return an error.
141 //
142 return(-1);
143 }
144
145 //*****************************************************************************
146 //
147 //! Enables the timer(s).
148 //!
149 //! \param ulBase is the base address of the timer module.
150 //! \param ulTimer specifies the timer(s) to enable; must be one of \b TIMER_A,
151 //! \b TIMER_B, or \b TIMER_BOTH.
152 //!
153 //! This function enables operation of the timer module. The timer must be
154 //! configured before it is enabled.
155 //!
156 //! \return None.
157 //
158 //*****************************************************************************
159 void
TimerEnable(unsigned long ulBase,unsigned long ulTimer)160 TimerEnable(unsigned long ulBase, unsigned long ulTimer)
161 {
162 //
163 // Check the arguments.
164 //
165 ASSERT(TimerBaseValid(ulBase));
166 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
167 (ulTimer == TIMER_BOTH));
168
169 //
170 // Enable the timer(s) module.
171 //
172 HWREG(ulBase + TIMER_O_CTL) |= ulTimer & (TIMER_CTL_TAEN | TIMER_CTL_TBEN);
173 }
174
175 //*****************************************************************************
176 //
177 //! Disables the timer(s).
178 //!
179 //! \param ulBase is the base address of the timer module.
180 //! \param ulTimer specifies the timer(s) to disable; must be one of
181 //! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
182 //!
183 //! This function disables operation of the timer module.
184 //!
185 //! \return None.
186 //
187 //*****************************************************************************
188 void
TimerDisable(unsigned long ulBase,unsigned long ulTimer)189 TimerDisable(unsigned long ulBase, unsigned long ulTimer)
190 {
191 //
192 // Check the arguments.
193 //
194 ASSERT(TimerBaseValid(ulBase));
195 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
196 (ulTimer == TIMER_BOTH));
197
198 //
199 // Disable the timer module.
200 //
201 HWREG(ulBase + TIMER_O_CTL) &= ~(ulTimer &
202 (TIMER_CTL_TAEN | TIMER_CTL_TBEN));
203 }
204
205 //*****************************************************************************
206 //
207 //! Configures the timer(s).
208 //!
209 //! \param ulBase is the base address of the timer module.
210 //! \param ulConfig is the configuration for the timer.
211 //!
212 //! This function configures the operating mode of the timer(s). The timer
213 //! module is disabled before being configured and is left in the disabled
214 //! state. The timer can be configured to be a single full-width timer
215 //! by using the \b TIMER_CFG_* values or a pair of half-width timers using the
216 //! \b TIMER_CFG_A_* and \b TIMER_CFG_B_* values passed in the \e ulConfig
217 //! parameter.
218 //!
219 //! The configuration is specified in \e ulConfig as one of the following
220 //! values:
221 //!
222 //! - \b TIMER_CFG_ONE_SHOT - Full-width one-shot timer
223 //! - \b TIMER_CFG_ONE_SHOT_UP - Full-width one-shot timer that counts up
224 //! instead of down (not available on all parts)
225 //! - \b TIMER_CFG_PERIODIC - Full-width periodic timer
226 //! - \b TIMER_CFG_PERIODIC_UP - Full-width periodic timer that counts up
227 //! instead of down (not available on all parts)
228 //! - \b TIMER_CFG_RTC - Full-width real time clock timer
229 //! - \b TIMER_CFG_SPLIT_PAIR - Two half-width timers
230 //!
231 //! When configured for a pair of half-width timers, each timer is separately
232 //! configured. The first timer is configured by setting \e ulConfig to
233 //! the result of a logical OR operation between one of the following values
234 //! and \e ulConfig:
235 //!
236 //! - \b TIMER_CFG_A_ONE_SHOT - Half-width one-shot timer
237 //! - \b TIMER_CFG_A_ONE_SHOT_UP - Half-width one-shot timer that counts up
238 //! instead of down (not available on all parts)
239 //! - \b TIMER_CFG_A_PERIODIC - Half-width periodic timer
240 //! - \b TIMER_CFG_A_PERIODIC_UP - Half-width periodic timer that counts up
241 //! instead of down (not available on all parts)
242 //! - \b TIMER_CFG_A_CAP_COUNT - Half-width edge count capture
243 //! - \b TIMER_CFG_A_CAP_COUNT_UP - Half-width edge count capture that counts
244 //! up instead of down (not available on all parts)
245 //! - \b TIMER_CFG_A_CAP_TIME - Half-width edge time capture
246 //! - \b TIMER_CFG_A_CAP_TIME_UP - Half-width edge time capture that counts up
247 //! instead of down (not available on all parts)
248 //! - \b TIMER_CFG_A_PWM - Half-width PWM output
249 //!
250 //! Similarly, the second timer is configured by setting \e ulConfig to
251 //! the result of a logical OR operation between one of the corresponding
252 //! \b TIMER_CFG_B_* values and \e ulConfig.
253 //!
254 //! \return None.
255 //
256 //*****************************************************************************
257 void
TimerConfigure(unsigned long ulBase,unsigned long ulConfig)258 TimerConfigure(unsigned long ulBase, unsigned long ulConfig)
259 {
260 //
261 // Check the arguments.
262 //
263 ASSERT(TimerBaseValid(ulBase));
264 ASSERT((ulConfig == TIMER_CFG_ONE_SHOT) ||
265 (ulConfig == TIMER_CFG_ONE_SHOT_UP) ||
266 (ulConfig == TIMER_CFG_PERIODIC) ||
267 (ulConfig == TIMER_CFG_PERIODIC_UP) ||
268 (ulConfig == TIMER_CFG_RTC) ||
269 ((ulConfig & 0xff000000) == TIMER_CFG_SPLIT_PAIR));
270 ASSERT(((ulConfig & 0xff000000) != TIMER_CFG_SPLIT_PAIR) ||
271 ((((ulConfig & 0x000000ff) == TIMER_CFG_A_ONE_SHOT) ||
272 ((ulConfig & 0x000000ff) == TIMER_CFG_A_ONE_SHOT_UP) ||
273 ((ulConfig & 0x000000ff) == TIMER_CFG_A_PERIODIC) ||
274 ((ulConfig & 0x000000ff) == TIMER_CFG_A_PERIODIC_UP) ||
275 ((ulConfig & 0x000000ff) == TIMER_CFG_A_CAP_COUNT) ||
276 ((ulConfig & 0x000000ff) == TIMER_CFG_A_CAP_TIME) ||
277 ((ulConfig & 0x000000ff) == TIMER_CFG_A_PWM)) &&
278 (((ulConfig & 0x0000ff00) == TIMER_CFG_B_ONE_SHOT) ||
279 ((ulConfig & 0x0000ff00) == TIMER_CFG_B_ONE_SHOT_UP) ||
280 ((ulConfig & 0x0000ff00) == TIMER_CFG_B_PERIODIC) ||
281 ((ulConfig & 0x0000ff00) == TIMER_CFG_B_PERIODIC_UP) ||
282 ((ulConfig & 0x0000ff00) == TIMER_CFG_B_CAP_COUNT) ||
283 ((ulConfig & 0x0000ff00) == TIMER_CFG_B_CAP_COUNT_UP) ||
284 ((ulConfig & 0x0000ff00) == TIMER_CFG_B_CAP_TIME) ||
285 ((ulConfig & 0x0000ff00) == TIMER_CFG_B_CAP_TIME_UP) ||
286 ((ulConfig & 0x0000ff00) == TIMER_CFG_B_PWM))));
287
288 //
289 // Disable the timers.
290 //
291 HWREG(ulBase + TIMER_O_CTL) &= ~(TIMER_CTL_TAEN | TIMER_CTL_TBEN);
292
293 //
294 // Set the global timer configuration.
295 //
296 HWREG(ulBase + TIMER_O_CFG) = ulConfig >> 24;
297
298 //
299 // Set the configuration of the A and B timers. Note that the B timer
300 // configuration is ignored by the hardware in 32-bit modes.
301 //
302 HWREG(ulBase + TIMER_O_TAMR) = (ulConfig & 255) | TIMER_TAMR_TAPWMIE;
303 HWREG(ulBase + TIMER_O_TBMR) =
304 ((ulConfig >> 8) & 255) | TIMER_TBMR_TBPWMIE;
305 }
306
307 //*****************************************************************************
308 //
309 //! Controls the output level.
310 //!
311 //! \param ulBase is the base address of the timer module.
312 //! \param ulTimer specifies the timer(s) to adjust; must be one of \b TIMER_A,
313 //! \b TIMER_B, or \b TIMER_BOTH.
314 //! \param bInvert specifies the output level.
315 //!
316 //! This function configures the PWM output level for the specified timer. If
317 //! the \e bInvert parameter is \b true, then the timer's output is made active
318 //! low; otherwise, it is made active high.
319 //!
320 //! \return None.
321 //
322 //*****************************************************************************
323 void
TimerControlLevel(unsigned long ulBase,unsigned long ulTimer,tBoolean bInvert)324 TimerControlLevel(unsigned long ulBase, unsigned long ulTimer,
325 tBoolean bInvert)
326 {
327 //
328 // Check the arguments.
329 //
330 ASSERT(TimerBaseValid(ulBase));
331 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
332 (ulTimer == TIMER_BOTH));
333
334 //
335 // Set the output levels as requested.
336 //
337 ulTimer &= TIMER_CTL_TAPWML | TIMER_CTL_TBPWML;
338 HWREG(ulBase + TIMER_O_CTL) = (bInvert ?
339 (HWREG(ulBase + TIMER_O_CTL) | ulTimer) :
340 (HWREG(ulBase + TIMER_O_CTL) & ~(ulTimer)));
341 }
342
343 //*****************************************************************************
344 //
345 //! Enables or disables the ADC trigger output.
346 //!
347 //! \param ulBase is the base address of the timer module.
348 //! \param ulTimer specifies the timer to adjust; must be one of \b TIMER_A,
349 //! \b TIMER_B, or \b TIMER_BOTH.
350 //! \param bEnable specifies the desired ADC trigger state.
351 //!
352 //! This function controls the ADC trigger output for the specified timer. If
353 //! the \e bEnable parameter is \b true, then the timer's ADC output trigger is
354 //! enabled; otherwise it is disabled.
355 //!
356 //! \return None.
357 //
358 //*****************************************************************************
359 void
TimerControlTrigger(unsigned long ulBase,unsigned long ulTimer,tBoolean bEnable)360 TimerControlTrigger(unsigned long ulBase, unsigned long ulTimer,
361 tBoolean bEnable)
362 {
363 //
364 // Check the arguments.
365 //
366 ASSERT(TimerBaseValid(ulBase));
367 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
368 (ulTimer == TIMER_BOTH));
369
370 //
371 // Set the trigger output as requested.
372 // Set the ADC trigger output as requested.
373 //
374 ulTimer &= TIMER_CTL_TAOTE | TIMER_CTL_TBOTE;
375 HWREG(ulBase + TIMER_O_CTL) = (bEnable ?
376 (HWREG(ulBase + TIMER_O_CTL) | ulTimer) :
377 (HWREG(ulBase + TIMER_O_CTL) & ~(ulTimer)));
378 }
379
380 //*****************************************************************************
381 //
382 //! Controls the event type.
383 //!
384 //! \param ulBase is the base address of the timer module.
385 //! \param ulTimer specifies the timer(s) to be adjusted; must be one of
386 //! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
387 //! \param ulEvent specifies the type of event; must be one of
388 //! \b TIMER_EVENT_POS_EDGE, \b TIMER_EVENT_NEG_EDGE, or
389 //! \b TIMER_EVENT_BOTH_EDGES.
390 //!
391 //! This function configures the signal edge(s) that triggers the timer when
392 //! in capture mode.
393 //!
394 //! \return None.
395 //
396 //*****************************************************************************
397 void
TimerControlEvent(unsigned long ulBase,unsigned long ulTimer,unsigned long ulEvent)398 TimerControlEvent(unsigned long ulBase, unsigned long ulTimer,
399 unsigned long ulEvent)
400 {
401 //
402 // Check the arguments.
403 //
404 ASSERT(TimerBaseValid(ulBase));
405 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
406 (ulTimer == TIMER_BOTH));
407
408 //
409 // Set the event type.
410 //
411 ulTimer &= TIMER_CTL_TAEVENT_M | TIMER_CTL_TBEVENT_M;
412 HWREG(ulBase + TIMER_O_CTL) = ((HWREG(ulBase + TIMER_O_CTL) & ~ulTimer) |
413 (ulEvent & ulTimer));
414 }
415
416 //*****************************************************************************
417 //
418 //! Controls the stall handling.
419 //!
420 //! \param ulBase is the base address of the timer module.
421 //! \param ulTimer specifies the timer(s) to be adjusted; must be one of
422 //! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
423 //! \param bStall specifies the response to a stall signal.
424 //!
425 //! This function controls the stall response for the specified timer. If the
426 //! \e bStall parameter is \b true, then the timer stops counting if the
427 //! processor enters debug mode; otherwise the timer keeps running while in
428 //! debug mode.
429 //!
430 //! \return None.
431 //
432 //*****************************************************************************
433 void
TimerControlStall(unsigned long ulBase,unsigned long ulTimer,tBoolean bStall)434 TimerControlStall(unsigned long ulBase, unsigned long ulTimer,
435 tBoolean bStall)
436 {
437 //
438 // Check the arguments.
439 //
440 ASSERT(TimerBaseValid(ulBase));
441 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
442 (ulTimer == TIMER_BOTH));
443
444 //
445 // Set the stall mode.
446 //
447 ulTimer &= TIMER_CTL_TASTALL | TIMER_CTL_TBSTALL;
448 HWREG(ulBase + TIMER_O_CTL) = (bStall ?
449 (HWREG(ulBase + TIMER_O_CTL) | ulTimer) :
450 (HWREG(ulBase + TIMER_O_CTL) & ~(ulTimer)));
451 }
452
453 //*****************************************************************************
454 //
455 //! Controls the wait on trigger handling.
456 //!
457 //! \param ulBase is the base address of the timer module.
458 //! \param ulTimer specifies the timer(s) to be adjusted; must be one of
459 //! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
460 //! \param bWait specifies if the timer should wait for a trigger input.
461 //!
462 //! This function controls whether or not a timer waits for a trigger input to
463 //! start counting. When enabled, the previous timer in the trigger chain must
464 //! count to its timeout in order for this timer to start counting. Refer to
465 //! the part's data sheet for a description of the trigger chain.
466 //!
467 //! \note This functionality is not available on all parts. This function
468 //! should not be used for Timer 0A or Wide Timer 0A.
469 //!
470 //! \return None.
471 //
472 //*****************************************************************************
473 void
TimerControlWaitOnTrigger(unsigned long ulBase,unsigned long ulTimer,tBoolean bWait)474 TimerControlWaitOnTrigger(unsigned long ulBase, unsigned long ulTimer,
475 tBoolean bWait)
476 {
477 //
478 // Check the arguments.
479 //
480 ASSERT(TimerBaseValid(ulBase));
481 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
482 (ulTimer == TIMER_BOTH));
483
484 //
485 // Set the wait on trigger mode for timer A.
486 //
487 if((ulTimer & TIMER_A) != 0)
488 {
489 if(bWait)
490 {
491 HWREG(ulBase + TIMER_O_TAMR) |= TIMER_TAMR_TAWOT;
492 }
493 else
494 {
495 HWREG(ulBase + TIMER_O_TAMR) &= ~(TIMER_TAMR_TAWOT);
496 }
497 }
498
499 //
500 // Set the wait on trigger mode for timer B.
501 //
502 if((ulTimer & TIMER_B) != 0)
503 {
504 if(bWait)
505 {
506 HWREG(ulBase + TIMER_O_TBMR) |= TIMER_TBMR_TBWOT;
507 }
508 else
509 {
510 HWREG(ulBase + TIMER_O_TBMR) &= ~(TIMER_TBMR_TBWOT);
511 }
512 }
513 }
514
515 //*****************************************************************************
516 //
517 //! Enable RTC counting.
518 //!
519 //! \param ulBase is the base address of the timer module.
520 //!
521 //! This function causes the timer to start counting when in RTC mode. If not
522 //! configured for RTC mode, this function does nothing.
523 //!
524 //! \return None.
525 //
526 //*****************************************************************************
527 void
TimerRTCEnable(unsigned long ulBase)528 TimerRTCEnable(unsigned long ulBase)
529 {
530 //
531 // Check the arguments.
532 //
533 ASSERT(TimerBaseValid(ulBase));
534
535 //
536 // Enable RTC counting.
537 //
538 HWREG(ulBase + TIMER_O_CTL) |= TIMER_CTL_RTCEN;
539 }
540
541 //*****************************************************************************
542 //
543 //! Disable RTC counting.
544 //!
545 //! \param ulBase is the base address of the timer module.
546 //!
547 //! This function causes the timer to stop counting when in RTC mode.
548 //!
549 //! \return None.
550 //
551 //*****************************************************************************
552 void
TimerRTCDisable(unsigned long ulBase)553 TimerRTCDisable(unsigned long ulBase)
554 {
555 //
556 // Check the arguments.
557 //
558 ASSERT(TimerBaseValid(ulBase));
559
560 //
561 // Disable RTC counting.
562 //
563 HWREG(ulBase + TIMER_O_CTL) &= ~(TIMER_CTL_RTCEN);
564 }
565
566 //*****************************************************************************
567 //
568 //! Set the timer prescale value.
569 //!
570 //! \param ulBase is the base address of the timer module.
571 //! \param ulTimer specifies the timer(s) to adjust; must be one of \b TIMER_A,
572 //! \b TIMER_B, or \b TIMER_BOTH.
573 //! \param ulValue is the timer prescale value which must be between 0 and 255
574 //! (inclusive) for 16/32-bit timers and between 0 and 65535 (inclusive) for
575 //! 32/64-bit timers.
576 //!
577 //! This function configures the value of the input clock prescaler. The
578 //! prescaler is only operational when in half-width mode and is used to extend
579 //! the range of the half-width timer modes. The prescaler provides the least
580 //! significant bits when counting down in periodic and one-shot modes; in all
581 //! other modes, the prescaler provides the most significant bits.
582 //!
583 //! \note The availability of the prescaler varies with the Stellaris part and
584 //! timer mode in use. Please consult the datasheet for the part you are using
585 //! to determine whether this support is available.
586 //!
587 //! \return None.
588 //
589 //*****************************************************************************
590 void
TimerPrescaleSet(unsigned long ulBase,unsigned long ulTimer,unsigned long ulValue)591 TimerPrescaleSet(unsigned long ulBase, unsigned long ulTimer,
592 unsigned long ulValue)
593 {
594 //
595 // Check the arguments.
596 //
597 ASSERT(TimerBaseValid(ulBase));
598 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
599 (ulTimer == TIMER_BOTH));
600 ASSERT(ulValue < 256);
601
602 //
603 // Set the timer A prescaler if requested.
604 //
605 if(ulTimer & TIMER_A)
606 {
607 HWREG(ulBase + TIMER_O_TAPR) = ulValue;
608 }
609
610 //
611 // Set the timer B prescaler if requested.
612 //
613 if(ulTimer & TIMER_B)
614 {
615 HWREG(ulBase + TIMER_O_TBPR) = ulValue;
616 }
617 }
618
619 //*****************************************************************************
620 //
621 //! Get the timer prescale value.
622 //!
623 //! \param ulBase is the base address of the timer module.
624 //! \param ulTimer specifies the timer; must be one of \b TIMER_A or
625 //! \b TIMER_B.
626 //!
627 //! This function gets the value of the input clock prescaler. The prescaler
628 //! is only operational when in half-width mode and is used to extend the range
629 //! of the half-width timer modes. The prescaler provides the least significant
630 //! bits when counting down in periodic and one-shot modes; in all other modes,
631 //! the prescaler provides the most significant bits.
632 //!
633 //! \note The availability of the prescaler varies with the Stellaris part and
634 //! timer mode in use. Please consult the datasheet for the part you are using
635 //! to determine whether this support is available.
636 //!
637 //! \return The value of the timer prescaler.
638 //
639 //*****************************************************************************
640 unsigned long
TimerPrescaleGet(unsigned long ulBase,unsigned long ulTimer)641 TimerPrescaleGet(unsigned long ulBase, unsigned long ulTimer)
642 {
643 //
644 // Check the arguments.
645 //
646 ASSERT(TimerBaseValid(ulBase));
647 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
648 (ulTimer == TIMER_BOTH));
649
650 //
651 // Return the appropriate prescale value.
652 //
653 return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAPR) :
654 HWREG(ulBase + TIMER_O_TBPR));
655 }
656
657 //*****************************************************************************
658 //
659 //! Set the timer prescale match value.
660 //!
661 //! \param ulBase is the base address of the timer module.
662 //! \param ulTimer specifies the timer(s) to adjust; must be one of \b TIMER_A,
663 //! \b TIMER_B, or \b TIMER_BOTH.
664 //! \param ulValue is the timer prescale match value which must be between 0
665 //! and 255 (inclusive) for 16/32-bit timers and between 0 and 65535
666 //! (inclusive) for 32/64-bit timers.
667 //!
668 //! This function configures the value of the input clock prescaler match
669 //! value. When in a half-width mode that uses the counter match and the
670 //! prescaler, the prescale match effectively extends the range of the match.
671 //! The prescaler provides the least significant bits when counting down in
672 //! periodic and one-shot modes; in all other modes, the prescaler provides the
673 //! most significant bits.
674 //!
675 //! \note The availability of the prescaler match varies with the Stellaris
676 //! part and timer mode in use. Please consult the datasheet for the part you
677 //! are using to determine whether this support is available.
678 //!
679 //! \return None.
680 //
681 //*****************************************************************************
682 void
TimerPrescaleMatchSet(unsigned long ulBase,unsigned long ulTimer,unsigned long ulValue)683 TimerPrescaleMatchSet(unsigned long ulBase, unsigned long ulTimer,
684 unsigned long ulValue)
685 {
686 //
687 // Check the arguments.
688 //
689 ASSERT(TimerBaseValid(ulBase));
690 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
691 (ulTimer == TIMER_BOTH));
692 ASSERT(ulValue < 256);
693
694 //
695 // Set the timer A prescale match if requested.
696 //
697 if(ulTimer & TIMER_A)
698 {
699 HWREG(ulBase + TIMER_O_TAPMR) = ulValue;
700 }
701
702 //
703 // Set the timer B prescale match if requested.
704 //
705 if(ulTimer & TIMER_B)
706 {
707 HWREG(ulBase + TIMER_O_TBPMR) = ulValue;
708 }
709 }
710
711 //*****************************************************************************
712 //
713 //! Get the timer prescale match value.
714 //!
715 //! \param ulBase is the base address of the timer module.
716 //! \param ulTimer specifies the timer; must be one of \b TIMER_A or
717 //! \b TIMER_B.
718 //!
719 //! This function gets the value of the input clock prescaler match value.
720 //! When in a half-width mode that uses the counter match and prescaler, the
721 //! prescale match effectively extends the range of the match. The prescaler
722 //! provides the least significant bits when counting down in periodic and
723 //! one-shot modes; in all other modes, the prescaler provides the most
724 //! significant bits.
725 //!
726 //! \note The availability of the prescaler match varies with the Stellaris
727 //! part and timer mode in use. Please consult the datasheet for the part you
728 //! are using to determine whether this support is available.
729 //!
730 //! \return The value of the timer prescale match.
731 //
732 //*****************************************************************************
733 unsigned long
TimerPrescaleMatchGet(unsigned long ulBase,unsigned long ulTimer)734 TimerPrescaleMatchGet(unsigned long ulBase, unsigned long ulTimer)
735 {
736 //
737 // Check the arguments.
738 //
739 ASSERT(TimerBaseValid(ulBase));
740 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
741 (ulTimer == TIMER_BOTH));
742
743 //
744 // Return the appropriate prescale match value.
745 //
746 return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAPMR) :
747 HWREG(ulBase + TIMER_O_TBPMR));
748 }
749
750 //*****************************************************************************
751 //
752 //! Sets the timer load value.
753 //!
754 //! \param ulBase is the base address of the timer module.
755 //! \param ulTimer specifies the timer(s) to adjust; must be one of \b TIMER_A,
756 //! \b TIMER_B, or \b TIMER_BOTH. Only \b TIMER_A should be used when the
757 //! timer is configured for full-width operation.
758 //! \param ulValue is the load value.
759 //!
760 //! This function configures the timer load value; if the timer is running then
761 //! the value is immediately loaded into the timer.
762 //!
763 //! \note This function can be used for both full- and half-width modes of
764 //! 16/32-bit timers and for half-width modes of 32/64-bit timers. Use
765 //! TimerLoadSet64() for full-width modes of 32/64-bit timers.
766 //!
767 //! \return None.
768 //
769 //*****************************************************************************
770 void
TimerLoadSet(unsigned long ulBase,unsigned long ulTimer,unsigned long ulValue)771 TimerLoadSet(unsigned long ulBase, unsigned long ulTimer,
772 unsigned long ulValue)
773 {
774 //
775 // Check the arguments.
776 //
777 ASSERT(TimerBaseValid(ulBase));
778 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
779 (ulTimer == TIMER_BOTH));
780
781 //
782 // Set the timer A load value if requested.
783 //
784 if(ulTimer & TIMER_A)
785 {
786 HWREG(ulBase + TIMER_O_TAILR) = ulValue;
787 }
788
789 //
790 // Set the timer B load value if requested.
791 //
792 if(ulTimer & TIMER_B)
793 {
794 HWREG(ulBase + TIMER_O_TBILR) = ulValue;
795 }
796 }
797
798 //*****************************************************************************
799 //
800 //! Gets the timer load value.
801 //!
802 //! \param ulBase is the base address of the timer module.
803 //! \param ulTimer specifies the timer; must be one of \b TIMER_A or
804 //! \b TIMER_B. Only \b TIMER_A should be used when the timer is configured
805 //! for full-width operation.
806 //!
807 //! This function gets the currently programmed interval load value for the
808 //! specified timer.
809 //!
810 //! \note This function can be used for both full- and half-width modes of
811 //! 16/32-bit timers and for half-width modes of 32/64-bit timers. Use
812 //! TimerLoadGet64() for full-width modes of 32/64-bit timers.
813 //!
814 //! \return Returns the load value for the timer.
815 //
816 //*****************************************************************************
817 unsigned long
TimerLoadGet(unsigned long ulBase,unsigned long ulTimer)818 TimerLoadGet(unsigned long ulBase, unsigned long ulTimer)
819 {
820 //
821 // Check the arguments.
822 //
823 ASSERT(TimerBaseValid(ulBase));
824 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B));
825
826 //
827 // Return the appropriate load value.
828 //
829 return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAILR) :
830 HWREG(ulBase + TIMER_O_TBILR));
831 }
832
833 //*****************************************************************************
834 //
835 //! Sets the timer load value for a 64-bit timer.
836 //!
837 //! \param ulBase is the base address of the timer module.
838 //! \param ullValue is the load value.
839 //!
840 //! This function configures the timer load value for a 64-bit timer; if the
841 //! timer is running, then the value is immediately loaded into the timer.
842 //!
843 //! \return None.
844 //
845 //*****************************************************************************
846 void
TimerLoadSet64(unsigned long ulBase,unsigned long long ullValue)847 TimerLoadSet64(unsigned long ulBase, unsigned long long ullValue)
848 {
849 //
850 // Check the arguments.
851 //
852 ASSERT(TimerBaseValid(ulBase));
853
854 //
855 // Set the timer load value. The upper 32-bits must be written before the
856 // lower 32-bits in order to adhere to the hardware interlocks on the
857 // 64-bit value.
858 //
859 HWREG(ulBase + TIMER_O_TBILR) = ullValue >> 32;
860 HWREG(ulBase + TIMER_O_TAILR) = ullValue & 0xffffffff;
861 }
862
863 //*****************************************************************************
864 //
865 //! Gets the timer load value for a 64-bit timer.
866 //!
867 //! \param ulBase is the base address of the timer module.
868 //!
869 //! This function gets the currently programmed interval load value for the
870 //! specified 64-bit timer.
871 //!
872 //! \return Returns the load value for the timer.
873 //
874 //*****************************************************************************
875 unsigned long long
TimerLoadGet64(unsigned long ulBase)876 TimerLoadGet64(unsigned long ulBase)
877 {
878 unsigned long ulHigh1, ulHigh2, ulLow;
879
880 //
881 // Check the arguments.
882 //
883 ASSERT(TimerBaseValid(ulBase));
884
885 //
886 // Read the 64-bit load value. A read of the low 32-bits is performed
887 // between two reads of the upper 32-bits; if the upper 32-bit values match
888 // then the 64-bit value is consistent. If they do not match, then the
889 // read is performed again until they do match (it should never execute the
890 // loop body more than twice).
891 //
892 do
893 {
894 ulHigh1 = HWREG(ulBase + TIMER_O_TBILR);
895 ulLow = HWREG(ulBase + TIMER_O_TAILR);
896 ulHigh2 = HWREG(ulBase + TIMER_O_TBILR);
897 }
898 while(ulHigh1 != ulHigh2);
899
900 //
901 // Return the load value.
902 //
903 return(((unsigned long long)ulHigh1 << 32) | (unsigned long long)ulLow);
904 }
905
906 //*****************************************************************************
907 //
908 //! Gets the current timer value.
909 //!
910 //! \param ulBase is the base address of the timer module.
911 //! \param ulTimer specifies the timer; must be one of \b TIMER_A or
912 //! \b TIMER_B. Only \b TIMER_A should be used when the timer is configured
913 //! for full-width operation.
914 //!
915 //! This function reads the current value of the specified timer.
916 //!
917 //! \note This function can be used for both full- and half-width modes of
918 //! 16/32-bit timers and for half-width modes of 32/64-bit timers. Use
919 //! TimerValueGet64() for full-width modes of 32/64-bit timers.
920 //!
921 //! \return Returns the current value of the timer.
922 //
923 //*****************************************************************************
924 unsigned long
TimerValueGet(unsigned long ulBase,unsigned long ulTimer)925 TimerValueGet(unsigned long ulBase, unsigned long ulTimer)
926 {
927 //
928 // Check the arguments.
929 //
930 ASSERT(TimerBaseValid(ulBase));
931 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B));
932
933 //
934 // Return the appropriate timer value.
935 //
936 return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAR) :
937 HWREG(ulBase + TIMER_O_TBR));
938 }
939
940 //*****************************************************************************
941 //
942 //! Gets the current 64-bit timer value.
943 //!
944 //! \param ulBase is the base address of the timer module.
945 //!
946 //! This function reads the current value of the specified timer.
947 //!
948 //! \return Returns the current value of the timer.
949 //
950 //*****************************************************************************
951 unsigned long long
TimerValueGet64(unsigned long ulBase)952 TimerValueGet64(unsigned long ulBase)
953 {
954 unsigned long ulHigh1, ulHigh2, ulLow;
955
956 //
957 // Check the arguments.
958 //
959 ASSERT(TimerBaseValid(ulBase));
960
961 //
962 // Read the 64-bit timer value. A read of the low 32-bits is performed
963 // between two reads of the upper 32-bits; if the upper 32-bit values match
964 // then the 64-bit value is consistent. If they do not match, then the
965 // read is performed again until they do match (it should never execute the
966 // loop body more than twice).
967 //
968 do
969 {
970 ulHigh1 = HWREG(ulBase + TIMER_O_TBR);
971 ulLow = HWREG(ulBase + TIMER_O_TAR);
972 ulHigh2 = HWREG(ulBase + TIMER_O_TBR);
973 }
974 while(ulHigh1 != ulHigh2);
975
976 //
977 // Return the timer value.
978 //
979 return(((unsigned long long)ulHigh1 << 32) | (unsigned long long)ulLow);
980 }
981
982 //*****************************************************************************
983 //
984 //! Sets the timer match value.
985 //!
986 //! \param ulBase is the base address of the timer module.
987 //! \param ulTimer specifies the timer(s) to adjust; must be one of \b TIMER_A,
988 //! \b TIMER_B, or \b TIMER_BOTH. Only \b TIMER_A should be used when the
989 //! timer is configured for full-width operation.
990 //! \param ulValue is the match value.
991 //!
992 //! This function configures the match value for a timer. This value is used
993 //! in capture count mode to determine when to interrupt the processor and in
994 //! PWM mode to determine the duty cycle of the output signal. On some
995 //! Stellaris devices, match interrupts can also be generated in periodic and
996 //! one-shot modes.
997 //!
998 //! \note This function can be used for both full- and half-width modes of
999 //! 16/32-bit timers and for half-width modes of 32/64-bit timers. Use
1000 //! TimerMatchSet64() for full-width modes of 32/64-bit timers.
1001 //!
1002 //! \return None.
1003 //
1004 //*****************************************************************************
1005 void
TimerMatchSet(unsigned long ulBase,unsigned long ulTimer,unsigned long ulValue)1006 TimerMatchSet(unsigned long ulBase, unsigned long ulTimer,
1007 unsigned long ulValue)
1008 {
1009 //
1010 // Check the arguments.
1011 //
1012 ASSERT(TimerBaseValid(ulBase));
1013 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
1014 (ulTimer == TIMER_BOTH));
1015
1016 //
1017 // Set the timer A match value if requested.
1018 //
1019 if(ulTimer & TIMER_A)
1020 {
1021 HWREG(ulBase + TIMER_O_TAMATCHR) = ulValue;
1022 }
1023
1024 //
1025 // Set the timer B match value if requested.
1026 //
1027 if(ulTimer & TIMER_B)
1028 {
1029 HWREG(ulBase + TIMER_O_TBMATCHR) = ulValue;
1030 }
1031 }
1032
1033 //*****************************************************************************
1034 //
1035 //! Gets the timer match value.
1036 //!
1037 //! \param ulBase is the base address of the timer module.
1038 //! \param ulTimer specifies the timer; must be one of \b TIMER_A or
1039 //! \b TIMER_B. Only \b TIMER_A should be used when the timer is configured
1040 //! for full-width operation.
1041 //!
1042 //! This function gets the match value for the specified timer.
1043 //!
1044 //! \note This function can be used for both full- and half-width modes of
1045 //! 16/32-bit timers and for half-width modes of 32/64-bit timers. Use
1046 //! TimerMatchGet64() for full-width modes of 32/64-bit timers.
1047 //!
1048 //! \return Returns the match value for the timer.
1049 //
1050 //*****************************************************************************
1051 unsigned long
TimerMatchGet(unsigned long ulBase,unsigned long ulTimer)1052 TimerMatchGet(unsigned long ulBase, unsigned long ulTimer)
1053 {
1054 //
1055 // Check the arguments.
1056 //
1057 ASSERT(TimerBaseValid(ulBase));
1058 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B));
1059
1060 //
1061 // Return the appropriate match value.
1062 //
1063 return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAMATCHR) :
1064 HWREG(ulBase + TIMER_O_TBMATCHR));
1065 }
1066
1067 //*****************************************************************************
1068 //
1069 //! Sets the timer match value for a 64-bit timer.
1070 //!
1071 //! \param ulBase is the base address of the timer module.
1072 //! \param ullValue is the match value.
1073 //!
1074 //! This function configures the match value for a timer. This value is used
1075 //! in capture count mode to determine when to interrupt the processor and in
1076 //! PWM mode to determine the duty cycle of the output signal.
1077 //!
1078 //! \return None.
1079 //
1080 //*****************************************************************************
1081 void
TimerMatchSet64(unsigned long ulBase,unsigned long long ullValue)1082 TimerMatchSet64(unsigned long ulBase, unsigned long long ullValue)
1083 {
1084 //
1085 // Check the arguments.
1086 //
1087 ASSERT(TimerBaseValid(ulBase));
1088
1089 //
1090 // Set the timer match value. The upper 32-bits must be written before the
1091 // lower 32-bits in order to adhere to the hardware interlocks on the
1092 // 64-bit value.
1093 //
1094 HWREG(ulBase + TIMER_O_TBMATCHR) = ullValue >> 32;
1095 HWREG(ulBase + TIMER_O_TAMATCHR) = ullValue & 0xffffffff;
1096 }
1097
1098 //*****************************************************************************
1099 //
1100 //! Gets the timer match value for a 64-bit timer.
1101 //!
1102 //! \param ulBase is the base address of the timer module.
1103 //!
1104 //! This function gets the match value for the specified timer.
1105 //!
1106 //! \return Returns the match value for the timer.
1107 //
1108 //*****************************************************************************
1109 unsigned long long
TimerMatchGet64(unsigned long ulBase)1110 TimerMatchGet64(unsigned long ulBase)
1111 {
1112 unsigned long ulHigh1, ulHigh2, ulLow;
1113
1114 //
1115 // Check the arguments.
1116 //
1117 ASSERT(TimerBaseValid(ulBase));
1118
1119 //
1120 // Read the 64-bit match value. A read of the low 32-bits is performed
1121 // between two reads of the upper 32-bits; if the upper 32-bit values match
1122 // then the 64-bit value is consistent. If they do not match, then the
1123 // read is performed again until they do match (it should never execute the
1124 // loop body more than twice).
1125 //
1126 do
1127 {
1128 ulHigh1 = HWREG(ulBase + TIMER_O_TBMATCHR);
1129 ulLow = HWREG(ulBase + TIMER_O_TAMATCHR);
1130 ulHigh2 = HWREG(ulBase + TIMER_O_TBMATCHR);
1131 }
1132 while(ulHigh1 != ulHigh2);
1133
1134 //
1135 // Return the match value.
1136 //
1137 return(((unsigned long long)ulHigh1 << 32) | (unsigned long long)ulLow);
1138 }
1139
1140 //*****************************************************************************
1141 //
1142 //! Registers an interrupt handler for the timer interrupt.
1143 //!
1144 //! \param ulBase is the base address of the timer module.
1145 //! \param ulTimer specifies the timer(s); must be one of \b TIMER_A,
1146 //! \b TIMER_B, or \b TIMER_BOTH.
1147 //! \param pfnHandler is a pointer to the function to be called when the timer
1148 //! interrupt occurs.
1149 //!
1150 //! This function registers the handler to be called when a timer interrupt
1151 //! occurs. In addition, this function enables the global interrupt in the
1152 //! interrupt controller; specific timer interrupts must be enabled via
1153 //! TimerIntEnable(). It is the interrupt handler's responsibility to clear the
1154 //! interrupt source via TimerIntClear().
1155 //!
1156 //! \sa IntRegister() for important information about registering interrupt
1157 //! handlers.
1158 //!
1159 //! \return None.
1160 //
1161 //*****************************************************************************
1162 void
TimerIntRegister(unsigned long ulBase,unsigned long ulTimer,void (* pfnHandler)(void))1163 TimerIntRegister(unsigned long ulBase, unsigned long ulTimer,
1164 void (*pfnHandler)(void))
1165 {
1166 //
1167 // Check the arguments.
1168 //
1169 ASSERT(TimerBaseValid(ulBase));
1170 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
1171 (ulTimer == TIMER_BOTH));
1172
1173 //
1174 // Get the interrupt number for this timer module.
1175 //
1176 ulBase = TimerIntNumberGet(ulBase);
1177
1178 //
1179 // Register an interrupt handler for timer A if requested.
1180 //
1181 if(ulTimer & TIMER_A)
1182 {
1183 //
1184 // Register the interrupt handler.
1185 //
1186 IntRegister(ulBase, pfnHandler);
1187
1188 //
1189 // Enable the interrupt.
1190 //
1191 IntEnable(ulBase);
1192 }
1193
1194 //
1195 // Register an interrupt handler for timer B if requested.
1196 //
1197 if(ulTimer & TIMER_B)
1198 {
1199 //
1200 // Register the interrupt handler.
1201 //
1202 IntRegister(ulBase + 1, pfnHandler);
1203
1204 //
1205 // Enable the interrupt.
1206 //
1207 IntEnable(ulBase + 1);
1208 }
1209 }
1210
1211 //*****************************************************************************
1212 //
1213 //! Unregisters an interrupt handler for the timer interrupt.
1214 //!
1215 //! \param ulBase is the base address of the timer module.
1216 //! \param ulTimer specifies the timer(s); must be one of \b TIMER_A,
1217 //! \b TIMER_B, or \b TIMER_BOTH.
1218 //!
1219 //! This function unregisters the handler to be called when a timer interrupt
1220 //! occurs. This function also masks off the interrupt in the interrupt
1221 //! controller so that the interrupt handler is no longer called.
1222 //!
1223 //! \sa IntRegister() for important information about registering interrupt
1224 //! handlers.
1225 //!
1226 //! \return None.
1227 //
1228 //*****************************************************************************
1229 void
TimerIntUnregister(unsigned long ulBase,unsigned long ulTimer)1230 TimerIntUnregister(unsigned long ulBase, unsigned long ulTimer)
1231 {
1232 //
1233 // Check the arguments.
1234 //
1235 ASSERT(TimerBaseValid(ulBase));
1236 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
1237 (ulTimer == TIMER_BOTH));
1238
1239 //
1240 // Get the interrupt number for this timer module.
1241 //
1242 ulBase = TimerIntNumberGet(ulBase);
1243
1244 //
1245 // Unregister the interrupt handler for timer A if requested.
1246 //
1247 if(ulTimer & TIMER_A)
1248 {
1249 //
1250 // Disable the interrupt.
1251 //
1252 IntDisable(ulBase);
1253
1254 //
1255 // Unregister the interrupt handler.
1256 //
1257 IntUnregister(ulBase);
1258 }
1259
1260 //
1261 // Unregister the interrupt handler for timer B if requested.
1262 //
1263 if(ulTimer & TIMER_B)
1264 {
1265 //
1266 // Disable the interrupt.
1267 //
1268 IntDisable(ulBase + 1);
1269
1270 //
1271 // Unregister the interrupt handler.
1272 //
1273 IntUnregister(ulBase + 1);
1274 }
1275 }
1276
1277 //*****************************************************************************
1278 //
1279 //! Enables individual timer interrupt sources.
1280 //!
1281 //! \param ulBase is the base address of the timer module.
1282 //! \param ulIntFlags is the bit mask of the interrupt sources to be enabled.
1283 //!
1284 //! This function enables the indicated timer interrupt sources. Only the
1285 //! sources that are enabled can be reflected to the processor interrupt;
1286 //! disabled sources have no effect on the processor.
1287 //!
1288 //! The \e ulIntFlags parameter must be the logical OR of any combination of
1289 //! the following:
1290 //!
1291 //! - \b TIMER_CAPB_EVENT - Capture B event interrupt
1292 //! - \b TIMER_CAPB_MATCH - Capture B match interrupt
1293 //! - \b TIMER_TIMB_TIMEOUT - Timer B timeout interrupt
1294 //! - \b TIMER_RTC_MATCH - RTC interrupt mask
1295 //! - \b TIMER_CAPA_EVENT - Capture A event interrupt
1296 //! - \b TIMER_CAPA_MATCH - Capture A match interrupt
1297 //! - \b TIMER_TIMA_TIMEOUT - Timer A timeout interrupt
1298 //!
1299 //! \return None.
1300 //
1301 //*****************************************************************************
1302 void
TimerIntEnable(unsigned long ulBase,unsigned long ulIntFlags)1303 TimerIntEnable(unsigned long ulBase, unsigned long ulIntFlags)
1304 {
1305 //
1306 // Check the arguments.
1307 //
1308 ASSERT(TimerBaseValid(ulBase));
1309
1310 //
1311 // Enable the specified interrupts.
1312 //
1313 HWREG(ulBase + TIMER_O_IMR) |= ulIntFlags;
1314 }
1315
1316 //*****************************************************************************
1317 //
1318 //! Disables individual timer interrupt sources.
1319 //!
1320 //! \param ulBase is the base address of the timer module.
1321 //! \param ulIntFlags is the bit mask of the interrupt sources to be disabled.
1322 //!
1323 //! This function disables the indicated timer interrupt sources. Only the
1324 //! sources that are enabled can be reflected to the processor interrupt;
1325 //! disabled sources have no effect on the processor.
1326 //!
1327 //! The \e ulIntFlags parameter has the same definition as the \e ulIntFlags
1328 //! parameter to TimerIntEnable().
1329 //!
1330 //! \return None.
1331 //
1332 //*****************************************************************************
1333 void
TimerIntDisable(unsigned long ulBase,unsigned long ulIntFlags)1334 TimerIntDisable(unsigned long ulBase, unsigned long ulIntFlags)
1335 {
1336 //
1337 // Check the arguments.
1338 //
1339 ASSERT(TimerBaseValid(ulBase));
1340
1341 //
1342 // Disable the specified interrupts.
1343 //
1344 HWREG(ulBase + TIMER_O_IMR) &= ~(ulIntFlags);
1345 }
1346
1347 //*****************************************************************************
1348 //
1349 //! Gets the current interrupt status.
1350 //!
1351 //! \param ulBase is the base address of the timer module.
1352 //! \param bMasked is false if the raw interrupt status is required and true if
1353 //! the masked interrupt status is required.
1354 //!
1355 //! This function returns the interrupt status for the timer module. Either
1356 //! the raw interrupt status or the status of interrupts that are allowed to
1357 //! reflect to the processor can be returned.
1358 //!
1359 //! \return The current interrupt status, enumerated as a bit field of
1360 //! values described in TimerIntEnable().
1361 //
1362 //*****************************************************************************
1363 unsigned long
TimerIntStatus(unsigned long ulBase,tBoolean bMasked)1364 TimerIntStatus(unsigned long ulBase, tBoolean bMasked)
1365 {
1366 //
1367 // Check the arguments.
1368 //
1369 ASSERT(TimerBaseValid(ulBase));
1370
1371 //
1372 // Return either the interrupt status or the raw interrupt status as
1373 // requested.
1374 //
1375 return(bMasked ? HWREG(ulBase + TIMER_O_MIS) :
1376 HWREG(ulBase + TIMER_O_RIS));
1377 }
1378
1379 //*****************************************************************************
1380 //
1381 //! Clears timer interrupt sources.
1382 //!
1383 //! \param ulBase is the base address of the timer module.
1384 //! \param ulIntFlags is a bit mask of the interrupt sources to be cleared.
1385 //!
1386 //! The specified timer interrupt sources are cleared, so that they no longer
1387 //! assert. This function must be called in the interrupt handler to keep the
1388 //! interrupt from being triggered again immediately upon exit.
1389 //!
1390 //! The \e ulIntFlags parameter has the same definition as the \e ulIntFlags
1391 //! parameter to TimerIntEnable().
1392 //!
1393 //! \note Because there is a write buffer in the Cortex-M processor, it may
1394 //! take several clock cycles before the interrupt source is actually cleared.
1395 //! Therefore, it is recommended that the interrupt source be cleared early in
1396 //! the interrupt handler (as opposed to the very last action) to avoid
1397 //! returning from the interrupt handler before the interrupt source is
1398 //! actually cleared. Failure to do so may result in the interrupt handler
1399 //! being immediately reentered (because the interrupt controller still sees
1400 //! the interrupt source asserted).
1401 //!
1402 //! \return None.
1403 //
1404 //*****************************************************************************
1405 void
TimerIntClear(unsigned long ulBase,unsigned long ulIntFlags)1406 TimerIntClear(unsigned long ulBase, unsigned long ulIntFlags)
1407 {
1408 //
1409 // Check the arguments.
1410 //
1411 ASSERT(TimerBaseValid(ulBase));
1412
1413 //
1414 // Clear the requested interrupt sources.
1415 //
1416 HWREG(ulBase + TIMER_O_ICR) = ulIntFlags;
1417 }
1418
1419 //*****************************************************************************
1420 //
1421 //! Synchronizes the counters in a set of timers.
1422 //!
1423 //! \param ulBase is the base address of the timer module. This parameter must
1424 //! be the base address of Timer0 (in other words, \b TIMER0_BASE).
1425 //! \param ulTimers is the set of timers to synchronize.
1426 //!
1427 //! This function synchronizes the counters in a specified set of timers.
1428 //! When a timer is running in half-width mode, each half can be included or
1429 //! excluded in the synchronization event. When a timer is running in
1430 //! full-width mode, only the A timer can be synchronized (specifying the B
1431 //! timer has no effect).
1432 //!
1433 //! The \e ulTimers parameter is the logical OR of any of the following
1434 //! defines:
1435 //!
1436 //! - \b TIMER_0A_SYNC
1437 //! - \b TIMER_0B_SYNC
1438 //! - \b TIMER_1A_SYNC
1439 //! - \b TIMER_1B_SYNC
1440 //! - \b TIMER_2A_SYNC
1441 //! - \b TIMER_2B_SYNC
1442 //! - \b TIMER_3A_SYNC
1443 //! - \b TIMER_3B_SYNC
1444 //! - \b TIMER_4A_SYNC
1445 //! - \b TIMER_4B_SYNC
1446 //! - \b TIMER_5A_SYNC
1447 //! - \b TIMER_5B_SYNC
1448 //! - \b WTIMER_0A_SYNC
1449 //! - \b WTIMER_0B_SYNC
1450 //! - \b WTIMER_1A_SYNC
1451 //! - \b WTIMER_1B_SYNC
1452 //! - \b WTIMER_2A_SYNC
1453 //! - \b WTIMER_2B_SYNC
1454 //! - \b WTIMER_3A_SYNC
1455 //! - \b WTIMER_3B_SYNC
1456 //! - \b WTIMER_4A_SYNC
1457 //! - \b WTIMER_4B_SYNC
1458 //! - \b WTIMER_5A_SYNC
1459 //! - \b WTIMER_5B_SYNC
1460 //!
1461 //! \note This functionality is not available on all parts.
1462 //!
1463 //! \return None.
1464 //
1465 //*****************************************************************************
1466 void
TimerSynchronize(unsigned long ulBase,unsigned long ulTimers)1467 TimerSynchronize(unsigned long ulBase, unsigned long ulTimers)
1468 {
1469 //
1470 // Check the arguments.
1471 //
1472 ASSERT(ulBase == TIMER0_BASE);
1473
1474 //
1475 // Synchronize the specified timers.
1476 //
1477 HWREG(ulBase + TIMER_O_SYNC) = ulTimers;
1478 }
1479
1480 //*****************************************************************************
1481 //
1482 // Puts the timer into its reset state.
1483 //
1484 // \param ulBase is the base address of the timer module.
1485 //
1486 // This function disables the specified timer, and all its interrupts are
1487 // disabled, cleared, and unregistered. Then the timer registers are set to
1488 // their reset value.
1489 //
1490 // \return None.
1491 //
1492 //*****************************************************************************
1493 #ifndef DEPRECATED
1494 void
TimerQuiesce(unsigned long ulBase)1495 TimerQuiesce(unsigned long ulBase)
1496 {
1497 //
1498 // Check the arguments.
1499 //
1500 ASSERT(TimerBaseValid(ulBase));
1501
1502 //
1503 // Disable the timer.
1504 //
1505 HWREG(ulBase + TIMER_O_CTL) = TIMER_RV_CTL;
1506
1507 //
1508 // Disable all the timer interrupts.
1509 //
1510 HWREG(ulBase + TIMER_O_IMR) = TIMER_RV_IMR;
1511
1512 //
1513 // Clear all the timer interrupts.
1514 //
1515 HWREG(ulBase + TIMER_O_ICR) = 0xFFFFFFFF;
1516
1517 //
1518 // Unregister the interrupt handler, which also disables interrupts to the
1519 // core.
1520 //
1521 TimerIntUnregister(ulBase, TIMER_BOTH);
1522
1523 //
1524 // Set all the registers to their reset value.
1525 //
1526 HWREG(ulBase + TIMER_O_CFG) = TIMER_RV_CFG;
1527 HWREG(ulBase + TIMER_O_TAMR) = TIMER_RV_TAMR;
1528 HWREG(ulBase + TIMER_O_TBMR) = TIMER_RV_TBMR;
1529 HWREG(ulBase + TIMER_O_RIS) = TIMER_RV_RIS;
1530 HWREG(ulBase + TIMER_O_MIS) = TIMER_RV_MIS;
1531 HWREG(ulBase + TIMER_O_TAILR) = TIMER_RV_TAILR;
1532 HWREG(ulBase + TIMER_O_TBILR) = TIMER_RV_TBILR;
1533 HWREG(ulBase + TIMER_O_TAMATCHR) = TIMER_RV_TAMATCHR;
1534 HWREG(ulBase + TIMER_O_TBMATCHR) = TIMER_RV_TBMATCHR;
1535 HWREG(ulBase + TIMER_O_TAPR) = TIMER_RV_TAPR;
1536 HWREG(ulBase + TIMER_O_TBPR) = TIMER_RV_TBPR;
1537 HWREG(ulBase + TIMER_O_TAPMR) = TIMER_RV_TAPMR;
1538 HWREG(ulBase + TIMER_O_TBPMR) = TIMER_RV_TBPMR;
1539 HWREG(ulBase + TIMER_O_TAR) = TIMER_RV_TAR;
1540 HWREG(ulBase + TIMER_O_TBR) = TIMER_RV_TBR;
1541 }
1542 #endif // DEPRECATED
1543
1544 //*****************************************************************************
1545 //
1546 // Close the Doxygen group.
1547 //! @}
1548 //
1549 //*****************************************************************************
1550