Functions | |
static void | TimerEnable (uint32_t ui32Base, uint32_t ui32Timer) |
Enables the timer(s). More... | |
static void | TimerDisable (uint32_t ui32Base, uint32_t ui32Timer) |
Disables the timer(s). More... | |
void | TimerConfigure (uint32_t ui32Base, uint32_t ui32Config) |
Configures the timer(s). More... | |
void | TimerLevelControl (uint32_t ui32Base, uint32_t ui32Timer, bool bInvert) |
Controls the output level. More... | |
static void | TimerEventControl (uint32_t ui32Base, uint32_t ui32Timer, uint32_t ui32Event) |
Controls the event type. More... | |
void | TimerStallControl (uint32_t ui32Base, uint32_t ui32Timer, bool bStall) |
Controls the stall handling. More... | |
void | TimerWaitOnTriggerControl (uint32_t ui32Base, uint32_t ui32Timer, bool bWait) |
Controls the wait on trigger handling. More... | |
static void | TimerPrescaleSet (uint32_t ui32Base, uint32_t ui32Timer, uint32_t ui32Value) |
Set the timer prescale value. More... | |
static uint32_t | TimerPrescaleGet (uint32_t ui32Base, uint32_t ui32Timer) |
Get the timer prescale value. More... | |
static void | TimerPrescaleMatchSet (uint32_t ui32Base, uint32_t ui32Timer, uint32_t ui32Value) |
Set the timer prescale match value. More... | |
static uint32_t | TimerPrescaleMatchGet (uint32_t ui32Base, uint32_t ui32Timer) |
Get the timer prescale match value. More... | |
static void | TimerLoadSet (uint32_t ui32Base, uint32_t ui32Timer, uint32_t ui32Value) |
Sets the timer load value. More... | |
static uint32_t | TimerLoadGet (uint32_t ui32Base, uint32_t ui32Timer) |
Gets the timer load value. More... | |
static uint32_t | TimerValueGet (uint32_t ui32Base, uint32_t ui32Timer) |
Gets the current timer value. More... | |
static void | TimerMatchSet (uint32_t ui32Base, uint32_t ui32Timer, uint32_t ui32Value) |
Sets the timer match value. More... | |
static uint32_t | TimerMatchGet (uint32_t ui32Base, uint32_t ui32Timer) |
Gets the timer match value. More... | |
void | TimerIntRegister (uint32_t ui32Base, uint32_t ui32Timer, void(*pfnHandler)(void)) |
Registers an interrupt handler for the timer interrupt in the dynamic interrupt table. More... | |
void | TimerIntUnregister (uint32_t ui32Base, uint32_t ui32Timer) |
Unregisters an interrupt handler for the timer interrupt in the dynamic interrupt table. More... | |
static void | TimerIntEnable (uint32_t ui32Base, uint32_t ui32IntFlags) |
Enables individual timer interrupt sources. More... | |
static void | TimerIntDisable (uint32_t ui32Base, uint32_t ui32IntFlags) |
Disables individual timer interrupt sources. More... | |
static uint32_t | TimerIntStatus (uint32_t ui32Base, bool bMasked) |
Gets the current interrupt status. More... | |
static void | TimerIntClear (uint32_t ui32Base, uint32_t ui32IntFlags) |
Clears timer interrupt sources. More... | |
static void | TimerSynchronize (uint32_t ui32Base, uint32_t ui32Timers) |
Synchronizes the counters in a set of timers. More... | |
static void | TimerCcpCombineEnable (uint32_t ui32Base) |
Enables AND'ing of the CCP outputs from Timer A and Timer B. More... | |
static void | TimerCcpCombineDisable (uint32_t ui32Base) |
Disables AND'ing of the CCP outputs from Timer A and Timer B. More... | |
void | TimerMatchUpdateMode (uint32_t ui32Base, uint32_t ui32Timer, uint32_t ui32Mode) |
Sets the Match Register Update mode. More... | |
void | TimerIntervalLoadMode (uint32_t ui32Base, uint32_t ui32Timer, uint32_t ui32Mode) |
Sets the Interval Load mode. More... | |
The timer API provides a set of functions for using the general-purpose timer module.
The timer module contains four timer blocks with the following functional options:
Each timer block provides two half-width timers/counters that can be configured to operate independently as timers or event counters or to operate as a combined full-width timer. The timers provide 16-bit half-width timers and a 32-bit full-width timer. For the purposes of this API, the two half-width timers provided by a timer block are referred to as TimerA and TimerB, and the full-width timer is referred to as TimerA.
When in half-width mode, the timer can also be configured for event capture or as a pulse width modulation (PWM) generator. When configured for event capture, the timer acts as a counter. It can be configured to count either the time between events or the events themselves. The type of event being counted can be configured as a positive edge, a negative edge, or both edges. When a timer is configured as a PWM generator, the input signal used to capture events becomes an output signal, and the timer drives an edge-aligned pulse onto that signal.
Control is also provided over interrupt sources and events. Interrupts can be generated to indicate that an event has been captured, or that a certain number of events have been captured. Interrupts can also be generated when the timer has counted down to 0 or when the timer matches a certain value.
Timer configuration is handled by TimerConfigure(), which performs the high level setup of the timer module; that is, it is used to set up full- or half-width modes, and to select between PWM, capture, and timer operations.
The API functions can be grouped like this:
Functions to perform timer control:
Functions to manage timer content:
Functions to manage the interrupt handler for the timer interrupt:
The individual interrupt sources within the timer module are managed with:
|
inlinestatic |
Disables AND'ing of the CCP outputs from Timer A and Timer B.
ui32Base | is the base address of the timer module. |
|
inlinestatic |
Enables AND'ing of the CCP outputs from Timer A and Timer B.
ui32Base | is the base address of the timer module. |
void TimerConfigure | ( | uint32_t | ui32Base, |
uint32_t | ui32Config | ||
) |
Configures the timer(s).
This function configures the operating mode of the timer(s). The timer module is disabled before being configured and is left in the disabled state.
The timers are comprised of two 16-bit timers that can operate independently or be concatenated to form a 32-bit timer.
When configuring for full-width timer ui32Config
is set as one of the following values:
When configuring for a pair of half-width timers, each timer is separately configured. The timers are configured by setting ui32Config
to the bitwise OR of one of each of the following three:
ui32Base | is the base address of the timer module. |
ui32Config | is the configuration for the timer. |
Referenced by TimerDisable().
|
inlinestatic |
Disables the timer(s).
This function disables operation of the timer module.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer(s) to disable. Must be one of: |
|
inlinestatic |
Enables the timer(s).
This function enables operation of the timer module. The timer must be configured before it is enabled.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer(s) to enable. Must be one of: |
|
inlinestatic |
Controls the event type.
This function configures the signal edge(s) that triggers the timer when in capture mode.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer(s) to be adjusted; must be one of: |
ui32Event | specifies the type of event; must be one of: |
|
inlinestatic |
Clears timer interrupt sources.
The specified timer interrupt sources are cleared, so that they no longer assert. This function must be called in the interrupt handler to keep the interrupt from being triggered again immediately upon exit.
ui32Base | is the base address of the timer module. |
ui32IntFlags | is a bit mask of the interrupt sources to be cleared. The parameter must be the bitwise OR of any combination of the following:
|
|
inlinestatic |
Disables individual timer interrupt sources.
This function disables the indicated timer interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt; disabled sources have no effect on the processor.
ui32Base | is the base address of the timer module. |
ui32IntFlags | is the bit mask of the interrupt sources to be disabled. The parameter must be the bitwise OR of any combination of the following:
|
|
inlinestatic |
Enables individual timer interrupt sources.
This function enables the indicated timer interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt; disabled sources have no effect on the processor.
ui32Base | is the base address of the timer module. |
ui32IntFlags | is the bit mask of the interrupt sources to be enabled. The parameter must be the bitwise OR of any combination of the following:
|
void TimerIntervalLoadMode | ( | uint32_t | ui32Base, |
uint32_t | ui32Timer, | ||
uint32_t | ui32Mode | ||
) |
Sets the Interval Load mode.
This function controls when the Timer Register and Prescale Snap-shot (if used) are updated.
Timer Register (TAR/TBR) is updated when Interval Load Register (TAILR/TBILR) is written and the Prescale Snap-shot (TAPS/TBPS) is updated when Prescale Register (TAPR/TBPR) is written depending on the mode of operation.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer(s) to configure; must be one of: |
ui32Mode | sets the mode:
|
Referenced by TimerCcpCombineDisable().
void TimerIntRegister | ( | uint32_t | ui32Base, |
uint32_t | ui32Timer, | ||
void(*)(void) | pfnHandler | ||
) |
Registers an interrupt handler for the timer interrupt in the dynamic interrupt table.
This function registers a function as the interrupt handler for a specific interrupt and enables the corresponding interrupt in the interrupt controller.
Specific timer interrupts must be enabled via TimerIntEnable(). It is the interrupt handler's responsibility to clear the interrupt source via TimerIntClear().
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer(s); must be one of: |
pfnHandler | is a pointer to the function to be called when the timer interrupt occurs. |
Referenced by TimerMatchGet().
|
inlinestatic |
Gets the current interrupt status.
This function returns the interrupt status for the timer module. Either the raw interrupt status or the status of interrupts that are allowed to reflect to the processor can be returned.
ui32Base | is the base address of the timer module. |
bMasked | selects either raw or masked interrupt status:
|
void TimerIntUnregister | ( | uint32_t | ui32Base, |
uint32_t | ui32Timer | ||
) |
Unregisters an interrupt handler for the timer interrupt in the dynamic interrupt table.
This function unregisters the handler to be called when a timer interrupt occurs. This function also masks off the interrupt in the interrupt controller so that the interrupt handler is no longer called.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer(s); must be one of: |
Referenced by TimerMatchGet().
void TimerLevelControl | ( | uint32_t | ui32Base, |
uint32_t | ui32Timer, | ||
bool | bInvert | ||
) |
Controls the output level.
This function configures the PWM output level for the specified timer.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer(s) to adjust. Must be one of: |
bInvert | specifies the output level.
|
Referenced by TimerDisable().
|
inlinestatic |
Gets the timer load value.
This function gets the currently programmed interval load value for the specified timer.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer; must be one of: |
|
inlinestatic |
Sets the timer load value.
This function configures the timer load value; if the timer is running then the value is immediately loaded into the timer.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer(s) to adjust; must be one of: |
ui32Value | is the load value. |
|
inlinestatic |
Gets the timer match value.
This function gets the match value for the specified timer.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer; must be one of: |
|
inlinestatic |
Sets the timer match value.
This function configures the match value for a timer. This value is used in capture count mode to determine when to interrupt the processor and in PWM mode to determine the duty cycle of the output signal. Match interrupts can also be generated in periodic and one-shot modes when the value of the counter matches this register.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer(s) to adjust; must be one of: |
ui32Value | is the match value. |
void TimerMatchUpdateMode | ( | uint32_t | ui32Base, |
uint32_t | ui32Timer, | ||
uint32_t | ui32Mode | ||
) |
Sets the Match Register Update mode.
This function controls when the Match Register value and Prescale Register value are applied after writing these registers while a timer is enabled.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer(s) to configure; must be one of: |
ui32Mode | sets the mode:
|
Referenced by TimerCcpCombineDisable().
|
inlinestatic |
Get the timer prescale value.
This function gets the value of the timer clock prescaler. The prescaler is only operational when in half-width mode and is used to extend the range of the half-width timer modes.
When in one-shot or periodic down count modes, ui32Value defines the prescaler for the timer counter. When acting as a true prescaler, the prescaler counts down to 0 before the value in timer registers are incremented.
In all other individual/split modes, ui32Value is a linear extension of the upper range of the timer counter, holding bits 23:16 in the 16-bit modes of the 16/32-bit timer.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer; must be one of: |
|
inlinestatic |
Get the timer prescale match value.
This function gets the value of the input clock prescaler match value. When in a half-width mode that uses the counter match and prescaler, the prescale match effectively extends the range of the match. The prescaler provides the least significant bits when counting down in periodic and one-shot modes; in all other modes, the prescaler provides the most significant bits.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer; must be one of: |
|
inlinestatic |
Set the timer prescale match value.
This function configures the value of the input clock prescaler match value. When in a half-width mode that uses the counter match and the prescaler, the prescale match effectively extends the range of the match. The prescaler provides the least significant bits when counting down in periodic and one-shot modes; in all other modes, the prescaler provides the most significant bits.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer(s) to adjust; must be one of: |
ui32Value | is the timer prescale match value which must be between 0 and 255 (both included). |
|
inlinestatic |
Set the timer prescale value.
This function configures the value of the timer clock prescaler. The prescaler is only operational when in half-width mode and is used to extend the range of the half-width timer modes.
When in one-shot or periodic down count modes, ui32Value defines the prescaler for the timer counter. When acting as a true prescaler, the prescaler counts down to 0 before the value in timer registers are incremented.
In all other individual/split modes, ui32Value is a linear extension of the upper range of the timer counter, holding bits 23:16 in the 16-bit modes of the 16/32-bit timer.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer(s) to adjust; must be one of: |
ui32Value | is the timer prescale value which must be between 0 and 255 (both included).
|
void TimerStallControl | ( | uint32_t | ui32Base, |
uint32_t | ui32Timer, | ||
bool | bStall | ||
) |
Controls the stall handling.
This function controls the stall response for the specified timer. If the bStall parameter is true, then the timer stops counting if the processor enters debug mode; otherwise the timer keeps running while in debug mode.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer(s) to be adjusted; must be one of: |
bStall | specifies the response to a stall signal.
|
Referenced by TimerEventControl().
|
inlinestatic |
Synchronizes the counters in a set of timers.
This function synchronizes the counters in a specified set of timers. When a timer is running in half-width mode, each half can be included or excluded in the synchronization event. When a timer is running in full-width mode, only the A timer can be synchronized (specifying the B timer has no effect).
ui32Base | is the base address of the timer module. This parameter must be the base address of Timer0 (in other words, GPT0_BASE). |
ui32Timers | is the set of timers to synchronize. The parameter is the bitwise OR of any of the following: |
|
inlinestatic |
Gets the current timer value.
This function reads the current value of the specified timer.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer; must be one of: |
void TimerWaitOnTriggerControl | ( | uint32_t | ui32Base, |
uint32_t | ui32Timer, | ||
bool | bWait | ||
) |
Controls the wait on trigger handling.
This function controls whether or not a timer waits for a trigger input to start counting. When enabled, the previous timer in the trigger chain must count to its timeout in order for this timer to start counting. Refer to the part's data sheet for a description of the trigger chain.
ui32Base | is the base address of the timer module. |
ui32Timer | specifies the timer(s) to be adjusted; must be one of: |
bWait | specifies if the timer should wait for a trigger input.
|
Referenced by TimerEventControl().
#define TIMER_0A_SYNC 0x00000001 |
#define TIMER_0B_SYNC 0x00000002 |
#define TIMER_1A_SYNC 0x00000004 |
#define TIMER_1B_SYNC 0x00000008 |
#define TIMER_2A_SYNC 0x00000010 |
#define TIMER_2B_SYNC 0x00000020 |
#define TIMER_3A_SYNC 0x00000040 |
#define TIMER_3B_SYNC 0x00000080 |
#define TIMER_A 0x000000FF |
Referenced by TimerDisable(), TimerEnable(), TimerEventControl(), TimerIntervalLoadMode(), TimerIntRegister(), TimerIntUnregister(), TimerLevelControl(), TimerLoadGet(), TimerLoadSet(), TimerMatchGet(), TimerMatchSet(), TimerMatchUpdateMode(), TimerPrescaleGet(), TimerPrescaleMatchGet(), TimerPrescaleMatchSet(), TimerPrescaleSet(), TimerStallControl(), TimerValueGet(), and TimerWaitOnTriggerControl().
#define TIMER_B 0x0000FF00 |
Referenced by TimerDisable(), TimerEnable(), TimerEventControl(), TimerIntervalLoadMode(), TimerIntRegister(), TimerIntUnregister(), TimerLevelControl(), TimerLoadGet(), TimerLoadSet(), TimerMatchGet(), TimerMatchSet(), TimerMatchUpdateMode(), TimerPrescaleGet(), TimerPrescaleMatchGet(), TimerPrescaleMatchSet(), TimerPrescaleSet(), TimerStallControl(), TimerValueGet(), and TimerWaitOnTriggerControl().
#define TIMER_BOTH 0x0000FFFF |
Referenced by TimerDisable(), TimerEnable(), TimerEventControl(), TimerIntervalLoadMode(), TimerIntRegister(), TimerIntUnregister(), TimerLevelControl(), TimerLoadSet(), TimerMatchSet(), TimerMatchUpdateMode(), TimerPrescaleGet(), TimerPrescaleMatchSet(), TimerPrescaleSet(), TimerStallControl(), and TimerWaitOnTriggerControl().
#define TIMER_CAPA_EVENT 0x00000004 |
#define TIMER_CAPA_MATCH 0x00000002 |
#define TIMER_CAPB_EVENT 0x00000400 |
#define TIMER_CAPB_MATCH 0x00000200 |
#define TIMER_CFG_A_CAP_COUNT 0x00000003 |
Referenced by TimerConfigure().
#define TIMER_CFG_A_CAP_COUNT_UP 0x00000013 |
Referenced by TimerConfigure().
#define TIMER_CFG_A_CAP_TIME 0x00000007 |
Referenced by TimerConfigure().
#define TIMER_CFG_A_CAP_TIME_UP 0x00000017 |
Referenced by TimerConfigure().
#define TIMER_CFG_A_ONE_SHOT 0x00000021 |
Referenced by TimerConfigure().
#define TIMER_CFG_A_ONE_SHOT_UP 0x00000031 |
Referenced by TimerConfigure().
#define TIMER_CFG_A_PERIODIC 0x00000022 |
Referenced by TimerConfigure().
#define TIMER_CFG_A_PERIODIC_UP 0x00000032 |
Referenced by TimerConfigure().
#define TIMER_CFG_A_PWM 0x0000000A |
Referenced by TimerConfigure().
#define TIMER_CFG_B_CAP_COUNT 0x00000300 |
Referenced by TimerConfigure().
#define TIMER_CFG_B_CAP_COUNT_UP 0x00001300 |
Referenced by TimerConfigure().
#define TIMER_CFG_B_CAP_TIME 0x00000700 |
Referenced by TimerConfigure().
#define TIMER_CFG_B_CAP_TIME_UP 0x00001700 |
Referenced by TimerConfigure().
#define TIMER_CFG_B_ONE_SHOT 0x00002100 |
Referenced by TimerConfigure().
#define TIMER_CFG_B_ONE_SHOT_UP 0x00003100 |
Referenced by TimerConfigure().
#define TIMER_CFG_B_PERIODIC 0x00002200 |
Referenced by TimerConfigure().
#define TIMER_CFG_B_PERIODIC_UP 0x00003200 |
Referenced by TimerConfigure().
#define TIMER_CFG_B_PWM 0x00000A00 |
Referenced by TimerConfigure().
#define TIMER_CFG_ONE_SHOT 0x00000021 |
Referenced by TimerConfigure().
#define TIMER_CFG_ONE_SHOT_UP 0x00000031 |
Referenced by TimerConfigure().
#define TIMER_CFG_PERIODIC 0x00000022 |
Referenced by TimerConfigure().
#define TIMER_CFG_PERIODIC_UP 0x00000032 |
Referenced by TimerConfigure().
#define TIMER_CFG_SPLIT_PAIR 0x04000000 |
Referenced by TimerConfigure().
#define TIMER_EVENT_BOTH_EDGES 0x00000C0C |
#define TIMER_EVENT_NEG_EDGE 0x00000404 |
#define TIMER_EVENT_POS_EDGE 0x00000000 |
#define TIMER_INTERVALLOAD_NEXTCYCLE 0x00000000 |
Referenced by TimerIntervalLoadMode().
#define TIMER_INTERVALLOAD_TIMEOUT 0x00000001 |
Referenced by TimerIntervalLoadMode().
#define TIMER_MATCHUPDATE_NEXTCYCLE 0x00000000 |
Referenced by TimerMatchUpdateMode().
#define TIMER_MATCHUPDATE_TIMEOUT 0x00000001 |
Referenced by TimerMatchUpdateMode().
#define TIMER_TIMA_DMA 0x00000020 |
#define TIMER_TIMA_MATCH 0x00000010 |
#define TIMER_TIMA_TIMEOUT 0x00000001 |
#define TIMER_TIMB_DMA 0x00002000 |
#define TIMER_TIMB_MATCH 0x00000800 |
#define TIMER_TIMB_TIMEOUT 0x00000100 |