gpio.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  1. /******************************************************************************
  2. * Filename: gpio.c
  3. * Revised: $Date: 2013-04-29 09:36:44 +0200 (Mon, 29 Apr 2013) $
  4. * Revision: $Revision: 9922 $
  5. *
  6. * Description: Driver for the GPIO 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 gpio_api
  42. //! @{
  43. //
  44. //*****************************************************************************
  45. #include "hw_gpio.h"
  46. #include "hw_ints.h"
  47. #include "hw_sys_ctrl.h"
  48. #include "hw_memmap.h"
  49. #include "debug.h"
  50. #include "gpio.h"
  51. #include "interrupt.h"
  52. #include "ioc.h"
  53. //*****************************************************************************
  54. //
  55. //! \internal
  56. //! Checks a GPIO base address
  57. //!
  58. //! \param ui32Port is the base address of the GPIO port.
  59. //!
  60. //! This function determines if a GPIO port base address is valid.
  61. //!
  62. //! \return Returns \b true if the base address is valid and \b false
  63. //! otherwise.
  64. //
  65. //*****************************************************************************
  66. #ifdef ENABLE_ASSERT
  67. static bool
  68. GPIOBaseValid(uint32_t ui32Port)
  69. {
  70. return((ui32Port == GPIO_A_BASE) || (ui32Port == GPIO_B_BASE) ||
  71. (ui32Port == GPIO_C_BASE) || (ui32Port == GPIO_D_BASE));
  72. }
  73. #endif
  74. //*****************************************************************************
  75. //
  76. //! \internal
  77. //! Gets the GPIO interrupt number
  78. //!
  79. //! \param ui32Port is the base address of the GPIO port.
  80. //!
  81. //! Given a GPIO base address, returns the corresponding interrupt number.
  82. //!
  83. //! \return Returns a GPIO interrupt number, or 0 if \e ui32Port is invalid.
  84. //
  85. //*****************************************************************************
  86. uint32_t
  87. GPIOGetIntNumber(uint32_t ui32Port)
  88. {
  89. uint32_t ui32Int;
  90. //
  91. // Check the arguments.
  92. //
  93. ASSERT(GPIOBaseValid(ui32Port));
  94. //
  95. // Determine the GPIO interrupt number for the given module.
  96. //
  97. switch(ui32Port)
  98. {
  99. case GPIO_A_BASE:
  100. {
  101. ui32Int = INT_GPIOA;
  102. break;
  103. }
  104. case GPIO_B_BASE:
  105. {
  106. ui32Int = INT_GPIOB;
  107. break;
  108. }
  109. case GPIO_C_BASE:
  110. {
  111. ui32Int = INT_GPIOC;
  112. break;
  113. }
  114. case GPIO_D_BASE:
  115. {
  116. ui32Int = INT_GPIOD;
  117. break;
  118. }
  119. default:
  120. {
  121. return(0);
  122. }
  123. }
  124. //
  125. // Return GPIO interrupt number.
  126. //
  127. return(ui32Int);
  128. }
  129. //*****************************************************************************
  130. //
  131. //! Sets the direction and mode of the specified pin(s)
  132. //!
  133. //! \param ui32Port is the base address of the GPIO port.
  134. //! \param ui8Pins is the bit-packed representation of the pin(s).
  135. //! \param ui32PinIO is the pin direction and/or mode.
  136. //!
  137. //! This function sets the specified pin(s) on the selected GPIO port
  138. //! as either an input or output under software control or sets the
  139. //! pin to be under hardware control.
  140. //!
  141. //! The parameter \e ui32PinIO is an enumerated data type that can be one of
  142. //! the following values:
  143. //!
  144. //! - \b GPIO_DIR_MODE_IN
  145. //! - \b GPIO_DIR_MODE_OUT
  146. //! - \b GPIO_DIR_MODE_HW
  147. //!
  148. //! where \b GPIO_DIR_MODE_IN specifies that the pin will be programmed as
  149. //! a software controlled input, \b GPIO_DIR_MODE_OUT specifies that the pin
  150. //! will be programmed as a software controlled output, and
  151. //! \b GPIO_DIR_MODE_HW specifies that the pin will be placed under
  152. //! hardware control.
  153. //!
  154. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  155. //! set identifies the pin to be accessed, and where bit 0 of the byte
  156. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  157. //!
  158. //! \return None
  159. //
  160. //*****************************************************************************
  161. void
  162. GPIODirModeSet(uint32_t ui32Port, uint8_t ui8Pins,
  163. uint32_t ui32PinIO)
  164. {
  165. //
  166. // Check the arguments.
  167. //
  168. ASSERT(GPIOBaseValid(ui32Port));
  169. ASSERT((ui32PinIO == GPIO_DIR_MODE_IN) || (ui32PinIO == GPIO_DIR_MODE_OUT) ||
  170. (ui32PinIO == GPIO_DIR_MODE_HW));
  171. //
  172. // Set the pin direction and mode.
  173. //
  174. HWREG(ui32Port + GPIO_O_DIR) = ((ui32PinIO & GPIO_DIR_MODE_OUT) ?
  175. (HWREG(ui32Port + GPIO_O_DIR) | ui8Pins) :
  176. (HWREG(ui32Port + GPIO_O_DIR) & ~(ui8Pins)));
  177. HWREG(ui32Port + GPIO_O_AFSEL) = ((ui32PinIO & GPIO_DIR_MODE_HW) ?
  178. (HWREG(ui32Port + GPIO_O_AFSEL) | ui8Pins) :
  179. (HWREG(ui32Port + GPIO_O_AFSEL) & ~(ui8Pins)));
  180. }
  181. //*****************************************************************************
  182. //
  183. //! Gets the direction and mode of a pin
  184. //!
  185. //! \param ui32Port is the base address of the GPIO port.
  186. //! \param ui8Pin is the pin number.
  187. //!
  188. //! This function gets the direction and control mode for a specified pin on
  189. //! the selected GPIO port. The pin can be configured as either an input or
  190. //! output under software control, or it can be under hardware control. The
  191. //! type of control and direction are returned as an enumerated data type.
  192. //!
  193. //! \return Returns one of the enumerated data types described for
  194. //! GPIODirModeSet().
  195. //
  196. //*****************************************************************************
  197. uint32_t
  198. GPIODirModeGet(uint32_t ui32Port, uint8_t ui8Pin)
  199. {
  200. uint32_t ui32Dir;
  201. uint32_t ui32AFSEL;
  202. //
  203. // Check the arguments.
  204. //
  205. ASSERT(GPIOBaseValid(ui32Port));
  206. ASSERT(ui8Pin < 8);
  207. //
  208. // Convert from a pin number to a bit position.
  209. //
  210. ui8Pin = 1 << ui8Pin;
  211. //
  212. // Return the pin direction and mode.
  213. //
  214. ui32Dir = HWREG(ui32Port + GPIO_O_DIR);
  215. ui32AFSEL = HWREG(ui32Port + GPIO_O_AFSEL);
  216. return(((ui32Dir & ui8Pin) ? GPIO_DIR_MODE_OUT : GPIO_DIR_MODE_IN) |
  217. ((ui32AFSEL & ui8Pin) ? GPIO_DIR_MODE_HW : GPIO_DIR_MODE_IN));
  218. }
  219. //*****************************************************************************
  220. //
  221. //! Sets the interrupt type for the specified pin(s)
  222. //!
  223. //! \param ui32Port is the base address of the GPIO port.
  224. //! \param ui8Pins is the bit-packed representation of the pin(s).
  225. //! \param ui32IntType specifies the type of interrupt trigger mechanism.
  226. //!
  227. //! This function sets up the various interrupt trigger mechanisms for the
  228. //! specified pin(s) on the selected GPIO port.
  229. //!
  230. //! The parameter \e ui32IntType is an enumerated data type that can be one of
  231. //! the following values:
  232. //!
  233. //! - \b GPIO_FALLING_EDGE
  234. //! - \b GPIO_RISING_EDGE
  235. //! - \b GPIO_BOTH_EDGES
  236. //! - \b GPIO_LOW_LEVEL
  237. //! - \b GPIO_HIGH_LEVEL
  238. //!
  239. //! where the different values describe the interrupt detection mechanism
  240. //! (edge or level) and the particular triggering event (falling, rising,
  241. //! or both edges for edge detect, low or high for level detect).
  242. //!
  243. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  244. //! set identifies the pin to be accessed, and where bit 0 of the byte
  245. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  246. //!
  247. //! \note To avoid any spurious interrupts, the user must
  248. //! ensure that the GPIO inputs remain stable for the duration of
  249. //! this function.
  250. //!
  251. //! \return None
  252. //
  253. //*****************************************************************************
  254. void
  255. GPIOIntTypeSet(uint32_t ui32Port, uint8_t ui8Pins,
  256. uint32_t ui32IntType)
  257. {
  258. //
  259. // Check the arguments.
  260. //
  261. ASSERT(GPIOBaseValid(ui32Port));
  262. ASSERT((ui32IntType == GPIO_FALLING_EDGE) ||
  263. (ui32IntType == GPIO_RISING_EDGE) || (ui32IntType == GPIO_BOTH_EDGES) ||
  264. (ui32IntType == GPIO_LOW_LEVEL) || (ui32IntType == GPIO_HIGH_LEVEL));
  265. //
  266. // Set the pin interrupt type.
  267. //
  268. HWREG(ui32Port + GPIO_O_IBE) = ((ui32IntType & 1) ?
  269. (HWREG(ui32Port + GPIO_O_IBE) | ui8Pins) :
  270. (HWREG(ui32Port + GPIO_O_IBE) & ~(ui8Pins)));
  271. HWREG(ui32Port + GPIO_O_IS) = ((ui32IntType & 2) ?
  272. (HWREG(ui32Port + GPIO_O_IS) | ui8Pins) :
  273. (HWREG(ui32Port + GPIO_O_IS) & ~(ui8Pins)));
  274. HWREG(ui32Port + GPIO_O_IEV) = ((ui32IntType & 4) ?
  275. (HWREG(ui32Port + GPIO_O_IEV) | ui8Pins) :
  276. (HWREG(ui32Port + GPIO_O_IEV) & ~(ui8Pins)));
  277. }
  278. //*****************************************************************************
  279. //
  280. //! Gets the interrupt type for a pin
  281. //!
  282. //! \param ui32Port is the base address of the GPIO port.
  283. //! \param ui8Pin is the pin number.
  284. //!
  285. //! This function gets the interrupt type for a specified pin on the selected
  286. //! GPIO port. The pin can be configured as a falling edge, rising edge, or
  287. //! both edge detected interrupt, or can be configured as a low level or
  288. //! high level detected interrupt. The type of interrupt detection mechanism
  289. //! is returned as an enumerated data type.
  290. //!
  291. //! \return Returns one of the enumerated data types described for
  292. //! GPIOIntTypeSet().
  293. //
  294. //*****************************************************************************
  295. uint32_t
  296. GPIOIntTypeGet(uint32_t ui32Port, uint8_t ui8Pin)
  297. {
  298. uint32_t ui32IBE, ui32IS, ui32IEV;
  299. //
  300. // Check the arguments.
  301. //
  302. ASSERT(GPIOBaseValid(ui32Port));
  303. ASSERT(ui8Pin < 8);
  304. //
  305. // Convert from a pin number to a bit position.
  306. //
  307. ui8Pin = 1 << ui8Pin;
  308. //
  309. // Return the pin interrupt type.
  310. //
  311. ui32IBE = HWREG(ui32Port + GPIO_O_IBE);
  312. ui32IS = HWREG(ui32Port + GPIO_O_IS);
  313. ui32IEV = HWREG(ui32Port + GPIO_O_IEV);
  314. return(((ui32IBE & ui8Pin) ? 1 : 0) | ((ui32IS & ui8Pin) ? 2 : 0) |
  315. ((ui32IEV & ui8Pin) ? 4 : 0));
  316. }
  317. //*****************************************************************************
  318. //
  319. //! Enables interrupts for the specified pin(s)
  320. //!
  321. //! \param ui32Port is the base address of the GPIO port.
  322. //! \param ui8Pins is the bit-packed representation of the pin(s).
  323. //!
  324. //! Unmasks the interrupt for the specified pin(s).
  325. //!
  326. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  327. //! set identifies the pin to be accessed, and where bit 0 of the byte
  328. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  329. //!
  330. //! \return None
  331. //
  332. //*****************************************************************************
  333. void
  334. GPIOPinIntEnable(uint32_t ui32Port, uint8_t ui8Pins)
  335. {
  336. //
  337. // Check the arguments.
  338. //
  339. ASSERT(GPIOBaseValid(ui32Port));
  340. //
  341. // Enable the interrupts.
  342. //
  343. HWREG(ui32Port + GPIO_O_IE) |= ui8Pins;
  344. }
  345. //*****************************************************************************
  346. //
  347. //! Disables interrupts for the specified pin(s)
  348. //!
  349. //! \param ui32Port is the base address of the GPIO port.
  350. //! \param ui8Pins is the bit-packed representation of the pin(s).
  351. //!
  352. //! Masks the interrupt for the specified pin(s)
  353. //!
  354. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  355. //! set identifies the pin to be accessed, and where bit 0 of the byte
  356. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  357. //!
  358. //! \return None
  359. //
  360. //*****************************************************************************
  361. void
  362. GPIOPinIntDisable(uint32_t ui32Port, uint8_t ui8Pins)
  363. {
  364. //
  365. // Check the arguments.
  366. //
  367. ASSERT(GPIOBaseValid(ui32Port));
  368. //
  369. // Disable the interrupts.
  370. //
  371. HWREG(ui32Port + GPIO_O_IE) &= ~(ui8Pins);
  372. }
  373. //*****************************************************************************
  374. //
  375. //! Gets interrupt status for the specified GPIO port
  376. //!
  377. //! \param ui32Port is the base address of the GPIO port.
  378. //! \param bMasked specifies whether masked or raw interrupt status is
  379. //! returned.
  380. //!
  381. //! If \e bMasked is set as \b true, then the masked interrupt status is
  382. //! returned; otherwise, the raw interrupt status is returned.
  383. //!
  384. //! \return Returns a bit-packed byte, where each bit that is set identifies
  385. //! an active masked or raw interrupt, and where bit 0 of the byte
  386. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  387. //! Bits 31:8 should be ignored.
  388. //
  389. //*****************************************************************************
  390. uint32_t
  391. GPIOPinIntStatus(uint32_t ui32Port, bool bMasked)
  392. {
  393. //
  394. // Check the arguments.
  395. //
  396. ASSERT(GPIOBaseValid(ui32Port));
  397. //
  398. // Return the interrupt status.
  399. //
  400. if(bMasked)
  401. {
  402. return(HWREG(ui32Port + GPIO_O_MIS));
  403. }
  404. else
  405. {
  406. return(HWREG(ui32Port + GPIO_O_RIS));
  407. }
  408. }
  409. //*****************************************************************************
  410. //
  411. //! Clears the interrupt for the specified pin(s)
  412. //!
  413. //! \param ui32Port is the base address of the GPIO port.
  414. //! \param ui8Pins is the bit-packed representation of the pin(s).
  415. //!
  416. //! Clears the interrupt for the specified pin(s).
  417. //!
  418. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  419. //! set identifies the pin to be accessed, and where bit 0 of the byte
  420. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  421. //!
  422. //! \note The write buffer in the Cortex-M3 processor can cause the interrupt
  423. //! source to take several clock cycles before clearing.
  424. //! Therefore, TI recommends clearing the interrupt source early in the
  425. //! interrupt handler (as opposed to the very last action) to avoid
  426. //! returning from the interrupt handler before the interrupt source is
  427. //! actually cleared. Failure to clear the interrupt source early can result in
  428. //! the interrupt handler being immediately reentered (because NVIC still sees
  429. //! the interrupt source asserted).
  430. //!
  431. //! \return None
  432. //
  433. //*****************************************************************************
  434. void
  435. GPIOPinIntClear(uint32_t ui32Port, uint8_t ui8Pins)
  436. {
  437. //
  438. // Check the arguments.
  439. //
  440. ASSERT(GPIOBaseValid(ui32Port));
  441. //
  442. // Clear the interrupts.
  443. //
  444. HWREG(ui32Port + GPIO_O_IC) = ui8Pins;
  445. }
  446. //*****************************************************************************
  447. //
  448. //! Registers an interrupt handler for a GPIO port
  449. //!
  450. //! \param ui32Port is the base address of the GPIO port.
  451. //! \param pfnHandler is a pointer to the GPIO port interrupt handling
  452. //! function.
  453. //!
  454. //! This function ensures that the interrupt handler specified by
  455. //! \e pfnHandler is called when an interrupt is detected from the selected
  456. //! GPIO port. This function also enables the corresponding GPIO interrupt
  457. //! in the interrupt controller; individual pin interrupts and interrupt
  458. //! sources must be enabled with GPIOPinIntEnable().
  459. //!
  460. //! \sa IntRegister() for important information about registering interrupt
  461. //! handlers.
  462. //!
  463. //! \return None
  464. //
  465. //*****************************************************************************
  466. void
  467. GPIOPortIntRegister(uint32_t ui32Port, void (*pfnHandler)(void))
  468. {
  469. //
  470. // Check the arguments.
  471. //
  472. ASSERT(GPIOBaseValid(ui32Port));
  473. //
  474. // Get the interrupt number associated with the specified GPIO.
  475. //
  476. ui32Port = GPIOGetIntNumber(ui32Port);
  477. //
  478. // Register the interrupt handler.
  479. //
  480. IntRegister(ui32Port, pfnHandler);
  481. //
  482. // Enable the GPIO interrupt.
  483. //
  484. IntEnable(ui32Port);
  485. }
  486. //*****************************************************************************
  487. //
  488. //! Removes an interrupt handler for a GPIO port
  489. //!
  490. //! \param ui32Port is the base address of the GPIO port.
  491. //!
  492. //! This function unregisters the interrupt handler for the specified
  493. //! GPIO port. This function also disables the corresponding
  494. //! GPIO port interrupt in the interrupt controller; individual GPIO interrupts
  495. //! and interrupt sources must be disabled with GPIOPinIntDisable().
  496. //!
  497. //! \sa IntRegister() for important information about registering interrupt
  498. //! handlers.
  499. //!
  500. //! \return None
  501. //
  502. //*****************************************************************************
  503. void
  504. GPIOPortIntUnregister(uint32_t ui32Port)
  505. {
  506. //
  507. // Check the arguments.
  508. //
  509. ASSERT(GPIOBaseValid(ui32Port));
  510. //
  511. // Get the interrupt number associated with the specified GPIO.
  512. //
  513. ui32Port = GPIOGetIntNumber(ui32Port);
  514. //
  515. // Disable the GPIO interrupt.
  516. //
  517. IntDisable(ui32Port);
  518. //
  519. // Unregister the interrupt handler.
  520. //
  521. IntUnregister(ui32Port);
  522. }
  523. //*****************************************************************************
  524. //
  525. //! Reads the values present of the specified pin(s)
  526. //!
  527. //! \param ui32Port is the base address of the GPIO port.
  528. //! \param ui8Pins is the bit-packed representation of the pin(s).
  529. //!
  530. //! The values at the specified pin(s) are read, as specified by \e ui8Pins.
  531. //! Values are returned for both input and output pin(s), and the value
  532. //! for pin(s) that are not specified by \e ui8Pins are set to 0.
  533. //!
  534. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  535. //! set identifies the pin to be accessed, and where bit 0 of the byte
  536. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  537. //!
  538. //! \return Returns a bit-packed byte providing the state of the specified
  539. //! pin, where bit 0 of the byte represents GPIO port pin 0, bit 1 represents
  540. //! GPIO port pin 1, and so on. Any bit that is not specified by \e ui8Pins
  541. //! is returned as a 0. Bits 31:8 should be ignored.
  542. //
  543. //*****************************************************************************
  544. uint32_t
  545. GPIOPinRead(uint32_t ui32Port, uint8_t ui8Pins)
  546. {
  547. //
  548. // Check the arguments.
  549. //
  550. ASSERT(GPIOBaseValid(ui32Port));
  551. //
  552. // Return the pin value(s).
  553. //
  554. return(HWREG(ui32Port + (GPIO_O_DATA + (ui8Pins << 2))));
  555. }
  556. //*****************************************************************************
  557. //
  558. //! Writes a value to the specified pin(s)
  559. //!
  560. //! \param ui32Port is the base address of the GPIO port.
  561. //! \param ui8Pins is the bit-packed representation of the pin(s).
  562. //! \param ui8Val is the value to write to the pin(s).
  563. //!
  564. //! Writes the corresponding bit values to the output pin(s) specified by
  565. //! \e ui8Pins. Writing to a pin configured as an input pin has no effect.
  566. //!
  567. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  568. //! set identifies the pin to be accessed, and where bit 0 of the byte
  569. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  570. //!
  571. //! \return None
  572. //
  573. //*****************************************************************************
  574. void
  575. GPIOPinWrite(uint32_t ui32Port, uint8_t ui8Pins, uint8_t ui8Val)
  576. {
  577. //
  578. // Check the arguments.
  579. //
  580. ASSERT(GPIOBaseValid(ui32Port));
  581. //
  582. // Write the pins.
  583. //
  584. HWREG(ui32Port + (GPIO_O_DATA + (ui8Pins << 2))) = ui8Val;
  585. }
  586. //*****************************************************************************
  587. //
  588. //! Configures pin(s) for use as GPIO inputs
  589. //!
  590. //! \param ui32Port is the base address of the GPIO port.
  591. //! \param ui8Pins is the bit-packed representation of the pin(s).
  592. //!
  593. //! The GPIO pins must be properly configured in order to function correctly as
  594. //! GPIO inputs. This function provides the proper configuration for those
  595. //! pin(s).
  596. //!
  597. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  598. //! set identifies the pin to be accessed, and where bit 0 of the byte
  599. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  600. //!
  601. //! \return None
  602. //
  603. //*****************************************************************************
  604. void
  605. GPIOPinTypeGPIOInput(uint32_t ui32Port, uint8_t ui8Pins)
  606. {
  607. //
  608. // Check the arguments.
  609. //
  610. ASSERT(GPIOBaseValid(ui32Port));
  611. //
  612. // Make the pin(s) be inputs.
  613. //
  614. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_IN);
  615. //
  616. // Set the pad(s) to no override of the drive type.
  617. //
  618. IOCPadConfigSet(ui32Port, ui8Pins, IOC_OVERRIDE_DIS);
  619. }
  620. //*****************************************************************************
  621. //
  622. //! Configures pin(s) for use as GPIO outputs
  623. //!
  624. //! \param ui32Port is the base address of the GPIO port.
  625. //! \param ui8Pins is the bit-packed representation of the pin(s).
  626. //!
  627. //! The GPIO pins must be properly configured to function correctly as
  628. //! GPIO outputs. This function provides the proper configuration for those
  629. //! pin(s).
  630. //!
  631. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  632. //! set identifies the pin to be accessed, and where bit 0 of the byte
  633. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  634. //!
  635. //! \return None
  636. //
  637. //*****************************************************************************
  638. void
  639. GPIOPinTypeGPIOOutput(uint32_t ui32Port, uint8_t ui8Pins)
  640. {
  641. //
  642. // Check the arguments.
  643. //
  644. ASSERT(GPIOBaseValid(ui32Port));
  645. //
  646. // Make the pin(s) be outputs.
  647. //
  648. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_OUT);
  649. //
  650. // Set the pad(s) no override of the drive type.
  651. //
  652. IOCPadConfigSet(ui32Port, ui8Pins, IOC_OVERRIDE_DIS);
  653. }
  654. //*****************************************************************************
  655. //
  656. //! Configures pin(s) for use by the I2C peripheral
  657. //!
  658. //! \param ui32Port is the base address of the GPIO port.
  659. //! \param ui8Pins is the bit-packed representation of the pin(s).
  660. //!
  661. //! The I2C pins must be properly configured for the I2C peripheral to function
  662. //! correctly. This function provides the proper configuration for those
  663. //! pin(s).
  664. //!
  665. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  666. //! set identifies the pin to be accessed, and where bit 0 of the byte
  667. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  668. //!
  669. //! \note This function cannot be used to turn any pin into an I2C pin; it only
  670. //! configures an I2C pin for proper operation.
  671. //!
  672. //! \return None
  673. //
  674. //*****************************************************************************
  675. void
  676. GPIOPinTypeI2C(uint32_t ui32Port, uint8_t ui8Pins)
  677. {
  678. //
  679. // Check the arguments.
  680. //
  681. ASSERT(GPIOBaseValid(ui32Port));
  682. //
  683. // Make the pin(s) be peripheral controlled.
  684. //
  685. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  686. //
  687. // Set the pad(s) to no drive type.
  688. //
  689. IOCPadConfigSet(ui32Port, ui8Pins, IOC_OVERRIDE_DIS);
  690. }
  691. //*****************************************************************************
  692. //
  693. //! Configures pin(s) for use by the SSI peripheral
  694. //!
  695. //! \param ui32Port is the base address of the GPIO port.
  696. //! \param ui8Pins is the bit-packed representation of the pin(s).
  697. //!
  698. //! The SSI pins must be properly configured for the SSI peripheral to function
  699. //! correctly. This function provides a typical configuration for those
  700. //! pin(s); other configurations might work as well depending upon the board
  701. //! setup (for example, using the on-chip pull-ups).
  702. //!
  703. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  704. //! set identifies the pin to be accessed, and where bit 0 of the byte
  705. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  706. //!
  707. //! \note This function cannot be used to turn any pin into a SSI pin; but only
  708. //! configures an SSI pin for proper operation.
  709. //!
  710. //! \return None
  711. //
  712. //*****************************************************************************
  713. void
  714. GPIOPinTypeSSI(uint32_t ui32Port, uint8_t ui8Pins)
  715. {
  716. //
  717. // Check the arguments.
  718. //
  719. ASSERT(GPIOBaseValid(ui32Port));
  720. //
  721. // Make the pin(s) be peripheral controlled.
  722. //
  723. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  724. //
  725. // Set the pad(s) to no drive type.
  726. //
  727. IOCPadConfigSet(ui32Port, ui8Pins, IOC_OVERRIDE_DIS);
  728. }
  729. //*****************************************************************************
  730. //
  731. //! Configures pin(s) for use by the Timer peripheral
  732. //!
  733. //! \param ui32Port is the base address of the GPIO port.
  734. //! \param ui8Pins is the bit-packed representation of the pin(s).
  735. //!
  736. //! The CCP pins must be properly configured for the timer peripheral to
  737. //! function correctly. This function provides a typical configuration for
  738. //! those pin(s); other configurations might work as well depending upon the
  739. //! board setup (for example, using the on-chip pull-ups).
  740. //!
  741. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  742. //! set identifies the pin to be accessed, and where bit 0 of the byte
  743. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  744. //!
  745. //! \note This function cannot be used to turn any pin into a timer pin but only
  746. //! configures a timer pin for proper operation.
  747. //!
  748. //! \return None
  749. //
  750. //*****************************************************************************
  751. void
  752. GPIOPinTypeTimer(uint32_t ui32Port, uint8_t ui8Pins)
  753. {
  754. //
  755. // Check the arguments.
  756. //
  757. ASSERT(GPIOBaseValid(ui32Port));
  758. //
  759. // Make the pin(s) be peripheral controlled.
  760. //
  761. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  762. //
  763. // Set the pad(s) to no drive type.
  764. //
  765. IOCPadConfigSet(ui32Port, ui8Pins, IOC_OVERRIDE_DIS);
  766. }
  767. //*****************************************************************************
  768. //
  769. //! Configures input pin(s) for use by the UART peripheral
  770. //!
  771. //! \param ui32Port is the base address of the GPIO port.
  772. //! \param ui8Pins is the bit-packed representation of the pin(s).
  773. //!
  774. //! The UART input pins must be properly configured for the UART peripheral to
  775. //! function correctly. This function provides a typical configuration for
  776. //! those pin(s); other configurations might work as well depending upon the
  777. //! board setup (for example, using the on-chip pull-ups).
  778. //!
  779. //! \note For PC0 through PC3 the function GPIOPinTypeUARTHiDrive() should
  780. //! be used to configure these high drive pins.
  781. //!
  782. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  783. //! set identifies the pin to be accessed, and where bit 0 of the byte
  784. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  785. //!
  786. //! \note This function cannot be used to turn any pin into a UART pin; but only
  787. //! configures a UART pin for proper operation.
  788. //!
  789. //! \return None
  790. //
  791. //*****************************************************************************
  792. void
  793. GPIOPinTypeUARTInput(uint32_t ui32Port, uint8_t ui8Pins)
  794. {
  795. //
  796. // Check the arguments.
  797. //
  798. ASSERT(GPIOBaseValid(ui32Port));
  799. ASSERT(!((ui32Port == GPIO_C_BASE) && ((ui8Pins & 0xf) > 0)));
  800. //
  801. // Make the pin(s) be peripheral controlled.
  802. //
  803. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  804. //
  805. // Set the pad(s) to override disable.
  806. //
  807. IOCPadConfigSet(ui32Port, ui8Pins, IOC_OVERRIDE_DIS);
  808. }
  809. //*****************************************************************************
  810. //
  811. //! Configures output pin(s) for use by the UART peripheral
  812. //!
  813. //! \param ui32Port is the base address of the GPIO port.
  814. //! \param ui8Pins is the bit-packed representation of the pin(s).
  815. //!
  816. //! The UART output pins must be properly configured for the UART peripheral to
  817. //! function correctly. This function provides a typical configuration for
  818. //! those pin(s); other configurations might work as well depending upon the
  819. //! board setup (for example, using the on-chip pull-ups).
  820. //!
  821. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  822. //! set identifies the pin to be accessed, and where bit 0 of the byte
  823. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  824. //!
  825. //! \note This function cannot be used to turn any pin into a UART pin; but only
  826. //! configures a UART pin for proper operation.
  827. //!
  828. //! \return None
  829. //
  830. //*****************************************************************************
  831. void
  832. GPIOPinTypeUARTOutput(uint32_t ui32Port, uint8_t ui8Pins)
  833. {
  834. //
  835. // Check the arguments.
  836. //
  837. ASSERT(GPIOBaseValid(ui32Port));
  838. ASSERT(!((ui32Port == GPIO_C_BASE) && ((ui8Pins & 0xf) > 0)));
  839. //
  840. // Make the pin(s) be peripheral controlled.
  841. //
  842. GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
  843. //
  844. // Set the pad(s) to output enable.
  845. //
  846. IOCPadConfigSet(ui32Port, ui8Pins, IOC_OVERRIDE_OE);
  847. }
  848. //*****************************************************************************
  849. //
  850. //! Sets the power-up interrupt type for the specified pin(s)
  851. //!
  852. //! \param ui32Port is the base address of the GPIO port.
  853. //! \param ui8Pins is the bit-packed representation of the pin(s).
  854. //! \param ui32IntType specifies type of power-up interrupt trigger mechanism.
  855. //!
  856. //! This function sets up the various interrupt trigger mechanisms for the
  857. //! specified pin(s) on the selected GPIO port.
  858. //!
  859. //! The parameter \e ui32IntType is an enumerated data type that can be one of
  860. //! the following values:
  861. //!
  862. //! - \b GPIO_POW_FALLING_EDGE
  863. //! - \b GPIO_POW_RISING_EDGE
  864. //!
  865. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  866. //! set identifies the pin to be accessed, and where bit 0 of the byte
  867. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  868. //!
  869. //! \note To avoid any spurious interrupts, the user must
  870. //! ensure that the GPIO inputs remain stable for the duration of
  871. //! this function.
  872. //!
  873. //! \return None
  874. //
  875. //*****************************************************************************
  876. void
  877. GPIOPowIntTypeSet(uint32_t ui32Port, uint8_t ui8Pins,
  878. uint32_t ui32IntType)
  879. {
  880. uint32_t ui32PortOffset;
  881. uint32_t ui32IntPins;
  882. //
  883. // Initialize value
  884. //
  885. ui32PortOffset = 0;
  886. //
  887. // Check the arguments.
  888. //
  889. ASSERT(GPIOBaseValid(ui32Port));
  890. ASSERT((ui32IntType == GPIO_POW_FALLING_EDGE) ||
  891. (ui32IntType == GPIO_POW_RISING_EDGE));
  892. //
  893. // Find bit mask for wanted pin(s)
  894. //
  895. if(ui32Port == GPIO_A_BASE)
  896. {
  897. ui32PortOffset = 0;
  898. }
  899. if(ui32Port == GPIO_B_BASE)
  900. {
  901. ui32PortOffset = 8;
  902. }
  903. if(ui32Port == GPIO_C_BASE)
  904. {
  905. ui32PortOffset = 16;
  906. }
  907. if(ui32Port == GPIO_D_BASE)
  908. {
  909. ui32PortOffset = 24;
  910. }
  911. ui32IntPins = ui8Pins << ui32PortOffset;
  912. //
  913. // Set the pin interrupt type.
  914. //
  915. if(ui32IntType == GPIO_POW_FALLING_EDGE)
  916. {
  917. HWREG(ui32Port + GPIO_O_P_EDGE_CTRL) |= ui32IntPins;
  918. }
  919. else // GPIO_POW_RAISING_EDGE
  920. {
  921. HWREG(ui32Port + GPIO_O_P_EDGE_CTRL) &= ~(ui32IntPins);
  922. }
  923. }
  924. //*****************************************************************************
  925. //
  926. //! Gets the power-up interrupt type for a pin
  927. //!
  928. //! \param ui32Port is the base address of the GPIO port.
  929. //! \param ui8Pin is the pin number.
  930. //!
  931. //! This function gets the interrupt type for a specified pin on the selected
  932. //! GPIO port. The pin can be configured as a falling edge, rising edge, or
  933. //! both edge detected interrupt, or it can be configured as a low level or
  934. //! high level detected interrupt. The type of interrupt detection mechanism
  935. //! is returned as an enumerated data type.
  936. //!
  937. //! \return Returns one of the enumerated data types described for
  938. //! GPIOIntTypeSet().
  939. //
  940. //*****************************************************************************
  941. uint32_t
  942. GPIOPowIntTypeGet(uint32_t ui32Port, uint8_t ui8Pin)
  943. {
  944. uint32_t ui32PortOffset;
  945. uint32_t ui32IntPin;
  946. //
  947. // Initialize value
  948. //
  949. ui32PortOffset = 0;
  950. //
  951. // Check the arguments.
  952. //
  953. ASSERT(GPIOBaseValid(ui32Port));
  954. ASSERT(ui8Pin < 8);
  955. //
  956. // Convert from a port- pin number to a bit position.
  957. //
  958. if(ui32Port == GPIO_A_BASE)
  959. {
  960. ui32PortOffset = 0;
  961. }
  962. if(ui32Port == GPIO_B_BASE)
  963. {
  964. ui32PortOffset = 8;
  965. }
  966. if(ui32Port == GPIO_C_BASE)
  967. {
  968. ui32PortOffset = 16;
  969. }
  970. if(ui32Port == GPIO_D_BASE)
  971. {
  972. ui32PortOffset = 24;
  973. }
  974. ui32IntPin = 1 << (ui8Pin + ui32PortOffset);
  975. //
  976. // Return the pin interrupt type.
  977. //
  978. if(HWREG(ui32Port + GPIO_O_P_EDGE_CTRL) & ui32IntPin)
  979. {
  980. return(GPIO_POW_FALLING_EDGE);
  981. }
  982. else
  983. {
  984. return(GPIO_POW_RISING_EDGE);
  985. }
  986. }
  987. //*****************************************************************************
  988. //
  989. //! Enables power-up interrupts for the specified pin(s)
  990. //!
  991. //! \param ui32Port is the base address of the GPIO port.
  992. //! \param ui8Pins is the bit-packed representation of the pin(s).
  993. //!
  994. //! Unmasks the interrupt for the specified pin(s).
  995. //!
  996. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  997. //! set identifies the pin to be accessed, and where bit 0 of the byte
  998. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  999. //!
  1000. //! \return None
  1001. //
  1002. //*****************************************************************************
  1003. void
  1004. GPIOPowIntEnable(uint32_t ui32Port, uint8_t ui8Pins)
  1005. {
  1006. uint32_t ui32PortOffset;
  1007. uint32_t ui32IntPins;
  1008. //
  1009. // Initialize value
  1010. //
  1011. ui32PortOffset = 0;
  1012. //
  1013. // Check the arguments.
  1014. //
  1015. ASSERT(GPIOBaseValid(ui32Port));
  1016. //
  1017. // Find bit mask for wanted pin(s)
  1018. //
  1019. if(ui32Port == GPIO_A_BASE)
  1020. {
  1021. ui32PortOffset = 0;
  1022. }
  1023. if(ui32Port == GPIO_B_BASE)
  1024. {
  1025. ui32PortOffset = 8;
  1026. }
  1027. if(ui32Port == GPIO_C_BASE)
  1028. {
  1029. ui32PortOffset = 16;
  1030. }
  1031. if(ui32Port == GPIO_D_BASE)
  1032. {
  1033. ui32PortOffset = 24;
  1034. }
  1035. ui32IntPins = ui8Pins << ui32PortOffset;
  1036. //
  1037. // Enable the interrupts.
  1038. //
  1039. HWREG(ui32Port + GPIO_O_PI_IEN) |= ui32IntPins;
  1040. }
  1041. //*****************************************************************************
  1042. //
  1043. //! Disables power-up interrupts for the specified pin(s)
  1044. //!
  1045. //! \param ui32Port is the base address of the GPIO port.
  1046. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1047. //!
  1048. //! Masks the interrupt for the specified pin(s).
  1049. //!
  1050. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1051. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1052. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1053. //!
  1054. //! \return None
  1055. //
  1056. //*****************************************************************************
  1057. void
  1058. GPIOPowIntDisable(uint32_t ui32Port, uint8_t ui8Pins)
  1059. {
  1060. uint32_t ui32PortOffset;
  1061. uint32_t ui32IntPins;
  1062. //
  1063. // Initialize value
  1064. //
  1065. ui32PortOffset = 0;
  1066. //
  1067. // Check the arguments.
  1068. //
  1069. ASSERT(GPIOBaseValid(ui32Port));
  1070. //
  1071. // Find bit mask for wanted pin(s)
  1072. //
  1073. if(ui32Port == GPIO_A_BASE)
  1074. {
  1075. ui32PortOffset = 0;
  1076. }
  1077. if(ui32Port == GPIO_B_BASE)
  1078. {
  1079. ui32PortOffset = 8;
  1080. }
  1081. if(ui32Port == GPIO_C_BASE)
  1082. {
  1083. ui32PortOffset = 16;
  1084. }
  1085. if(ui32Port == GPIO_D_BASE)
  1086. {
  1087. ui32PortOffset = 24;
  1088. }
  1089. ui32IntPins = ui8Pins << ui32PortOffset;
  1090. //
  1091. // Disable the interrupts.
  1092. //
  1093. HWREG(ui32Port + GPIO_O_PI_IEN) &= ~(ui32IntPins);
  1094. }
  1095. //*****************************************************************************
  1096. //
  1097. //! Gets power-up interrupt status for the specified GPIO port
  1098. //!
  1099. //! \param ui32Port is the base address of the GPIO port.
  1100. //! \param bMasked specifies whether masked or raw interrupt status is
  1101. //! returned.
  1102. //!
  1103. //! If \e bMasked is set as \b true, then the masked interrupt status is
  1104. //! returned; otherwise, the raw interrupt status is returned.
  1105. //!
  1106. //! \return Returns a bit-packed byte, where each bit that is set identifies
  1107. //! an active masked or raw interrupt, and where bit 0 of the byte
  1108. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1109. //! Bits 31:8 should be ignored.
  1110. //
  1111. //*****************************************************************************
  1112. uint32_t
  1113. GPIOPowIntStatus(uint32_t ui32Port, bool bMasked)
  1114. {
  1115. uint32_t ui32PortOffset;
  1116. //
  1117. // Initialize value
  1118. //
  1119. ui32PortOffset = 0;
  1120. // Check the arguments.
  1121. ASSERT(GPIOBaseValid(ui32Port));
  1122. //
  1123. // Find bit mask for wanted pin(s)
  1124. //
  1125. if(ui32Port == GPIO_A_BASE)
  1126. {
  1127. ui32PortOffset = 0;
  1128. }
  1129. if(ui32Port == GPIO_B_BASE)
  1130. {
  1131. ui32PortOffset = 8;
  1132. }
  1133. if(ui32Port == GPIO_C_BASE)
  1134. {
  1135. ui32PortOffset = 16;
  1136. }
  1137. if(ui32Port == GPIO_D_BASE)
  1138. {
  1139. ui32PortOffset = 24;
  1140. }
  1141. // Return the interrupt status.
  1142. if(bMasked)
  1143. {
  1144. return((HWREG(ui32Port + GPIO_O_IRQ_DETECT_ACK) >> ui32PortOffset) &
  1145. 0xFF);
  1146. }
  1147. else
  1148. {
  1149. return((HWREG(ui32Port + GPIO_O_IRQ_DETECT_UNMASK) >> ui32PortOffset) &
  1150. 0xFF);
  1151. }
  1152. }
  1153. //*****************************************************************************
  1154. //
  1155. //! Clears the power-up interrupt for the specified pin(s)
  1156. //!
  1157. //! \param ui32Port is the base address of the GPIO port.
  1158. //! \param ui8Pins is the bit-packed representation of the pin(s).
  1159. //!
  1160. //! Clears the interrupt for the specified pin(s).
  1161. //!
  1162. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  1163. //! set identifies the pin to be accessed, and where bit 0 of the byte
  1164. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  1165. //!
  1166. //! \return None
  1167. //
  1168. //*****************************************************************************
  1169. void
  1170. GPIOPowIntClear(uint32_t ui32Port, uint8_t ui8Pins)
  1171. {
  1172. uint32_t ui32PortOffset;
  1173. uint32_t ui32IntPins;
  1174. //
  1175. // Initialize value
  1176. //
  1177. ui32PortOffset = 0;
  1178. //
  1179. // Check the arguments.
  1180. //
  1181. ASSERT(GPIOBaseValid(ui32Port));
  1182. //
  1183. // Find bit mask for wanted pin(s)
  1184. //
  1185. if(ui32Port == GPIO_A_BASE)
  1186. {
  1187. ui32PortOffset = 0;
  1188. }
  1189. if(ui32Port == GPIO_B_BASE)
  1190. {
  1191. ui32PortOffset = 8;
  1192. }
  1193. if(ui32Port == GPIO_C_BASE)
  1194. {
  1195. ui32PortOffset = 16;
  1196. }
  1197. if(ui32Port == GPIO_D_BASE)
  1198. {
  1199. ui32PortOffset = 24;
  1200. }
  1201. ui32IntPins = ui8Pins << ui32PortOffset;
  1202. //
  1203. // Clear the interrupts.
  1204. //
  1205. HWREG(ui32Port + GPIO_O_IRQ_DETECT_ACK) |= ui32IntPins;
  1206. }
  1207. //*****************************************************************************
  1208. //
  1209. //! Enable Wake Up Interrupt
  1210. //!
  1211. //! \param ui32Config is the source to enable wake up on interrupt.
  1212. //!
  1213. //! This function enables wake up on interrupt from the selected sources.
  1214. //!
  1215. //! The \e ui32Config argument must be one or the logical or of several of
  1216. //! the following values:
  1217. //!
  1218. //! \b GPIO_IWE_PORT_A, \b GPIO_IWE_PORT_B, \b GPIO_IWE_PORT_C,
  1219. //! \b GPIO_IWE_PORT_D, \b GPIO_IWE_USB,
  1220. //! \b GPIO_IWE_SM_TIMER.
  1221. //!
  1222. //! \return None
  1223. //
  1224. //*****************************************************************************
  1225. void
  1226. GPIOIntWakeupEnable(uint32_t ui32Config)
  1227. {
  1228. ASSERT((ui32Config &
  1229. (GPIO_IWE_PORT_A |
  1230. GPIO_IWE_PORT_B |
  1231. GPIO_IWE_PORT_C |
  1232. GPIO_IWE_PORT_D |
  1233. GPIO_IWE_USB |
  1234. GPIO_IWE_SM_TIMER)) != 0);
  1235. //
  1236. // Enable Wakeup from selected Interrupt sources
  1237. //
  1238. HWREG(SYS_CTRL_IWE) |= ui32Config;
  1239. }
  1240. //*****************************************************************************
  1241. //
  1242. //! Disable Wake Up Interrupt
  1243. //!
  1244. //! \param ui32Config is the source to disable wake on interrupt from.
  1245. //!
  1246. //! This function disables Wake up on interrupt from the selected sources.
  1247. //!
  1248. //! The \e ui32Config argument must be one or the logical or of several of
  1249. //! the following values:
  1250. //!
  1251. //! \b GPIO_IWE_PORT_A, \b GPIO_IWE_PORT_B, \b GPIO_IWE_PORT_C,
  1252. //! \b GPIO_IWE_PORT_D, \b GPIO_IWE_USB,
  1253. //! \b GPIO_IWE_SM_TIMER,
  1254. //!
  1255. //! \return None
  1256. //
  1257. //*****************************************************************************
  1258. void
  1259. GPIOIntWakeupDisable(uint32_t ui32Config)
  1260. {
  1261. ASSERT((ui32Config &
  1262. (GPIO_IWE_PORT_A |
  1263. GPIO_IWE_PORT_B |
  1264. GPIO_IWE_PORT_C |
  1265. GPIO_IWE_PORT_D |
  1266. GPIO_IWE_USB |
  1267. GPIO_IWE_SM_TIMER)) != 0);
  1268. //
  1269. // Disable Wakeup from selected Interrupt sources
  1270. //
  1271. HWREG(SYS_CTRL_IWE) &= ~ui32Config;
  1272. }
  1273. //*****************************************************************************
  1274. //! Close the Doxygen group.
  1275. //! @}
  1276. //*****************************************************************************