GPTimerCC26XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2018, 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_UP;
115  * params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
116  * hTimer = GPTimerCC26XX_open(CC2650_GPTIMER0A, &params);
117  * if(hTimer == NULL) {
118  * Log_error0("Failed to open GPTimer");
119  * Task_exit();
120  * }
121  *
122  * Types_FreqHz freq;
123  * BIOS_getCpuFreq(&freq);
124  * GPTimerCC26XX_Value loadVal = freq.lo / 1000 - 1; //47999
125  * GPTimerCC26XX_setLoadValue(hTimer, loadVal);
126  * GPTimerCC26XX_registerInterrupt(hTimer, timerCallback, GPT_INT_TIMEOUT);
127  *
128  * GPTimerCC26XX_start(hTimer);
129  *
130  * while(1) {
131  * Task_sleep(BIOS_WAIT_FOREVER);
132  * }
133  * }
134  * @endcode
135  *
136  *
137  * ## PWM output ##
138  * See the PWM2TimerCC26XX driver
139  *******************************************************************************
140  */
141 
142 #ifndef ti_drivers_timer_GPTIMERCC26XX__include
143 #define ti_drivers_timer_GPTIMERCC26XX__include
144 
145 #ifdef __cplusplus
146 extern "C" {
147 #endif
148 
149 #include <stdint.h>
150 #include <stdbool.h>
151 #include <stddef.h>
152 
153 #include <ti/drivers/dpl/HwiP.h>
154 
155 #include <ti/devices/DeviceFamily.h>
156 #include DeviceFamily_constructPath(inc/hw_gpt.h)
157 #include DeviceFamily_constructPath(driverlib/event.h)
158 #include DeviceFamily_constructPath(driverlib/ioc.h)
159 #include DeviceFamily_constructPath(driverlib/timer.h)
160 
166 {
167  GPT_CONFIG_32BIT = GPT_CFG_CFG_32BIT_TIMER,
168  GPT_CONFIG_16BIT = GPT_CFG_CFG_16BIT_TIMER,
170 
179 typedef enum GPTimerCC26XX_Mode
180 {
181  /* One shot mode counting upwards */
182  GPT_MODE_ONESHOT_UP = GPT_TAMR_TAMR_ONE_SHOT | GPT_TAMR_TACDIR_UP | \
183  GPT_TAMR_TAMIE,
184  /* Periodic mode counting upwards */
185  GPT_MODE_PERIODIC_UP = GPT_TAMR_TAMR_PERIODIC | GPT_TAMR_TACDIR_UP | \
186  GPT_TAMR_TAMIE,
187  /* Edge count mode counting upwards */
188  GPT_MODE_EDGE_COUNT_UP = GPT_TAMR_TAMR_CAPTURE | GPT_TAMR_TACDIR_UP | \
189  GPT_TAMR_TACM_EDGCNT,
190  /* Edge count mode counting upwards */
191  GPT_MODE_EDGE_TIME_UP = GPT_TAMR_TAMR_CAPTURE | GPT_TAMR_TACDIR_UP | \
192  GPT_TAMR_TACM_EDGTIME,
193  /* PWM mode counting downwards. This specific configuration is used by the
194  PWM2TimerCC26XX driver */
195  GPT_MODE_PWM = GPT_TAMR_TAMR_PERIODIC | GPT_TAMR_TACDIR_UP | \
196  GPT_TAMR_TAAMS_PWM | GPT_TAMR_TACM_EDGCNT | \
197  GPT_TAMR_TAPLO_CCP_ON_TO | GPT_TAMR_TAPWMIE_EN | \
198  GPT_TAMR_TAMRSU_CYCLEUPDATE,
200 
208 {
209  GPT_INT_TIMEOUT = 1 << 0,
211  GPT_INT_CAPTURE = 1 << 2,
212  GPT_INT_MATCH = 1 << 3,
214 
215 /* Number of entries in GPTimerCC26XX_Interrupt */
216 #define GPT_NUM_INTS 4
217 
224 typedef enum GPTimerCC26XX_Part
225 {
226  GPT_A = 0,
229 
230 #define GPT_PARTS_COUNT 2
231 
241 {
242  GPT_PIN_0A = IOC_PORT_MCU_PORT_EVENT0,
243  GPT_PIN_0B = IOC_PORT_MCU_PORT_EVENT1,
244  GPT_PIN_1A = IOC_PORT_MCU_PORT_EVENT2,
245  GPT_PIN_1B = IOC_PORT_MCU_PORT_EVENT3,
246  GPT_PIN_2A = IOC_PORT_MCU_PORT_EVENT4,
247  GPT_PIN_2B = IOC_PORT_MCU_PORT_EVENT5,
248  GPT_PIN_3A = IOC_PORT_MCU_PORT_EVENT6,
249  GPT_PIN_3B = IOC_PORT_MCU_PORT_EVENT7,
251 
257 {
261 
267 typedef enum GPTimerCC26XX_Edge
268 {
269  GPTimerCC26XX_POS_EDGE = GPT_CTL_TAEVENT_POS,
270  GPTimerCC26XX_NEG_EDGE = GPT_CTL_TAEVENT_NEG,
271  GPTimerCC26XX_BOTH_EDGES = GPT_CTL_TAEVENT_BOTH,
273 
274 
275 /* Forward declaration of GPTimer configuration */
277 
278 /* GPTimer handle is pointer to configuration structure */
280 
281 /* Interrupt bit vector. See GPTimerCC26XX_Interrupt for available interrupts */
282 typedef uint16_t GPTimerCC26XX_IntMask;
283 
284 /* Timer value */
285 typedef uint32_t GPTimerCC26XX_Value;
286 
287 /* Function prototype for interrupt callbacks */
288 typedef void (*GPTimerCC26XX_HwiFxn) (GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
289 
310 typedef struct GPTimerCC26XX_HWAttrs
311 {
313  uint32_t baseAddr;
315  uint8_t intNum;
325  uint8_t intPriority;
327  uint8_t powerMngrId;
329  GPTimerCC26XX_Part timer;
331  GPTimerCC26XX_PinMux pinMux;
333 
348 typedef struct GPTimerCC26XX_Object
349 {
350  GPTimerCC26XX_Width width;
351  bool isOpen[GPT_PARTS_COUNT];
352  HwiP_Struct hwi[GPT_PARTS_COUNT];
354  volatile bool powerConstraint[GPT_PARTS_COUNT];
356 
357 
379 {
382  GPTimerCC26XX_Part timerPart;
383 };
384 
393 typedef struct GPTimerCC26XX_Params
394 {
395  GPTimerCC26XX_Width width;
396  GPTimerCC26XX_Mode mode;
397  GPTimerCC26XX_DebugMode debugStallMode;
399 
400 
414 
431 extern GPTimerCC26XX_Handle GPTimerCC26XX_open(unsigned int index, const GPTimerCC26XX_Params *params);
432 
446 extern void GPTimerCC26XX_close(GPTimerCC26XX_Handle handle);
447 
458 extern void GPTimerCC26XX_start(GPTimerCC26XX_Handle handle);
459 
470 extern void GPTimerCC26XX_stop(GPTimerCC26XX_Handle handle);
471 
483 extern void GPTimerCC26XX_setLoadValue(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value loadValue);
484 
496 extern void GPTimerCC26XX_setMatchValue(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value matchValue);
497 
498 
511 extern void GPTimerCC26XX_setCaptureEdge(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Edge edge);
512 
524 extern GPTimerCC26XX_Value GPTimerCC26XX_getFreeRunValue(GPTimerCC26XX_Handle handle);
525 
543 extern GPTimerCC26XX_Value GPTimerCC26XX_getValue(GPTimerCC26XX_Handle handle);
544 
545 
573 extern void GPTimerCC26XX_registerInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_HwiFxn callback, GPTimerCC26XX_IntMask intMask);
574 
590 extern void GPTimerCC26XX_unregisterInterrupt(GPTimerCC26XX_Handle handle);
591 
605 extern void GPTimerCC26XX_enableInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
617 extern void GPTimerCC26XX_disableInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
618 
630 extern void GPTimerCC26XX_configureDebugStall(GPTimerCC26XX_Handle handle, GPTimerCC26XX_DebugMode mode);
631 
647 static inline GPTimerCC26XX_PinMux GPTimerCC26XX_getPinMux(GPTimerCC26XX_Handle handle)
648 {
649  return handle->hwAttrs->pinMux;
650 }
651 
652 
653 #ifdef __cplusplus
654 }
655 #endif
656 #endif /* ti_drivers_timer_GPTIMERCC26XX__include */
uint32_t GPTimerCC26XX_Value
Definition: GPTimerCC26XX.h:285
GPTimerCC26XX_DebugMode debugStallMode
Definition: GPTimerCC26XX.h:397
GPTimerCC26XX_DebugMode
Definitions for controlling timer debug stall mode.
Definition: GPTimerCC26XX.h:256
Definition: GPTimerCC26XX.h:211
Definition: GPTimerCC26XX.h:167
struct GPTimerCC26XX_Object GPTimerCC26XX_Object
GPTimer26XX Object.
Definition: GPTimerCC26XX.h:227
uint8_t intNum
Definition: GPTimerCC26XX.h:315
Definition: GPTimerCC26XX.h:259
uint8_t intPriority
Definition: GPTimerCC26XX.h:325
GPTimerCC26XX Parameters.
Definition: GPTimerCC26XX.h:393
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:179
Definition: GPTimerCC26XX.h:212
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...
uint16_t GPTimerCC26XX_IntMask
Definition: GPTimerCC26XX.h:282
void GPTimerCC26XX_disableInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
Function to disable a set of GPTimer interrupt sources.
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:647
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:246
uint8_t powerMngrId
Definition: GPTimerCC26XX.h:327
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:240
Definition: GPTimerCC26XX.h:245
GPTimerCC26XX_Config * GPTimerCC26XX_Handle
Definition: GPTimerCC26XX.h:279
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:244
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:271
uint32_t baseAddr
Definition: GPTimerCC26XX.h:313
Definition: GPTimerCC26XX.h:247
struct GPTimerCC26XX_HWAttrs GPTimerCC26XX_HWAttrs
GPTimer26XX Hardware attributes.
GPTimerCC26XX_Mode mode
Definition: GPTimerCC26XX.h:396
Definition: GPTimerCC26XX.h:249
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:258
Definition: GPTimerCC26XX.h:210
Definition: GPTimerCC26XX.h:269
Definition: GPTimerCC26XX.h:243
GPTimer26XX Object.
Definition: GPTimerCC26XX.h:348
GPTimerCC26XX_Part timer
Definition: GPTimerCC26XX.h:329
GPTimer Global configuration.
Definition: GPTimerCC26XX.h:378
#define GPT_PARTS_COUNT
Definition: GPTimerCC26XX.h:230
Definition: GPTimerCC26XX.h:168
GPTimerCC26XX_Edge
Definitions for controlling edges used for timer capture. Used in GPTimer edge-time and edge-count mo...
Definition: GPTimerCC26XX.h:267
GPTimerCC26XX_Width width
Definition: GPTimerCC26XX.h:350
Definition: GPTimerCC26XX.h:195
GPTimer26XX Hardware attributes.
Definition: GPTimerCC26XX.h:310
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:182
Definition: GPTimerCC26XX.h:248
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:331
GPTimerCC26XX_Part
Definitions for GPTimer parts (Timer A / Timer B). Used in GPTimer configuration structure GPTimerCC2...
Definition: GPTimerCC26XX.h:224
Definition: GPTimerCC26XX.h:270
Definition: GPTimerCC26XX.h:226
void(* GPTimerCC26XX_HwiFxn)(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
Definition: GPTimerCC26XX.h:288
GPTimerCC26XX_Interrupt
Definitions for supported GPTimer interrupts. GPTimerCC26XX_IntMask arguments should be a bit vector ...
Definition: GPTimerCC26XX.h:207
void GPTimerCC26XX_stop(GPTimerCC26XX_Handle handle)
Function to stop the specified GPTimer.
GPTimerCC26XX_Part timerPart
Definition: GPTimerCC26XX.h:382
GPTimerCC26XX_Width
Definitions for specifying the GPTimer configuration (width)
Definition: GPTimerCC26XX.h:165
GPTimerCC26XX_Width width
Definition: GPTimerCC26XX.h:395
Definition: GPTimerCC26XX.h:191
Definition: GPTimerCC26XX.h:185
Definition: GPTimerCC26XX.h:242
GPTimerCC26XX_Object * object
Definition: GPTimerCC26XX.h:380
void GPTimerCC26XX_Params_init(GPTimerCC26XX_Params *params)
Function to initialize the GPTimerCC26XX_Params struct to its default values.
Definition: GPTimerCC26XX.h:209
const GPTimerCC26XX_HWAttrs * hwAttrs
Definition: GPTimerCC26XX.h:381
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:188
Copyright 2018, Texas Instruments Incorporated