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 | GPT_TAMR_TAAMS_PWM | GPT_TAMR_TACM_EDGCNT |
199  GPT_TAMR_TAPLO_CCP_ON_TO,
201 
209 {
210  GPT_INT_TIMEOUT = 1 << 0,
212  GPT_INT_CAPTURE = 1 << 2,
213  GPT_INT_MATCH = 1 << 3,
215 
216 /* Number of entries in GPTimerCC26XX_Interrupt */
217 #define GPT_NUM_INTS 4
218 
225 typedef enum GPTimerCC26XX_Part
226 {
227  GPT_A = 0,
230 
231 #define GPT_PARTS_COUNT 2
232 
242 {
243  GPT_PIN_0A = IOC_PORT_MCU_PORT_EVENT0,
244  GPT_PIN_0B = IOC_PORT_MCU_PORT_EVENT1,
245  GPT_PIN_1A = IOC_PORT_MCU_PORT_EVENT2,
246  GPT_PIN_1B = IOC_PORT_MCU_PORT_EVENT3,
247  GPT_PIN_2A = IOC_PORT_MCU_PORT_EVENT4,
248  GPT_PIN_2B = IOC_PORT_MCU_PORT_EVENT5,
249  GPT_PIN_3A = IOC_PORT_MCU_PORT_EVENT6,
250  GPT_PIN_3B = IOC_PORT_MCU_PORT_EVENT7,
252 
258 {
262 
269 {
273 
284 {
288 
294 typedef enum GPTimerCC26XX_Edge
295 {
296  GPTimerCC26XX_POS_EDGE = GPT_CTL_TAEVENT_POS,
297  GPTimerCC26XX_NEG_EDGE = GPT_CTL_TAEVENT_NEG,
298  GPTimerCC26XX_BOTH_EDGES = GPT_CTL_TAEVENT_BOTH,
300 
301 /* Forward declaration of GPTimer configuration */
303 
304 /* GPTimer handle is pointer to configuration structure */
306 
307 /* Interrupt bit vector. See GPTimerCC26XX_Interrupt for available interrupts */
308 typedef uint16_t GPTimerCC26XX_IntMask;
309 
310 /* Timer value */
311 typedef uint32_t GPTimerCC26XX_Value;
312 
313 /* Function prototype for interrupt callbacks */
314 typedef void (*GPTimerCC26XX_HwiFxn)(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
315 
336 typedef struct GPTimerCC26XX_HWAttrs
337 {
339  uint32_t baseAddr;
341  uint8_t intNum;
351  uint8_t intPriority;
353  uint8_t powerMngrId;
355  GPTimerCC26XX_Part timer;
357  GPTimerCC26XX_PinMux pinMux;
359 
374 typedef struct GPTimerCC26XX_Object
375 {
376  GPTimerCC26XX_Width width;
377  bool isOpen[GPT_PARTS_COUNT];
378  HwiP_Struct hwi[GPT_PARTS_COUNT];
380  volatile bool powerConstraint[GPT_PARTS_COUNT];
381  uint32_t arg;
383 
405 {
408  GPTimerCC26XX_Part timerPart;
409 };
410 
419 typedef struct GPTimerCC26XX_Params
420 {
421  GPTimerCC26XX_Width width;
422  GPTimerCC26XX_Mode mode;
423  GPTimerCC26XX_SetMatchTiming matchTiming;
424  GPTimerCC26XX_Direction direction;
425  GPTimerCC26XX_DebugMode debugStallMode;
427 
441 
458 extern GPTimerCC26XX_Handle GPTimerCC26XX_open(unsigned int index, const GPTimerCC26XX_Params *params);
459 
473 extern void GPTimerCC26XX_close(GPTimerCC26XX_Handle handle);
474 
485 extern void GPTimerCC26XX_start(GPTimerCC26XX_Handle handle);
486 
497 extern void GPTimerCC26XX_stop(GPTimerCC26XX_Handle handle);
498 
510 extern void GPTimerCC26XX_setLoadValue(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value loadValue);
511 
523 extern void GPTimerCC26XX_setMatchValue(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value matchValue);
524 
537 extern void GPTimerCC26XX_setCaptureEdge(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Edge edge);
538 
550 extern GPTimerCC26XX_Value GPTimerCC26XX_getFreeRunValue(GPTimerCC26XX_Handle handle);
551 
569 extern GPTimerCC26XX_Value GPTimerCC26XX_getValue(GPTimerCC26XX_Handle handle);
570 
598 extern void GPTimerCC26XX_registerInterrupt(GPTimerCC26XX_Handle handle,
599  GPTimerCC26XX_HwiFxn callback,
600  GPTimerCC26XX_IntMask intMask);
601 
617 extern void GPTimerCC26XX_unregisterInterrupt(GPTimerCC26XX_Handle handle);
618 
632 extern void GPTimerCC26XX_enableInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
644 extern void GPTimerCC26XX_disableInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
645 
657 extern void GPTimerCC26XX_configureDebugStall(GPTimerCC26XX_Handle handle, GPTimerCC26XX_DebugMode mode);
658 
670 extern uint32_t GPTimerCC26XX_getArg(GPTimerCC26XX_Handle handle);
671 
683 extern void GPTimerCC26XX_setArg(GPTimerCC26XX_Handle handle, void *arg);
684 
700 static inline GPTimerCC26XX_PinMux GPTimerCC26XX_getPinMux(GPTimerCC26XX_Handle handle)
701 {
702  return handle->hwAttrs->pinMux;
703 }
704 
705 #ifdef __cplusplus
706 }
707 #endif
708 #endif /* ti_drivers_timer_GPTIMERCC26XX__include */
uint32_t GPTimerCC26XX_Value
Definition: GPTimerCC26XX.h:311
void GPTimerCC26XX_setArg(GPTimerCC26XX_Handle handle, void *arg)
Function to set a custom argument.
GPTimerCC26XX_DebugMode debugStallMode
Definition: GPTimerCC26XX.h:425
ADC_Params params
Definition: Driver_Init.h:11
Definition: GPTimerCC26XX.h:195
GPTimerCC26XX_DebugMode
Definitions for controlling timer debug stall mode.
Definition: GPTimerCC26XX.h:257
Definition: GPTimerCC26XX.h:212
Definition: GPTimerCC26XX.h:270
Definition: GPTimerCC26XX.h:174
struct GPTimerCC26XX_Object GPTimerCC26XX_Object
GPTimer26XX Object.
Definition: GPTimerCC26XX.h:228
uint8_t intNum
Definition: GPTimerCC26XX.h:341
uint32_t arg
Definition: GPTimerCC26XX.h:381
Definition: GPTimerCC26XX.h:260
uint8_t intPriority
Definition: GPTimerCC26XX.h:351
GPTimerCC26XX Parameters.
Definition: GPTimerCC26XX.h:419
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:213
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:271
uint16_t GPTimerCC26XX_IntMask
Definition: GPTimerCC26XX.h:308
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:268
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:700
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:247
uint8_t powerMngrId
Definition: GPTimerCC26XX.h:353
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:241
Definition: GPTimerCC26XX.h:246
GPTimerCC26XX_Config * GPTimerCC26XX_Handle
Definition: GPTimerCC26XX.h:305
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:245
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:298
uint32_t baseAddr
Definition: GPTimerCC26XX.h:339
Definition: GPTimerCC26XX.h:248
Definition: GPTimerCC26XX.h:286
struct GPTimerCC26XX_HWAttrs GPTimerCC26XX_HWAttrs
GPTimer26XX Hardware attributes.
GPTimerCC26XX_Mode mode
Definition: GPTimerCC26XX.h:422
Definition: GPTimerCC26XX.h:250
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:259
Definition: GPTimerCC26XX.h:211
GPTimerCC26XX_SetMatchTiming matchTiming
Definition: GPTimerCC26XX.h:423
Definition: GPTimerCC26XX.h:296
Definition: GPTimerCC26XX.h:244
GPTimer26XX Object.
Definition: GPTimerCC26XX.h:374
GPTimerCC26XX_Part timer
Definition: GPTimerCC26XX.h:355
GPTimerCC26XX_Direction direction
Definition: GPTimerCC26XX.h:424
GPTimer Global configuration.
Definition: GPTimerCC26XX.h:404
#define GPT_PARTS_COUNT
Definition: GPTimerCC26XX.h:231
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:294
GPTimerCC26XX_Width width
Definition: GPTimerCC26XX.h:376
Definition: GPTimerCC26XX.h:198
GPTimer26XX Hardware attributes.
Definition: GPTimerCC26XX.h:336
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:249
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:357
GPTimerCC26XX_Part
Definitions for GPTimer parts (Timer A / Timer B). Used in GPTimer configuration structure GPTimerCC2...
Definition: GPTimerCC26XX.h:225
Definition: GPTimerCC26XX.h:297
Definition: GPTimerCC26XX.h:227
void(* GPTimerCC26XX_HwiFxn)(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
Definition: GPTimerCC26XX.h:314
GPTimerCC26XX_Interrupt
Definitions for supported GPTimer interrupts. GPTimerCC26XX_IntMask arguments should be a bit vector ...
Definition: GPTimerCC26XX.h:208
void GPTimerCC26XX_stop(GPTimerCC26XX_Handle handle)
Function to stop the specified GPTimer.
GPTimerCC26XX_Part timerPart
Definition: GPTimerCC26XX.h:408
GPTimerCC26XX_Width
Definitions for specifying the GPTimer configuration (width)
Definition: GPTimerCC26XX.h:172
GPTimerCC26XX_Width width
Definition: GPTimerCC26XX.h:421
Definition: GPTimerCC26XX.h:243
GPTimerCC26XX_Object * object
Definition: GPTimerCC26XX.h:406
void GPTimerCC26XX_Params_init(GPTimerCC26XX_Params *params)
Function to initialize the GPTimerCC26XX_Params struct to its default values.
Definition: GPTimerCC26XX.h:210
Definition: GPTimerCC26XX.h:285
const GPTimerCC26XX_HWAttrs * hwAttrs
Definition: GPTimerCC26XX.h:407
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:283
© Copyright 1995-2022, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale