![]() |
![]() |
LGPTimer driver implementation for Low Power F3 devices.
The LGPTimer driver allows you to measure elapsed time with simple and portable APIs. It also allows for asynchronous callbacks after a certain amount of time has elapsed.
The LGPTimer driver also handles the general purpose timer resource allocation. For each driver that requires use of a general purpose timer, it calls LGPTimerLPF3_open() to occupy the specified timer, and calls LGPTimerLPF3_close() to release the occupied timer resource.
The LGPT peripherals support different timer counter widths depending on the peripheral instance number (LGPT0, LGPT1, ..). The table below lists supported counter widths for each peripheral instance number on available device types. The timer counter clock is sourced from the internal prescaler stage which has the high frequency clock (CLKSVT) as input. The prescaler can be configured to divide the input system clock, effectively extending the maximal time interval for the timer counter while reducing the timer resolution.
Device type | LGPT0 | LGPT1 | LGPT2 | LGPT3 |
---|---|---|---|---|
CC2340R2 | 16 bits | 16 bits | N.A | N.A |
CC2340R5 | 16 bits | 16 bits | 16 bits | 24 bits |
CC27X5 | 16 bits | 16 bits | 16 bits | 24 bits |
The LGPTimer driver supports the following timer counter modes:
The power management framework will try to put the device into the most power efficient mode whenever possible. Please see the technical reference manual for further details on each power mode.
The LGPTimer driver will set constraints on disallowed power modes when needed, removing the need for the application to handle this. The following statements are valid:
The timer clock of the LGPT peripheral is dependent on the high frequency clock (CLKSVT).
This documentation provides a basic example in the form of a commented code fragment.
The code example below will generate an interrupt using the LGPTimer every 1 ms.
Refer to the Driver's Configuration section for driver configuration information.
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <ti/drivers/dpl/HwiP.h>
#include <ti/drivers/Power.h>
#include <ti/devices/DeviceFamily.h>
#include <DeviceFamily_constructPath(inc/hw_lgpt.h)>
Go to the source code of this file.
Data Structures | |
struct | LGPTimerLPF3_Params |
LGPTimerLPF3 Parameters. More... | |
struct | LGPTimerLPF3_HWAttrs |
LGPTimerLPF3 Hardware attributes. More... | |
struct | LGPTimerLPF3_Object |
LGPTimerLPF3 Object. More... | |
struct | LGPTimerLPF3_Config |
LGPTimer Global configuration. More... | |
Typedefs | |
typedef struct LGPTimerLPF3_Config | LGPTimerLPF3_Config |
typedef LGPTimerLPF3_Config * | LGPTimerLPF3_Handle |
typedef uint16_t | LGPTimerLPF3_IntMask |
typedef void(* | LGPTimerLPF3_HwiFxn) (LGPTimerLPF3_Handle handle, LGPTimerLPF3_IntMask interruptMask) |
The definition of a callback function used by the LGPTimer driver. More... | |
typedef struct LGPTimerLPF3_Params | LGPTimerLPF3_Params |
LGPTimerLPF3 Parameters. More... | |
typedef struct LGPTimerLPF3_HWAttrs | LGPTimerLPF3_HWAttrs |
LGPTimerLPF3 Hardware attributes. More... | |
typedef struct LGPTimerLPF3_Object | LGPTimerLPF3_Object |
LGPTimerLPF3 Object. More... | |
Enumerations | |
enum | LGPTimerLPF3_Mode { LGPTimerLPF3_CTL_MODE_DIS = LGPT_CTL_MODE_DIS, LGPTimerLPF3_CTL_MODE_UP_ONCE = LGPT_CTL_MODE_UP_ONCE, LGPTimerLPF3_CTL_MODE_UP_PER = LGPT_CTL_MODE_UP_PER, LGPTimerLPF3_CTL_MODE_UPDWN_PER = LGPT_CTL_MODE_UPDWN_PER } |
Definitions for supported LGPTimer counting modes. More... | |
enum | LGPTimerLPF3_Interrupt { LGPTimerLPF3_INT_TGT = 1 << LGPT_RIS_TGT_S, LGPTimerLPF3_INT_ZERO = 1 << LGPT_RIS_ZERO_S } |
Definitions for supported LGPTimer interrupts. LGPTimerLPF3_IntMask arguments should be a bit vector containing these definitions. More... | |
enum | LGPTimerLPF3_DebugMode { LGPTimerLPF3_DEBUG_STALL_OFF = LGPT_EMU_HALT_DIS, LGPTimerLPF3_DEBUG_STALL_IMMEDIATE = (LGPT_EMU_HALT_EN | LGPT_EMU_CTL_IMMEDIATE), LGPTimerLPF3_DEBUG_STALL_ON_ZERO = (LGPT_EMU_HALT_EN | LGPT_EMU_CTL_ZERCOND) } |
Definitions for controlling timer debug stall mode. More... | |
Functions | |
void | LGPTimerLPF3_Params_init (LGPTimerLPF3_Params *params) |
Function that initializes the LGPTimerLPF3_Params struct to its default values. More... | |
LGPTimerLPF3_Handle | LGPTimerLPF3_open (uint_least8_t index, const LGPTimerLPF3_Params *params) |
Function that opens a driver for the given LGPT peripheral. Will set power dependency on timer and configure it into specified configuration. More... | |
void | LGPTimerLPF3_close (LGPTimerLPF3_Handle handle) |
Function that closes a LGPTimer driver specified by the LGPTimer handle. Closing LGPTimer driver will release power dependency on timer and clear configuration. More... | |
void | LGPTimerLPF3_start (LGPTimerLPF3_Handle handle, LGPTimerLPF3_Mode mode) |
Function that starts the timer counter of the specified LGPTimer handle with current settings and specified timer counter mode. More... | |
void | LGPTimerLPF3_stop (LGPTimerLPF3_Handle handle) |
Function that stops the timer counter of the specified LGPTimer driver. More... | |
void | LGPTimerLPF3_setInitialCounterTarget (LGPTimerLPF3_Handle handle, uint32_t value, bool intFlagClr) |
Function that sets the initial timer counter target on the specified LGPTimer. This function must be called before the timer is started. The LGPTimerLPF3_INT_TGT and LGPTimerLPF3_INT_ZERO interrupt status flags are cleared. Timer counter width (16 or 24 bits) depends on selected peripheral instance. More... | |
void | LGPTimerLPF3_setNextCounterTarget (LGPTimerLPF3_Handle handle, uint32_t value, bool intFlagClr) |
Function that sets the next timer counter target on the specified LGPTimer. The specified target value will be valid as timer counter target on the upcoming zero crossing. When counting repeatedly upwards a zero crossing is regarded as when the timer counter restarts counting from 0. The LGPTimerLPF3_INT_TGT and LGPTimerLPF3_INT_ZERO interrupt status flags are cleared at the counter zero crossing. This function can be called after the timer has started. Timer counter width (16 or 24 bits) depends on selected peripheral instance. More... | |
uint32_t | LGPTimerLPF3_getCounter (LGPTimerLPF3_Handle handle) |
Function that returns the current timer counter value. More... | |
uint32_t | LGPTimerLPF3_getArg (LGPTimerLPF3_Handle handle) |
Function to get a custom argument. More... | |
void | LGPTimerLPF3_setArg (LGPTimerLPF3_Handle handle, void *arg) |
Function to set a custom argument. More... | |
void | LGPTimerLPF3_enableInterrupt (LGPTimerLPF3_Handle handle, LGPTimerLPF3_IntMask intMask) |
Enable interrupt source for the LGPTimer handle. More... | |
void | LGPTimerLPF3_disableInterrupt (LGPTimerLPF3_Handle handle, LGPTimerLPF3_IntMask intMask) |
Disable interrupt source for the LGPTimer handle. More... | |
typedef struct LGPTimerLPF3_Config LGPTimerLPF3_Config |
typedef LGPTimerLPF3_Config* LGPTimerLPF3_Handle |
typedef uint16_t LGPTimerLPF3_IntMask |
typedef void(* LGPTimerLPF3_HwiFxn) (LGPTimerLPF3_Handle handle, LGPTimerLPF3_IntMask interruptMask) |
The definition of a callback function used by the LGPTimer driver.
[in] | handle | A LGPTimer handle |
[in] | interruptMask | LGPTimer interrupt mask |
typedef struct LGPTimerLPF3_Params LGPTimerLPF3_Params |
LGPTimerLPF3 Parameters.
LGPTimer parameters are used by the LGPTimerLPF3_open() call. Default values for these parameters are set using LGPTimerLPF3_Params_init().
typedef struct LGPTimerLPF3_HWAttrs LGPTimerLPF3_HWAttrs |
LGPTimerLPF3 Hardware attributes.
These fields are used by the driver to set up underlying LGPTimer driver statically. A sample structure is shown below:
typedef struct LGPTimerLPF3_Object LGPTimerLPF3_Object |
LGPTimerLPF3 Object.
These fields are used by the driver to store and modify LGPTimer configuration during run-time. The application must not edit any member variables of this structure. Appplications should also not access member variables of this structure as backwards compatibility is not guaranteed. An example structure is shown below:
enum LGPTimerLPF3_Mode |
Definitions for supported LGPTimer counting modes.
Definitions for controlling timer debug stall mode.
void LGPTimerLPF3_Params_init | ( | LGPTimerLPF3_Params * | params | ) |
Function that initializes the LGPTimerLPF3_Params struct to its default values.
[in] | params | An pointer to LGPTimerLPF3_Params structure for initialization |
Default values are: Interrupt callback fxn: NULL, Interrupt phase late : false, Prescaler division : 0, Timer debug stall mode: LGPTimerLPF3_DEBUG_STALL_OFF
LGPTimerLPF3_Handle LGPTimerLPF3_open | ( | uint_least8_t | index, |
const LGPTimerLPF3_Params * | params | ||
) |
Function that opens a driver for the given LGPT peripheral. Will set power dependency on timer and configure it into specified configuration.
[in] | index | Index in the LGPTimerLPF3_config table. |
[in] | params | Pointer to a parameter block. If NULL, it will use default values. |
void LGPTimerLPF3_close | ( | LGPTimerLPF3_Handle | handle | ) |
Function that closes a LGPTimer driver specified by the LGPTimer handle. Closing LGPTimer driver will release power dependency on timer and clear configuration.
[in] | handle | A LGPTimerLPF3 handle returned from LGPTimerLPF3_open() |
void LGPTimerLPF3_start | ( | LGPTimerLPF3_Handle | handle, |
LGPTimerLPF3_Mode | mode | ||
) |
Function that starts the timer counter of the specified LGPTimer handle with current settings and specified timer counter mode.
[in] | handle | A LGPTimerLPF3 handle returned from LGPTimerLPF3_open(). |
[in] | mode | The timer counter mode. |
void LGPTimerLPF3_stop | ( | LGPTimerLPF3_Handle | handle | ) |
Function that stops the timer counter of the specified LGPTimer driver.
[in] | handle | A LGPTimerLPF3 handle returned from LGPTimerLPF3_open() |
void LGPTimerLPF3_setInitialCounterTarget | ( | LGPTimerLPF3_Handle | handle, |
uint32_t | value, | ||
bool | intFlagClr | ||
) |
Function that sets the initial timer counter target on the specified LGPTimer. This function must be called before the timer is started. The LGPTimerLPF3_INT_TGT and LGPTimerLPF3_INT_ZERO interrupt status flags are cleared. Timer counter width (16 or 24 bits) depends on selected peripheral instance.
[in] | handle | A LGPTimerLPF3 handle returned from LGPTimerLPF3_open |
[in] | value | Initial target value of the timer counter. Max value: LGPT peripheral properties |
[in] | intFlagClr | Controls if the LGPTimerLPF3_INT_TGT and LGPTimerLPF3_INT_ZERO interrupt status flags are cleared or not when this function is executed. |
void LGPTimerLPF3_setNextCounterTarget | ( | LGPTimerLPF3_Handle | handle, |
uint32_t | value, | ||
bool | intFlagClr | ||
) |
Function that sets the next timer counter target on the specified LGPTimer. The specified target value will be valid as timer counter target on the upcoming zero crossing. When counting repeatedly upwards a zero crossing is regarded as when the timer counter restarts counting from 0. The LGPTimerLPF3_INT_TGT and LGPTimerLPF3_INT_ZERO interrupt status flags are cleared at the counter zero crossing. This function can be called after the timer has started. Timer counter width (16 or 24 bits) depends on selected peripheral instance.
[in] | handle | A LGPTimerLPF3 handle returned from LGPTimerLPF3_open |
[in] | value | Next target value of the timer counter. Max value Max value: LGPT peripheral properties" |
[in] | intFlagClr | Controls if the LGPTimerLPF3_INT_TGT and LGPTimerLPF3_INT_ZERO interrupt status flags are cleared or not when this function is executed. |
uint32_t LGPTimerLPF3_getCounter | ( | LGPTimerLPF3_Handle | handle | ) |
Function that returns the current timer counter value.
[in] | handle | A LGPTimerLPF3 handle returned from LGPTimerLPF3_open |
uint32_t LGPTimerLPF3_getArg | ( | LGPTimerLPF3_Handle | handle | ) |
Function to get a custom argument.
[in] | handle | A LGPTimerLPF3 handle returned from LGPTimerLPF3_open |
void LGPTimerLPF3_setArg | ( | LGPTimerLPF3_Handle | handle, |
void * | arg | ||
) |
Function to set a custom argument.
[in] | handle | A LGPTimerLPF3 handle returned from LGPTimerLPF3_open |
[in] | arg | Pointer to a custom argument |
void LGPTimerLPF3_enableInterrupt | ( | LGPTimerLPF3_Handle | handle, |
LGPTimerLPF3_IntMask | intMask | ||
) |
Enable interrupt source for the LGPTimer handle.
[in] | handle | A LGPTimerLPF3 handle returned from LGPTimerLPF3_open |
[in] | intMask | A bit mask of interrupt flags to enable |
void LGPTimerLPF3_disableInterrupt | ( | LGPTimerLPF3_Handle | handle, |
LGPTimerLPF3_IntMask | intMask | ||
) |
Disable interrupt source for the LGPTimer handle.
[in] | handle | A LGPTimerLPF3 handle returned from LGPTimerLPF3_open |
[in] | intMask | A bit mask of interrupt flags to disable |