ioc.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. /******************************************************************************
  2. * Filename: ioc.c
  3. * Revised: $Date: 2013-03-22 15:36:20 +0100 (Fri, 22 Mar 2013) $
  4. * Revision: $Revision: 9511 $
  5. *
  6. * Description: Driver for the I/O controller.
  7. *
  8. * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
  9. *
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. *
  18. * Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. *
  22. * Neither the name of Texas Instruments Incorporated nor the names of
  23. * its contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  29. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  30. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  31. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  32. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  33. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  34. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  35. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  36. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. ******************************************************************************/
  39. //*****************************************************************************
  40. //
  41. //! \addtogroup ioc_api
  42. //! @{
  43. //
  44. //*****************************************************************************
  45. #include "hw_ioc.h"
  46. #include "hw_gpio.h"
  47. #include "hw_memmap.h"
  48. #include "debug.h"
  49. #include "ioc.h"
  50. #include "gpio.h"
  51. //*****************************************************************************
  52. //
  53. // This is the mapping between a pin number within port A and the corresponding
  54. // override register.
  55. //
  56. //*****************************************************************************
  57. static const uint32_t g_pui32IOCPortAOverrideReg[] =
  58. {
  59. IOC_PA0_OVER, IOC_PA1_OVER, IOC_PA2_OVER, IOC_PA3_OVER,
  60. IOC_PA4_OVER, IOC_PA5_OVER, IOC_PA6_OVER, IOC_PA7_OVER
  61. };
  62. //*****************************************************************************
  63. //
  64. // This is the mapping between a pin number within port B and the corresponding
  65. // override register.
  66. //
  67. //*****************************************************************************
  68. static const uint32_t g_pui32IOCPortBOverrideReg[] =
  69. {
  70. IOC_PB0_OVER, IOC_PB1_OVER, IOC_PB2_OVER, IOC_PB3_OVER,
  71. IOC_PB4_OVER, IOC_PB5_OVER, IOC_PB6_OVER, IOC_PB7_OVER
  72. };
  73. //*****************************************************************************
  74. //
  75. // This is the mapping between a pin number within port C and the corresponding
  76. // override register.
  77. //
  78. //*****************************************************************************
  79. static const uint32_t g_pui32IOCPortCOverrideReg[] =
  80. {
  81. IOC_PC0_OVER, IOC_PC1_OVER, IOC_PC2_OVER, IOC_PC3_OVER,
  82. IOC_PC4_OVER, IOC_PC5_OVER, IOC_PC6_OVER, IOC_PC7_OVER
  83. };
  84. //*****************************************************************************
  85. //
  86. // This is the mapping between a pin number within port D and the corresponding
  87. // override register.
  88. //
  89. //*****************************************************************************
  90. static const uint32_t g_pui32IOCPortDOverrideReg[] =
  91. {
  92. IOC_PD0_OVER, IOC_PD1_OVER, IOC_PD2_OVER, IOC_PD3_OVER,
  93. IOC_PD4_OVER, IOC_PD5_OVER, IOC_PD6_OVER, IOC_PD7_OVER
  94. };
  95. //*****************************************************************************
  96. //
  97. // This is the mapping between a pin number within port A and the corresponding
  98. // signal select register.
  99. //
  100. //*****************************************************************************
  101. static const uint32_t g_pui32IOCPortASignSelectReg[] =
  102. {
  103. IOC_PA0_SEL, IOC_PA1_SEL, IOC_PA2_SEL, IOC_PA3_SEL,
  104. IOC_PA4_SEL, IOC_PA5_SEL, IOC_PA6_SEL, IOC_PA7_SEL
  105. };
  106. //*****************************************************************************
  107. //
  108. // This is the mapping between a pin number within port B and the corresponding
  109. // signal select register.
  110. //
  111. //*****************************************************************************
  112. static const uint32_t g_pui32IOCPortBSignSelectReg[] =
  113. {
  114. IOC_PB0_SEL, IOC_PB1_SEL, IOC_PB2_SEL, IOC_PB3_SEL,
  115. IOC_PB4_SEL, IOC_PB5_SEL, IOC_PB6_SEL, IOC_PB7_SEL
  116. };
  117. //*****************************************************************************
  118. //
  119. // This is the mapping between a pin number within port C and the corresponding
  120. // signal select register.
  121. //
  122. //*****************************************************************************
  123. static const uint32_t g_pui32IOCPortCSignSelectReg[] =
  124. {
  125. IOC_PC0_SEL, IOC_PC1_SEL, IOC_PC2_SEL, IOC_PC3_SEL,
  126. IOC_PC4_SEL, IOC_PC5_SEL, IOC_PC6_SEL, IOC_PC7_SEL
  127. };
  128. //*****************************************************************************
  129. //
  130. // This is the mapping between a pin number within port D and the corresponding
  131. // signal select register.
  132. //
  133. //*****************************************************************************
  134. static const uint32_t g_pui32IOCPortDSignSelectReg[] =
  135. {
  136. IOC_PD0_SEL, IOC_PD1_SEL, IOC_PD2_SEL, IOC_PD3_SEL,
  137. IOC_PD4_SEL, IOC_PD5_SEL, IOC_PD6_SEL, IOC_PD7_SEL
  138. };
  139. //*****************************************************************************
  140. //
  141. // Defined values for the port select registers.
  142. // (The registers are in the addr range: IOC_UARTRXD_UART0 - IOC_GPT3OCP2).
  143. //
  144. //*****************************************************************************
  145. #define IOC_PAD_IN_SEL_PA0 0x00000000 // PA0
  146. #define IOC_PAD_IN_SEL_PA1 0x00000001 // PA1
  147. #define IOC_PAD_IN_SEL_PA2 0x00000002 // PA2
  148. #define IOC_PAD_IN_SEL_PA3 0x00000003 // PA3
  149. #define IOC_PAD_IN_SEL_PA4 0x00000004 // PA4
  150. #define IOC_PAD_IN_SEL_PA5 0x00000005 // PA5
  151. #define IOC_PAD_IN_SEL_PA6 0x00000006 // PA6
  152. #define IOC_PAD_IN_SEL_PA7 0x00000007 // PA7
  153. #define IOC_PAD_IN_SEL_PB0 0x00000008 // PB0
  154. #define IOC_PAD_IN_SEL_PB1 0x00000009 // PB1
  155. #define IOC_PAD_IN_SEL_PB2 0x0000000A // PB2
  156. #define IOC_PAD_IN_SEL_PB3 0x0000000B // PB3
  157. #define IOC_PAD_IN_SEL_PB4 0x0000000C // PB4
  158. #define IOC_PAD_IN_SEL_PB5 0x0000000D // PB5
  159. #define IOC_PAD_IN_SEL_PB6 0x0000000E // PB6
  160. #define IOC_PAD_IN_SEL_PB7 0x0000000F // PB7
  161. #define IOC_PAD_IN_SEL_PC0 0x00000010 // PC0
  162. #define IOC_PAD_IN_SEL_PC1 0x00000011 // PC1
  163. #define IOC_PAD_IN_SEL_PC2 0x00000012 // PC2
  164. #define IOC_PAD_IN_SEL_PC3 0x00000013 // PC3
  165. #define IOC_PAD_IN_SEL_PC4 0x00000014 // PC4
  166. #define IOC_PAD_IN_SEL_PC5 0x00000015 // PC5
  167. #define IOC_PAD_IN_SEL_PC6 0x00000016 // PC6
  168. #define IOC_PAD_IN_SEL_PC7 0x00000017 // PC7
  169. #define IOC_PAD_IN_SEL_PD0 0x00000018 // PD0
  170. #define IOC_PAD_IN_SEL_PD1 0x00000019 // PD1
  171. #define IOC_PAD_IN_SEL_PD2 0x0000001A // PD2
  172. #define IOC_PAD_IN_SEL_PD3 0x0000001B // PD3
  173. #define IOC_PAD_IN_SEL_PD4 0x0000001C // PD4
  174. #define IOC_PAD_IN_SEL_PD5 0x0000001D // PD5
  175. #define IOC_PAD_IN_SEL_PD6 0x0000001E // PD6
  176. #define IOC_PAD_IN_SEL_PD7 0x0000001F // PD7
  177. //*****************************************************************************
  178. //
  179. //! Mux desired on-chip peripheral output signal to the desired port pin(s).
  180. //!
  181. //! \param ui32Port is the base address of the GPIO port.
  182. //! \param ui8Pins is the bit-packed representation of the port pin(s).
  183. //! \param ui32OutputSignal is the desired peripheral output signal to drive the
  184. //! desired port pin(s).
  185. //!
  186. //! This function routes the desired on-chip peripheral signal to the
  187. //! desired pin(s) on the selected GPIO port. Functions are available within
  188. //! the GPIO device driver that can set the peripheral signal to be under
  189. //! hardware control. The IOCPadConfigSet() function can be used to set the pin
  190. //! drive type on the desired port pin.
  191. //!
  192. //! The \e ui32OutputSignal parameter is an enumerated type that controls which
  193. //! peripheral output signal to route to the desired port pin(s).
  194. //! This parameter can have any of the following values:
  195. //!
  196. //! - \b IOC_MUX_OUT_SEL_UART0_TXD
  197. //! - \b IOC_MUX_OUT_SEL_UART1_RTS
  198. //! - \b IOC_MUX_OUT_SEL_UART1_TXD
  199. //! - \b IOC_MUX_OUT_SEL_SSI0_TXD
  200. //! - \b IOC_MUX_OUT_SEL_SSI0_CLKOUT
  201. //! - \b IOC_MUX_OUT_SEL_SSI0_FSSOUT
  202. //! - \b IOC_MUX_OUT_SEL_SSI0_STXSER_EN
  203. //! - \b IOC_MUX_OUT_SEL_SSI1_TXD
  204. //! - \b IOC_MUX_OUT_SEL_SSI1_CLKOUT
  205. //! - \b IOC_MUX_OUT_SEL_SSI1_FSSOUT
  206. //! - \b IOC_MUX_OUT_SEL_SSI1_STXSER_EN
  207. //! - \b IOC_MUX_OUT_SEL_I2C_CMSSDA
  208. //! - \b IOC_MUX_OUT_SEL_I2C_CMSSCL
  209. //! - \b IOC_MUX_OUT_SEL_GPT0_ICP1
  210. //! - \b IOC_MUX_OUT_SEL_GPT0_ICP2
  211. //! - \b IOC_MUX_OUT_SEL_GPT1_ICP1
  212. //! - \b IOC_MUX_OUT_SEL_GPT1_ICP2
  213. //! - \b IOC_MUX_OUT_SEL_GPT2_ICP1
  214. //! - \b IOC_MUX_OUT_SEL_GPT2_ICP2
  215. //! - \b IOC_MUX_OUT_SEL_GPT3_ICP1
  216. //! - \b IOC_MUX_OUT_SEL_GPT3_ICP2
  217. //!
  218. //! The pin(s) in \e ui8Pins are specified using a bit-packed byte, where each
  219. //! bit that is set identifies the pin to be accessed, and where bit 0 of the
  220. //! byte represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so
  221. //! on.
  222. //!
  223. //! \return None
  224. //
  225. //*****************************************************************************
  226. void
  227. IOCPinConfigPeriphOutput(uint32_t ui32Port, uint8_t ui8Pins,
  228. uint32_t ui32OutputSignal)
  229. {
  230. uint32_t ui32PortAddr;
  231. uint32_t ui32PinNo;
  232. uint32_t ui32PinBit;
  233. //
  234. // Check the arguments
  235. //
  236. ASSERT((ui32Port == GPIO_A_BASE) || (ui32Port == GPIO_B_BASE) ||
  237. (ui32Port == GPIO_C_BASE) || (ui32Port == GPIO_D_BASE));
  238. ASSERT(ui8Pins != 0);
  239. //
  240. // Initialize to default value
  241. //
  242. ui32PortAddr = IOC_PA0_SEL;
  243. //
  244. // Look for specified port pins to be configured, multiple pins are allowed
  245. //
  246. for(ui32PinNo = 0; ui32PinNo < 8; ui32PinNo++)
  247. {
  248. ui32PinBit = (ui8Pins >> ui32PinNo) & 0x00000001;
  249. if(ui32PinBit != 0)
  250. {
  251. //
  252. // Find register addresses for configuring specified port pin
  253. //
  254. switch(ui32Port)
  255. {
  256. case GPIO_A_BASE:
  257. ui32PortAddr = g_pui32IOCPortASignSelectReg[ui32PinNo];
  258. break;
  259. case GPIO_B_BASE:
  260. ui32PortAddr = g_pui32IOCPortBSignSelectReg[ui32PinNo];
  261. break;
  262. case GPIO_C_BASE:
  263. ui32PortAddr = g_pui32IOCPortCSignSelectReg[ui32PinNo];
  264. break;
  265. case GPIO_D_BASE:
  266. ui32PortAddr = g_pui32IOCPortDSignSelectReg[ui32PinNo];
  267. break;
  268. default:
  269. // Default to port A pin 0
  270. ui32PortAddr = IOC_PA0_SEL;
  271. break;
  272. }
  273. //
  274. // Set the mux for the desired port pin to select the desired
  275. // peripheral output signal
  276. //
  277. HWREG(ui32PortAddr) = ui32OutputSignal;
  278. }
  279. }
  280. }
  281. //*****************************************************************************
  282. //
  283. //! Mux the desired port pin to the desired on-chip peripheral input signal
  284. //!
  285. //! \param ui32Port is the base address of the GPIO port.
  286. //! \param ui8Pin is the bit-packed representation of the desired port pin.
  287. //! \param ui32PinSelectReg is the address of the IOC mux-register for the
  288. //! desired peripheral input signal to which the desired port pin shall be
  289. //! routed.
  290. //!
  291. //! This function routes the desired port pin to the desired on-chip
  292. //! peripheral input signal. Functions are available within the GPIO device
  293. //! driver that set the peripheral signal to be under hardware control and
  294. //! configures the pin drive type on the desired port pin.
  295. //!
  296. //! The parameter \e ui32PinSelectReg is an enumerated data type that can be one
  297. //! of the following values:
  298. //!
  299. //! - \b IOC_UARTRXD_UART0
  300. //! - \b IOC_UARTCTS_UART1
  301. //! - \b IOC_UARTRXD_UART1
  302. //! - \b IOC_CLK_SSI_SSI0
  303. //! - \b IOC_SSIRXD_SSI0
  304. //! - \b IOC_SSIFSSIN_SSI0
  305. //! - \b IOC_CLK_SSIIN_SSI0
  306. //! - \b IOC_CLK_SSI_SSI1
  307. //! - \b IOC_SSIRXD_SSI1
  308. //! - \b IOC_SSIFSSIN_SSI1
  309. //! - \b IOC_CLK_SSIIN_SSI1
  310. //! - \b IOC_I2CMSSDA
  311. //! - \b IOC_I2CMSSCL
  312. //! - \b IOC_GPT0OCP1
  313. //! - \b IOC_GPT0OCP2
  314. //! - \b IOC_GPT1OCP1
  315. //! - \b IOC_GPT1OCP2
  316. //! - \b IOC_GPT2OCP1
  317. //! - \b IOC_GPT2OCP2
  318. //! - \b IOC_GPT3OCP1
  319. //! - \b IOC_GPT3OCP2
  320. //!
  321. //! The pin in ui8Pin is specified using a bit-packed byte, where the bit that
  322. //! is set identifies the pin to be accessed, and where bit 0 of the byte
  323. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  324. //!
  325. //! \return None
  326. //
  327. //*****************************************************************************
  328. void
  329. IOCPinConfigPeriphInput(uint32_t ui32Port, uint8_t ui8Pin,
  330. uint32_t ui32PinSelectReg)
  331. {
  332. uint32_t ui32PortPin;
  333. //
  334. //Set initial values
  335. //
  336. ui32PortPin = IOC_PAD_IN_SEL_PA0;
  337. //
  338. // Check the arguments
  339. //
  340. ASSERT((ui32Port == GPIO_A_BASE) || (ui32Port == GPIO_B_BASE) ||
  341. (ui32Port == GPIO_C_BASE) || (ui32Port == GPIO_D_BASE));
  342. ASSERT((ui8Pin == GPIO_PIN_0) || (ui8Pin == GPIO_PIN_1) ||
  343. (ui8Pin == GPIO_PIN_2) || (ui8Pin == GPIO_PIN_3) ||
  344. (ui8Pin == GPIO_PIN_4) || (ui8Pin == GPIO_PIN_5) ||
  345. (ui8Pin == GPIO_PIN_6) || (ui8Pin == GPIO_PIN_7));
  346. ASSERT((ui32PinSelectReg == IOC_UARTRXD_UART0) ||
  347. (ui32PinSelectReg == IOC_UARTCTS_UART1) ||
  348. (ui32PinSelectReg == IOC_UARTRXD_UART1) ||
  349. (ui32PinSelectReg == IOC_CLK_SSI_SSI0) ||
  350. (ui32PinSelectReg == IOC_SSIRXD_SSI0) ||
  351. (ui32PinSelectReg == IOC_SSIFSSIN_SSI0) ||
  352. (ui32PinSelectReg == IOC_CLK_SSIIN_SSI0) ||
  353. (ui32PinSelectReg == IOC_CLK_SSI_SSI1) ||
  354. (ui32PinSelectReg == IOC_SSIRXD_SSI1) ||
  355. (ui32PinSelectReg == IOC_SSIFSSIN_SSI1) ||
  356. (ui32PinSelectReg == IOC_CLK_SSIIN_SSI1) ||
  357. (ui32PinSelectReg == IOC_I2CMSSDA) ||
  358. (ui32PinSelectReg == IOC_I2CMSSCL) ||
  359. (ui32PinSelectReg == IOC_GPT0OCP1) ||
  360. (ui32PinSelectReg == IOC_GPT0OCP2) ||
  361. (ui32PinSelectReg == IOC_GPT1OCP1) ||
  362. (ui32PinSelectReg == IOC_GPT1OCP2) ||
  363. (ui32PinSelectReg == IOC_GPT2OCP1) ||
  364. (ui32PinSelectReg == IOC_GPT2OCP2) ||
  365. (ui32PinSelectReg == IOC_GPT3OCP1) ||
  366. (ui32PinSelectReg == IOC_GPT3OCP2));
  367. switch(ui32Port)
  368. {
  369. case GPIO_A_BASE:
  370. if(ui8Pin == GPIO_PIN_0)
  371. {
  372. ui32PortPin = IOC_PAD_IN_SEL_PA0;
  373. }
  374. if(ui8Pin == GPIO_PIN_1)
  375. {
  376. ui32PortPin = IOC_PAD_IN_SEL_PA1;
  377. }
  378. if(ui8Pin == GPIO_PIN_2)
  379. {
  380. ui32PortPin = IOC_PAD_IN_SEL_PA2;
  381. }
  382. if(ui8Pin == GPIO_PIN_3)
  383. {
  384. ui32PortPin = IOC_PAD_IN_SEL_PA3;
  385. }
  386. if(ui8Pin == GPIO_PIN_4)
  387. {
  388. ui32PortPin = IOC_PAD_IN_SEL_PA4;
  389. }
  390. if(ui8Pin == GPIO_PIN_5)
  391. {
  392. ui32PortPin = IOC_PAD_IN_SEL_PA5;
  393. }
  394. if(ui8Pin == GPIO_PIN_6)
  395. {
  396. ui32PortPin = IOC_PAD_IN_SEL_PA6;
  397. }
  398. if(ui8Pin == GPIO_PIN_7)
  399. {
  400. ui32PortPin = IOC_PAD_IN_SEL_PA7;
  401. }
  402. break;
  403. case GPIO_B_BASE:
  404. if(ui8Pin == GPIO_PIN_0)
  405. {
  406. ui32PortPin = IOC_PAD_IN_SEL_PB0;
  407. }
  408. if(ui8Pin == GPIO_PIN_1)
  409. {
  410. ui32PortPin = IOC_PAD_IN_SEL_PB1;
  411. }
  412. if(ui8Pin == GPIO_PIN_2)
  413. {
  414. ui32PortPin = IOC_PAD_IN_SEL_PB2;
  415. }
  416. if(ui8Pin == GPIO_PIN_3)
  417. {
  418. ui32PortPin = IOC_PAD_IN_SEL_PB3;
  419. }
  420. if(ui8Pin == GPIO_PIN_4)
  421. {
  422. ui32PortPin = IOC_PAD_IN_SEL_PB4;
  423. }
  424. if(ui8Pin == GPIO_PIN_5)
  425. {
  426. ui32PortPin = IOC_PAD_IN_SEL_PB5;
  427. }
  428. if(ui8Pin == GPIO_PIN_6)
  429. {
  430. ui32PortPin = IOC_PAD_IN_SEL_PB6;
  431. }
  432. if(ui8Pin == GPIO_PIN_7)
  433. {
  434. ui32PortPin = IOC_PAD_IN_SEL_PB7;
  435. }
  436. break;
  437. case GPIO_C_BASE:
  438. if(ui8Pin == GPIO_PIN_0)
  439. {
  440. ui32PortPin = IOC_PAD_IN_SEL_PC0;
  441. }
  442. if(ui8Pin == GPIO_PIN_1)
  443. {
  444. ui32PortPin = IOC_PAD_IN_SEL_PC1;
  445. }
  446. if(ui8Pin == GPIO_PIN_2)
  447. {
  448. ui32PortPin = IOC_PAD_IN_SEL_PC2;
  449. }
  450. if(ui8Pin == GPIO_PIN_3)
  451. {
  452. ui32PortPin = IOC_PAD_IN_SEL_PC3;
  453. }
  454. if(ui8Pin == GPIO_PIN_4)
  455. {
  456. ui32PortPin = IOC_PAD_IN_SEL_PC4;
  457. }
  458. if(ui8Pin == GPIO_PIN_5)
  459. {
  460. ui32PortPin = IOC_PAD_IN_SEL_PC5;
  461. }
  462. if(ui8Pin == GPIO_PIN_6)
  463. {
  464. ui32PortPin = IOC_PAD_IN_SEL_PC6;
  465. }
  466. if(ui8Pin == GPIO_PIN_7)
  467. {
  468. ui32PortPin = IOC_PAD_IN_SEL_PC7;
  469. }
  470. break;
  471. case GPIO_D_BASE:
  472. if(ui8Pin == GPIO_PIN_0)
  473. {
  474. ui32PortPin = IOC_PAD_IN_SEL_PD0;
  475. }
  476. if(ui8Pin == GPIO_PIN_1)
  477. {
  478. ui32PortPin = IOC_PAD_IN_SEL_PD1;
  479. }
  480. if(ui8Pin == GPIO_PIN_2)
  481. {
  482. ui32PortPin = IOC_PAD_IN_SEL_PD2;
  483. }
  484. if(ui8Pin == GPIO_PIN_3)
  485. {
  486. ui32PortPin = IOC_PAD_IN_SEL_PD3;
  487. }
  488. if(ui8Pin == GPIO_PIN_4)
  489. {
  490. ui32PortPin = IOC_PAD_IN_SEL_PD4;
  491. }
  492. if(ui8Pin == GPIO_PIN_5)
  493. {
  494. ui32PortPin = IOC_PAD_IN_SEL_PD5;
  495. }
  496. if(ui8Pin == GPIO_PIN_6)
  497. {
  498. ui32PortPin = IOC_PAD_IN_SEL_PD6;
  499. }
  500. if(ui8Pin == GPIO_PIN_7)
  501. {
  502. ui32PortPin = IOC_PAD_IN_SEL_PD7;
  503. }
  504. break;
  505. default:
  506. // Default to port A pin 0
  507. ui32PortPin = IOC_PAD_IN_SEL_PA0;
  508. break;
  509. }
  510. //
  511. // Set the mux for the desired peripheral inputsignal to select the
  512. // the desired port pin.
  513. //
  514. HWREG(ui32PinSelectReg) = ui32PortPin;
  515. }
  516. //*****************************************************************************
  517. //
  518. //! Set desired drive type on the pad for the desired port pin(s).
  519. //!
  520. //! \param ui32Port is the base address of the GPIO port.
  521. //! \param ui8Pins is the bit-packed representation of the port pin(s).
  522. //! \param ui32PinDrive is the drive configuration of the desired port
  523. //! pin.
  524. //!
  525. //! This function sets the desired pin drive type for the desired pin(s)
  526. //! on the selected GPIO port.
  527. //!
  528. //! The \e ui32PinDrive parameter controls the configuration of the pin drive on
  529. //! the pad for the desired pin(s). The parameter is the logical OR of any of
  530. //! the following:
  531. //!
  532. //! - \b IOC_OVERRIDE_OE
  533. //! - \b IOC_OVERRIDE_PUE
  534. //! - \b IOC_OVERRIDE_PDE
  535. //! - \b IOC_OVERRIDE_ANA
  536. //! - \b IOC_OVERRIDE_DIS
  537. //!
  538. //! where \b IOC_OVERRIDE_OE is the output enable bit connected directly
  539. //! to the output enable pin for the IO driver cell, after it is ORed
  540. //! with any OE signal from the desired peripheral. The OE is driven from the
  541. //! SSI, I2C and GPT peripherals. \b IOC_OVERRIDE_PUE is the enable bit for
  542. //! the pull-up. \b IOC_OVERRIDE_PDE is the enable bit for the pull-down.
  543. //! \b IOC_OVERRIDE_ANA must be set for the analog signal.
  544. //!
  545. //! The pin(s) in \e ui8Pins are specified using a bit-packed byte, where each
  546. //! bit that is set identifies the pin to be accessed, and where bit 0 of the
  547. //! byte represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so
  548. //! on.
  549. //!
  550. //! \note PC0 through PC3 are bidirectional high-drive pad-cells. They do not
  551. //! support on-die pullup or pulldown resistors or analog connectivity.
  552. //! For these four pins the \e ui32PinDrive parameter must be set to either
  553. //! \b IOC_OVERRIDE_OE or IOC_OVERRIDE_DIS.
  554. //!
  555. //! \return None
  556. //
  557. //*****************************************************************************
  558. void
  559. IOCPadConfigSet(uint32_t ui32Port, uint8_t ui8Pins,
  560. uint32_t ui32PinDrive)
  561. {
  562. uint32_t ui32OverrideRegAddr;
  563. uint32_t ui32PinNo;
  564. uint32_t ui32PinBit;
  565. //
  566. // Check the arguments
  567. //
  568. ASSERT((ui32Port == GPIO_A_BASE) || (ui32Port == GPIO_B_BASE) ||
  569. (ui32Port == GPIO_C_BASE) || (ui32Port == GPIO_D_BASE));
  570. ASSERT(ui8Pins != 0);
  571. ASSERT((ui32PinDrive == IOC_OVERRIDE_OE) ||
  572. (ui32PinDrive == IOC_OVERRIDE_PUE) ||
  573. (ui32PinDrive == IOC_OVERRIDE_PDE) ||
  574. (ui32PinDrive == IOC_OVERRIDE_ANA) ||
  575. (ui32PinDrive == IOC_OVERRIDE_DIS));
  576. //
  577. // PC0-PC3 does not support on-die pullup, pulldown or analog connectivity.
  578. //
  579. ASSERT(!((ui32Port == GPIO_C_BASE) && ((ui8Pins & 0xf) > 0) &&
  580. ((ui32PinDrive == IOC_OVERRIDE_PUE) ||
  581. (ui32PinDrive == IOC_OVERRIDE_PDE) ||
  582. (ui32PinDrive == IOC_OVERRIDE_ANA))));
  583. //
  584. // Initialize to default value
  585. //
  586. ui32OverrideRegAddr = IOC_PA0_SEL;
  587. //
  588. // Look for specified port pins to be configured, multiple pins are allowed
  589. //
  590. for(ui32PinNo = 0; ui32PinNo < 8; ui32PinNo++)
  591. {
  592. ui32PinBit = (ui8Pins >> ui32PinNo) & 0x00000001;
  593. if(ui32PinBit != 0)
  594. {
  595. //
  596. // Find register addresses for configuring specified port pin
  597. //
  598. switch(ui32Port)
  599. {
  600. case GPIO_A_BASE:
  601. ui32OverrideRegAddr = g_pui32IOCPortAOverrideReg[ui32PinNo];
  602. break;
  603. case GPIO_B_BASE:
  604. ui32OverrideRegAddr = g_pui32IOCPortBOverrideReg[ui32PinNo];
  605. break;
  606. case GPIO_C_BASE:
  607. ui32OverrideRegAddr = g_pui32IOCPortCOverrideReg[ui32PinNo];
  608. break;
  609. case GPIO_D_BASE:
  610. ui32OverrideRegAddr = g_pui32IOCPortDOverrideReg[ui32PinNo];
  611. break;
  612. default:
  613. // Default to port A pin 0
  614. ui32OverrideRegAddr = IOC_PA0_OVER;
  615. break;
  616. }
  617. //
  618. // Set desired pin drive for the desired port pin
  619. //
  620. HWREG(ui32OverrideRegAddr) = ui32PinDrive;
  621. }
  622. }
  623. }
  624. //*****************************************************************************
  625. //
  626. //! Get drive type on the pad for the desired port pin.
  627. //!
  628. //! \param ui32Port is the base address of the GPIO port.
  629. //! \param ui8Pin is the bit-packed representation of the port pin.
  630. //!
  631. //! This function returns the configured pin drive type for the desired
  632. //! pin on the selected GPIO port.
  633. //!
  634. //! The pin in \e ui8Pin is specified using a bit-packed byte, where the bit
  635. //! that is set identifies the pin to be accessed, and where bit 0 of the byte
  636. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  637. //!
  638. //! \return Returns the logical OR of the enumerated data types described for
  639. //! \e ui32PinDrive parameter in IOCPadConfigSet().
  640. //!
  641. //! \sa IOCPadConfigSet()
  642. //
  643. //*****************************************************************************
  644. uint32_t
  645. IOCPadConfigGet(uint32_t ui32Port, uint8_t ui8Pin)
  646. {
  647. uint32_t ui32OverrideRegAddr;
  648. //
  649. //Set initial values
  650. //
  651. ui32OverrideRegAddr = IOC_PA0_OVER;
  652. //
  653. // Check the arguments
  654. //
  655. ASSERT((ui32Port == GPIO_A_BASE) || (ui32Port == GPIO_B_BASE) ||
  656. (ui32Port == GPIO_C_BASE) || (ui32Port == GPIO_D_BASE));
  657. ASSERT((ui8Pin == GPIO_PIN_0) || (ui8Pin == GPIO_PIN_1) ||
  658. (ui8Pin == GPIO_PIN_2) || (ui8Pin == GPIO_PIN_3) ||
  659. (ui8Pin == GPIO_PIN_4) || (ui8Pin == GPIO_PIN_5) ||
  660. (ui8Pin == GPIO_PIN_6) || (ui8Pin == GPIO_PIN_7));
  661. //
  662. // Find the address of the override register for the desired pin
  663. //
  664. switch(ui32Port)
  665. {
  666. case GPIO_A_BASE:
  667. if(ui8Pin == GPIO_PIN_0)
  668. {
  669. ui32OverrideRegAddr = IOC_PA0_OVER;
  670. }
  671. if(ui8Pin == GPIO_PIN_1)
  672. {
  673. ui32OverrideRegAddr = IOC_PA1_OVER;
  674. }
  675. if(ui8Pin == GPIO_PIN_2)
  676. {
  677. ui32OverrideRegAddr = IOC_PA2_OVER;
  678. }
  679. if(ui8Pin == GPIO_PIN_3)
  680. {
  681. ui32OverrideRegAddr = IOC_PA3_OVER;
  682. }
  683. if(ui8Pin == GPIO_PIN_4)
  684. {
  685. ui32OverrideRegAddr = IOC_PA4_OVER;
  686. }
  687. if(ui8Pin == GPIO_PIN_5)
  688. {
  689. ui32OverrideRegAddr = IOC_PA5_OVER;
  690. }
  691. if(ui8Pin == GPIO_PIN_6)
  692. {
  693. ui32OverrideRegAddr = IOC_PA6_OVER;
  694. }
  695. if(ui8Pin == GPIO_PIN_7)
  696. {
  697. ui32OverrideRegAddr = IOC_PA7_OVER;
  698. }
  699. break;
  700. case GPIO_B_BASE:
  701. if(ui8Pin == GPIO_PIN_0)
  702. {
  703. ui32OverrideRegAddr = IOC_PB0_OVER;
  704. }
  705. if(ui8Pin == GPIO_PIN_1)
  706. {
  707. ui32OverrideRegAddr = IOC_PB1_OVER;
  708. }
  709. if(ui8Pin == GPIO_PIN_2)
  710. {
  711. ui32OverrideRegAddr = IOC_PB2_OVER;
  712. }
  713. if(ui8Pin == GPIO_PIN_3)
  714. {
  715. ui32OverrideRegAddr = IOC_PB3_OVER;
  716. }
  717. if(ui8Pin == GPIO_PIN_4)
  718. {
  719. ui32OverrideRegAddr = IOC_PB4_OVER;
  720. }
  721. if(ui8Pin == GPIO_PIN_5)
  722. {
  723. ui32OverrideRegAddr = IOC_PB5_OVER;
  724. }
  725. if(ui8Pin == GPIO_PIN_6)
  726. {
  727. ui32OverrideRegAddr = IOC_PB6_OVER;
  728. }
  729. if(ui8Pin == GPIO_PIN_7)
  730. {
  731. ui32OverrideRegAddr = IOC_PB7_OVER;
  732. }
  733. break;
  734. case GPIO_C_BASE:
  735. if(ui8Pin == GPIO_PIN_0)
  736. {
  737. ui32OverrideRegAddr = IOC_PC0_OVER;
  738. }
  739. if(ui8Pin == GPIO_PIN_1)
  740. {
  741. ui32OverrideRegAddr = IOC_PC1_OVER;
  742. }
  743. if(ui8Pin == GPIO_PIN_2)
  744. {
  745. ui32OverrideRegAddr = IOC_PC2_OVER;
  746. }
  747. if(ui8Pin == GPIO_PIN_3)
  748. {
  749. ui32OverrideRegAddr = IOC_PC3_OVER;
  750. }
  751. if(ui8Pin == GPIO_PIN_4)
  752. {
  753. ui32OverrideRegAddr = IOC_PC4_OVER;
  754. }
  755. if(ui8Pin == GPIO_PIN_5)
  756. {
  757. ui32OverrideRegAddr = IOC_PC5_OVER;
  758. }
  759. if(ui8Pin == GPIO_PIN_6)
  760. {
  761. ui32OverrideRegAddr = IOC_PC6_OVER;
  762. }
  763. if(ui8Pin == GPIO_PIN_7)
  764. {
  765. ui32OverrideRegAddr = IOC_PC7_OVER;
  766. }
  767. break;
  768. case GPIO_D_BASE:
  769. if(ui8Pin == GPIO_PIN_0)
  770. {
  771. ui32OverrideRegAddr = IOC_PD0_OVER;
  772. }
  773. if(ui8Pin == GPIO_PIN_1)
  774. {
  775. ui32OverrideRegAddr = IOC_PD1_OVER;
  776. }
  777. if(ui8Pin == GPIO_PIN_2)
  778. {
  779. ui32OverrideRegAddr = IOC_PD2_OVER;
  780. }
  781. if(ui8Pin == GPIO_PIN_3)
  782. {
  783. ui32OverrideRegAddr = IOC_PD3_OVER;
  784. }
  785. if(ui8Pin == GPIO_PIN_4)
  786. {
  787. ui32OverrideRegAddr = IOC_PD4_OVER;
  788. }
  789. if(ui8Pin == GPIO_PIN_5)
  790. {
  791. ui32OverrideRegAddr = IOC_PD5_OVER;
  792. }
  793. if(ui8Pin == GPIO_PIN_6)
  794. {
  795. ui32OverrideRegAddr = IOC_PD6_OVER;
  796. }
  797. if(ui8Pin == GPIO_PIN_7)
  798. {
  799. ui32OverrideRegAddr = IOC_PD7_OVER;
  800. }
  801. break;
  802. default:
  803. // Default to port A pin 0
  804. ui32OverrideRegAddr = IOC_PA0_OVER;
  805. break;
  806. }
  807. //
  808. // Return pin drive type
  809. //
  810. return(HWREG(ui32OverrideRegAddr));
  811. }
  812. //*****************************************************************************
  813. //
  814. //! Close the Doxygen group.
  815. //! @}
  816. //
  817. //*****************************************************************************