Macros | Functions
Timer32

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)
 

Detailed Description

Dual 32-bit Timer with interrupt capability.


Timer32 Module Operation


The Timer32 module in MSP432 is a simple 32-bit (or 16-bit depending on configuration) down counter which was implemented by ARM. While the user's guide for Timer32 treats the module as one unified timer, the DriverLib API separates the two timers into two separate modules. To choose between the module, the user either provides TIMER32_0 or TIMER32_1 to the timer in order to specify which timer is to be used.


Basic Operation Modes


The Timer32 module has two modes of operation:

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.


Programming Example


The DriverLib package contains a variety of different code examples that demonstrate the usage of the Timer32 module. These code examples are accessible under the examples/ folder of the SDK release as well as through TI Resource Explorer if using Code Composer Studio. These code examples provide a comprehensive list of use cases as well as practical applications involving each module.

Below is a very brief code example showing how to configure the Timer32 as a simple down counter with interrupts enabled:

Macro Definition Documentation

#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

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().

Function Documentation

void Timer32_initModule ( uint32_t  timer,
uint32_t  preScaler,
uint32_t  resolution,
uint32_t  mode 
)

Initializes the Timer32 module

Parameters
timeris the instance of the Timer32 module. Valid parameters must be one of the following values:
  • TIMER32_0_BASE
  • TIMER32_1_BASE
preScaleris the prescaler (or divider) to apply to the clock source given to the Timer32 module. Valid values are
  • TIMER32_PRESCALER_1 [DEFAULT]
  • TIMER32_PRESCALER_16
  • TIMER32_PRESCALER_256
resolutionis the bit resolution of the Timer32 module. Valid values are
  • TIMER32_16BIT [DEFAULT]
  • TIMER32_32BIT
modeselects 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
  • TIMER32_FREE_RUN_MODE [DEFAULT]
  • TIMER32_PERIODIC_MODE
Returns
None.

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

Parameters
timeris the instance of the Timer32 module. Valid parameters must be one of the following values:
  • TIMER32_0_BASE
  • TIMER32_1_BASE
countValue 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).

Returns
None

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.

Parameters
timeris the instance of the Timer32 module. Valid parameters must be one of the following values:
  • TIMER32_0_BASE
  • TIMER32_1_BASE
countValue 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).

Returns
None

References TIMER32_CMSIS.

uint32_t Timer32_getValue ( uint32_t  timer)

Returns the current value of the timer.

Parameters
timeris the instance of the Timer32 module. Valid parameters must be one of the following values:
  • TIMER32_0_BASE
  • TIMER32_1_BASE
Returns
The current count of the timer.

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

Parameters
timeris the instance of the Timer32 module. Valid parameters must be one of the following values:
  • TIMER32_0_BASE
  • TIMER32_1_BASE
oneShotsets 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:
  • The user calls the Timer32PeriodSet function
  • The Timer32_initModule is called to reinitialize the timer with one-shot mode disabled.

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

Returns
None

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.

Parameters
timeris the instance of the Timer32 module. Valid parameters must be one of the following values:
  • TIMER32_0_BASE
  • TIMER32_1_BASE
Returns
None

References ASSERT, TIMER32_0_BASE, TIMER32_1_BASE, and TIMER32_CMSIS.

void Timer32_enableInterrupt ( uint32_t  timer)

Enables a Timer32 interrupt source.

Parameters
timeris the instance of the Timer32 module. Valid parameters must be one of the following values:
  • TIMER32_0_BASE
  • TIMER32_1_BASE

Enables the indicated Timer32 interrupt source.

Returns
None.

References TIMER32_CMSIS.

void Timer32_disableInterrupt ( uint32_t  timer)

Disables a Timer32 interrupt source.

Parameters
timeris the instance of the Timer32 module. Valid parameters must be one of the following values:
  • TIMER32_0_BASE
  • TIMER32_1_BASE

Disables the indicated Timer32 interrupt source.

Returns
None.

References TIMER32_CMSIS.

void Timer32_clearInterruptFlag ( uint32_t  timer)

Clears Timer32 interrupt source.

Parameters
timeris the instance of the Timer32 module. Valid parameters must be one of the following values:
  • TIMER32_0_BASE
  • TIMER32_1_BASE

The Timer32 interrupt source is cleared, so that it no longer asserts.

Returns
None.

References TIMER32_CMSIS.

uint32_t Timer32_getInterruptStatus ( uint32_t  timer)

Gets the current Timer32 interrupt status.

Parameters
timeris the instance of the Timer32 module. Valid parameters must be one of the following values:
  • TIMER32_0_BASE
  • TIMER32_1_BASE

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.

Returns
The current interrupt status

References TIMER32_CMSIS.

void Timer32_registerInterrupt ( uint32_t  timerInterrupt,
void(*)(void)  intHandler 
)

Registers an interrupt handler for Timer32 interrupts.

Parameters
timerInterruptis 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.
  • TIMER32_0_INTERRUPT
  • TIMER32_1_INTERRUPT
  • TIMER32_COMBINED_INTERRUPT
intHandleris 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().

Returns
None.

References Interrupt_enableInterrupt(), and Interrupt_registerInterrupt().

void Timer32_unregisterInterrupt ( uint32_t  timerInterrupt)

Unregisters the interrupt handler for the Timer32 interrupt.

Parameters
timerInterruptis 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.
  • TIMER32_0_INTERRUPT
  • TIMER32_1_INTERRUPT
  • TIMER32_COMBINED_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.

See Also
Interrupt_registerInterrupt() for important information about registering interrupt handlers.
Returns
None.

References Interrupt_disableInterrupt(), and Interrupt_unregisterInterrupt().


Copyright 2018, Texas Instruments Incorporated