GPTimerCC26XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, 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(UArg a0, UArg 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 <xdc/std.h>
150 #include <stdint.h>
151 #include <stdbool.h>
152 #include <stddef.h>
153 
154 //#include <ti/sysbios/family/arm/cc26xx/Power.h>
155 #include <ti/sysbios/family/arm/m3/Hwi.h>
156 
157 #ifdef DEVICE_FAMILY
158  #undef DEVICE_FAMILY_PATH
159  #define DEVICE_FAMILY_PATH(x) <ti/devices/DEVICE_FAMILY/x>
160 #else
161  #error "You must define DEVICE_FAMILY at the project level as one of cc26x0, cc26x0r2, cc13x0, etc."
162 #endif
163 
164 #include DEVICE_FAMILY_PATH(inc/hw_gpt.h)
165 #include DEVICE_FAMILY_PATH(driverlib/event.h)
166 #include DEVICE_FAMILY_PATH(driverlib/ioc.h)
167 #include DEVICE_FAMILY_PATH(driverlib/timer.h)
168 
174 {
175  GPT_CONFIG_32BIT = GPT_CFG_CFG_32BIT_TIMER,
176  GPT_CONFIG_16BIT = GPT_CFG_CFG_16BIT_TIMER,
178 
187 typedef enum GPTimerCC26XX_Mode
188 {
189  /* One shot mode counting upwards */
190  GPT_MODE_ONESHOT_UP = GPT_TAMR_TAMR_ONE_SHOT | GPT_TAMR_TACDIR_UP | \
191  GPT_TAMR_TAMIE,
192  /* Periodic mode counting upwards */
193  GPT_MODE_PERIODIC_UP = GPT_TAMR_TAMR_PERIODIC | GPT_TAMR_TACDIR_UP | \
194  GPT_TAMR_TAMIE,
195  /* Edge count mode counting upwards */
196  GPT_MODE_EDGE_COUNT_UP = GPT_TAMR_TAMR_CAPTURE | GPT_TAMR_TACDIR_UP | \
197  GPT_TAMR_TACM_EDGCNT,
198  /* Edge count mode counting upwards */
199  GPT_MODE_EDGE_TIME_UP = GPT_TAMR_TAMR_CAPTURE | GPT_TAMR_TACDIR_UP | \
200  GPT_TAMR_TACM_EDGTIME,
201  /* PWM mode counting downwards. This specific configuration is used by the
202  PWM2TimerCC26XX driver */
203  GPT_MODE_PWM = GPT_TAMR_TAMR_PERIODIC | GPT_TAMR_TACDIR_UP | \
204  GPT_TAMR_TAAMS_PWM | GPT_TAMR_TACM_EDGCNT | \
205  GPT_TAMR_TAPLO_CCP_ON_TO | GPT_TAMR_TAPWMIE_EN | \
206  GPT_TAMR_TAMRSU_CYCLEUPDATE,
208 
216 {
217  GPT_INT_TIMEOUT = 1 << 0,
219  GPT_INT_CAPTURE = 1 << 2,
220  GPT_INT_MATCH = 1 << 3,
222 
223 /* Number of entries in GPTimerCC26XX_Interrupt */
224 #define GPT_NUM_INTS 4
225 
232 typedef enum GPTimerCC26XX_Part
233 {
234  GPT_A = 0,
238 
248 {
249  GPT_PIN_0A = IOC_PORT_MCU_PORT_EVENT0,
250  GPT_PIN_0B = IOC_PORT_MCU_PORT_EVENT1,
251  GPT_PIN_1A = IOC_PORT_MCU_PORT_EVENT2,
252  GPT_PIN_1B = IOC_PORT_MCU_PORT_EVENT3,
253  GPT_PIN_2A = IOC_PORT_MCU_PORT_EVENT4,
254  GPT_PIN_2B = IOC_PORT_MCU_PORT_EVENT5,
255  GPT_PIN_3A = IOC_PORT_MCU_PORT_EVENT6,
256  GPT_PIN_3B = IOC_PORT_MCU_PORT_EVENT7,
258 
264 {
268 
274 typedef enum GPTimerCC26XX_Edge
275 {
276  GPTimerCC26XX_POS_EDGE = GPT_CTL_TAEVENT_POS,
277  GPTimerCC26XX_NEG_EDGE = GPT_CTL_TAEVENT_NEG,
278  GPTimerCC26XX_BOTH_EDGES = GPT_CTL_TAEVENT_BOTH,
280 
281 
282 /* Forward declaration of GPTimer configuration */
284 
285 /* GPTimer handle is pointer to configuration structure */
287 
288 /* Interrupt bit vector. See GPTimerCC26XX_Interrupt for available interrupts */
289 typedef uint16_t GPTimerCC26XX_IntMask;
290 
291 /* Timer value */
292 typedef uint32_t GPTimerCC26XX_Value;
293 
294 /* Function prototype for interrupt callbacks */
295 typedef void (*GPTimerCC26XX_HwiFxn) (GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
296 
317 typedef struct GPTimerCC26XX_HWAttrs
318 {
320  uint32_t baseAddr;
322  uint8_t intNum;
332  uint8_t intPriority;
334  uint8_t powerMngrId;
336  GPTimerCC26XX_Part timer;
338  GPTimerCC26XX_PinMux pinMux;
340 
355 typedef struct GPTimerCC26XX_Object
356 {
357  GPTimerCC26XX_Width width;
358  bool isOpen[GPT_PARTS_COUNT];
359  Hwi_Struct hwi[GPT_PARTS_COUNT];
361  volatile bool powerConstraint[GPT_PARTS_COUNT];
363 
364 
386 {
389  GPTimerCC26XX_Part timerPart;
390 };
391 
400 typedef struct GPTimerCC26XX_Params
401 {
402  GPTimerCC26XX_Width width;
403  GPTimerCC26XX_Mode mode;
404  GPTimerCC26XX_DebugMode debugStallMode;
406 
407 
421 
438 extern GPTimerCC26XX_Handle GPTimerCC26XX_open(unsigned int index, const GPTimerCC26XX_Params *params);
439 
453 extern void GPTimerCC26XX_close(GPTimerCC26XX_Handle handle);
454 
465 extern void GPTimerCC26XX_start(GPTimerCC26XX_Handle handle);
466 
477 extern void GPTimerCC26XX_stop(GPTimerCC26XX_Handle handle);
478 
490 extern void GPTimerCC26XX_setLoadValue(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value loadValue);
491 
503 extern void GPTimerCC26XX_setMatchValue(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value matchValue);
504 
505 
518 extern void GPTimerCC26XX_setCaptureEdge(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Edge edge);
519 
531 extern GPTimerCC26XX_Value GPTimerCC26XX_getFreeRunValue(GPTimerCC26XX_Handle handle);
532 
550 extern GPTimerCC26XX_Value GPTimerCC26XX_getValue(GPTimerCC26XX_Handle handle);
551 
552 
580 extern void GPTimerCC26XX_registerInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_HwiFxn callback, GPTimerCC26XX_IntMask intMask);
581 
597 extern void GPTimerCC26XX_unregisterInterrupt(GPTimerCC26XX_Handle handle);
598 
612 extern void GPTimerCC26XX_enableInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
624 extern void GPTimerCC26XX_disableInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
625 
637 extern void GPTimerCC26XX_configureDebugStall(GPTimerCC26XX_Handle handle, GPTimerCC26XX_DebugMode mode);
638 
654 static inline GPTimerCC26XX_PinMux GPTimerCC26XX_getPinMux(GPTimerCC26XX_Handle handle)
655 {
656  return handle->hwAttrs->pinMux;
657 }
658 
659 
660 #ifdef __cplusplus
661 }
662 #endif
663 #endif /* ti_drivers_timer_GPTIMERCC26XX__include */
uint32_t GPTimerCC26XX_Value
Definition: GPTimerCC26XX.h:292
GPTimerCC26XX_DebugMode debugStallMode
Definition: GPTimerCC26XX.h:404
GPTimerCC26XX_DebugMode
Definitions for controlling timer debug stall mode.
Definition: GPTimerCC26XX.h:263
Definition: GPTimerCC26XX.h:219
Definition: GPTimerCC26XX.h:236
Definition: GPTimerCC26XX.h:175
struct GPTimerCC26XX_Object GPTimerCC26XX_Object
GPTimer26XX Object.
Definition: GPTimerCC26XX.h:235
uint8_t intNum
Definition: GPTimerCC26XX.h:322
Definition: GPTimerCC26XX.h:266
uint8_t intPriority
Definition: GPTimerCC26XX.h:332
GPTimerCC26XX Parameters.
Definition: GPTimerCC26XX.h:400
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:187
Definition: GPTimerCC26XX.h:220
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:289
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...
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:253
uint8_t powerMngrId
Definition: GPTimerCC26XX.h:334
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:247
Definition: GPTimerCC26XX.h:252
GPTimerCC26XX_Config * GPTimerCC26XX_Handle
Definition: GPTimerCC26XX.h:286
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:251
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:278
uint32_t baseAddr
Definition: GPTimerCC26XX.h:320
Definition: GPTimerCC26XX.h:254
struct GPTimerCC26XX_HWAttrs GPTimerCC26XX_HWAttrs
GPTimer26XX Hardware attributes.
GPTimerCC26XX_Mode mode
Definition: GPTimerCC26XX.h:403
Definition: GPTimerCC26XX.h:256
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:265
Definition: GPTimerCC26XX.h:218
Definition: GPTimerCC26XX.h:276
Definition: GPTimerCC26XX.h:250
GPTimer26XX Object.
Definition: GPTimerCC26XX.h:355
GPTimerCC26XX_Part timer
Definition: GPTimerCC26XX.h:336
GPTimer Global configuration.
Definition: GPTimerCC26XX.h:385
Definition: GPTimerCC26XX.h:176
GPTimerCC26XX_Edge
Definitions for controlling edges used for timer capture. Used in GPTimer edge-time and edge-count mo...
Definition: GPTimerCC26XX.h:274
GPTimerCC26XX_Width width
Definition: GPTimerCC26XX.h:357
Definition: GPTimerCC26XX.h:203
GPTimer26XX Hardware attributes.
Definition: GPTimerCC26XX.h:317
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:190
Definition: GPTimerCC26XX.h:255
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:338
GPTimerCC26XX_Part
Definitions for GPTimer parts (Timer A / Timer B). Used in GPTimer configuration structure GPTimerCC2...
Definition: GPTimerCC26XX.h:232
Definition: GPTimerCC26XX.h:277
Definition: GPTimerCC26XX.h:234
void(* GPTimerCC26XX_HwiFxn)(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
Definition: GPTimerCC26XX.h:295
GPTimerCC26XX_Interrupt
Definitions for supported GPTimer interrupts. GPTimerCC26XX_IntMask arguments should be a bit vector ...
Definition: GPTimerCC26XX.h:215
void GPTimerCC26XX_stop(GPTimerCC26XX_Handle handle)
Function to stop the specified GPTimer.
GPTimerCC26XX_Part timerPart
Definition: GPTimerCC26XX.h:389
GPTimerCC26XX_Width
Definitions for specifying the GPTimer configuration (width)
Definition: GPTimerCC26XX.h:173
GPTimerCC26XX_Width width
Definition: GPTimerCC26XX.h:402
Definition: GPTimerCC26XX.h:199
Definition: GPTimerCC26XX.h:193
Definition: GPTimerCC26XX.h:249
GPTimerCC26XX_Object * object
Definition: GPTimerCC26XX.h:387
void GPTimerCC26XX_Params_init(GPTimerCC26XX_Params *params)
Function to initialize the GPTimerCC26XX_Params struct to its default values.
Definition: GPTimerCC26XX.h:217
const GPTimerCC26XX_HWAttrs * hwAttrs
Definition: GPTimerCC26XX.h:388
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:196
Copyright 2017, Texas Instruments Incorporated