Dual 32-bit Timer with interrupt capability. More...
Macros | |
#define | TIMER32_CMSIS(x) ((Timer32_Type *) x) |
#define | TIMER_OFFSET 0x020 |
#define | TIMER32_0_BASE (uint32_t)TIMER32_1 |
#define | TIMER32_1_BASE (uint32_t)TIMER32_2 |
#define | TIMER32_0_INTERRUPT INT_T32_INT1 |
#define | TIMER32_1_INTERRUPT INT_T32_INT2 |
#define | TIMER32_COMBINED_INTERRUPT INT_T32_INTC |
#define | TIMER32_16BIT 0x00 |
#define | TIMER32_32BIT 0x01 |
#define | TIMER32_PRESCALER_1 0x00 |
#define | TIMER32_PRESCALER_16 0x04 |
#define | TIMER32_PRESCALER_256 0x08 |
#define | TIMER32_FREE_RUN_MODE 0x00 |
#define | TIMER32_PERIODIC_MODE 0x01 |
Functions | |
void | Timer32_initModule (uint32_t timer, uint32_t preScaler, uint32_t resolution, uint32_t mode) |
void | Timer32_setCount (uint32_t timer, uint32_t count) |
void | Timer32_setCountInBackground (uint32_t timer, uint32_t count) |
uint32_t | Timer32_getValue (uint32_t timer) |
void | Timer32_startTimer (uint32_t timer, bool oneShot) |
void | Timer32_haltTimer (uint32_t timer) |
void | Timer32_enableInterrupt (uint32_t timer) |
void | Timer32_disableInterrupt (uint32_t timer) |
void | Timer32_clearInterruptFlag (uint32_t timer) |
uint32_t | Timer32_getInterruptStatus (uint32_t timer) |
void | Timer32_registerInterrupt (uint32_t timerInterrupt, void(*intHandler)(void)) |
void | Timer32_unregisterInterrupt (uint32_t timerInterrupt) |
Dual 32-bit Timer with interrupt capability.
Free Run Mode In free run mode, the timer will run from a value of UINT16_MAX or UINT32_MAX (depending on what resolution is selected).
Periodic Mode In periodic mode, the timer will run to a specified period by the user.
For both periodic and free run modes, the one shot boolean option in the Timer32_startTimer() function. If specified, when the count reaches zero from the specified period the timer will stop and not automatically resume with the next iteration of the count.
Below is a very brief code example showing how to configure the Timer32 as a simple down counter with interrupts enabled:
#define TIMER32_CMSIS | ( | x | ) | ((Timer32_Type *) x) |
#define TIMER_OFFSET 0x020 |
#define TIMER32_0_BASE (uint32_t)TIMER32_1 |
Referenced by Timer32_haltTimer(), and Timer32_startTimer().
#define TIMER32_1_BASE (uint32_t)TIMER32_2 |
Referenced by Timer32_haltTimer(), and Timer32_startTimer().
#define TIMER32_0_INTERRUPT INT_T32_INT1 |
#define TIMER32_1_INTERRUPT INT_T32_INT2 |
#define TIMER32_COMBINED_INTERRUPT INT_T32_INTC |
#define TIMER32_16BIT 0x00 |
Referenced by Timer32_initModule().
#define TIMER32_32BIT 0x01 |
Referenced by Timer32_initModule().
#define TIMER32_PRESCALER_1 0x00 |
Referenced by Timer32_initModule().
#define TIMER32_PRESCALER_16 0x04 |
Referenced by Timer32_initModule().
#define TIMER32_PRESCALER_256 0x08 |
Referenced by Timer32_initModule().
#define TIMER32_FREE_RUN_MODE 0x00 |
Referenced by Timer32_initModule().
#define TIMER32_PERIODIC_MODE 0x01 |
Referenced by Timer32_initModule().
void Timer32_initModule | ( | uint32_t | timer, |
uint32_t | preScaler, | ||
uint32_t | resolution, | ||
uint32_t | mode | ||
) |
Initializes the Timer32 module
timer | is the instance of the Timer32 module. Valid parameters must be one of the following values:
|
preScaler | is the prescaler (or divider) to apply to the clock source given to the Timer32 module. Valid values are
|
resolution | is the bit resolution of the Timer32 module. Valid values are
|
mode | selects between free run and periodic mode. In free run mode, the value of the timer is reset to UINT16_MAX (for 16-bit mode) or UINT32_MAX (for 16-bit mode) when the timer reaches zero. In periodic mode, the timer is reset to the value set by the Timer32_setCount function. Valid values are
|
References ASSERT, TIMER32_16BIT, TIMER32_32BIT, TIMER32_CMSIS, TIMER32_FREE_RUN_MODE, TIMER32_PERIODIC_MODE, TIMER32_PRESCALER_1, TIMER32_PRESCALER_16, and TIMER32_PRESCALER_256.
void Timer32_setCount | ( | uint32_t | timer, |
uint32_t | count | ||
) |
Sets the count of the timer and resets the current value to the value passed. This value is set on the next rising edge of the clock provided to the timer module
timer | is the instance of the Timer32 module. Valid parameters must be one of the following values:
|
count | Value of the timer to set. Note that if the timer is in 16-bit mode and a value is passed in that exceeds UINT16_MAX, the value will be truncated to UINT16_MAX. |
Also note that if the timer is operating in periodic mode, the value passed into this function will represent the new period of the timer (the value which is reloaded into the timer each time it reaches a zero value).
References TIMER32_CMSIS.
void Timer32_setCountInBackground | ( | uint32_t | timer, |
uint32_t | count | ||
) |
Sets the count of the timer without resetting the current value. When the current value of the timer reaches zero, the value passed into this function will be set as the new count value.
timer | is the instance of the Timer32 module. Valid parameters must be one of the following values:
|
count | Value of the timer to set in the background. Note that if the timer is in 16-bit mode and a value is passed in that exceeds UINT16_MAX, the value will be truncated to UINT16_MAX. |
Also note that if the timer is operating in periodic mode, the value passed into this function will represent the new period of the timer (the value which is reloaded into the timer each time it reaches a zero value).
References TIMER32_CMSIS.
uint32_t Timer32_getValue | ( | uint32_t | timer | ) |
Returns the current value of the timer.
timer | is the instance of the Timer32 module. Valid parameters must be one of the following values:
|
References TIMER32_CMSIS.
void Timer32_startTimer | ( | uint32_t | timer, |
bool | oneShot | ||
) |
Starts the timer. The Timer32_initModule function should be called (in conjunction with Timer32_setCount if periodic mode is desired) prior to
timer | is the instance of the Timer32 module. Valid parameters must be one of the following values:
|
oneShot | sets whether the Timer32 module operates in one shot or continuous mode. In one shot mode, the timer will halt when a zero is reached and stay halted until either:
|
A true value will cause the timer to operate in one shot mode while a false value will cause the timer to operate in continuous mode
References ASSERT, TIMER32_0_BASE, TIMER32_1_BASE, and TIMER32_CMSIS.
void Timer32_haltTimer | ( | uint32_t | timer | ) |
Halts the timer. Current count and setting values are preserved.
timer | is the instance of the Timer32 module. Valid parameters must be one of the following values:
|
References ASSERT, TIMER32_0_BASE, TIMER32_1_BASE, and TIMER32_CMSIS.
void Timer32_enableInterrupt | ( | uint32_t | timer | ) |
Enables a Timer32 interrupt source.
timer | is the instance of the Timer32 module. Valid parameters must be one of the following values:
|
Enables the indicated Timer32 interrupt source.
References TIMER32_CMSIS.
void Timer32_disableInterrupt | ( | uint32_t | timer | ) |
Disables a Timer32 interrupt source.
timer | is the instance of the Timer32 module. Valid parameters must be one of the following values:
|
Disables the indicated Timer32 interrupt source.
References TIMER32_CMSIS.
void Timer32_clearInterruptFlag | ( | uint32_t | timer | ) |
Clears Timer32 interrupt source.
timer | is the instance of the Timer32 module. Valid parameters must be one of the following values:
|
The Timer32 interrupt source is cleared, so that it no longer asserts.
References TIMER32_CMSIS.
uint32_t Timer32_getInterruptStatus | ( | uint32_t | timer | ) |
Gets the current Timer32 interrupt status.
timer | is the instance of the Timer32 module. Valid parameters must be one of the following values:
|
This returns the interrupt status for the Timer32 module. A positive value will indicate that an interrupt is pending while a zero value will indicate that no interrupt is pending.
References TIMER32_CMSIS.
void Timer32_registerInterrupt | ( | uint32_t | timerInterrupt, |
void(*)(void) | intHandler | ||
) |
Registers an interrupt handler for Timer32 interrupts.
timerInterrupt | is the specific interrupt to register. For the Timer32 module, there are a total of three different interrupts: one interrupt for each two Timer32 modules, and a "combined" interrupt which is a logical OR of each individual Timer32 interrupt.
|
intHandler | is a pointer to the function to be called when the Timer32 interrupt occurs. |
This function registers the handler to be called when an Timer32 interrupt occurs. This function enables the global interrupt in the interrupt controller; specific Timer32 interrupts must be enabled via Timer32_enableInterrupt(). It is the interrupt handler's responsibility to clear the interrupt source via Timer32_clearInterruptFlag().
References Interrupt_enableInterrupt(), and Interrupt_registerInterrupt().
void Timer32_unregisterInterrupt | ( | uint32_t | timerInterrupt | ) |
Unregisters the interrupt handler for the Timer32 interrupt.
timerInterrupt | is the specific interrupt to register. For the Timer32 module, there are a total of three different interrupts: one interrupt for each two Timer32 modules, and a "combined" interrupt which is a logical OR of each individual Timer32 interrupt.
|
This function unregisters the handler to be called when a Timer32 interrupt occurs. This function also masks off the interrupt in the interrupt controller so that the interrupt handler no longer is called.
References Interrupt_disableInterrupt(), and Interrupt_unregisterInterrupt().