![]() |
![]() |
TI-RTOS Drivers
tidrivers_full_2_20_01_10
|
GPTimer driver implementation for CC26XX/CC13XX.
# Overview #
This TI RTOS driver can be used to configure GPTimer modules to the modes supported by the GPTimer. The board file or application must define the device specific configuration before using the driver.
The GPTimer can be used in two different configurations. In 32-bit mode the timer will act as a full-width timer and is controlled using the Timer A unit. In split (16-bit) mode the timer is split into 2x 16-bit timers. In 16-bit mode a prescaler is available for each timer unit, effectively increasing the resolution in this mode to 24-bit. All supported modes by driver in split configuration uses prescaler as timer extension.
The GPTimer driver supports the following timer modes:
The TI-RTOS 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 GPTimerCC26XX 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 GPTimer clock is dependent on the MCU system clock. If very high-accuracy outputs are needed, the application should request using the external HF crystal:
The example below will generate an interrupt using the GPTimer every 1 ms.
See the PWM2TimerCC26XX driver
#include <xdc/std.h>
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <ti/sysbios/family/arm/m3/Hwi.h>
#include <driverlib/event.h>
#include <driverlib/ioc.h>
#include <driverlib/timer.h>
#include <inc/hw_gpt.h>
Go to the source code of this file.
Data Structures | |
struct | GPTimerCC26XX_HWAttrs |
GPTimer26XX Hardware attributes. More... | |
struct | GPTimerCC26XX_Object |
GPTimer26XX Object. More... | |
struct | GPTimerCC26XX_Config |
GPTimer Global configuration. More... | |
struct | GPTimerCC26XX_Params |
GPTimerCC26XX Parameters. More... | |
Macros | |
#define | GPT_NUM_INTS 4 |
Typedefs | |
typedef enum GPTimerCC26XX_Width | GPTimerCC26XX_Width |
Definitions for specifying the GPTimer configuration (width) More... | |
typedef enum GPTimerCC26XX_Mode | GPTimerCC26XX_Mode |
Definitions for supported GPTimer modes. Driver code assumes only modes using prescaler as timer extension in 16-bit configuration are used. Therefore new modes must not be added to the below description without also updating driver. More... | |
typedef enum GPTimerCC26XX_Interrupt | GPTimerCC26XX_Interrupt |
Definitions for supported GPTimer interrupts. GPTimerCC26XX_IntMask arguments should be a bit vector containing these definitions. See description in Technical Reference. More... | |
typedef enum GPTimerCC26XX_Part | GPTimerCC26XX_Part |
Definitions for GPTimer parts (Timer A / Timer B). Used in GPTimer configuration structure GPTimerCC26XX_config to configure the corresponding timer unit. More... | |
typedef enum GPTimerCC26XX_PinMux | GPTimerCC26XX_PinMux |
Definitions for input / output ports in IO controller to connect GPTimer to a pin. Used in gptimerCC26xxHWAttrs for static timer configuration PIN driver is used to mux a pin to the timer. More... | |
typedef enum GPTimerCC26XX_DebugMode | GPTimerCC26XX_DebugMode |
Definitions for controlling timer debug stall mode. More... | |
typedef enum GPTimerCC26XX_Edge | GPTimerCC26XX_Edge |
Definitions for controlling edges used for timer capture. Used in GPTimer edge-time and edge-count modes. More... | |
typedef const struct GPTimerCC26XX_Config | GPTimerCC26XX_Config |
typedef GPTimerCC26XX_Config * | GPTimerCC26XX_Handle |
typedef uint16_t | GPTimerCC26XX_IntMask |
typedef uint32_t | GPTimerCC26XX_Value |
typedef void(* | GPTimerCC26XX_HwiFxn) (GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask) |
typedef struct GPTimerCC26XX_HWAttrs | GPTimerCC26XX_HWAttrs |
GPTimer26XX Hardware attributes. More... | |
typedef struct GPTimerCC26XX_Object | GPTimerCC26XX_Object |
GPTimer26XX Object. More... | |
typedef struct GPTimerCC26XX_Params | GPTimerCC26XX_Params |
GPTimerCC26XX Parameters. More... | |
Enumerations | |
enum | GPTimerCC26XX_Width { GPT_CONFIG_32BIT = GPT_CFG_CFG_32BIT_TIMER, GPT_CONFIG_16BIT = GPT_CFG_CFG_16BIT_TIMER } |
Definitions for specifying the GPTimer configuration (width) More... | |
enum | GPTimerCC26XX_Mode { GPT_MODE_ONESHOT_UP, GPT_MODE_PERIODIC_UP, GPT_MODE_EDGE_COUNT_UP, GPT_MODE_EDGE_TIME_UP, GPT_MODE_PWM } |
Definitions for supported GPTimer modes. Driver code assumes only modes using prescaler as timer extension in 16-bit configuration are used. Therefore new modes must not be added to the below description without also updating driver. More... | |
enum | GPTimerCC26XX_Interrupt { GPT_INT_TIMEOUT = 1 << 0, GPT_INT_CAPTURE_MATCH = 1 << 1, GPT_INT_CAPTURE = 1 << 2, GPT_INT_MATCH = 1 << 3 } |
Definitions for supported GPTimer interrupts. GPTimerCC26XX_IntMask arguments should be a bit vector containing these definitions. See description in Technical Reference. More... | |
enum | GPTimerCC26XX_Part { GPT_A = 0, GPT_B, GPT_PARTS_COUNT } |
Definitions for GPTimer parts (Timer A / Timer B). Used in GPTimer configuration structure GPTimerCC26XX_config to configure the corresponding timer unit. More... | |
enum | GPTimerCC26XX_PinMux { GPT_PIN_0A = IOC_PORT_MCU_PORT_EVENT0, GPT_PIN_0B = IOC_PORT_MCU_PORT_EVENT1, GPT_PIN_1A = IOC_PORT_MCU_PORT_EVENT2, GPT_PIN_1B = IOC_PORT_MCU_PORT_EVENT3, GPT_PIN_2A = IOC_PORT_MCU_PORT_EVENT4, GPT_PIN_2B = IOC_PORT_MCU_PORT_EVENT5, GPT_PIN_3A = IOC_PORT_MCU_PORT_EVENT6, GPT_PIN_3B = IOC_PORT_MCU_PORT_EVENT7 } |
Definitions for input / output ports in IO controller to connect GPTimer to a pin. Used in gptimerCC26xxHWAttrs for static timer configuration PIN driver is used to mux a pin to the timer. More... | |
enum | GPTimerCC26XX_DebugMode { GPTimerCC26XX_DEBUG_STALL_OFF = 0, GPTimerCC26XX_DEBUG_STALL_ON } |
Definitions for controlling timer debug stall mode. More... | |
enum | GPTimerCC26XX_Edge { GPTimerCC26XX_POS_EDGE = GPT_CTL_TAEVENT_POS, GPTimerCC26XX_NEG_EDGE = GPT_CTL_TAEVENT_NEG, GPTimerCC26XX_BOTH_EDGES = GPT_CTL_TAEVENT_BOTH } |
Definitions for controlling edges used for timer capture. Used in GPTimer edge-time and edge-count modes. More... | |
Functions | |
void | GPTimerCC26XX_Params_init (GPTimerCC26XX_Params *params) |
Function to initialize the GPTimerCC26XX_Params struct to its default values. More... | |
GPTimerCC26XX_Handle | GPTimerCC26XX_open (unsigned int index, const GPTimerCC26XX_Params *params) |
This function opens a given GPTimer peripheral. Will set dependency on timer and configure it into specified mode. More... | |
void | GPTimerCC26XX_close (GPTimerCC26XX_Handle handle) |
Function to close a GPTimer peripheral specified by the GPTimer handle. Closing timer will releae dependency on timer and clear configuration. More... | |
void | GPTimerCC26XX_start (GPTimerCC26XX_Handle handle) |
Function to start the specified GPTimer with current settings. More... | |
void | GPTimerCC26XX_stop (GPTimerCC26XX_Handle handle) |
Function to stop the specified GPTimer. More... | |
void | GPTimerCC26XX_setLoadValue (GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value loadValue) |
Function to set load value of the specified GPTimer. Function can be called while GPTimer is running. More... | |
void | GPTimerCC26XX_setMatchValue (GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value matchValue) |
Function to set match value of the specified GPTimer. Function can be called while GPTimer is running. More... | |
void | GPTimerCC26XX_setCaptureEdge (GPTimerCC26XX_Handle handle, GPTimerCC26XX_Edge edge) |
Function to set which input edge the GPTimer capture should use. Applies to edge-count and edge-time modes Function can be called while GPTimer is running. More... | |
GPTimerCC26XX_Value | GPTimerCC26XX_getFreeRunValue (GPTimerCC26XX_Handle handle) |
Function to retrieve the current free-running value of timer. More... | |
GPTimerCC26XX_Value | GPTimerCC26XX_getValue (GPTimerCC26XX_Handle handle) |
Function to retrieve the current value of timer This returns the value of the timer in all modes except for input edge count and input edge time mode. In edge count mode, this register contains the number of edges that have occurred. In input edge time, this register contains the timer value at which the last edge event took place. More... | |
void | GPTimerCC26XX_registerInterrupt (GPTimerCC26XX_Handle handle, GPTimerCC26XX_HwiFxn callback, GPTimerCC26XX_IntMask intMask) |
Function to register a CPU interrupt for a given timer handle and enable a set of timer interrupt sources. The interrupt to the CPU will be a bitwise OR of the enabled interrupt sources. When an interrupt occurs, the driver will clear the interrupt source and call the application provided callback. The callback is executed in HW interrupt context and processing in callback should be minimized. More... | |
void | GPTimerCC26XX_unregisterInterrupt (GPTimerCC26XX_Handle handle) |
Function to disable a CPU interrupt for a given timer handle and disable all interrupt sources for corresponding GPTimer unit. More... | |
void | GPTimerCC26XX_enableInterrupt (GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask) |
Function to enable a set of GPTimer interrupt sources. The interrupt to the CPU must be enabled using GPTimerCC26XX_registerInterrupt. More... | |
void | GPTimerCC26XX_disableInterrupt (GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask) |
Function to disable a set of GPTimer interrupt sources. More... | |
void | GPTimerCC26XX_configureDebugStall (GPTimerCC26XX_Handle handle, GPTimerCC26XX_DebugMode mode) |
Function to control timer debug stall mode. When enabled, the timer will stop when the debugger halts the CPU. More... | |
#define GPT_NUM_INTS 4 |
typedef enum GPTimerCC26XX_Width GPTimerCC26XX_Width |
Definitions for specifying the GPTimer configuration (width)
typedef enum GPTimerCC26XX_Mode GPTimerCC26XX_Mode |
Definitions for supported GPTimer modes. Driver code assumes only modes using prescaler as timer extension in 16-bit configuration are used. Therefore new modes must not be added to the below description without also updating driver.
typedef enum GPTimerCC26XX_Interrupt GPTimerCC26XX_Interrupt |
Definitions for supported GPTimer interrupts. GPTimerCC26XX_IntMask arguments should be a bit vector containing these definitions. See description in Technical Reference.
typedef enum GPTimerCC26XX_Part GPTimerCC26XX_Part |
Definitions for GPTimer parts (Timer A / Timer B). Used in GPTimer configuration structure GPTimerCC26XX_config to configure the corresponding timer unit.
typedef enum GPTimerCC26XX_PinMux GPTimerCC26XX_PinMux |
Definitions for input / output ports in IO controller to connect GPTimer to a pin. Used in gptimerCC26xxHWAttrs for static timer configuration PIN driver is used to mux a pin to the timer.
typedef enum GPTimerCC26XX_DebugMode GPTimerCC26XX_DebugMode |
Definitions for controlling timer debug stall mode.
typedef enum GPTimerCC26XX_Edge GPTimerCC26XX_Edge |
Definitions for controlling edges used for timer capture. Used in GPTimer edge-time and edge-count modes.
typedef const struct GPTimerCC26XX_Config GPTimerCC26XX_Config |
typedef GPTimerCC26XX_Config* GPTimerCC26XX_Handle |
typedef uint16_t GPTimerCC26XX_IntMask |
typedef uint32_t GPTimerCC26XX_Value |
typedef void(* GPTimerCC26XX_HwiFxn) (GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask) |
typedef struct GPTimerCC26XX_HWAttrs GPTimerCC26XX_HWAttrs |
GPTimer26XX Hardware attributes.
These fields are used by the driver to set up underlying GPTimer driver statically. A sample structure is shown below:
typedef struct GPTimerCC26XX_Object GPTimerCC26XX_Object |
GPTimer26XX Object.
These fields are used by the driver to store and modify GPTimer 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:
typedef struct GPTimerCC26XX_Params GPTimerCC26XX_Params |
GPTimerCC26XX Parameters.
GPTimer parameters are used to with the GPTimerCC26XX_open() call. Default values for these parameters are set using GPTimerCC26XX_Params_init().
enum GPTimerCC26XX_Width |
enum GPTimerCC26XX_Mode |
Definitions for supported GPTimer modes. Driver code assumes only modes using prescaler as timer extension in 16-bit configuration are used. Therefore new modes must not be added to the below description without also updating driver.
Enumerator | |
---|---|
GPT_MODE_ONESHOT_UP | |
GPT_MODE_PERIODIC_UP | |
GPT_MODE_EDGE_COUNT_UP | |
GPT_MODE_EDGE_TIME_UP | |
GPT_MODE_PWM |
enum GPTimerCC26XX_Part |
enum GPTimerCC26XX_PinMux |
Definitions for input / output ports in IO controller to connect GPTimer to a pin. Used in gptimerCC26xxHWAttrs for static timer configuration PIN driver is used to mux a pin to the timer.
Enumerator | |
---|---|
GPT_PIN_0A | |
GPT_PIN_0B | |
GPT_PIN_1A | |
GPT_PIN_1B | |
GPT_PIN_2A | |
GPT_PIN_2B | |
GPT_PIN_3A | |
GPT_PIN_3B |
enum GPTimerCC26XX_Edge |
void GPTimerCC26XX_Params_init | ( | GPTimerCC26XX_Params * | params | ) |
Function to initialize the GPTimerCC26XX_Params struct to its default values.
params | An pointer to GPTimerCC26XX_Params structure for initialization |
Defaults values are:
GPTimerCC26XX_Handle GPTimerCC26XX_open | ( | unsigned int | index, |
const GPTimerCC26XX_Params * | params | ||
) |
This function opens a given GPTimer peripheral. Will set dependency on timer and configure it into specified mode.
index | Logical peripheral number for the GPTimer indexed into the GPTimerCC26XX_config table |
params | Pointer to a parameter block. If NULL, it will use default values. |
void GPTimerCC26XX_close | ( | GPTimerCC26XX_Handle | handle | ) |
Function to close a GPTimer peripheral specified by the GPTimer handle. Closing timer will releae dependency on timer and clear configuration.
handle | A GPTimerCC26XX handle returned from GPTimerCC26XX_open() |
void GPTimerCC26XX_start | ( | GPTimerCC26XX_Handle | handle | ) |
Function to start the specified GPTimer with current settings.
handle | A GPTimerCC26XX handle returned from GPTimerCC26XX_open() |
void GPTimerCC26XX_stop | ( | GPTimerCC26XX_Handle | handle | ) |
Function to stop the specified GPTimer.
handle | A GPTimerCC26XX handle returned from GPTimerCC26XX_open() |
void GPTimerCC26XX_setLoadValue | ( | GPTimerCC26XX_Handle | handle, |
GPTimerCC26XX_Value | loadValue | ||
) |
Function to set load value of the specified GPTimer. Function can be called while GPTimer is running.
handle | A GPTimerCC26XX handle returned from GPTimerCC26XX_open |
loadValue | Load value to set the GPTimer to. |
void GPTimerCC26XX_setMatchValue | ( | GPTimerCC26XX_Handle | handle, |
GPTimerCC26XX_Value | matchValue | ||
) |
Function to set match value of the specified GPTimer. Function can be called while GPTimer is running.
handle | A GPTimerCC26XX handle returned from GPTimerCC26XX_open |
matchValue | Match value to set the GPTimer to. |
void GPTimerCC26XX_setCaptureEdge | ( | GPTimerCC26XX_Handle | handle, |
GPTimerCC26XX_Edge | edge | ||
) |
Function to set which input edge the GPTimer capture should use. Applies to edge-count and edge-time modes Function can be called while GPTimer is running.
handle | A GPTimerCC26XX handle returned from GPTimerCC26XX_open |
edge | The edge that should trigger a capture |
GPTimerCC26XX_Value GPTimerCC26XX_getFreeRunValue | ( | GPTimerCC26XX_Handle | handle | ) |
Function to retrieve the current free-running value of timer.
handle | A GPTimerCC26XX handle returned from GPTimerCC26XX_open |
GPTimerCC26XX_Value GPTimerCC26XX_getValue | ( | GPTimerCC26XX_Handle | handle | ) |
Function to retrieve the current value of timer This returns the value of the timer in all modes except for input edge count and input edge time mode. In edge count mode, this register contains the number of edges that have occurred. In input edge time, this register contains the timer value at which the last edge event took place.
handle | A GPTimerCC26XX handle returned from GPTimerCC26XX_open |
void GPTimerCC26XX_registerInterrupt | ( | GPTimerCC26XX_Handle | handle, |
GPTimerCC26XX_HwiFxn | callback, | ||
GPTimerCC26XX_IntMask | intMask | ||
) |
Function to register a CPU interrupt for a given timer handle and enable a set of timer interrupt sources. The interrupt to the CPU will be a bitwise OR of the enabled interrupt sources. When an interrupt occurs, the driver will clear the interrupt source and call the application provided callback. The callback is executed in HW interrupt context and processing in callback should be minimized.
Interrupt sources can also be individually disabled and enabled by using GPTimerCC26XX_enableInterrupt / GPTimerCC26XX_disableInterrupt.
This function should only be called once for a handle after opening the timer. If closing a GPTimer, interrupts for the timer should be unregistered first using GPTimerCC26XX_unregisterInterrupt.
handle | A GPTimerCC26XX handle returned from GPTimerCC26XX_open |
callback | An application provided callback function |
intMask | A bit vector mask containing values from GPTimerCC26XX_Interrupt |
void GPTimerCC26XX_unregisterInterrupt | ( | GPTimerCC26XX_Handle | handle | ) |
Function to disable a CPU interrupt for a given timer handle and disable all interrupt sources for corresponding GPTimer unit.
This function should only be called once for a handle after opening the timer and registering the interrupt.
handle | A GPTimerCC26XX handle returned from GPTimerCC26XX_open |
void GPTimerCC26XX_enableInterrupt | ( | GPTimerCC26XX_Handle | handle, |
GPTimerCC26XX_IntMask | interruptMask | ||
) |
Function to enable a set of GPTimer interrupt sources. The interrupt to the CPU must be enabled using GPTimerCC26XX_registerInterrupt.
handle | A GPTimerCC26XX handle returned from GPTimerCC26XX_open |
interruptMask | A bit vector mask containing values from GPTimerCC26XX_Interrupt |
void GPTimerCC26XX_disableInterrupt | ( | GPTimerCC26XX_Handle | handle, |
GPTimerCC26XX_IntMask | interruptMask | ||
) |
Function to disable a set of GPTimer interrupt sources.
handle | A GPTimerCC26XX handle returned from GPTimerCC26XX_open |
interruptMask | A bit vector mask containing values from GPTimerCC26XX_Interrupt |
void GPTimerCC26XX_configureDebugStall | ( | GPTimerCC26XX_Handle | handle, |
GPTimerCC26XX_DebugMode | mode | ||
) |
Function to control timer debug stall mode. When enabled, the timer will stop when the debugger halts the CPU.
handle | A GPTimerCC26XX handle returned from GPTimerCC26XX_open |
mode | Configuration for debug stall mode (enable/disable) |