PINCC26XX.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 /*!*****************************************************************************
34  * @file PINCC26XX.h
35  * @brief Device-specific pin & GPIO driver for CC26xx family [def]
36  *
37  * # Overview #
38  * This is the device-specific implementation of the generic PIN driver for the
39  * CC26xx family of devices.
40  *
41  * Refer to @ref PIN.h for a complete description of APIs & example of use.
42  *
43  *******************************************************************************
44  */
45 
46 #ifndef ti_drivers_PINCC26XX__include
47 #define ti_drivers_PINCC26XX__include
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 #include <stdint.h>
53 #include <stddef.h>
54 
55 #include <ti/sysbios/family/arm/m3/Hwi.h>
56 
57 #include <ti/drivers/PIN.h>
58 
59 #ifdef DEVICE_FAMILY
60  #undef DEVICE_FAMILY_PATH
61  #define DEVICE_FAMILY_PATH(x) <ti/devices/DEVICE_FAMILY/x>
62 #else
63  #error "You must define DEVICE_FAMILY at the project level as one of cc26x0, cc26x0r2, cc13x0, etc."
64 #endif
65 
66 #include DEVICE_FAMILY_PATH(driverlib/ioc.h)
67 #include DEVICE_FAMILY_PATH(driverlib/gpio.h)
68 
69 //------------------------------------------------------------------------------
70 // Internal function used to find the index of the rightmost set bit in
71 // efficient way
72 #if defined(__IAR_SYSTEMS_ICC__) || defined(DOXYGEN)
73  #include <intrinsics.h>
74 #endif
75 
76 __STATIC_INLINE uint32_t PIN_ctz(uint32_t x) {
77 #if defined(codered) || defined(gcc) || defined(sourcerygxx) || defined(__GNUC__)
78  return __builtin_ctz(x);
79 #elif defined(__IAR_SYSTEMS_ICC__) || defined(DOXYGEN)
80  return __CLZ(__RBIT(x));
81 #elif defined(rvmdk) || defined(__ARMCC_VERSION)
82  return __clz(__rbit(x));
83 #elif defined(__TI_COMPILER_VERSION__)
84  return __clz(__rbit(x));
85 #else
86  #error "Unsupported compiler used"
87 #endif
88 }
89 
90 //------------------------------------------------------------------------------
91 
92 // Constant that can be used to remove run-time checks for improved efficiency
93 // Activate through preprocessor define PIN_DISABLE_RUNTIME_CHECKS
94 #ifdef PIN_DISABLE_RUNTIME_CHECKS
95  #define PIN_CHKEN 0
96 #else
97  #define PIN_CHKEN 1
98 #endif
99 
108 #define PINCC26XX_INPUT_EN (1<<29)
109 #define PINCC26XX_HYSTERESIS (1<<30)
110 #define PINCC26XX_NOPULL (0x3<<13)
111 #define PINCC26XX_PULLUP (0x2<<13)
112 #define PINCC26XX_PULLDOWN (0x1<<13)
113 #define PINCC26XX_BM_INPUT_EN (0x01<<29)
114 #define PINCC26XX_BM_HYSTERESIS (0x01<<30)
115 #define PINCC26XX_BM_PULLING (0x03<<13)
116 #define PINCC26XX_BM_INPUT_MODE (PINCC26XX_BM_INPUT_EN|PINCC26XX_BM_HYSTERESIS| \
118  PINCC26XX_BM_PULLING)
119 
120 #define PINCC26XX_GPIO_OUTPUT_EN (1<<23)
121 #define PINCC26XX_GPIO_LOW (0<<22)
122 #define PINCC26XX_GPIO_HIGH (1<<22)
123 #define PINCC26XX_PUSHPULL (0x0<<25)
124 #define PINCC26XX_OPENDRAIN (0x2<<25)
125 #define PINCC26XX_OPENSOURCE (0x3<<25)
126 #define PINCC26XX_SLEWCTRL (1<<12)
127 #define PINCC26XX_DRVSTR_MIN (0x0<<8)
128 #define PINCC26XX_DRVSTR_MED (0x4<<8)
129 #define PINCC26XX_DRVSTR_MAX (0x8<<8)
130 #define PINCC26XX_BM_GPIO_OUTPUT_EN (1<<23)
131 #define PINCC26XX_BM_GPIO_OUTPUT_VAL (1<<22)
132 #define PINCC26XX_BM_OUTPUT_BUF (3<<25)
133 #define PINCC26XX_BM_SLEWCTRL (1<<12)
134 #define PINCC26XX_BM_DRVSTR (0xF<<8)
135 #define PINCC26XX_BM_GPIO_OUTPUT_MODE (PINCC26XX_BM_GPIO_OUTPUT_EN|PINCC26XX_BM_GPIO_OUTPUT_VAL)
137 #define PINCC26XX_BM_OUTPUT_MODE (PINCC26XX_BM_GPIO_OUTPUT_MODE|PINCC26XX_BM_OUTPUT_BUF| \
139  PINCC26XX_BM_SLEWCTRL|PINCC26XX_BM_DRVSTR)
140 
141 #define PINCC26XX_INV_INOUT (1<<24)
142 #define PINCC26XX_IRQ_DIS (0x0<<16)
143 #define PINCC26XX_IRQ_NEGEDGE (0x5<<16)
144 #define PINCC26XX_IRQ_POSEDGE (0x6<<16)
145 #define PINCC26XX_IRQ_BOTHEDGES (0x7<<16)
146 #define PINCC26XX_BM_INV_INOUT (1<<24)
147 #define PINCC26XX_BM_IRQ (0x7<<16)
148 
149 #define PINCC26XX_NO_WAKEUP (0<<27)
150 #define PINCC26XX_WAKEUP_POSEDGE (3<<27)
151 #define PINCC26XX_WAKEUP_NEGEDGE (2<<27)
152 #define PINCC26XX_BM_WAKEUP (3<<27)
153 
154 #define PINCC26XX_BM_IOCFG (PINCC26XX_BM_INPUT_MODE|PINCC26XX_BM_OUTPUT_BUF| \
156  PINCC26XX_BM_SLEWCTRL|PINCC26XX_BM_DRVSTR| \
157  PINCC26XX_BM_INV_INOUT|PINCC26XX_BM_IRQ|PINCC26XX_BM_WAKEUP)
158 #define PINCC26XX_BM_ALL (PINCC26XX_BM_IOCFG|PINCC26XX_BM_GPIO_OUTPUT_MODE)
160 
172 #define PINCC26XX_DIO0 0
173 #define PINCC26XX_DIO1 1
174 #define PINCC26XX_DIO2 2
175 #define PINCC26XX_DIO3 3
176 #define PINCC26XX_DIO4 4
177 #define PINCC26XX_DIO5 5
178 #define PINCC26XX_DIO6 6
179 #define PINCC26XX_DIO7 7
180 #define PINCC26XX_DIO8 8
181 #define PINCC26XX_DIO9 9
182 #define PINCC26XX_DIO10 10
183 #define PINCC26XX_DIO11 11
184 #define PINCC26XX_DIO12 12
185 #define PINCC26XX_DIO13 13
186 #define PINCC26XX_DIO14 14
187 #define PINCC26XX_DIO15 15
188 #define PINCC26XX_DIO16 16
189 #define PINCC26XX_DIO17 17
190 #define PINCC26XX_DIO18 18
191 #define PINCC26XX_DIO19 19
192 #define PINCC26XX_DIO20 20
193 #define PINCC26XX_DIO21 21
194 #define PINCC26XX_DIO22 22
195 #define PINCC26XX_DIO23 23
196 #define PINCC26XX_DIO24 24
197 #define PINCC26XX_DIO25 25
198 #define PINCC26XX_DIO26 26
199 #define PINCC26XX_DIO27 27
200 #define PINCC26XX_DIO28 28
201 #define PINCC26XX_DIO29 29
202 #define PINCC26XX_DIO30 30
203 #define PINCC26XX_DIO31 31
204 
208 // Array of handles, one per pin (pin id is index)
209 extern PIN_Handle PIN_HandleTable[];
210 
211 // Number of pins available on device
212 extern uint_t PIN_NumPins;
213 
216 __STATIC_INLINE uint_t PINCC26XX_getInputValue(PIN_Id pinId) {
217  return (HWREG(GPIO_BASE+GPIO_O_DIN31_0)>>pinId)&1;
218 }
219 
220 
221 /* @brief Fast/efficient version of #PIN_setOutputEnable()
222  * @note Does not include any checks on handle for efficiency reasons,
223  * use #PIN_setOutputEnable() for checked version
224  */
225 __STATIC_INLINE void PINCC26XX_setOutputEnable(PIN_Id pinId, bool bOutEn) {
226  uint32_t key = Hwi_disable();
227  HWREG(GPIO_BASE+GPIO_O_DOE31_0) =
228  ((HWREG(GPIO_BASE+GPIO_O_DOE31_0) & ~(1<<pinId)) | (bOutEn<<pinId));
229  Hwi_restore(key);
230 }
231 
232 
233 /* @brief Fast/efficient version of #PIN_setOutputValue()
234  * @note Does not include any checks on handle for efficiency reasons,
235  * use #PIN_setOutputValue() for checked version
236  */
237 __STATIC_INLINE void PINCC26XX_setOutputValue(PIN_Id pinId, uint_t val) {
238  HWREGB(GPIO_BASE+GPIO_O_DOUT3_0+pinId) = (val) ? 1 : 0;
239 }
240 
243 __STATIC_INLINE uint_t PINCC26XX_getOutputValue(PIN_Id pinId) {
244  return (HWREG(GPIO_BASE+GPIO_O_DOUT31_0)>>pinId)&1;
245 }
247 
248 __STATIC_INLINE void PINCC26XX_clrPendInterrupt(PIN_Id pinId) {
249  HWREG(GPIO_NONBUF_BASE+GPIO_O_EVFLAGS31_0) = (1<<pinId);
250 }
251 
254 __STATIC_INLINE uint_t PINCC26XX_getPortInputValue(PIN_Handle handle) {
255  // Only a single port on CC26xx
256  return HWREG(GPIO_BASE+GPIO_O_DIN31_0);
257 }
258 
261 __STATIC_INLINE uint_t PINCC26XX_getPortOutputValue(PIN_Handle handle) {
262  // Only a single port on CC26xx
263  return HWREG(GPIO_BASE+GPIO_O_DOUT31_0);
264 }
265 
266 
267 /* @brief Fast/efficient version of #PIN_setPortOutputValue()
268  * @note Does not include any checks on handle for efficiency reasons,
269  * use #PIN_setPortOutputValue() for checked version
270  */
271 __STATIC_INLINE void PINCC26XX_setPortOutputValue(PIN_Handle handle, uint_t bmOutVal) {
272  // Only a single port on CC26xx
273  HWREG(GPIO_BASE+GPIO_O_DOUTTGL31_0) =
274  (HWREG(GPIO_BASE+GPIO_O_DOUT31_0) ^ bmOutVal) & handle->bmPort;
275 }
276 
277 
278 /* @brief Fast/efficient version of #PIN_setPortOutputEnable()
279  * @note Does not include any checks on handle for efficiency reasons,
280  * use #PIN_setPortOutputEnable() for checked version
281  */
282 __STATIC_INLINE void PINCC26XX_setPortOutputEnable(PIN_Handle handle, uint_t bmOutEn) {
283  // Only a single port on CC26xx
284  uint32_t key = Hwi_disable();
285  HWREG(GPIO_BASE+GPIO_O_DOE31_0) =
286  (HWREG(GPIO_BASE+GPIO_O_DOE31_0) & (~handle->bmPort)) | (bmOutEn & handle->bmPort);
287  Hwi_restore(key);
288 }
289 
290 
299 
300 
316 extern PIN_Status PINCC26XX_setWakeup(const PIN_Config aPinCfg[]);
317 
318 
332 extern int_t PINCC26XX_getMux(PIN_Id pinId);
333 
340 
354 extern PIN_Status PINCC26XX_setMux(PIN_Handle handle, PIN_Id pinId, int32_t nMux);
355 
373 typedef struct PINCC26XX_HWAttrs{
387  uint8_t intPriority;
393  uint32_t swiPriority;
395 
403 #define PINCC26XX_MUX_GPIO IOC_PORT_GPIO // Default general purpose IO usage
404 #define PINCC26XX_MUX_AON_CLK32K IOC_PORT_AON_CLK32K // AON External 32kHz clock
405 #define PINCC26XX_MUX_AUX_IO IOC_PORT_AUX_IO // AUX IO Pin
406 #define PINCC26XX_MUX_MCU_SSI0_RX IOC_PORT_MCU_SSI0_RX // MCU SSI0 Receive Pin
407 #define PINCC26XX_MUX_MCU_SSI0_TX IOC_PORT_MCU_SSI0_TX // MCU SSI0 Transmit Pin
408 #define PINCC26XX_MUX_MCU_SSI0_FSS IOC_PORT_MCU_SSI0_FSS // MCU SSI0 FSS Pin
409 #define PINCC26XX_MUX_MCU_SSI0_CLK IOC_PORT_MCU_SSI0_CLK // MCU SSI0 Clock Pin
410 #define PINCC26XX_MUX_MCU_I2C_MSSDA IOC_PORT_MCU_I2C_MSSDA // MCU I2C Data Pin
411 #define PINCC26XX_MUX_MCU_I2C_MSSCL IOC_PORT_MCU_I2C_MSSCL // MCU I2C Clock Pin
412 #define PINCC26XX_MUX_MCU_UART0_RX IOC_PORT_MCU_UART0_RX // MCU UART0 Receive Pin
413 #define PINCC26XX_MUX_MCU_UART0_TX IOC_PORT_MCU_UART0_TX // MCU UART0 Transmit Pin
414 #define PINCC26XX_MUX_MCU_UART0_CTS IOC_PORT_MCU_UART0_CTS // MCU UART0 Clear To Send Pin
415 #define PINCC26XX_MUX_MCU_UART0_RTS IOC_PORT_MCU_UART0_RTS // MCU UART0 Request To Send Pin
416 #define PINCC26XX_MUX_MCU_PORT_EV_0 IOC_PORT_MCU_PORT_EVENT0 // MCU power event 0
417 #define PINCC26XX_MUX_MCU_PORT_EV_1 IOC_PORT_MCU_PORT_EVENT1 // MCU power event 1
418 #define PINCC26XX_MUX_MCU_PORT_EV_2 IOC_PORT_MCU_PORT_EVENT2 // MCU power event 2
419 #define PINCC26XX_MUX_MCU_PORT_EV_3 IOC_PORT_MCU_PORT_EVENT3 // MCU power event 3
420 #define PINCC26XX_MUX_MCU_PORT_EV_4 IOC_PORT_MCU_PORT_EVENT4 // MCU power event 4
421 #define PINCC26XX_MUX_MCU_PORT_EV_5 IOC_PORT_MCU_PORT_EVENT5 // MCU power event 5
422 #define PINCC26XX_MUX_MCU_PORT_EV_6 IOC_PORT_MCU_PORT_EVENT6 // MCU power event 6
423 #define PINCC26XX_MUX_MCU_PORT_EV_7 IOC_PORT_MCU_PORT_EVENT7 // MCU power event 7
424 #define PINCC26XX_MUX_SWV IOC_PORT_MCU_SWV // MCU serial wire viewer
425 #define PINCC26XX_MUX_MCU_SSI1_RX IOC_PORT_MCU_SSI1_RX // MCU SSI1 Receive Pin
426 #define PINCC26XX_MUX_MCU_SSI1_TX IOC_PORT_MCU_SSI1_TX // MCU SSI1 Transmit Pin
427 #define PINCC26XX_MUX_MCU_SSI1_FSS IOC_PORT_MCU_SSI1_FSS // MCU SSI1 FSS Pin
428 #define PINCC26XX_MUX_MCU_SSI1_CLK IOC_PORT_MCU_SSI1_CLK // MCU SSI1 Clock Pin
429 #define PINCC26XX_MUX_MCU_I2S_AD0 IOC_PORT_MCU_I2S_AD0 // MCU I2S Data Pin 0
430 #define PINCC26XX_MUX_MCU_I2S_AD1 IOC_PORT_MCU_I2S_AD1 // MCU I2S Data Pin 1
431 #define PINCC26XX_MUX_MCU_I2S_WCLK IOC_PORT_MCU_I2S_WCLK // MCU I2S Frame/Word Clock
432 #define PINCC26XX_MUX_MCU_I2S_BCLK IOC_PORT_MCU_I2S_BCLK // MCU I2S Bit Clock
433 #define PINCC26XX_MUX_MCU_I2S_MCLK IOC_PORT_MCU_I2S_MCLK // MCU I2S Master clock 2
434 #define PINCC26XX_MUX_RFC_TRC IOC_PORT_RFC_TRC // RF Core Tracer
435 #define PINCC26XX_MUX_RFC_GPO0 IOC_PORT_RFC_GPO0 // RC Core Data Out Pin 0
436 #define PINCC26XX_MUX_RFC_GPO1 IOC_PORT_RFC_GPO1 // RC Core Data Out Pin 1
437 #define PINCC26XX_MUX_RFC_GPO2 IOC_PORT_RFC_GPO2 // RC Core Data Out Pin 2
438 #define PINCC26XX_MUX_RFC_GPO3 IOC_PORT_RFC_GPO3 // RC Core Data Out Pin 3
439 #define PINCC26XX_MUX_RFC_GPI0 IOC_PORT_RFC_GPI0 // RC Core Data In Pin 0
440 #define PINCC26XX_MUX_RFC_GPI1 IOC_PORT_RFC_GPI1 // RC Core Data In Pin 1
441 #define PINCC26XX_MUX_RFC_SMI_DL_OUT IOC_PORT_RFC_SMI_DL_OUT // RF Core SMI Data Link Out
442 #define PINCC26XX_MUX_RFC_SMI_DL_IN IOC_PORT_RFC_SMI_DL_IN // RF Core SMI Data Link in
443 #define PINCC26XX_MUX_RFC_SMI_CL_OUT IOC_PORT_RFC_SMI_CL_OUT // RF Core SMI Command Link Out
444 #define PINCC26XX_MUX_RFC_SMI_CL_IN IOC_PORT_RFC_SMI_CL_IN // RF Core SMI Command Link In
445 
449 #ifdef __cplusplus
450 }
451 #endif
452 #endif /* ti_drivers_PINCC26XX__include */
uint_t bmPort
Bitmask for pins allocated in port.
Definition: PIN.h:689
uint8_t PIN_Id
Pin identifier data type.
Definition: PIN.h:557
uint_t PINCC26XX_getPinCount()
Get device-specific count of how many pins are available on this device and package.
__STATIC_INLINE void PINCC26XX_setOutputValue(PIN_Id pinId, uint_t val)
Definition: PINCC26XX.h:235
unsigned int uint_t
Definition: PIN.h:542
__STATIC_INLINE uint_t PINCC26XX_getPortInputValue(PIN_Handle handle)
Fast/efficient version of PIN_getPortInputValue()
Definition: PINCC26XX.h:252
PINCC26XX Hardware attributes.
Definition: PINCC26XX.h:371
uint8_t intPriority
SPI CC26XXDMA Peripheral&#39;s interrupt priority.
Definition: PINCC26XX.h:385
__STATIC_INLINE uint_t PINCC26XX_getPortOutputValue(PIN_Handle handle)
Fast/efficient version of PIN_getPortOutputValue()
Definition: PINCC26XX.h:259
PIN_Status PINCC26XX_setMux(PIN_Handle handle, PIN_Id pinId, int32_t nMux)
Connect pin to HW peripheral, signal or to GPIO.
int int_t
Definition: PIN.h:543
PIN_Handle PIN_HandleTable[]
__STATIC_INLINE uint_t PINCC26XX_getInputValue(PIN_Id pinId)
Fast/efficient version of PIN_getInputValue()
Definition: PINCC26XX.h:214
__STATIC_INLINE void PINCC26XX_clrPendInterrupt(PIN_Id pinId)
Definition: PINCC26XX.h:246
__STATIC_INLINE void PINCC26XX_setPortOutputValue(PIN_Handle handle, uint_t bmOutVal)
Definition: PINCC26XX.h:269
__STATIC_INLINE uint_t PINCC26XX_getOutputValue(PIN_Id pinId)
Fast/efficient version of PIN_getOutputValue()
Definition: PINCC26XX.h:241
PIN_Config PINCC26XX_getConfig(PIN_Id pinId)
Returns CC26xx device-specific pin configuration.
__STATIC_INLINE void PINCC26XX_setOutputEnable(PIN_Id pinId, bool bOutEn)
Definition: PINCC26XX.h:223
__STATIC_INLINE uint32_t PIN_ctz(uint32_t x)
Definition: PINCC26XX.h:76
underlying data structure for type PIN_State
Definition: PIN.h:687
uint_t PIN_NumPins
int_t PINCC26XX_getMux(PIN_Id pinId)
Get device-specific pin mapping to GPIO, HW peripheral or HW signal.
uint32_t swiPriority
SPI SWI priority. The higher the number, the higher the priority. The minimum is 0 and the maximum is...
Definition: PINCC26XX.h:391
PIN_Status
Return value for many functions in the PIN driver interface.
Definition: PIN.h:695
__STATIC_INLINE void PINCC26XX_setPortOutputEnable(PIN_Handle handle, uint_t bmOutEn)
Definition: PINCC26XX.h:280
struct PINCC26XX_HWAttrs PINCC26XX_HWAttrs
PINCC26XX Hardware attributes.
PIN_Status PINCC26XX_setWakeup(const PIN_Config aPinCfg[])
Configure wakeup (from shutdown) on pins.
uint32_t PIN_Config
Pin configuration data type with embedded pin identifier.
Definition: PIN.h:577
Generic PIN & GPIO driver.
Copyright 2017, Texas Instruments Incorporated