TI-RTOS Drivers  tidrivers_full_2_20_00_08
PWMTimerCC26XX.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 PWMTimerCC26XX.h
34  * @brief PWM driver implementation for CC26XX/CC13XX
35  *
36  * # Overview #
37  * The general PWM API should be used in application code, i.e. PWM_open()
38  * should be used instead of PWMTimerCC26XX_open(). The board file will define the device
39  * specific config, and casting in the general API will ensure that the correct
40  * device specific functions are called.
41  *
42  * # General Behavior #
43  * Before using PWM on CC26XX:
44  * - The Timer HW is configured and system dependencies (for example IOs,
45  * power, etc.) is set by calling PWM_open().
46  *
47  * # Error handling #
48  * If providing unsupported arguments to an API returning an error code, the
49  * PWM configuration will *not* be updated and PWM will stay in the mode it
50  * was already configured to.
51  *
52  * # Power Management #
53  * The TI-RTOS power management framework will try to put the device into the most
54  * power efficient mode whenever possible. Please see the technical reference
55  * manual for further details on each power mode.
56  *
57  * The PWMTimerCC26XX.h driver is not explicitly setting a power constraint when the
58  * PWM is running to prevent standby as this is assumed to be done in the
59  * underlying GPTimer driver.
60  * The following statements are valid:
61  * - After PWM_open(): The device is still allowed to enter Standby. When the
62  * device is active the underlying GPTimer peripheral will
63  * be enabled and clocked.
64  * - After PWM_start(): The device can only go to Idle power mode since the
65  * high-frequency clock is needed for PWM operation:
66  * - After PWM_stop(): Conditions are equal as for after PWM_open
67  * - After PWM_close(): The underlying GPTimer is turned off and the device
68  * is allowed to go to standby.
69  *
70  * # Accuracy #
71  * The PWM output period and duty cycle are limited by the underlying timer.
72  * In PWM mode the timer is effectively 24 bits which results in a minimum
73  * frequency of 48MHz / (2^24-1) = 2.86Hz (349.525ms)
74  * The driver will round off the configured duty and period to a value limited
75  * by the timer resolution and the application is responsible for selecting
76  * duty and period that works with the underlying timer if high accuracy is
77  * needed.
78  * The effect of this is most visible when using high output frequencies as the
79  * available duty cycle resolution is reduced correspondingly. For a 24MHz PWM
80  * only a 0%/50%/100% duty is available as the timer uses only counts 0 and 1.
81  * Similarly for a 12MHz period the duty cycle will be limited to a 12.5%
82  * resolution.
83  * The PWM signals are generated using the high-frequency clock as source.
84  *
85  * If very high-accuracy outputs are needed, the application should request
86  * using the external HF crystal:
87  * @code
88  * #include <ti/sysbios/family/arm/cc26xx/Power.h>
89  * #include <ti/sysbios/family/arm/cc26xx/PowerCC2650.h>
90  * Power_setDependency(XOSC_HF);
91  * @endcode
92  *
93  * # Limitations #
94  * - The PWM output can currently not be synchronized with other PWM outputs
95  * - The PWM driver does not support updating duty and period using DMA.
96  * - When changing duty cycle there will be a period where the high level is
97  * either too short or too high since the timer match value is updated.
98  * # PWM usage #
99  *
100  * ## Basic PWM output ##
101  * The below example will output a 8MHz PWM signal with 50% duty cycle.
102  * @code
103  * void taskFxn(UArg a0, UArg a1) {
104  * PWM_Handle hPWM;
105  * PWM_Params pp;
106  * PWM_Params_init(&pp);
107  * pp.idleLevel = PWM_IDLE_LOW;
108  * pp.period.unit = PWM_PERIOD_HZ;
109  * pp.period.value = 8e6;
110  * pp.duty.unit = PWM_DUTY_FRACTION;
111  * pp.duty.value = PWM_DUTY_FRACTION_MAX / 2;
112  * hPWM = PWM_open(Board_PWM0);
113  * if(hPWM == NULL) {
114  * Log_error0("Failed to open PWM");
115  * Task_exit();
116  * }
117  * PWM_start(hPWM);
118  *
119  * while(1) {
120  * Task_sleep(BIOS_WAIT_FOREVER);
121  * }
122  * @endcode
123  *
124  *
125  *******************************************************************************
126  */
127 #ifndef ti_drivers_pwm__PWMTimerCC26XX_include
128 #define ti_drivers_pwm__PWMTimerCC26XX_include
129 
130 #ifdef __cplusplus
131 extern "C" {
132 #endif
133 
134 #include <stdint.h>
135 #include <stdbool.h>
136 
137 #include <ti/drivers/PIN.h>
138 #include <ti/drivers/PWM.h>
140 
141 
147 #define PWMTimerCC26XX_CMD_DEBUG_STALL PWM_CMD_RESERVED + 0
148 /* Arguments for PWMTimerCC26XX_CMD_DEBUG_STALL */
149 #define CMD_ARG_DEBUG_STALL_OFF (uint32_t)GPTimerCC26XX_DEBUG_STALL_OFF
150 #define CMD_ARG_DEBUG_STALL_ON (uint32_t)GPTimerCC26XX_DEBUG_STALL_ON
151 
172 typedef const struct PWMTimerCC26XX_HwAttrs
173 {
175  uint8_t gpTimerUnit;
177 
192 typedef struct PWMTimerCC26XX_Object
193 {
194  bool isOpen;
196  uint32_t periodValue;
197  uint32_t periodCounts;
199  uint32_t dutyValue;
200  uint32_t dutyCounts;
204 
205 #ifdef __cplusplus
206 }
207 #endif
208 #endif /* ti_driver_pwm_PWMTimerCC26XX_include */
uint8_t PIN_Id
Pin identifier data type.
Definition: PIN.h:557
PWM_IdleLevel idleLevel
Definition: PWMTimerCC26XX.h:201
bool isOpen
Definition: PWMTimerCC26XX.h:194
GPTimer driver implementation for CC26XX/CC13XX.
PWM_Period_Units periodUnit
Definition: PWMTimerCC26XX.h:195
PWMTimer26XX Object.
Definition: PWMTimerCC26XX.h:192
PWM_Duty_Units
PWM duty cycle unit definitions. Refer to device specific implementation if using PWM_DUTY_COUNTS (ra...
Definition: PWM.h:237
uint32_t periodCounts
Definition: PWMTimerCC26XX.h:197
uint32_t dutyValue
Definition: PWMTimerCC26XX.h:199
PWM driver interface.
PWM_Period_Units
PWM period unit definitions. Refer to device specific implementation if using PWM_PERIOD_COUNTS (raw ...
Definition: PWM.h:227
PWMTimer26XX Hardware attributes.
Definition: PWMTimerCC26XX.h:172
struct PWMTimerCC26XX_Object PWMTimerCC26XX_Object
PWMTimer26XX Object.
uint32_t periodValue
Definition: PWMTimerCC26XX.h:196
uint8_t gpTimerUnit
Definition: PWMTimerCC26XX.h:175
GPTimerCC26XX_Handle hTimer
Definition: PWMTimerCC26XX.h:202
PWM_Duty_Units dutyUnit
Definition: PWMTimerCC26XX.h:198
GPTimer Global configuration.
Definition: GPTimerCC26XX.h:379
const struct PWMTimerCC26XX_HwAttrs PWMTimerCC26XX_HwAttrs
PWMTimer26XX Hardware attributes.
PIN_Id pwmPin
Definition: PWMTimerCC26XX.h:174
uint32_t dutyCounts
Definition: PWMTimerCC26XX.h:200
PWM_IdleLevel
Idle output level when PWM is not running (stopped / not started).
Definition: PWM.h:246
Generic PIN & GPIO driver.
Copyright 2016, Texas Instruments Incorporated