TI-RTOS for SimpleLink Wireless MCUs  2.14.03.28
PINCC26XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, 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  *******************************************************************************
42  */
43 
44 #ifndef ti_drivers_PINCC26XX__include
45 #define ti_drivers_PINCC26XX__include
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 #include <ti/drivers/PIN.h>
51 #include <driverlib/ioc.h>
52 #include <driverlib/gpio.h>
53 #include <ti/sysbios/family/arm/m3/Hwi.h>
54 
55 #include <stdint.h>
56 #include <stddef.h>
57 
58 
59 
60 //------------------------------------------------------------------------------
61 // Internal function used to find the index of the rightmost set bit in
62 // efficient way
63 #if defined(__IAR_SYSTEMS_ICC__) || defined(DOXYGEN)
64  #include <intrinsics.h>
65 #endif
66 
67 __STATIC_INLINE uint32_t PIN_ctz(uint32_t x) {
68 #if defined(codered) || defined(gcc) || defined(sourcerygxx) || defined(__GNUC__)
69  return __builtin_ctz(x);
70 #elif defined(__IAR_SYSTEMS_ICC__) || defined(DOXYGEN)
71  return __CLZ(__RBIT(x));
72 #elif defined(rvmdk) || defined(__ARMCC_VERSION)
73  return __clz(__rbit(x));
74 #elif defined(__TI_COMPILER_VERSION__)
75  return __clz(__rbit(x));
76 #else
77  #error "Unsupported compiler used"
78 #endif
79 }
80 
81 //------------------------------------------------------------------------------
82 
83 // Constant that can be used to remove run-time checks for improved efficiency
84 // Activate through preprocessor define PIN_DISABLE_RUNTIME_CHECKS
85 #ifdef PIN_DISABLE_RUNTIME_CHECKS
86  #define PIN_CHKEN 0
87 #else
88  #define PIN_CHKEN 1
89 #endif
90 
99 #define PINCC26XX_INPUT_EN (1<<29)
100 #define PINCC26XX_HYSTERESIS (1<<30)
101 #define PINCC26XX_NOPULL (0x3<<13)
102 #define PINCC26XX_PULLUP (0x2<<13)
103 #define PINCC26XX_PULLDOWN (0x1<<13)
104 #define PINCC26XX_BM_INPUT_EN (0x01<<29)
105 #define PINCC26XX_BM_HYSTERESIS (0x01<<30)
106 #define PINCC26XX_BM_PULLING (0x03<<13)
107 #define PINCC26XX_BM_INPUT_MODE (PINCC26XX_BM_INPUT_EN|PINCC26XX_BM_HYSTERESIS| \
109  PINCC26XX_BM_PULLING)
110 
111 #define PINCC26XX_GPIO_OUTPUT_EN (1<<23)
112 #define PINCC26XX_GPIO_LOW (0<<22)
113 #define PINCC26XX_GPIO_HIGH (1<<22)
114 #define PINCC26XX_PUSHPULL (0x0<<25)
115 #define PINCC26XX_OPENDRAIN (0x2<<25)
116 #define PINCC26XX_OPENSOURCE (0x3<<25)
117 #define PINCC26XX_SLEWCTRL (1<<12)
118 #define PINCC26XX_DRVSTR_MIN (0x0<<8)
119 #define PINCC26XX_DRVSTR_MED (0x4<<8)
120 #define PINCC26XX_DRVSTR_MAX (0x8<<8)
121 #define PINCC26XX_BM_GPIO_OUTPUT_EN (1<<23)
122 #define PINCC26XX_BM_GPIO_OUTPUT_VAL (1<<22)
123 #define PINCC26XX_BM_OUTPUT_BUF (3<<25)
124 #define PINCC26XX_BM_SLEWCTRL (1<<12)
125 #define PINCC26XX_BM_DRVSTR (0xF<<8)
126 #define PINCC26XX_BM_GPIO_OUTPUT_MODE (PINCC26XX_BM_GPIO_OUTPUT_EN|PINCC26XX_BM_GPIO_OUTPUT_VAL)
128 #define PINCC26XX_BM_OUTPUT_MODE (PINCC26XX_BM_GPIO_OUTPUT_MODE|PINCC26XX_BM_OUTPUT_BUF| \
130  PINCC26XX_BM_SLEWCTRL|PINCC26XX_BM_DRVSTR)
131 
132 #define PINCC26XX_INV_INOUT (1<<24)
133 #define PINCC26XX_IRQ_DIS (0x0<<16)
134 #define PINCC26XX_IRQ_NEGEDGE (0x5<<16)
135 #define PINCC26XX_IRQ_POSEDGE (0x6<<16)
136 #define PINCC26XX_IRQ_BOTHEDGES (0x7<<16)
137 #define PINCC26XX_BM_INV_INOUT (1<<24)
138 #define PINCC26XX_BM_IRQ (0x7<<16)
139 
140 #define PINCC26XX_NO_WAKEUP (0<<27)
141 #define PINCC26XX_WAKEUP_POSEDGE (3<<27)
142 #define PINCC26XX_WAKEUP_NEGEDGE (2<<27)
143 #define PINCC26XX_BM_WAKEUP (3<<27)
144 
145 #define PINCC26XX_BM_IOCFG (PINCC26XX_BM_INPUT_MODE|PINCC26XX_BM_OUTPUT_BUF| \
147  PINCC26XX_BM_SLEWCTRL|PINCC26XX_BM_DRVSTR| \
148  PINCC26XX_BM_INV_INOUT|PINCC26XX_BM_IRQ|PINCC26XX_BM_WAKEUP)
149 #define PINCC26XX_BM_ALL (PINCC26XX_BM_IOCFG|PINCC26XX_BM_GPIO_OUTPUT_MODE)
151 
163 #define PINCC26XX_DIO0 0
164 #define PINCC26XX_DIO1 1
165 #define PINCC26XX_DIO2 2
166 #define PINCC26XX_DIO3 3
167 #define PINCC26XX_DIO4 4
168 #define PINCC26XX_DIO5 5
169 #define PINCC26XX_DIO6 6
170 #define PINCC26XX_DIO7 7
171 #define PINCC26XX_DIO8 8
172 #define PINCC26XX_DIO9 9
173 #define PINCC26XX_DIO10 10
174 #define PINCC26XX_DIO11 11
175 #define PINCC26XX_DIO12 12
176 #define PINCC26XX_DIO13 13
177 #define PINCC26XX_DIO14 14
178 #define PINCC26XX_DIO15 15
179 #define PINCC26XX_DIO16 16
180 #define PINCC26XX_DIO17 17
181 #define PINCC26XX_DIO18 18
182 #define PINCC26XX_DIO19 19
183 #define PINCC26XX_DIO20 20
184 #define PINCC26XX_DIO21 21
185 #define PINCC26XX_DIO22 22
186 #define PINCC26XX_DIO23 23
187 #define PINCC26XX_DIO24 24
188 #define PINCC26XX_DIO25 25
189 #define PINCC26XX_DIO26 26
190 #define PINCC26XX_DIO27 27
191 #define PINCC26XX_DIO28 28
192 #define PINCC26XX_DIO29 29
193 #define PINCC26XX_DIO30 30
194 #define PINCC26XX_DIO31 31
195 
199 // Array of handles, one per pin (pin id is index)
200 extern PIN_Handle PIN_HandleTable[];
201 
202 // Number of pins available on device
203 extern uint_t PIN_NumPins;
204 
207 __STATIC_INLINE uint_t PINCC26XX_getInputValue(PIN_Id pinId) {
208  return (HWREG(GPIO_BASE+GPIO_O_DIN31_0)>>pinId)&1;
209 }
210 
211 
212 /* @brief Fast/efficient version of #PIN_setOutputEnable()
213  * @note Does not include any checks on handle for efficiency reasons,
214  * use #PIN_setOutputEnable() for checked version
215  */
216 __STATIC_INLINE void PINCC26XX_setOutputEnable(PIN_Id pinId, bool bOutEn) {
217  uint32_t key = Hwi_disable();
218  HWREG(GPIO_BASE+GPIO_O_DOE31_0) =
219  ((HWREG(GPIO_BASE+GPIO_O_DOE31_0) & ~(1<<pinId)) | (bOutEn<<pinId));
220  Hwi_restore(key);
221 }
222 
223 
224 /* @brief Fast/efficient version of #PIN_setOutputValue()
225  * @note Does not include any checks on handle for efficiency reasons,
226  * use #PIN_setOutputValue() for checked version
227  */
228 __STATIC_INLINE void PINCC26XX_setOutputValue(PIN_Id pinId, uint_t val) {
229  HWREGB(GPIO_BASE+GPIO_O_DOUT3_0+pinId) = (val) ? 1 : 0;
230 }
231 
234 __STATIC_INLINE uint_t PINCC26XX_getOutputValue(PIN_Id pinId) {
235  return (HWREG(GPIO_BASE+GPIO_O_DOUT31_0)>>pinId)&1;
236 }
238 
239 __STATIC_INLINE void PINCC26XX_clrPendInterrupt(PIN_Id pinId) {
240  HWREG(GPIO_NONBUF_BASE+GPIO_O_EVFLAGS31_0) = (1<<pinId);
241 }
242 
245 __STATIC_INLINE uint_t PINCC26XX_getPortInputValue(PIN_Handle handle) {
246  // Only a single port on CC26xx
247  return HWREG(GPIO_BASE+GPIO_O_DIN31_0);
248 }
249 
252 __STATIC_INLINE uint_t PINCC26XX_getPortOutputValue(PIN_Handle handle) {
253  // Only a single port on CC26xx
254  return HWREG(GPIO_BASE+GPIO_O_DOUT31_0);
255 }
256 
257 
258 /* @brief Fast/efficient version of #PIN_setPortOutputValue()
259  * @note Does not include any checks on handle for efficiency reasons,
260  * use #PIN_setPortOutputValue() for checked version
261  */
262 __STATIC_INLINE void PINCC26XX_setPortOutputValue(PIN_Handle handle, uint_t bmOutVal) {
263  // Only a single port on CC26xx
264  HWREG(GPIO_BASE+GPIO_O_DOUTTGL31_0) =
265  (HWREG(GPIO_BASE+GPIO_O_DOUT31_0) ^ bmOutVal) & handle->bmPort;
266 }
267 
268 
269 /* @brief Fast/efficient version of #PIN_setPortOutputEnable()
270  * @note Does not include any checks on handle for efficiency reasons,
271  * use #PIN_setPortOutputEnable() for checked version
272  */
273 __STATIC_INLINE void PINCC26XX_setPortOutputEnable(PIN_Handle handle, uint_t bmOutEn) {
274  // Only a single port on CC26xx
275  uint32_t key = Hwi_disable();
276  HWREG(GPIO_BASE+GPIO_O_DOE31_0) =
277  (HWREG(GPIO_BASE+GPIO_O_DOE31_0) & (~handle->bmPort)) | (bmOutEn & handle->bmPort);
278  Hwi_restore(key);
279 }
280 
281 
290 
291 
307 extern PIN_Status PINCC26XX_setWakeup(const PIN_Config aPinCfg[]);
308 
309 
323 extern int_t PINCC26XX_getMux(PIN_Id pinId);
324 
325 
339 extern PIN_Status PINCC26XX_setMux(PIN_Handle handle, PIN_Id pinId, int32_t nMux);
340 
341 
342 
350 #define PINCC26XX_MUX_GPIO IOC_PORT_GPIO // Default general purpose IO usage
351 #define PINCC26XX_MUX_AON_SCS IOC_PORT_AON_SCS // AON SPI-S SCS Pin
352 #define PINCC26XX_MUX_AON_SCK IOC_PORT_AON_SCK // AON SPI-S SCK Pin
353 #define PINCC26XX_MUX_AON_SDI IOC_PORT_AON_SDI // AON SPI-S SDI Pin
354 #define PINCC26XX_MUX_AON_SDO IOC_PORT_AON_SDO // AON SPI-S SDO Pin
355 #define PINCC26XX_MUX_AON_TDI IOC_PORT_AON_TDI // AON JTAG TDI Pin
356 #define PINCC26XX_MUX_AON_TDO IOC_PORT_AON_TDO // AON JTAG TDO Pin
357 #define PINCC26XX_MUX_AON_CLK32K IOC_PORT_AON_CLK32K // AON External 32kHz clock
358 #define PINCC26XX_MUX_AUX_IO IOC_PORT_AUX_IO // AUX IO Pin
359 #define PINCC26XX_MUX_MCU_SSI0_RX IOC_PORT_MCU_SSI0_RX // MCU SSI0 Receive Pin
360 #define PINCC26XX_MUX_MCU_SSI0_TX IOC_PORT_MCU_SSI0_TX // MCU SSI0 Transmit Pin
361 #define PINCC26XX_MUX_MCU_SSI0_FSS IOC_PORT_MCU_SSI0_FSS // MCU SSI0 FSS Pin
362 #define PINCC26XX_MUX_MCU_SSI0_CLK IOC_PORT_MCU_SSI0_CLK // MCU SSI0 Clock Pin
363 #define PINCC26XX_MUX_MCU_I2C_MSSDA IOC_PORT_MCU_I2C_MSSDA // MCU I2C Data Pin
364 #define PINCC26XX_MUX_MCU_I2C_MSSCL IOC_PORT_MCU_I2C_MSSCL // MCU I2C Clock Pin
365 #define PINCC26XX_MUX_MCU_UART0_RX IOC_PORT_MCU_UART0_RX // MCU UART0 Receive Pin
366 #define PINCC26XX_MUX_MCU_UART0_TX IOC_PORT_MCU_UART0_TX // MCU UART0 Transmit Pin
367 #define PINCC26XX_MUX_MCU_UART0_CTS IOC_PORT_MCU_UART0_CTS // MCU UART0 Clear To Send Pin
368 #define PINCC26XX_MUX_MCU_UART0_RTS IOC_PORT_MCU_UART0_RTS // MCU UART0 Request To Send Pin
369 #define PINCC26XX_MUX_MCU_UART1_RX IOC_PORT_MCU_UART1_RX // MCU UART1 Receive Pin
370 #define PINCC26XX_MUX_MCU_UART1_TX IOC_PORT_MCU_UART1_TX // MCU UART1 Transmit Pin
371 #define PINCC26XX_MUX_MCU_UART1_CTS IOC_PORT_MCU_UART1_CTS // MCU UART1 Clear To Send Pin
372 #define PINCC26XX_MUX_MCU_UART1_RTS IOC_PORT_MCU_UART1_RTS // MCU UART1 Request To Send Pin
373 #define PINCC26XX_MUX_MCU_TIMER0 IOC_PORT_MCU_TIMER0 // MCU GPT Pin 0
374 #define PINCC26XX_MUX_MCU_TIMER1 IOC_PORT_MCU_TIMER1 // MCU GPT Pin 1
375 #define PINCC26XX_MUX_MCU_TIMER2 IOC_PORT_MCU_TIMER2 // MCU GPT Pin 2
376 #define PINCC26XX_MUX_MCU_TIMER3 IOC_PORT_MCU_TIMER3 // MCU GPT Pin 3
377 #define PINCC26XX_MUX_MCU_TIMER4 IOC_PORT_MCU_TIMER4 // MCU GPT Pin 4
378 #define PINCC26XX_MUX_MCU_TIMER5 IOC_PORT_MCU_TIMER5 // MCU GPT Pin 5
379 #define PINCC26XX_MUX_MCU_TIMER6 IOC_PORT_MCU_TIMER6 // MCU GPT Pin 6
380 #define PINCC26XX_MUX_MCU_TIMER7 IOC_PORT_MCU_TIMER7 // MCU GPT Pin 7
381 #define PINCC26XX_MUX_RESERVED0 IOC_PORT_RESERVED0 // Reserved0
382 #define PINCC26XX_MUX_RESERVED1 IOC_PORT_RESERVED1 // Reserved1
383 #define PINCC26XX_MUX_MCU_SSI1_RX IOC_PORT_MCU_SSI1_RX // MCU SSI1 Receive Pin
384 #define PINCC26XX_MUX_MCU_SSI1_TX IOC_PORT_MCU_SSI1_TX // MCU SSI1 Transmit Pin
385 #define PINCC26XX_MUX_MCU_SSI1_FSS IOC_PORT_MCU_SSI1_FSS // MCU SSI1 FSS Pin
386 #define PINCC26XX_MUX_MCU_SSI1_CLK IOC_PORT_MCU_SSI1_CLK // MCU SSI1 Clock Pin
387 #define PINCC26XX_MUX_MCU_I2S_AD0 IOC_PORT_MCU_I2S_AD0 // MCU I2S Data Pin 0
388 #define PINCC26XX_MUX_MCU_I2S_AD1 IOC_PORT_MCU_I2S_AD1 // MCU I2S Data Pin 1
389 #define PINCC26XX_MUX_MCU_I2S_WCLK IOC_PORT_MCU_I2S_WCLK // MCU I2S Frame/Word Clock
390 #define PINCC26XX_MUX_MCU_I2S_BCLK IOC_PORT_MCU_I2S_BCLK // MCU I2S Bit Clock
391 #define PINCC26XX_MUX_MCU_I2S_MCLK IOC_PORT_MCU_I2S_MCLK // MCU I2S Master clock 2
392 #define PINCC26XX_MUX_MCU_IOC_OBS0 IOC_PORT_MCU_IOC_OBS0 // MCU Port 0 for observation
393 #define PINCC26XX_MUX_MCU_IOC_OBS1 IOC_PORT_MCU_IOC_OBS1 // MCU Port 1 for observation
394 #define PINCC26XX_MUX_MCU_IOC_OBS2 IOC_PORT_MCU_IOC_OBS2 // MCU Port 2 for observation
395 #define PINCC26XX_MUX_MCU_IOC_OBS3 IOC_PORT_MCU_IOC_OBS3 // MCU Port 3 for observation
396 #define PINCC26XX_MUX_RFC_TRC IOC_PORT_RFC_TRC // RF Core Tracer
397 #define PINCC26XX_MUX_RFC_GPO0 IOC_PORT_RFC_GPO0 // RC Core Data Out Pin 0
398 #define PINCC26XX_MUX_RFC_GPO1 IOC_PORT_RFC_GPO1 // RC Core Data Out Pin 1
399 #define PINCC26XX_MUX_RFC_GPO2 IOC_PORT_RFC_GPO2 // RC Core Data Out Pin 2
400 #define PINCC26XX_MUX_RFC_GPO3 IOC_PORT_RFC_GPO3 // RC Core Data Out Pin 3
401 #define PINCC26XX_MUX_RFC_GPI0 IOC_PORT_RFC_GPI0 // RC Core Data In Pin 0
402 #define PINCC26XX_MUX_RFC_GPI1 IOC_PORT_RFC_GPI1 // RC Core Data In Pin 1
403 #define PINCC26XX_MUX_RFC_SMI_DL_OUT IOC_PORT_RFC_SMI_DL_OUT // RF Core SMI Data Link Out
404 #define PINCC26XX_MUX_RFC_SMI_DL_IN IOC_PORT_RFC_SMI_DL_IN // RF Core SMI Data Link in
405 #define PINCC26XX_MUX_RFC_SMI_CL_OUT IOC_PORT_RFC_SMI_CL_OUT // RF Core SMI Command Link Out
406 #define PINCC26XX_MUX_RFC_SMI_CL_IN IOC_PORT_RFC_SMI_CL_IN // RF Core SMI Command Link In
407 
411 #ifdef __cplusplus
412 }
413 #endif
414 #endif /* ti_drivers_PINCC26XX__include */
uint_t bmPort
Bitmask for pins allocated in port.
Definition: PIN.h:688
uint8_t PIN_Id
Pin identifier data type.
Definition: PIN.h:556
__STATIC_INLINE void PINCC26XX_setOutputValue(PIN_Id pinId, uint_t val)
Definition: PINCC26XX.h:226
unsigned int uint_t
Definition: PIN.h:541
__STATIC_INLINE uint_t PINCC26XX_getPortInputValue(PIN_Handle handle)
Fast/efficient version of PIN_getPortInputValue()
Definition: PINCC26XX.h:243
__STATIC_INLINE uint_t PINCC26XX_getPortOutputValue(PIN_Handle handle)
Fast/efficient version of PIN_getPortOutputValue()
Definition: PINCC26XX.h:250
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:542
PIN_Handle PIN_HandleTable[]
__STATIC_INLINE uint_t PINCC26XX_getInputValue(PIN_Id pinId)
Fast/efficient version of PIN_getInputValue()
Definition: PINCC26XX.h:205
__STATIC_INLINE void PINCC26XX_clrPendInterrupt(PIN_Id pinId)
Definition: PINCC26XX.h:237
__STATIC_INLINE void PINCC26XX_setPortOutputValue(PIN_Handle handle, uint_t bmOutVal)
Definition: PINCC26XX.h:260
__STATIC_INLINE uint_t PINCC26XX_getOutputValue(PIN_Id pinId)
Fast/efficient version of PIN_getOutputValue()
Definition: PINCC26XX.h:232
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:214
__STATIC_INLINE uint32_t PIN_ctz(uint32_t x)
Definition: PINCC26XX.h:67
underlying data structure for type PIN_State
Definition: PIN.h:686
uint_t PIN_NumPins
int_t PINCC26XX_getMux(PIN_Id pinId)
Get device-specific pin mapping to GPIO, HW peripheral or HW signal.
PIN_Status
Return value for many functions in the PIN driver interface.
Definition: PIN.h:694
__STATIC_INLINE void PINCC26XX_setPortOutputEnable(PIN_Handle handle, uint_t bmOutEn)
Definition: PINCC26XX.h:271
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:576
Generic PIN & GPIO driver.
Copyright 2015, Texas Instruments Incorporated