1 //*****************************************************************************
3 // timer.c - Driver for the timer module.
5 // Copyright (c) 2005,2006 Luminary Micro, Inc. All rights reserved.
7 // Software License Agreement
9 // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
10 // exclusively on LMI's Stellaris Family of microcontroller products.
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.
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.
24 // This is part of revision 991 of the Stellaris Driver Library.
26 //*****************************************************************************
28 //*****************************************************************************
30 //! \addtogroup timer_api
33 //*****************************************************************************
35 #include "../hw_ints.h"
36 #include "../hw_memmap.h"
37 #include "../hw_timer.h"
38 #include "../hw_types.h"
40 #include "interrupt.h"
43 //*****************************************************************************
45 //! Enables the timer(s).
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.
51 //! This will enable operation of the timer module. The timer must be
52 //! configured before it is enabled.
56 //*****************************************************************************
57 #if defined(GROUP_enable) || defined(BUILD_ALL) || defined(DOXYGEN)
59 TimerEnable(unsigned long ulBase, unsigned long ulTimer)
62 // Check the arguments.
64 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
65 (ulBase == TIMER2_BASE));
66 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
67 (ulTimer == TIMER_BOTH));
70 // Enable the timer(s) module.
72 HWREG(ulBase + TIMER_O_CTL) |= ulTimer & (TIMER_CTL_TAEN | TIMER_CTL_TBEN);
76 //*****************************************************************************
78 //! Disables the timer(s).
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.
84 //! This will disable operation of the timer module.
88 //*****************************************************************************
89 #if defined(GROUP_disable) || defined(BUILD_ALL) || defined(DOXYGEN)
91 TimerDisable(unsigned long ulBase, unsigned long ulTimer)
94 // Check the arguments.
96 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
97 (ulBase == TIMER2_BASE));
98 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
99 (ulTimer == TIMER_BOTH));
102 // Disable the timer module.
104 HWREG(ulBase + TIMER_O_CTL) &= ~(ulTimer &
105 (TIMER_CTL_TAEN | TIMER_CTL_TBEN));
109 //*****************************************************************************
111 //! Configures the timer(s).
113 //! \param ulBase is the base address of the timer module.
114 //! \param ulConfig is the configuration for the timer.
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:
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
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
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
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.
143 //*****************************************************************************
144 #if defined(GROUP_configure) || defined(BUILD_ALL) || defined(DOXYGEN)
146 TimerConfigure(unsigned long ulBase, unsigned long ulConfig)
149 // Check the arguments.
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))));
170 // Disable the timers.
172 HWREG(ulBase + TIMER_O_CTL) &= ~(TIMER_CTL_TAEN | TIMER_CTL_TBEN);
175 // Set the global timer configuration.
177 HWREG(ulBase + TIMER_O_CFG) = ulConfig >> 24;
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.
183 HWREG(ulBase + TIMER_O_TAMR) = ulConfig & 255;
184 HWREG(ulBase + TIMER_O_TBMR) = (ulConfig >> 8) & 255;
188 //*****************************************************************************
190 //! Controls the output level.
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.
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.
203 //*****************************************************************************
204 #if defined(GROUP_controllevel) || defined(BUILD_ALL) || defined(DOXYGEN)
206 TimerControlLevel(unsigned long ulBase, unsigned long ulTimer,
210 // Check the arguments.
212 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
213 (ulBase == TIMER2_BASE));
214 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
215 (ulTimer == TIMER_BOTH));
218 // Set the output levels as requested.
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)));
227 //*****************************************************************************
229 //! Enables or disables the trigger output.
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.
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.
242 //*****************************************************************************
243 #if defined(GROUP_controltrigger) || defined(BUILD_ALL) || defined(DOXYGEN)
245 TimerControlTrigger(unsigned long ulBase, unsigned long ulTimer,
249 // Check the arguments.
251 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
252 (ulBase == TIMER2_BASE));
253 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
254 (ulTimer == TIMER_BOTH));
257 // Set the trigger output as requested.
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)));
266 //*****************************************************************************
268 //! Controls the event type.
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.
277 //! This function sets the signal edge(s) that will trigger the timer when in
282 //*****************************************************************************
283 #if defined(GROUP_controlevent) || defined(BUILD_ALL) || defined(DOXYGEN)
285 TimerControlEvent(unsigned long ulBase, unsigned long ulTimer,
286 unsigned long ulEvent)
289 // Check the arguments.
291 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
292 (ulBase == TIMER2_BASE));
293 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
294 (ulTimer == TIMER_BOTH));
297 // Set the event type.
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);
306 //*****************************************************************************
308 //! Controls the stall handling.
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.
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
322 //*****************************************************************************
323 #if defined(GROUP_controlstall) || defined(BUILD_ALL) || defined(DOXYGEN)
325 TimerControlStall(unsigned long ulBase, unsigned long ulTimer,
329 // Check the arguments.
331 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
332 (ulBase == TIMER2_BASE));
333 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
334 (ulTimer == TIMER_BOTH));
337 // Set the stall mode.
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)));
346 //*****************************************************************************
348 //! Enable RTC counting.
350 //! \param ulBase is the base address of the timer module.
352 //! This function causes the timer to start counting when in RTC mode. If not
353 //! configured for RTC mode, this will do nothing.
357 //*****************************************************************************
358 #if defined(GROUP_rtcenable) || defined(BUILD_ALL) || defined(DOXYGEN)
360 TimerRTCEnable(unsigned long ulBase)
363 // Check the arguments.
365 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
366 (ulBase == TIMER2_BASE));
369 // Enable RTC counting.
371 HWREG(ulBase + TIMER_O_CTL) |= TIMER_CTL_RTCEN;
375 //*****************************************************************************
377 //! Disable RTC counting.
379 //! \param ulBase is the base address of the timer module.
381 //! This function causes the timer to stop counting when in RTC mode.
385 //*****************************************************************************
386 #if defined(GROUP_rtcdisable) || defined(BUILD_ALL) || defined(DOXYGEN)
388 TimerRTCDisable(unsigned long ulBase)
391 // Check the arguments.
393 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
394 (ulBase == TIMER2_BASE));
397 // Disable RTC counting.
399 HWREG(ulBase + TIMER_O_CTL) &= ~(TIMER_CTL_RTCEN);
403 //*****************************************************************************
405 //! Set the timer prescale value.
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,
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.
419 //*****************************************************************************
420 #if defined(GROUP_prescaleset) || defined(BUILD_ALL) || defined(DOXYGEN)
422 TimerPrescaleSet(unsigned long ulBase, unsigned long ulTimer,
423 unsigned long ulValue)
426 // Check the arguments.
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);
435 // Set the timer A prescaler if requested.
437 if(ulTimer & TIMER_A)
439 HWREG(ulBase + TIMER_O_TAPR) = ulValue;
443 // Set the timer B prescaler if requested.
445 if(ulTimer & TIMER_B)
447 HWREG(ulBase + TIMER_O_TBPR) = ulValue;
452 //*****************************************************************************
454 //! Get the timer prescale value.
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
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.
464 //! \return The value of the timer prescaler.
466 //*****************************************************************************
467 #if defined(GROUP_prescaleget) || defined(BUILD_ALL) || defined(DOXYGEN)
469 TimerPrescaleGet(unsigned long ulBase, unsigned long ulTimer)
472 // Check the arguments.
474 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
475 (ulBase == TIMER2_BASE));
476 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
477 (ulTimer == TIMER_BOTH));
480 // Return the appropriate prescale value.
482 return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAPR) :
483 HWREG(ulBase + TIMER_O_TBPR));
487 //*****************************************************************************
489 //! Set the timer prescale match value.
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
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.
503 //*****************************************************************************
504 #if defined(GROUP_prescalematchset) || defined(BUILD_ALL) || defined(DOXYGEN)
506 TimerPrescaleMatchSet(unsigned long ulBase, unsigned long ulTimer,
507 unsigned long ulValue)
510 // Check the arguments.
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);
519 // Set the timer A prescale match if requested.
521 if(ulTimer & TIMER_A)
523 HWREG(ulBase + TIMER_O_TAPMR) = ulValue;
527 // Set the timer B prescale match if requested.
529 if(ulTimer & TIMER_B)
531 HWREG(ulBase + TIMER_O_TBPMR) = ulValue;
536 //*****************************************************************************
538 //! Get the timer prescale match value.
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
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.
548 //! \return The value of the timer prescale match.
550 //*****************************************************************************
551 #if defined(GROUP_prescalematchget) || defined(BUILD_ALL) || defined(DOXYGEN)
553 TimerPrescaleMatchGet(unsigned long ulBase, unsigned long ulTimer)
556 // Check the arguments.
558 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
559 (ulBase == TIMER2_BASE));
560 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
561 (ulTimer == TIMER_BOTH));
564 // Return the appropriate prescale match value.
566 return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAPMR) :
567 HWREG(ulBase + TIMER_O_TBPMR));
571 //*****************************************************************************
573 //! Sets the timer load value.
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.
581 //! This function sets the timer load value; if the timer is running then the
582 //! value will be immediately loaded into the timer.
586 //*****************************************************************************
587 #if defined(GROUP_loadset) || defined(BUILD_ALL) || defined(DOXYGEN)
589 TimerLoadSet(unsigned long ulBase, unsigned long ulTimer,
590 unsigned long ulValue)
593 // Check the arguments.
595 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
596 (ulBase == TIMER2_BASE));
597 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
598 (ulTimer == TIMER_BOTH));
601 // Set the timer A load value if requested.
603 if(ulTimer & TIMER_A)
605 HWREG(ulBase + TIMER_O_TAILR) = ulValue;
609 // Set the timer B load value if requested.
611 if(ulTimer & TIMER_B)
613 HWREG(ulBase + TIMER_O_TBILR) = ulValue;
618 //*****************************************************************************
620 //! Gets the timer load value.
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.
627 //! This function gets the currently programmed interval load value for the
630 //! \return Returns the load value for the timer.
632 //*****************************************************************************
633 #if defined(GROUP_loadget) || defined(BUILD_ALL) || defined(DOXYGEN)
635 TimerLoadGet(unsigned long ulBase, unsigned long ulTimer)
638 // Check the arguments.
640 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
641 (ulBase == TIMER2_BASE));
642 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B));
645 // Return the appropriate load value.
647 return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAILR) :
648 HWREG(ulBase + TIMER_O_TBILR));
652 //*****************************************************************************
654 //! Gets the current timer value.
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.
661 //! This function reads the current value of the specified timer.
663 //! \return Returns the current value of the timer.
665 //*****************************************************************************
666 #if defined(GROUP_valueget) || defined(BUILD_ALL) || defined(DOXYGEN)
668 TimerValueGet(unsigned long ulBase, unsigned long ulTimer)
671 // Check the arguments.
673 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
674 (ulBase == TIMER2_BASE));
675 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B));
678 // Return the appropriate timer value.
680 return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAR) :
681 HWREG(ulBase + TIMER_O_TBR));
685 //*****************************************************************************
687 //! Sets the timer match value.
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.
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.
701 //*****************************************************************************
702 #if defined(GROUP_matchset) || defined(BUILD_ALL) || defined(DOXYGEN)
704 TimerMatchSet(unsigned long ulBase, unsigned long ulTimer,
705 unsigned long ulValue)
708 // Check the arguments.
710 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
711 (ulBase == TIMER2_BASE));
712 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
713 (ulTimer == TIMER_BOTH));
716 // Set the timer A match value if requested.
718 if(ulTimer & TIMER_A)
720 HWREG(ulBase + TIMER_O_TAMATCHR) = ulValue;
724 // Set the timer B match value if requested.
726 if(ulTimer & TIMER_B)
728 HWREG(ulBase + TIMER_O_TBMATCHR) = ulValue;
733 //*****************************************************************************
735 //! Gets the timer match value.
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.
742 //! This function gets the match value for the specified timer.
744 //! \return Returns the match value for the timer.
746 //*****************************************************************************
747 #if defined(GROUP_matchget) || defined(BUILD_ALL) || defined(DOXYGEN)
749 TimerMatchGet(unsigned long ulBase, unsigned long ulTimer)
752 // Check the arguments.
754 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
755 (ulBase == TIMER2_BASE));
756 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B));
759 // Return the appropriate match value.
761 return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAMATCHR) :
762 HWREG(ulBase + TIMER_O_TBMATCHR));
766 //*****************************************************************************
768 //! Registers an interrupt handler for the timer interrupt.
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.
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().
781 //! \sa IntRegister() for important information about registering interrupt
786 //*****************************************************************************
787 #if defined(GROUP_intregister) || defined(BUILD_ALL) || defined(DOXYGEN)
789 TimerIntRegister(unsigned long ulBase, unsigned long ulTimer,
790 void (*pfnHandler)(void))
793 // Check the arguments.
795 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
796 (ulBase == TIMER2_BASE));
797 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
798 (ulTimer == TIMER_BOTH));
801 // Get the interrupt number for this timer module.
803 ulBase = ((ulBase == TIMER0_BASE) ? INT_TIMER0A :
804 ((ulBase == TIMER1_BASE) ? INT_TIMER1A : INT_TIMER2A));
807 // Register an interrupt handler for timer A if requested.
809 if(ulTimer & TIMER_A)
812 // Register the interrupt handler.
814 IntRegister(ulBase, pfnHandler);
817 // Enable the interrupt.
823 // Register an interrupt handler for timer B if requested.
825 if(ulTimer & TIMER_B)
828 // Register the interrupt handler.
830 IntRegister(ulBase + 1, pfnHandler);
833 // Enable the interrupt.
835 IntEnable(ulBase + 1);
840 //*****************************************************************************
842 //! Unregisters an interrupt handler for the timer interrupt.
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.
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.
852 //! \sa IntRegister() for important information about registering interrupt
857 //*****************************************************************************
858 #if defined(GROUP_intunregister) || defined(BUILD_ALL) || defined(DOXYGEN)
860 TimerIntUnregister(unsigned long ulBase, unsigned long ulTimer)
863 // Check the arguments.
865 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
866 (ulBase == TIMER2_BASE));
867 ASSERT((ulTimer == TIMER_A) || (ulTimer == TIMER_B) ||
868 (ulTimer == TIMER_BOTH));
871 // Get the interrupt number for this timer module.
873 ulBase = ((ulBase == TIMER0_BASE) ? INT_TIMER0A :
874 ((ulBase == TIMER1_BASE) ? INT_TIMER1A : INT_TIMER2A));
877 // Unregister the interrupt handler for timer A if requested.
879 if(ulTimer & TIMER_A)
882 // Disable the interrupt.
887 // Unregister the interrupt handler.
889 IntUnregister(ulBase);
893 // Unregister the interrupt handler for timer B if requested.
895 if(ulTimer & TIMER_B)
898 // Disable the interrupt.
900 IntDisable(ulBase + 1);
903 // Unregister the interrupt handler.
905 IntUnregister(ulBase + 1);
910 //*****************************************************************************
912 //! Enables individual timer interrupt sources.
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.
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.
921 //! The parameter \e ulIntFlags must be the logical OR of any combination of
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
934 //*****************************************************************************
935 #if defined(GROUP_intenable) || defined(BUILD_ALL) || defined(DOXYGEN)
937 TimerIntEnable(unsigned long ulBase, unsigned long ulIntFlags)
940 // Check the arguments.
942 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
943 (ulBase == TIMER2_BASE));
946 // Enable the specified interrupts.
948 HWREG(ulBase + TIMER_O_IMR) |= ulIntFlags;
952 //*****************************************************************************
954 //! Disables individual timer interrupt sources.
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.
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.
963 //! The parameter \e ulIntFlags has the same definition as the \e ulIntFlags
964 //! parameter to TimerIntEnable().
968 //*****************************************************************************
969 #if defined(GROUP_intdisable) || defined(BUILD_ALL) || defined(DOXYGEN)
971 TimerIntDisable(unsigned long ulBase, unsigned long ulIntFlags)
974 // Check the arguments.
976 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
977 (ulBase == TIMER2_BASE));
980 // Disable the specified interrupts.
982 HWREG(ulBase + TIMER_O_IMR) &= ~(ulIntFlags);
986 //*****************************************************************************
988 //! Gets the current interrupt status.
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.
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.
998 //! \return The current interrupt status, enumerated as a bit field of
999 //! values described in TimerIntEnable().
1001 //*****************************************************************************
1002 #if defined(GROUP_intstatus) || defined(BUILD_ALL) || defined(DOXYGEN)
1004 TimerIntStatus(unsigned long ulBase, tBoolean bMasked)
1007 // Check the arguments.
1009 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
1010 (ulBase == TIMER2_BASE));
1013 // Return either the interrupt status or the raw interrupt status as
1016 return(bMasked ? HWREG(ulBase + TIMER_O_MIS) :
1017 HWREG(ulBase + TIMER_O_RIS));
1021 //*****************************************************************************
1023 //! Clears timer interrupt sources.
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.
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.
1032 //! The parameter \e ulIntFlags has the same definition as the \e ulIntFlags
1033 //! parameter to TimerIntEnable().
1037 //*****************************************************************************
1038 #if defined(GROUP_intclear) || defined(BUILD_ALL) || defined(DOXYGEN)
1040 TimerIntClear(unsigned long ulBase, unsigned long ulIntFlags)
1043 // Check the arguments.
1045 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
1046 (ulBase == TIMER2_BASE));
1049 // Clear the requested interrupt sources.
1051 HWREG(ulBase + TIMER_O_ICR) = ulIntFlags;
1055 //*****************************************************************************
1057 //! Puts the timer into its reset state.
1059 //! \param ulBase is the base address of the timer module.
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
1067 //*****************************************************************************
1068 #if defined(GROUP_quiesce) || defined(BUILD_ALL) || defined(DOXYGEN)
1070 TimerQuiesce(unsigned long ulBase)
1073 // Check the arguments.
1075 ASSERT((ulBase == TIMER0_BASE) || (ulBase == TIMER1_BASE) ||
1076 (ulBase == TIMER2_BASE));
1079 // Disable the timer.
1081 HWREG(ulBase + TIMER_O_CTL) = TIMER_RV_CTL;
1084 // Disable all the timer interrupts.
1086 HWREG(ulBase + TIMER_O_IMR) = TIMER_RV_IMR;
1089 // Clear all the timer interrupts.
1091 HWREG(ulBase + TIMER_O_ICR) = 0xFFFFFFFF;
1094 // Unregister the interrupt handler. This also disables interrupts to the
1097 TimerIntUnregister(ulBase, TIMER_BOTH);
1100 // Set all the registers to their reset value.
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;
1120 //*****************************************************************************
1122 // Close the Doxygen group.
1125 //*****************************************************************************