GPTimerCC26XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2019, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!*****************************************************************************
33  * @file GPTimerCC26XX.h
34  * @brief GPTimer driver implementation for CC26XX/CC13XX
35  *
36  * # Overview #
37  * This TI RTOS driver can be used to configure GPTimer modules to the modes
38  * supported by the GPTimer. The board file or application must define the device
39  * specific configuration before using the driver.
40  * # Configuration #
41  * The GPTimer can be used in two different configurations. In 32-bit mode the
42  * timer will act as a full-width timer and is controlled using the Timer A unit.
43  * In split (16-bit) mode the timer is split into 2x 16-bit timers. In 16-bit mode
44  * a prescaler is available for each timer unit, effectively increasing the
45  * resolution in this mode to 24-bit. All supported modes by driver in split
46  * configuration uses prescaler as timer extension.
47  *
48  * # Modes #
49  * The GPTimer driver supports the following timer modes:
50  * - Oneshot mode counting upwards. When timer reaches load value, the timer
51  * is stopped automatically. Supported in both 16 and 32-bit configuration.
52  * - Periodic mode counting upwards. When timer reaches load value it wraps and
53  * starts counting from 0 again. Supported in both 16 and 32-bit configuration.
54  * - Input edge-count. Timer counts the number of events on its input capture port
55  * upwards from 0. Events can be rising-edge, falling-edge, or both.
56  * Supported only in 16-bit mode.
57  * - Input edge-time. Timer counts upwards from 0 and captures the time of an
58  * event on its input capture port. This can be used to count the time
59  * between events. Events can be rising-edge, falling-edge or both.
60  * Supported only in 16-bit mode.
61  * - PWM mode. Timer counts downwards from load value. CCP is set to 1 when
62  * reaching timeout (0) and toggles when reaching match value.
63  *
64  * # Power Management #
65  * The TI-RTOS power management framework will try to put the device into the most
66  * power efficient mode whenever possible. Please see the technical reference
67  * manual for further details on each power mode.
68  *
69  * The GPTimerCC26XX driver will set constraints on disallowed power modes when
70  * needed, removing the need for the application to handle this.
71  * The following statements are valid:
72  * - After GPTimerCC26XX_open():
73  * The device is still allowed to enter Standby. When the device is
74  * active the corresponding GPTimer peripheral will be enabled and clocked.
75  * - After GPTimerCC26XX_start():
76  * The device will only go to Idle power mode since the high-frequency
77  * clock is needed for timer operation.
78  * - After GPTimerCC26XX_stop():
79  * Conditions are equal as for after GPTimerCC26XX_open
80  * - After GPTimerCC26XX_close():
81  * The underlying GPTimer is turned off and the device is allowed to go
82  * to standby.
83  *
84  * # Accuracy #
85  * The GPTimer clock is dependent on the MCU system clock.
86  * If very high-accuracy outputs are needed, the application should request
87  * using the external HF crystal:
88  * @code
89  * #include <ti/sysbios/family/arm/cc26xx/Power.h>
90  * #include <ti/sysbios/family/arm/cc26xx/PowerCC2650.h>
91  * Power_setDependency(XOSC_HF);
92  * @endcode
93  *
94  * # Limitations #
95  * - DMA usage is not supported
96  * - Timer synchronization is not supported
97  * - Down counting modes (except for PWM) are not supported by driver
98  *
99  * # GPTimerCC26XX usage #
100  *
101  * ## Periodic timer ##
102  * The example below will generate an interrupt using the GPTimer every 1 ms.
103  *
104  * @code
105  * GPTimerCC26XX_Handle hTimer;
106  * void timerCallback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask) {
107  * // interrupt callback code goes here. Minimize processing in interrupt.
108  * }
109  *
110  * void taskFxn(uintptr_t a0, uintptr_t a1) {
111  * GPTimerCC26XX_Params params;
112  * GPTimerCC26XX_Params_init(&params);
113  * params.width = GPT_CONFIG_16BIT;
114  * params.mode = GPT_MODE_PERIODIC;
115  * params.direction = GPTimerCC26XX_DIRECTION_UP;
116  * params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
117  * hTimer = GPTimerCC26XX_open(CC2650_GPTIMER0A, &params);
118  * if(hTimer == NULL) {
119  * Log_error0("Failed to open GPTimer");
120  * Task_exit();
121  * }
122  *
123  * Types_FreqHz freq;
124  * BIOS_getCpuFreq(&freq);
125  * GPTimerCC26XX_Value loadVal = freq.lo / 1000 - 1; //47999
126  * GPTimerCC26XX_setLoadValue(hTimer, loadVal);
127  * GPTimerCC26XX_registerInterrupt(hTimer, timerCallback, GPT_INT_TIMEOUT);
128  *
129  * GPTimerCC26XX_start(hTimer);
130  *
131  * while(1) {
132  * Task_sleep(BIOS_WAIT_FOREVER);
133  * }
134  * }
135  * @endcode
136  *
137  *
138  * ## PWM output ##
139  * See the PWM2TimerCC26XX driver
140  *******************************************************************************
141  */
142 
143 #ifndef ti_drivers_timer_GPTIMERCC26XX__include
144 #define ti_drivers_timer_GPTIMERCC26XX__include
145 
146 #include <stdint.h>
147 #include <stdbool.h>
148 #include <stddef.h>
149 
150 #include <ti/drivers/dpl/HwiP.h>
151 
152 #include <ti/devices/DeviceFamily.h>
153 #include DeviceFamily_constructPath(inc/hw_gpt.h)
154 #include DeviceFamily_constructPath(driverlib/event.h)
155 #include DeviceFamily_constructPath(driverlib/ioc.h)
156 #include DeviceFamily_constructPath(driverlib/timer.h)
157 
158 #ifdef __cplusplus
159 extern "C" {
160 #endif
161 
162 /* Backwards compatibility - old timer modes. New behaviour is count-up by default but configurable. */
163 #define GPT_MODE_ONESHOT_UP GPT_MODE_ONESHOT
164 #define GPT_MODE_PERIODIC_UP GPT_MODE_PERIODIC
165 #define GPT_MODE_EDGE_COUNT_UP GPT_MODE_EDGE_COUNT
166 #define GPT_MODE_EDGE_TIME_UP GPT_MODE_EDGE_TIME
167 
173 {
174  GPT_CONFIG_32BIT = GPT_CFG_CFG_32BIT_TIMER,
175  GPT_CONFIG_16BIT = GPT_CFG_CFG_16BIT_TIMER,
177 
186 typedef enum GPTimerCC26XX_Mode
187 {
188  /* One shot mode counting upwards */
189  GPT_MODE_ONESHOT = GPT_TAMR_TAMR_ONE_SHOT | GPT_TAMR_TAMIE,
190  /* Periodic mode counting upwards */
191  GPT_MODE_PERIODIC = GPT_TAMR_TAMR_PERIODIC | GPT_TAMR_TAMIE,
192  /* Edge count mode counting upwards */
193  GPT_MODE_EDGE_COUNT = GPT_TAMR_TAMR_CAPTURE | GPT_TAMR_TACM_EDGCNT,
194  /* Edge count mode counting upwards */
195  GPT_MODE_EDGE_TIME = GPT_TAMR_TAMR_CAPTURE | GPT_TAMR_TACM_EDGTIME,
196  /* PWM mode counting downwards. This specific configuration is used by the
197  PWM2TimerCC26XX driver */
198  GPT_MODE_PWM = GPT_TAMR_TAMR_PERIODIC | GPT_TAMR_TAPWMIE_EN | \
199  GPT_TAMR_TAAMS_PWM | GPT_TAMR_TACM_EDGCNT | \
200  GPT_TAMR_TAPLO_CCP_ON_TO,
202 
210 {
211  GPT_INT_TIMEOUT = 1 << 0,
213  GPT_INT_CAPTURE = 1 << 2,
214  GPT_INT_MATCH = 1 << 3,
216 
217 /* Number of entries in GPTimerCC26XX_Interrupt */
218 #define GPT_NUM_INTS 4
219 
226 typedef enum GPTimerCC26XX_Part
227 {
228  GPT_A = 0,
231 
232 #define GPT_PARTS_COUNT 2
233 
243 {
244  GPT_PIN_0A = IOC_PORT_MCU_PORT_EVENT0,
245  GPT_PIN_0B = IOC_PORT_MCU_PORT_EVENT1,
246  GPT_PIN_1A = IOC_PORT_MCU_PORT_EVENT2,
247  GPT_PIN_1B = IOC_PORT_MCU_PORT_EVENT3,
248  GPT_PIN_2A = IOC_PORT_MCU_PORT_EVENT4,
249  GPT_PIN_2B = IOC_PORT_MCU_PORT_EVENT5,
250  GPT_PIN_3A = IOC_PORT_MCU_PORT_EVENT6,
251  GPT_PIN_3B = IOC_PORT_MCU_PORT_EVENT7,
253 
259 {
263 
270 {
274 
285 {
289 
295 typedef enum GPTimerCC26XX_Edge
296 {
297  GPTimerCC26XX_POS_EDGE = GPT_CTL_TAEVENT_POS,
298  GPTimerCC26XX_NEG_EDGE = GPT_CTL_TAEVENT_NEG,
299  GPTimerCC26XX_BOTH_EDGES = GPT_CTL_TAEVENT_BOTH,
301 
302 
303 /* Forward declaration of GPTimer configuration */
305 
306 /* GPTimer handle is pointer to configuration structure */
308 
309 /* Interrupt bit vector. See GPTimerCC26XX_Interrupt for available interrupts */
310 typedef uint16_t GPTimerCC26XX_IntMask;
311 
312 /* Timer value */
313 typedef uint32_t GPTimerCC26XX_Value;
314 
315 /* Function prototype for interrupt callbacks */
316 typedef void (*GPTimerCC26XX_HwiFxn) (GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
317 
338 typedef struct GPTimerCC26XX_HWAttrs
339 {
341  uint32_t baseAddr;
343  uint8_t intNum;
353  uint8_t intPriority;
355  uint8_t powerMngrId;
357  GPTimerCC26XX_Part timer;
359  GPTimerCC26XX_PinMux pinMux;
361 
376 typedef struct GPTimerCC26XX_Object
377 {
378  GPTimerCC26XX_Width width;
379  bool isOpen[GPT_PARTS_COUNT];
380  HwiP_Struct hwi[GPT_PARTS_COUNT];
382  volatile bool powerConstraint[GPT_PARTS_COUNT];
383  uint32_t arg;
385 
386 
408 {
411  GPTimerCC26XX_Part timerPart;
412 };
413 
422 typedef struct GPTimerCC26XX_Params
423 {
424  GPTimerCC26XX_Width width;
425  GPTimerCC26XX_Mode mode;
426  GPTimerCC26XX_SetMatchTiming matchTiming;
427  GPTimerCC26XX_Direction direction;
428  GPTimerCC26XX_DebugMode debugStallMode;
430 
431 
445 
462 extern GPTimerCC26XX_Handle GPTimerCC26XX_open(unsigned int index, const GPTimerCC26XX_Params *params);
463 
477 extern void GPTimerCC26XX_close(GPTimerCC26XX_Handle handle);
478 
489 extern void GPTimerCC26XX_start(GPTimerCC26XX_Handle handle);
490 
501 extern void GPTimerCC26XX_stop(GPTimerCC26XX_Handle handle);
502 
514 extern void GPTimerCC26XX_setLoadValue(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value loadValue);
515 
527 extern void GPTimerCC26XX_setMatchValue(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value matchValue);
528 
529 
542 extern void GPTimerCC26XX_setCaptureEdge(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Edge edge);
543 
555 extern GPTimerCC26XX_Value GPTimerCC26XX_getFreeRunValue(GPTimerCC26XX_Handle handle);
556 
574 extern GPTimerCC26XX_Value GPTimerCC26XX_getValue(GPTimerCC26XX_Handle handle);
575 
576 
604 extern void GPTimerCC26XX_registerInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_HwiFxn callback, GPTimerCC26XX_IntMask intMask);
605 
621 extern void GPTimerCC26XX_unregisterInterrupt(GPTimerCC26XX_Handle handle);
622 
636 extern void GPTimerCC26XX_enableInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
648 extern void GPTimerCC26XX_disableInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
649 
661 extern void GPTimerCC26XX_configureDebugStall(GPTimerCC26XX_Handle handle, GPTimerCC26XX_DebugMode mode);
662 
674 extern uint32_t GPTimerCC26XX_getArg(GPTimerCC26XX_Handle handle);
675 
687 extern void GPTimerCC26XX_setArg(GPTimerCC26XX_Handle handle, void *arg);
688 
704 static inline GPTimerCC26XX_PinMux GPTimerCC26XX_getPinMux(GPTimerCC26XX_Handle handle)
705 {
706  return handle->hwAttrs->pinMux;
707 }
708 
709 
710 #ifdef __cplusplus
711 }
712 #endif
713 #endif /* ti_drivers_timer_GPTIMERCC26XX__include */
uint32_t GPTimerCC26XX_Value
Definition: GPTimerCC26XX.h:313
void GPTimerCC26XX_setArg(GPTimerCC26XX_Handle handle, void *arg)
Function to set a custom argument.
GPTimerCC26XX_DebugMode debugStallMode
Definition: GPTimerCC26XX.h:428
ADC_Params params
Definition: Driver_Init.h:11
Definition: GPTimerCC26XX.h:195
GPTimerCC26XX_DebugMode
Definitions for controlling timer debug stall mode.
Definition: GPTimerCC26XX.h:258
Definition: GPTimerCC26XX.h:213
Definition: GPTimerCC26XX.h:271
Definition: GPTimerCC26XX.h:174
struct GPTimerCC26XX_Object GPTimerCC26XX_Object
GPTimer26XX Object.
Definition: GPTimerCC26XX.h:229
uint8_t intNum
Definition: GPTimerCC26XX.h:343
uint32_t arg
Definition: GPTimerCC26XX.h:383
Definition: GPTimerCC26XX.h:261
uint8_t intPriority
Definition: GPTimerCC26XX.h:353
GPTimerCC26XX Parameters.
Definition: GPTimerCC26XX.h:422
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...
GPTimerCC26XX_Mode
Definitions for supported GPTimer modes. Driver code assumes only modes using prescaler as timer exte...
Definition: GPTimerCC26XX.h:186
Definition: GPTimerCC26XX.h:214
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...
Definition: GPTimerCC26XX.h:272
uint16_t GPTimerCC26XX_IntMask
Definition: GPTimerCC26XX.h:310
Definition: GPTimerCC26XX.h:191
void GPTimerCC26XX_disableInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
Function to disable a set of GPTimer interrupt sources.
GPTimerCC26XX_Direction
Definitions for controlling timer counting direction. Setting the Direction for PWM operation has no ...
Definition: GPTimerCC26XX.h:269
void GPTimerCC26XX_unregisterInterrupt(GPTimerCC26XX_Handle handle)
Function to disable a CPU interrupt for a given timer handle and disable all interrupt sources for co...
static GPTimerCC26XX_PinMux GPTimerCC26XX_getPinMux(GPTimerCC26XX_Handle handle)
Function to return the PIN mux used by the GPTimer identified by handle. This is used to connect a GP...
Definition: GPTimerCC26XX.h:704
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 sou...
Definition: GPTimerCC26XX.h:248
uint8_t powerMngrId
Definition: GPTimerCC26XX.h:355
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.
Definition: GPTimerCC26XX.h:242
Definition: GPTimerCC26XX.h:247
GPTimerCC26XX_Config * GPTimerCC26XX_Handle
Definition: GPTimerCC26XX.h:307
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 ...
Definition: GPTimerCC26XX.h:246
void GPTimerCC26XX_close(GPTimerCC26XX_Handle handle)
Function to close a GPTimer peripheral specified by the GPTimer handle. Closing timer will releae dep...
Definition: GPTimerCC26XX.h:299
uint32_t baseAddr
Definition: GPTimerCC26XX.h:341
Definition: GPTimerCC26XX.h:249
Definition: GPTimerCC26XX.h:287
struct GPTimerCC26XX_HWAttrs GPTimerCC26XX_HWAttrs
GPTimer26XX Hardware attributes.
GPTimerCC26XX_Mode mode
Definition: GPTimerCC26XX.h:425
Definition: GPTimerCC26XX.h:251
struct GPTimerCC26XX_Params GPTimerCC26XX_Params
GPTimerCC26XX Parameters.
GPTimerCC26XX_Value GPTimerCC26XX_getFreeRunValue(GPTimerCC26XX_Handle handle)
Function to retrieve the current free-running value of timer.
Definition: GPTimerCC26XX.h:260
Definition: GPTimerCC26XX.h:212
GPTimerCC26XX_SetMatchTiming matchTiming
Definition: GPTimerCC26XX.h:426
Definition: GPTimerCC26XX.h:297
Definition: GPTimerCC26XX.h:245
GPTimer26XX Object.
Definition: GPTimerCC26XX.h:376
GPTimerCC26XX_Part timer
Definition: GPTimerCC26XX.h:357
GPTimerCC26XX_Direction direction
Definition: GPTimerCC26XX.h:427
GPTimer Global configuration.
Definition: GPTimerCC26XX.h:407
#define GPT_PARTS_COUNT
Definition: GPTimerCC26XX.h:232
Definition: GPTimerCC26XX.h:193
Definition: GPTimerCC26XX.h:175
GPTimerCC26XX_Edge
Definitions for controlling edges used for timer capture. Used in GPTimer edge-time and edge-count mo...
Definition: GPTimerCC26XX.h:295
GPTimerCC26XX_Width width
Definition: GPTimerCC26XX.h:378
Definition: GPTimerCC26XX.h:198
GPTimer26XX Hardware attributes.
Definition: GPTimerCC26XX.h:338
void GPTimerCC26XX_start(GPTimerCC26XX_Handle handle)
Function to start the specified GPTimer with current settings.
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 exce...
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...
Definition: GPTimerCC26XX.h:250
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 sp...
GPTimerCC26XX_PinMux pinMux
Definition: GPTimerCC26XX.h:359
GPTimerCC26XX_Part
Definitions for GPTimer parts (Timer A / Timer B). Used in GPTimer configuration structure GPTimerCC2...
Definition: GPTimerCC26XX.h:226
Definition: GPTimerCC26XX.h:298
Definition: GPTimerCC26XX.h:228
void(* GPTimerCC26XX_HwiFxn)(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
Definition: GPTimerCC26XX.h:316
GPTimerCC26XX_Interrupt
Definitions for supported GPTimer interrupts. GPTimerCC26XX_IntMask arguments should be a bit vector ...
Definition: GPTimerCC26XX.h:209
void GPTimerCC26XX_stop(GPTimerCC26XX_Handle handle)
Function to stop the specified GPTimer.
GPTimerCC26XX_Part timerPart
Definition: GPTimerCC26XX.h:411
GPTimerCC26XX_Width
Definitions for specifying the GPTimer configuration (width)
Definition: GPTimerCC26XX.h:172
GPTimerCC26XX_Width width
Definition: GPTimerCC26XX.h:424
Definition: GPTimerCC26XX.h:244
GPTimerCC26XX_Object * object
Definition: GPTimerCC26XX.h:409
void GPTimerCC26XX_Params_init(GPTimerCC26XX_Params *params)
Function to initialize the GPTimerCC26XX_Params struct to its default values.
Definition: GPTimerCC26XX.h:211
Definition: GPTimerCC26XX.h:286
const GPTimerCC26XX_HWAttrs * hwAttrs
Definition: GPTimerCC26XX.h:410
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...
Definition: GPTimerCC26XX.h:189
uint32_t GPTimerCC26XX_getArg(GPTimerCC26XX_Handle handle)
Function to get a custom argument.
GPTimerCC26XX_SetMatchTiming
Definitions for new value loading behaviour.
Definition: GPTimerCC26XX.h:284
© Copyright 1995-2022, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale