gpio.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. //*****************************************************************************
  2. //
  3. // gpio.c
  4. //
  5. // Driver for the GPIO module.
  6. //
  7. // Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
  8. //
  9. //
  10. // Redistribution and use in source and binary forms, with or without
  11. // modification, are permitted provided that the following conditions
  12. // are met:
  13. //
  14. // Redistributions of source code must retain the above copyright
  15. // notice, this list of conditions and the following disclaimer.
  16. //
  17. // Redistributions in binary form must reproduce the above copyright
  18. // notice, this list of conditions and the following disclaimer in the
  19. // documentation and/or other materials provided with the
  20. // 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_General_Purpose_InputOutput_api
  42. //! @{
  43. //
  44. //*****************************************************************************
  45. #include "inc/hw_types.h"
  46. #include "inc/hw_gpio.h"
  47. #include "inc/hw_ints.h"
  48. #include "inc/hw_memmap.h"
  49. #include "inc/hw_common_reg.h"
  50. #include "debug.h"
  51. #include "gpio.h"
  52. #include "interrupt.h"
  53. //*****************************************************************************
  54. //
  55. //! \internal
  56. //! Checks a GPIO base address.
  57. //!
  58. //! \param ulPort 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. #if defined(DEBUG) && !defined(BOOTLOADER)
  67. static tBoolean
  68. GPIOBaseValid(unsigned long ulPort)
  69. {
  70. return((ulPort == GPIOA0_BASE) ||
  71. (ulPort == GPIOA1_BASE) ||
  72. (ulPort == GPIOA2_BASE) ||
  73. (ulPort == GPIOA3_BASE) ||
  74. (ulPort == GPIOA4_BASE));
  75. }
  76. #else
  77. #define GPIOBaseValid(ulPort) (ulPort)
  78. #endif
  79. //*****************************************************************************
  80. //
  81. //! \internal
  82. //! Gets the GPIO interrupt number.
  83. //!
  84. //! \param ulPort is the base address of the GPIO port.
  85. //!
  86. //! Given a GPIO base address, returns the corresponding interrupt number.
  87. //!
  88. //! \return Returns a GPIO interrupt number, or -1 if \e ulPort is invalid.
  89. //
  90. //*****************************************************************************
  91. static long
  92. GPIOGetIntNumber(unsigned long ulPort)
  93. {
  94. unsigned int ulInt;
  95. //
  96. // Determine the GPIO interrupt number for the given module.
  97. //
  98. switch(ulPort)
  99. {
  100. case GPIOA0_BASE:
  101. {
  102. ulInt = INT_GPIOA0;
  103. break;
  104. }
  105. case GPIOA1_BASE:
  106. {
  107. ulInt = INT_GPIOA1;
  108. break;
  109. }
  110. case GPIOA2_BASE:
  111. {
  112. ulInt = INT_GPIOA2;
  113. break;
  114. }
  115. case GPIOA3_BASE:
  116. {
  117. ulInt = INT_GPIOA3;
  118. break;
  119. }
  120. default:
  121. {
  122. return(-1);
  123. }
  124. }
  125. //
  126. // Return GPIO interrupt number.
  127. //
  128. return(ulInt);
  129. }
  130. //*****************************************************************************
  131. //
  132. //! Sets the direction and mode of the specified pin(s).
  133. //!
  134. //! \param ulPort is the base address of the GPIO port
  135. //! \param ucPins is the bit-packed representation of the pin(s).
  136. //! \param ulPinIO is the pin direction and/or mode.
  137. //!
  138. //! This function will set the specified pin(s) on the selected GPIO port
  139. //! as either an input or output under software control, or it will set the
  140. //! pin to be under hardware control.
  141. //!
  142. //! The parameter \e ulPinIO is an enumerated data type that can be one of
  143. //! the following values:
  144. //!
  145. //! - \b GPIO_DIR_MODE_IN
  146. //! - \b GPIO_DIR_MODE_OUT
  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.
  151. //!
  152. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  153. //! set identifies the pin to be accessed, and where bit 0 of the byte
  154. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  155. //!
  156. //! \note GPIOPadConfigSet() must also be used to configure the corresponding
  157. //! pad(s) in order for them to propagate the signal to/from the GPIO.
  158. //!
  159. //! \return None.
  160. //
  161. //*****************************************************************************
  162. void
  163. GPIODirModeSet(unsigned long ulPort, unsigned char ucPins,
  164. unsigned long ulPinIO)
  165. {
  166. //
  167. // Check the arguments.
  168. //
  169. ASSERT(GPIOBaseValid(ulPort));
  170. ASSERT((ulPinIO == GPIO_DIR_MODE_IN) || (ulPinIO == GPIO_DIR_MODE_OUT));
  171. //
  172. // Set the pin direction and mode.
  173. //
  174. HWREG(ulPort + GPIO_O_GPIO_DIR) = ((ulPinIO & 1) ?
  175. (HWREG(ulPort + GPIO_O_GPIO_DIR) | ucPins) :
  176. (HWREG(ulPort + GPIO_O_GPIO_DIR) & ~(ucPins)));
  177. }
  178. //*****************************************************************************
  179. //
  180. //! Gets the direction and mode of a pin.
  181. //!
  182. //! \param ulPort is the base address of the GPIO port.
  183. //! \param ucPin is the pin number.
  184. //!
  185. //! This function gets the direction and control mode for a specified pin on
  186. //! the selected GPIO port. The pin can be configured as either an input or
  187. //! output under software control, or it can be under hardware control. The
  188. //! type of control and direction are returned as an enumerated data type.
  189. //!
  190. //! \return Returns one of the enumerated data types described for
  191. //! GPIODirModeSet().
  192. //
  193. //*****************************************************************************
  194. unsigned long
  195. GPIODirModeGet(unsigned long ulPort, unsigned char ucPin)
  196. {
  197. unsigned long ulDir;
  198. //
  199. // Check the arguments.
  200. //
  201. ASSERT(GPIOBaseValid(ulPort));
  202. //
  203. // Return the pin direction
  204. //
  205. ulDir = HWREG(ulPort + GPIO_O_GPIO_DIR);
  206. return(((ulDir & ucPin) ? 1 : 0));
  207. }
  208. //*****************************************************************************
  209. //
  210. //! Sets the interrupt type for the specified pin(s).
  211. //!
  212. //! \param ulPort is the base address of the GPIO port.
  213. //! \param ucPins is the bit-packed representation of the pin(s).
  214. //! \param ulIntType specifies the type of interrupt trigger mechanism.
  215. //!
  216. //! This function sets up the various interrupt trigger mechanisms for the
  217. //! specified pin(s) on the selected GPIO port.
  218. //!
  219. //! The parameter \e ulIntType is an enumerated data type that can be one of
  220. //! the following values:
  221. //!
  222. //! - \b GPIO_FALLING_EDGE
  223. //! - \b GPIO_RISING_EDGE
  224. //! - \b GPIO_BOTH_EDGES
  225. //! - \b GPIO_LOW_LEVEL
  226. //! - \b GPIO_HIGH_LEVEL
  227. //!
  228. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  229. //! set identifies the pin to be accessed, and where bit 0 of the byte
  230. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  231. //!
  232. //! \note In order to avoid any spurious interrupts, the user must
  233. //! ensure that the GPIO inputs remain stable for the duration of
  234. //! this function.
  235. //!
  236. //! \return None.
  237. //
  238. //*****************************************************************************
  239. void
  240. GPIOIntTypeSet(unsigned long ulPort, unsigned char ucPins,
  241. unsigned long ulIntType)
  242. {
  243. //
  244. // Check the arguments.
  245. //
  246. ASSERT(GPIOBaseValid(ulPort));
  247. ASSERT((ulIntType == GPIO_FALLING_EDGE) ||
  248. (ulIntType == GPIO_RISING_EDGE) || (ulIntType == GPIO_BOTH_EDGES) ||
  249. (ulIntType == GPIO_LOW_LEVEL) || (ulIntType == GPIO_HIGH_LEVEL));
  250. //
  251. // Set the pin interrupt type.
  252. //
  253. HWREG(ulPort + GPIO_O_GPIO_IBE) = ((ulIntType & 1) ?
  254. (HWREG(ulPort + GPIO_O_GPIO_IBE) | ucPins) :
  255. (HWREG(ulPort + GPIO_O_GPIO_IBE) & ~(ucPins)));
  256. HWREG(ulPort + GPIO_O_GPIO_IS) = ((ulIntType & 2) ?
  257. (HWREG(ulPort + GPIO_O_GPIO_IS) | ucPins) :
  258. (HWREG(ulPort + GPIO_O_GPIO_IS) & ~(ucPins)));
  259. HWREG(ulPort + GPIO_O_GPIO_IEV) = ((ulIntType & 4) ?
  260. (HWREG(ulPort + GPIO_O_GPIO_IEV) | ucPins) :
  261. (HWREG(ulPort + GPIO_O_GPIO_IEV) & ~(ucPins)));
  262. }
  263. //*****************************************************************************
  264. //
  265. //! Gets the interrupt type for a pin.
  266. //!
  267. //! \param ulPort is the base address of the GPIO port.
  268. //! \param ucPin is the pin number.
  269. //!
  270. //! This function gets the interrupt type for a specified pin on the selected
  271. //! GPIO port. The pin can be configured as a falling edge, rising edge, or
  272. //! both edge detected interrupt, or it can be configured as a low level or
  273. //! high level detected interrupt. The type of interrupt detection mechanism
  274. //! is returned as an enumerated data type.
  275. //!
  276. //! \return Returns one of the enumerated data types described for
  277. //! GPIOIntTypeSet().
  278. //
  279. //*****************************************************************************
  280. unsigned long
  281. GPIOIntTypeGet(unsigned long ulPort, unsigned char ucPin)
  282. {
  283. unsigned long ulIBE, ulIS, ulIEV;
  284. //
  285. // Check the arguments.
  286. //
  287. ASSERT(GPIOBaseValid(ulPort));
  288. //
  289. // Return the pin interrupt type.
  290. //
  291. ulIBE = HWREG(ulPort + GPIO_O_GPIO_IBE);
  292. ulIS = HWREG(ulPort + GPIO_O_GPIO_IS);
  293. ulIEV = HWREG(ulPort + GPIO_O_GPIO_IEV);
  294. return(((ulIBE & ucPin) ? 1 : 0) | ((ulIS & ucPin) ? 2 : 0) |
  295. ((ulIEV & ucPin) ? 4 : 0));
  296. }
  297. //*****************************************************************************
  298. //
  299. //! Enables the specified GPIO interrupts.
  300. //!
  301. //! \param ulPort is the base address of the GPIO port.
  302. //! \param ulIntFlags is the bit mask of the interrupt sources to enable.
  303. //!
  304. //! This function enables the indicated GPIO interrupt sources. Only the
  305. //! sources that are enabled can be reflected to the processor interrupt;
  306. //! disabled sources have no effect on the processor.
  307. //!
  308. //! The \e ulIntFlags parameter is the logical OR of any of the following:
  309. //!
  310. //! - \b GPIO_INT_DMA - interrupt due to GPIO triggered DMA Done
  311. //! - \b GPIO_INT_PIN_0 - interrupt due to activity on Pin 0.
  312. //! - \b GPIO_INT_PIN_1 - interrupt due to activity on Pin 1.
  313. //! - \b GPIO_INT_PIN_2 - interrupt due to activity on Pin 2.
  314. //! - \b GPIO_INT_PIN_3 - interrupt due to activity on Pin 3.
  315. //! - \b GPIO_INT_PIN_4 - interrupt due to activity on Pin 4.
  316. //! - \b GPIO_INT_PIN_5 - interrupt due to activity on Pin 5.
  317. //! - \b GPIO_INT_PIN_6 - interrupt due to activity on Pin 6.
  318. //! - \b GPIO_INT_PIN_7 - interrupt due to activity on Pin 7.
  319. //!
  320. //! \return None.
  321. //
  322. //*****************************************************************************
  323. void
  324. GPIOIntEnable(unsigned long ulPort, unsigned long ulIntFlags)
  325. {
  326. //
  327. // Check the arguments.
  328. //
  329. ASSERT(GPIOBaseValid(ulPort));
  330. //
  331. // Enable the interrupts.
  332. //
  333. HWREG(ulPort + GPIO_O_GPIO_IM) |= ulIntFlags;
  334. }
  335. //*****************************************************************************
  336. //
  337. //! Disables the specified GPIO interrupts.
  338. //!
  339. //! \param ulPort is the base address of the GPIO port.
  340. //! \param ulIntFlags is the bit mask of the interrupt sources to disable.
  341. //!
  342. //! This function disables the indicated GPIO interrupt sources. Only the
  343. //! sources that are enabled can be reflected to the processor interrupt;
  344. //! disabled sources have no effect on the processor.
  345. //!
  346. //! The \e ulIntFlags parameter is the logical OR of any of the following:
  347. //!
  348. //! - \b GPIO_INT_DMA - interrupt due to GPIO triggered DMA Done
  349. //! - \b GPIO_INT_PIN_0 - interrupt due to activity on Pin 0.
  350. //! - \b GPIO_INT_PIN_1 - interrupt due to activity on Pin 1.
  351. //! - \b GPIO_INT_PIN_2 - interrupt due to activity on Pin 2.
  352. //! - \b GPIO_INT_PIN_3 - interrupt due to activity on Pin 3.
  353. //! - \b GPIO_INT_PIN_4 - interrupt due to activity on Pin 4.
  354. //! - \b GPIO_INT_PIN_5 - interrupt due to activity on Pin 5.
  355. //! - \b GPIO_INT_PIN_6 - interrupt due to activity on Pin 6.
  356. //! - \b GPIO_INT_PIN_7 - interrupt due to activity on Pin 7.
  357. //!
  358. //! \return None.
  359. //
  360. //*****************************************************************************
  361. void
  362. GPIOIntDisable(unsigned long ulPort, unsigned long ulIntFlags)
  363. {
  364. //
  365. // Check the arguments.
  366. //
  367. ASSERT(GPIOBaseValid(ulPort));
  368. //
  369. // Disable the interrupts.
  370. //
  371. HWREG(ulPort + GPIO_O_GPIO_IM) &= ~(ulIntFlags);
  372. }
  373. //*****************************************************************************
  374. //
  375. //! Gets interrupt status for the specified GPIO port.
  376. //!
  377. //! \param ulPort 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 will be returned.
  383. //!
  384. //! \return Returns the current interrupt status, enumerated as a bit field of
  385. //! values described in GPIOIntEnable().
  386. //
  387. //*****************************************************************************
  388. long
  389. GPIOIntStatus(unsigned long ulPort, tBoolean bMasked)
  390. {
  391. //
  392. // Check the arguments.
  393. //
  394. ASSERT(GPIOBaseValid(ulPort));
  395. //
  396. // Return the interrupt status.
  397. //
  398. if(bMasked)
  399. {
  400. return(HWREG(ulPort + GPIO_O_GPIO_MIS));
  401. }
  402. else
  403. {
  404. return(HWREG(ulPort + GPIO_O_GPIO_RIS));
  405. }
  406. }
  407. //*****************************************************************************
  408. //
  409. //! Clears the interrupt for the specified pin(s).
  410. //!
  411. //! \param ulPort is the base address of the GPIO port.
  412. //! \param ulIntFlags is a bit mask of the interrupt sources to be cleared.
  413. //!
  414. //! Clears the interrupt for the specified pin(s).
  415. //!
  416. //! The \e ulIntFlags parameter has the same definition as the \e ulIntFlags
  417. //! parameter to GPIOIntEnable().
  418. //!
  419. //!
  420. //! \return None.
  421. //
  422. //*****************************************************************************
  423. void
  424. GPIOIntClear(unsigned long ulPort, unsigned long ulIntFlags)
  425. {
  426. //
  427. // Check the arguments.
  428. //
  429. ASSERT(GPIOBaseValid(ulPort));
  430. //
  431. // Clear the interrupts.
  432. //
  433. HWREG(ulPort + GPIO_O_GPIO_ICR) = ulIntFlags;
  434. }
  435. //*****************************************************************************
  436. //
  437. //! Registers an interrupt handler for a GPIO port.
  438. //!
  439. //! \param ulPort is the base address of the GPIO port.
  440. //! \param pfnIntHandler is a pointer to the GPIO port interrupt handling
  441. //! function.
  442. //!
  443. //! This function will ensure that the interrupt handler specified by
  444. //! \e pfnIntHandler is called when an interrupt is detected from the selected
  445. //! GPIO port. This function will also enable the corresponding GPIO interrupt
  446. //! in the interrupt controller; individual pin interrupts and interrupt
  447. //! sources must be enabled with GPIOIntEnable().
  448. //!
  449. //! \sa IntRegister() for important information about registering interrupt
  450. //! handlers.
  451. //!
  452. //! \return None.
  453. //
  454. //*****************************************************************************
  455. void
  456. GPIOIntRegister(unsigned long ulPort, void (*pfnIntHandler)(void))
  457. {
  458. //
  459. // Check the arguments.
  460. //
  461. ASSERT(GPIOBaseValid(ulPort));
  462. //
  463. // Get the interrupt number associated with the specified GPIO.
  464. //
  465. ulPort = GPIOGetIntNumber(ulPort);
  466. //
  467. // Register the interrupt handler.
  468. //
  469. IntRegister(ulPort, pfnIntHandler);
  470. //
  471. // Enable the GPIO interrupt.
  472. //
  473. IntEnable(ulPort);
  474. }
  475. //*****************************************************************************
  476. //
  477. //! Removes an interrupt handler for a GPIO port.
  478. //!
  479. //! \param ulPort is the base address of the GPIO port.
  480. //!
  481. //! This function will unregister the interrupt handler for the specified
  482. //! GPIO port. This function will also disable the corresponding
  483. //! GPIO port interrupt in the interrupt controller; individual GPIO interrupts
  484. //! and interrupt sources must be disabled with GPIOIntDisable().
  485. //!
  486. //! \sa IntRegister() for important information about registering interrupt
  487. //! handlers.
  488. //!
  489. //! \return None.
  490. //
  491. //*****************************************************************************
  492. void
  493. GPIOIntUnregister(unsigned long ulPort)
  494. {
  495. //
  496. // Check the arguments.
  497. //
  498. ASSERT(GPIOBaseValid(ulPort));
  499. //
  500. // Get the interrupt number associated with the specified GPIO.
  501. //
  502. ulPort = GPIOGetIntNumber(ulPort);
  503. //
  504. // Disable the GPIO interrupt.
  505. //
  506. IntDisable(ulPort);
  507. //
  508. // Unregister the interrupt handler.
  509. //
  510. IntUnregister(ulPort);
  511. }
  512. //*****************************************************************************
  513. //
  514. //! Reads the values present of the specified pin(s).
  515. //!
  516. //! \param ulPort is the base address of the GPIO port.
  517. //! \param ucPins is the bit-packed representation of the pin(s).
  518. //!
  519. //! The values at the specified pin(s) are read, as specified by \e ucPins.
  520. //! Values are returned for both input and output pin(s), and the value
  521. //! for pin(s) that are not specified by \e ucPins are set to 0.
  522. //!
  523. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  524. //! set identifies the pin to be accessed, and where bit 0 of the byte
  525. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  526. //!
  527. //! \return Returns a bit-packed byte providing the state of the specified
  528. //! pin, where bit 0 of the byte represents GPIO port pin 0, bit 1 represents
  529. //! GPIO port pin 1, and so on. Any bit that is not specified by \e ucPins
  530. //! is returned as a 0. Bits 31:8 should be ignored.
  531. //
  532. //*****************************************************************************
  533. long
  534. GPIOPinRead(unsigned long ulPort, unsigned char ucPins)
  535. {
  536. //
  537. // Check the arguments.
  538. //
  539. ASSERT(GPIOBaseValid(ulPort));
  540. //
  541. // Return the pin value(s).
  542. //
  543. return(HWREG(ulPort + (GPIO_O_GPIO_DATA + (ucPins << 2))));
  544. }
  545. //*****************************************************************************
  546. //
  547. //! Writes a value to the specified pin(s).
  548. //!
  549. //! \param ulPort is the base address of the GPIO port.
  550. //! \param ucPins is the bit-packed representation of the pin(s).
  551. //! \param ucVal is the value to write to the pin(s).
  552. //!
  553. //! Writes the corresponding bit values to the output pin(s) specified by
  554. //! \e ucPins. Writing to a pin configured as an input pin has no effect.
  555. //!
  556. //! The pin(s) are specified using a bit-packed byte, where each bit that is
  557. //! set identifies the pin to be accessed, and where bit 0 of the byte
  558. //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
  559. //!
  560. //! \return None.
  561. //
  562. //*****************************************************************************
  563. void
  564. GPIOPinWrite(unsigned long ulPort, unsigned char ucPins, unsigned char ucVal)
  565. {
  566. //
  567. // Check the arguments.
  568. //
  569. ASSERT(GPIOBaseValid(ulPort));
  570. //
  571. // Write the pins.
  572. //
  573. HWREG(ulPort + (GPIO_O_GPIO_DATA + (ucPins << 2))) = ucVal;
  574. }
  575. //*****************************************************************************
  576. //
  577. //! Enables a GPIO port as a trigger to start a DMA transaction.
  578. //!
  579. //! \param ulPort is the base address of the GPIO port.
  580. //!
  581. //! This function enables a GPIO port to be used as a trigger to start a uDMA
  582. //! transaction. The GPIO pin will still generate interrupts if the interrupt is
  583. //! enabled for the selected pin.
  584. //!
  585. //! \return None.
  586. //
  587. //*****************************************************************************
  588. void
  589. GPIODMATriggerEnable(unsigned long ulPort)
  590. {
  591. //
  592. // Check the arguments.
  593. //
  594. ASSERT(GPIOBaseValid(ulPort));
  595. //
  596. // Set the pin as a DMA trigger.
  597. //
  598. if(ulPort == GPIOA0_BASE)
  599. {
  600. HWREG(COMMON_REG_BASE + COMMON_REG_O_APPS_GPIO_TRIG_EN) |= 0x1;
  601. }
  602. else if(ulPort == GPIOA1_BASE)
  603. {
  604. HWREG(COMMON_REG_BASE + COMMON_REG_O_APPS_GPIO_TRIG_EN) |= 0x2;
  605. }
  606. else if(ulPort == GPIOA2_BASE)
  607. {
  608. HWREG(COMMON_REG_BASE + COMMON_REG_O_APPS_GPIO_TRIG_EN) |= 0x4;
  609. }
  610. else if(ulPort == GPIOA3_BASE)
  611. {
  612. HWREG(COMMON_REG_BASE + COMMON_REG_O_APPS_GPIO_TRIG_EN) |= 0x8;
  613. }
  614. }
  615. //*****************************************************************************
  616. //
  617. //! Disables a GPIO port as a trigger to start a DMA transaction.
  618. //!
  619. //! \param ulPort is the base address of the GPIO port.
  620. //!
  621. //! This function disables a GPIO port to be used as a trigger to start a uDMA
  622. //! transaction. This function can be used to disable this feature if it was
  623. //! enabled via a call to GPIODMATriggerEnable().
  624. //!
  625. //! \return None.
  626. //
  627. //*****************************************************************************
  628. void
  629. GPIODMATriggerDisable(unsigned long ulPort)
  630. {
  631. //
  632. // Check the arguments.
  633. //
  634. ASSERT(GPIOBaseValid(ulPort));
  635. //
  636. // Set the pin as a DMA trigger.
  637. //
  638. if(ulPort == GPIOA0_BASE)
  639. {
  640. HWREG(COMMON_REG_BASE + COMMON_REG_O_APPS_GPIO_TRIG_EN) &= ~0x1;
  641. }
  642. else if(ulPort == GPIOA1_BASE)
  643. {
  644. HWREG(COMMON_REG_BASE + COMMON_REG_O_APPS_GPIO_TRIG_EN) &= ~0x2;
  645. }
  646. else if(ulPort == GPIOA2_BASE)
  647. {
  648. HWREG(COMMON_REG_BASE + COMMON_REG_O_APPS_GPIO_TRIG_EN) &= ~0x4;
  649. }
  650. else if(ulPort == GPIOA3_BASE)
  651. {
  652. HWREG(COMMON_REG_BASE + COMMON_REG_O_APPS_GPIO_TRIG_EN) &= ~0x8;
  653. }
  654. }
  655. //
  656. // Close the Doxygen group.
  657. //! @}
  658. //
  659. //*****************************************************************************