TI-RTOS Drivers  tidrivers_full_2_20_00_08
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 #include <driverlib/event.h>
158 #include <driverlib/ioc.h>
159 #include <driverlib/timer.h>
160 #include <inc/hw_gpt.h>
161 
162 
168 {
169  GPT_CONFIG_32BIT = GPT_CFG_CFG_32BIT_TIMER,
170  GPT_CONFIG_16BIT = GPT_CFG_CFG_16BIT_TIMER,
172 
181 typedef enum GPTimerCC26XX_Mode
182 {
183  /* One shot mode counting upwards */
184  GPT_MODE_ONESHOT_UP = GPT_TAMR_TAMR_ONE_SHOT | GPT_TAMR_TACDIR_UP | \
185  GPT_TAMR_TAMIE,
186  /* Periodic mode counting upwards */
187  GPT_MODE_PERIODIC_UP = GPT_TAMR_TAMR_PERIODIC | GPT_TAMR_TACDIR_UP | \
188  GPT_TAMR_TAMIE,
189  /* Edge count mode counting upwards */
190  GPT_MODE_EDGE_COUNT_UP = GPT_TAMR_TAMR_CAPTURE | GPT_TAMR_TACDIR_UP | \
191  GPT_TAMR_TACM_EDGCNT,
192  /* Edge count mode counting upwards */
193  GPT_MODE_EDGE_TIME_UP = GPT_TAMR_TAMR_CAPTURE | GPT_TAMR_TACDIR_UP | \
194  GPT_TAMR_TACM_EDGTIME,
195  /* PWM mode counting downwards. This specific configuration is used by the
196  PWM2TimerCC26XX driver */
197  GPT_MODE_PWM = GPT_TAMR_TAMR_PERIODIC | GPT_TAMR_TACDIR_UP | \
198  GPT_TAMR_TAAMS_PWM | GPT_TAMR_TACM_EDGCNT | \
199  GPT_TAMR_TAPLO_CCP_ON_TO | GPT_TAMR_TAPWMIE_EN | \
200  GPT_TAMR_TAMRSU_CYCLEUPDATE,
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,
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 
268 typedef enum GPTimerCC26XX_Edge
269 {
270  GPTimerCC26XX_POS_EDGE = GPT_CTL_TAEVENT_POS,
271  GPTimerCC26XX_NEG_EDGE = GPT_CTL_TAEVENT_NEG,
272  GPTimerCC26XX_BOTH_EDGES = GPT_CTL_TAEVENT_BOTH,
274 
275 
276 /* Forward declaration of GPTimer configuration */
278 
279 /* GPTimer handle is pointer to configuration structure */
281 
282 /* Interrupt bit vector. See GPTimerCC26XX_Interrupt for available interrupts */
283 typedef uint16_t GPTimerCC26XX_IntMask;
284 
285 /* Timer value */
286 typedef uint32_t GPTimerCC26XX_Value;
287 
288 /* Function prototype for interrupt callbacks */
289 typedef void (*GPTimerCC26XX_HwiFxn) (GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
290 
311 typedef struct GPTimerCC26XX_HWAttrs
312 {
314  uint32_t baseAddr;
316  uint8_t intNum;
326  uint8_t intPriority;
328  uint8_t powerMngrId;
334 
349 typedef struct GPTimerCC26XX_Object
350 {
353  Hwi_Struct hwi[GPT_PARTS_COUNT];
357 
358 
380 {
384 };
385 
394 typedef struct GPTimerCC26XX_Params
395 {
400 
401 
415 
432 extern GPTimerCC26XX_Handle GPTimerCC26XX_open(unsigned int index, const GPTimerCC26XX_Params *params);
433 
447 extern void GPTimerCC26XX_close(GPTimerCC26XX_Handle handle);
448 
459 extern void GPTimerCC26XX_start(GPTimerCC26XX_Handle handle);
460 
471 extern void GPTimerCC26XX_stop(GPTimerCC26XX_Handle handle);
472 
484 extern void GPTimerCC26XX_setLoadValue(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value loadValue);
485 
497 extern void GPTimerCC26XX_setMatchValue(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value matchValue);
498 
499 
512 extern void GPTimerCC26XX_setCaptureEdge(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Edge edge);
513 
525 extern GPTimerCC26XX_Value GPTimerCC26XX_getFreeRunValue(GPTimerCC26XX_Handle handle);
526 
544 extern GPTimerCC26XX_Value GPTimerCC26XX_getValue(GPTimerCC26XX_Handle handle);
545 
546 
574 extern void GPTimerCC26XX_registerInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_HwiFxn callback, GPTimerCC26XX_IntMask intMask);
575 
591 extern void GPTimerCC26XX_unregisterInterrupt(GPTimerCC26XX_Handle handle);
592 
606 extern void GPTimerCC26XX_enableInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
618 extern void GPTimerCC26XX_disableInterrupt(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
619 
631 extern void GPTimerCC26XX_configureDebugStall(GPTimerCC26XX_Handle handle, GPTimerCC26XX_DebugMode mode);
632 
648 static inline GPTimerCC26XX_PinMux GPTimerCC26XX_getPinMux(GPTimerCC26XX_Handle handle)
649 {
650  return handle->hwAttrs->pinMux;
651 }
652 
653 
654 #ifdef __cplusplus
655 }
656 #endif
657 #endif /* ti_drivers_timer_GPTIMERCC26XX__include */
uint32_t GPTimerCC26XX_Value
Definition: GPTimerCC26XX.h:286
bool isOpen[GPT_PARTS_COUNT]
Definition: GPTimerCC26XX.h:352
GPTimerCC26XX_DebugMode debugStallMode
Definition: GPTimerCC26XX.h:398
GPTimerCC26XX_DebugMode
Definitions for controlling timer debug stall mode.
Definition: GPTimerCC26XX.h:257
Definition: GPTimerCC26XX.h:213
Definition: GPTimerCC26XX.h:230
Definition: GPTimerCC26XX.h:169
struct GPTimerCC26XX_Object GPTimerCC26XX_Object
GPTimer26XX Object.
volatile bool powerConstraint[GPT_PARTS_COUNT]
Definition: GPTimerCC26XX.h:355
Definition: GPTimerCC26XX.h:229
uint8_t intNum
Definition: GPTimerCC26XX.h:316
Definition: GPTimerCC26XX.h:260
uint8_t intPriority
Definition: GPTimerCC26XX.h:326
GPTimerCC26XX Parameters.
Definition: GPTimerCC26XX.h:394
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:181
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...
uint16_t GPTimerCC26XX_IntMask
Definition: GPTimerCC26XX.h:283
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:247
uint8_t powerMngrId
Definition: GPTimerCC26XX.h:328
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:280
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:272
uint32_t baseAddr
Definition: GPTimerCC26XX.h:314
Hwi_Struct hwi[GPT_PARTS_COUNT]
Definition: GPTimerCC26XX.h:353
Definition: GPTimerCC26XX.h:248
struct GPTimerCC26XX_HWAttrs GPTimerCC26XX_HWAttrs
GPTimer26XX Hardware attributes.
GPTimerCC26XX_Mode mode
Definition: GPTimerCC26XX.h:397
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:212
Definition: GPTimerCC26XX.h:270
Definition: GPTimerCC26XX.h:244
GPTimer26XX Object.
Definition: GPTimerCC26XX.h:349
GPTimerCC26XX_Part timer
Definition: GPTimerCC26XX.h:330
GPTimer Global configuration.
Definition: GPTimerCC26XX.h:379
Definition: GPTimerCC26XX.h:170
GPTimerCC26XX_Edge
Definitions for controlling edges used for timer capture. Used in GPTimer edge-time and edge-count mo...
Definition: GPTimerCC26XX.h:268
GPTimerCC26XX_Width width
Definition: GPTimerCC26XX.h:351
Definition: GPTimerCC26XX.h:197
GPTimer26XX Hardware attributes.
Definition: GPTimerCC26XX.h:311
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:184
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:332
GPTimerCC26XX_Part
Definitions for GPTimer parts (Timer A / Timer B). Used in GPTimer configuration structure GPTimerCC2...
Definition: GPTimerCC26XX.h:226
Definition: GPTimerCC26XX.h:271
Definition: GPTimerCC26XX.h:228
void(* GPTimerCC26XX_HwiFxn)(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
Definition: GPTimerCC26XX.h:289
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:383
GPTimerCC26XX_Width
Definitions for specifying the GPTimer configuration (width)
Definition: GPTimerCC26XX.h:167
GPTimerCC26XX_Width width
Definition: GPTimerCC26XX.h:396
Definition: GPTimerCC26XX.h:193
Definition: GPTimerCC26XX.h:187
Definition: GPTimerCC26XX.h:243
GPTimerCC26XX_Object * object
Definition: GPTimerCC26XX.h:381
void GPTimerCC26XX_Params_init(GPTimerCC26XX_Params *params)
Function to initialize the GPTimerCC26XX_Params struct to its default values.
Definition: GPTimerCC26XX.h:211
const GPTimerCC26XX_HWAttrs * hwAttrs
Definition: GPTimerCC26XX.h:382
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_HwiFxn hwiCallbackFxn[GPT_PARTS_COUNT]
Definition: GPTimerCC26XX.h:354
Definition: GPTimerCC26XX.h:190
Copyright 2016, Texas Instruments Incorporated