udma.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  1. //*****************************************************************************
  2. //
  3. // udma.c - Driver for the micro-DMA controller.
  4. //
  5. // Copyright (c) 2007-2009 Luminary Micro, Inc. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
  9. // exclusively on LMI's microcontroller products.
  10. //
  11. // The software is owned by LMI and/or its suppliers, and is protected under
  12. // applicable copyright laws. All rights are reserved. You may not combine
  13. // this software with "viral" open-source software in order to form a larger
  14. // program. Any use in violation of the foregoing restrictions may subject
  15. // the user to criminal sanctions under applicable laws, as well as to civil
  16. // liability for the breach of the terms and conditions of this license.
  17. //
  18. // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
  19. // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  20. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
  21. // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
  22. // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  23. //
  24. // This is part of revision 4694 of the Stellaris Peripheral Driver Library.
  25. //
  26. //*****************************************************************************
  27. //*****************************************************************************
  28. //
  29. //! \addtogroup udma_api
  30. //! @{
  31. //
  32. //*****************************************************************************
  33. #include "inc/hw_types.h"
  34. #include "inc/hw_udma.h"
  35. #include "driverlib/debug.h"
  36. #include "driverlib/interrupt.h"
  37. #include "driverlib/udma.h"
  38. //*****************************************************************************
  39. //
  40. //! Enables the uDMA controller for use.
  41. //!
  42. //! This function enables the uDMA controller. The uDMA controller must be
  43. //! enabled before it can be configured and used.
  44. //!
  45. //! \return None.
  46. //
  47. //*****************************************************************************
  48. void
  49. uDMAEnable(void)
  50. {
  51. //
  52. // Set the master enable bit in the config register.
  53. //
  54. HWREG(UDMA_CFG) = UDMA_CFG_MASTEN;
  55. }
  56. //*****************************************************************************
  57. //
  58. //! Disables the uDMA controller for use.
  59. //!
  60. //! This function disables the uDMA controller. Once disabled, the uDMA
  61. //! controller will not operate until re-enabled with uDMAEnable().
  62. //!
  63. //! \return None.
  64. //
  65. //*****************************************************************************
  66. void
  67. uDMADisable(void)
  68. {
  69. //
  70. // Clear the master enable bit in the config register.
  71. //
  72. HWREG(UDMA_CFG) = 0;
  73. }
  74. //*****************************************************************************
  75. //
  76. //! Gets the uDMA error status.
  77. //!
  78. //! This function returns the uDMA error status. It should be called from
  79. //! within the uDMA error interrupt handler to determine if a uDMA error
  80. //! occurred.
  81. //!
  82. //! \return Returns non-zero if a uDMA error is pending.
  83. //
  84. //*****************************************************************************
  85. unsigned long
  86. uDMAErrorStatusGet(void)
  87. {
  88. //
  89. // Return the uDMA error status.
  90. //
  91. return(HWREG(UDMA_ERRCLR));
  92. }
  93. //*****************************************************************************
  94. //
  95. //! Clears the uDMA error interrupt.
  96. //!
  97. //! This function clears a pending uDMA error interrupt. It should be called
  98. //! from within the uDMA error interrupt handler to clear the interrupt.
  99. //!
  100. //! \return None.
  101. //
  102. //*****************************************************************************
  103. void
  104. uDMAErrorStatusClear(void)
  105. {
  106. //
  107. // Clear the uDMA error interrupt.
  108. //
  109. HWREG(UDMA_ERRCLR) = 1;
  110. }
  111. //*****************************************************************************
  112. //
  113. //! Enables a uDMA channel for operation.
  114. //!
  115. //! \param ulChannel is the channel number to enable.
  116. //!
  117. //! This function enables a specific uDMA channel for use. This function must
  118. //! be used to enable a channel before it can be used to perform a uDMA
  119. //! transfer.
  120. //!
  121. //! When a uDMA transfer is completed, the channel will be automatically
  122. //! disabled by the uDMA controller. Therefore, this function should be called
  123. //! prior to starting up any new transfer.
  124. //!
  125. //! The \e ulChannel parameter must be one of the following:
  126. //!
  127. //! - \b UDMA_CHANNEL_UART0RX for UART 0 receive channel
  128. //! - \b UDMA_CHANNEL_UART0TX for UART 0 transmit channel
  129. //! - \b UDMA_CHANNEL_UART1RX for UART 1 receive channel
  130. //! - \b UDMA_CHANNEL_UART1TX for UART 1 transmit channel
  131. //! - \b UDMA_CHANNEL_SSI0RX for SSI 0 receive channel
  132. //! - \b UDMA_CHANNEL_SSI0TX for SSI 0 transmit channel
  133. //! - \b UDMA_CHANNEL_SSI1RX for SSI 1 receive channel
  134. //! - \b UDMA_CHANNEL_SSI1TX for SSI 1 transmit channel
  135. //! - \b UDMA_CHANNEL_SW for the software dedicated uDMA channel
  136. //!
  137. //! And for microcontrollers that have a USB peripheral:
  138. //!
  139. //! - \b UDMA_CHANNEL_USBEP1RX for USB endpoint 1 receive
  140. //! - \b UDMA_CHANNEL_USBEP1TX for USB endpoint 1 transmit
  141. //! - \b UDMA_CHANNEL_USBEP2RX for USB endpoint 2 receive
  142. //! - \b UDMA_CHANNEL_USBEP2TX for USB endpoint 2 transmit
  143. //! - \b UDMA_CHANNEL_USBEP3RX for USB endpoint 3 receive
  144. //! - \b UDMA_CHANNEL_USBEP3TX for USB endpoint 3 transmit
  145. //!
  146. //! \return None.
  147. //
  148. //*****************************************************************************
  149. void
  150. uDMAChannelEnable(unsigned long ulChannel)
  151. {
  152. //
  153. // Check the arguments.
  154. //
  155. ASSERT(ulChannel < 32);
  156. //
  157. // Set the bit for this channel in the enable set register.
  158. //
  159. HWREG(UDMA_ENASET) = 1 << ulChannel;
  160. }
  161. //*****************************************************************************
  162. //
  163. //! Disables a uDMA channel for operation.
  164. //!
  165. //! \param ulChannel is the channel number to disable.
  166. //!
  167. //! This function disables a specific uDMA channel. Once disabled, a channel
  168. //! will not respond to uDMA transfer requests until re-enabled via
  169. //! uDMAChannelEnable().
  170. //!
  171. //! The \e ulChannel parameter must be one of the following:
  172. //!
  173. //! - \b UDMA_CHANNEL_UART0RX for UART 0 receive channel
  174. //! - \b UDMA_CHANNEL_UART0TX for UART 0 transmit channel
  175. //! - \b UDMA_CHANNEL_UART1RX for UART 1 receive channel
  176. //! - \b UDMA_CHANNEL_UART1TX for UART 1 transmit channel
  177. //! - \b UDMA_CHANNEL_SSI0RX for SSI 0 receive channel
  178. //! - \b UDMA_CHANNEL_SSI0TX for SSI 0 transmit channel
  179. //! - \b UDMA_CHANNEL_SSI1RX for SSI 1 receive channel
  180. //! - \b UDMA_CHANNEL_SSI1TX for SSI 1 transmit channel
  181. //! - \b UDMA_CHANNEL_SW for the software dedicated uDMA channel
  182. //!
  183. //! And for microcontrollers that have a USB peripheral:
  184. //!
  185. //! - \b UDMA_CHANNEL_USBEP1RX for USB endpoint 1 receive
  186. //! - \b UDMA_CHANNEL_USBEP1TX for USB endpoint 1 transmit
  187. //! - \b UDMA_CHANNEL_USBEP2RX for USB endpoint 2 receive
  188. //! - \b UDMA_CHANNEL_USBEP2TX for USB endpoint 2 transmit
  189. //! - \b UDMA_CHANNEL_USBEP3RX for USB endpoint 3 receive
  190. //! - \b UDMA_CHANNEL_USBEP3TX for USB endpoint 3 transmit
  191. //!
  192. //! \return None.
  193. //
  194. //*****************************************************************************
  195. void
  196. uDMAChannelDisable(unsigned long ulChannel)
  197. {
  198. //
  199. // Check the arguments.
  200. //
  201. ASSERT(ulChannel < 32);
  202. //
  203. // Set the bit for this channel in the enable clear register.
  204. //
  205. HWREG(UDMA_ENACLR) = 1 << ulChannel;
  206. }
  207. //*****************************************************************************
  208. //
  209. //! Checks if a uDMA channel is enabled for operation.
  210. //!
  211. //! \param ulChannel is the channel number to check.
  212. //!
  213. //! This function checks to see if a specific uDMA channel is enabled. This
  214. //! can be used to check the status of a transfer, since the channel will
  215. //! be automatically disabled at the end of a transfer.
  216. //!
  217. //! The \e ulChannel parameter must be one of the following:
  218. //!
  219. //! - \b UDMA_CHANNEL_UART0RX for UART 0 receive channel
  220. //! - \b UDMA_CHANNEL_UART0TX for UART 0 transmit channel
  221. //! - \b UDMA_CHANNEL_UART1RX for UART 1 receive channel
  222. //! - \b UDMA_CHANNEL_UART1TX for UART 1 transmit channel
  223. //! - \b UDMA_CHANNEL_SSI0RX for SSI 0 receive channel
  224. //! - \b UDMA_CHANNEL_SSI0TX for SSI 0 transmit channel
  225. //! - \b UDMA_CHANNEL_SSI1RX for SSI 1 receive channel
  226. //! - \b UDMA_CHANNEL_SSI1TX for SSI 1 transmit channel
  227. //! - \b UDMA_CHANNEL_SW for the software dedicated uDMA channel
  228. //!
  229. //! And for microcontrollers that have a USB peripheral:
  230. //!
  231. //! - \b UDMA_CHANNEL_USBEP1RX for USB endpoint 1 receive
  232. //! - \b UDMA_CHANNEL_USBEP1TX for USB endpoint 1 transmit
  233. //! - \b UDMA_CHANNEL_USBEP2RX for USB endpoint 2 receive
  234. //! - \b UDMA_CHANNEL_USBEP2TX for USB endpoint 2 transmit
  235. //! - \b UDMA_CHANNEL_USBEP3RX for USB endpoint 3 receive
  236. //! - \b UDMA_CHANNEL_USBEP3TX for USB endpoint 3 transmit
  237. //!
  238. //! \return Returns \b true if the channel is enabled, \b false if disabled.
  239. //
  240. //*****************************************************************************
  241. tBoolean
  242. uDMAChannelIsEnabled(unsigned long ulChannel)
  243. {
  244. //
  245. // Check the arguments.
  246. //
  247. ASSERT(ulChannel < 32);
  248. //
  249. // AND the specified channel bit with the enable register, and return the
  250. // result.
  251. //
  252. return((HWREG(UDMA_ENASET) & (1 << ulChannel)) ? true : false);
  253. }
  254. //*****************************************************************************
  255. //
  256. //! Sets the base address for the channel control table.
  257. //!
  258. //! \param pControlTable is a pointer to the 1024 byte aligned base address
  259. //! of the uDMA channel control table.
  260. //!
  261. //! This function sets the base address of the channel control table. This
  262. //! table resides in system memory and holds control information for each uDMA
  263. //! channel. The table must be aligned on a 1024 byte boundary. The base
  264. //! address must be set before any of the channel functions can be used.
  265. //!
  266. //! The size of the channel control table depends on the number of uDMA
  267. //! channels, and which transfer modes are used. Refer to the introductory
  268. //! text and the microcontroller datasheet for more information about the
  269. //! channel control table.
  270. //!
  271. //! \return None.
  272. //
  273. //*****************************************************************************
  274. void
  275. uDMAControlBaseSet(void *pControlTable)
  276. {
  277. //
  278. // Check the arguments.
  279. //
  280. ASSERT(((unsigned long)pControlTable & ~0x3FF) ==
  281. (unsigned long)pControlTable);
  282. ASSERT((unsigned long)pControlTable >= 0x20000000);
  283. //
  284. // Program the base address into the register.
  285. //
  286. HWREG(UDMA_CTLBASE) = (unsigned long)pControlTable;
  287. }
  288. //*****************************************************************************
  289. //
  290. //! Gets the base address for the channel control table.
  291. //!
  292. //! This function gets the base address of the channel control table. This
  293. //! table resides in system memory and holds control information for each uDMA
  294. //! channel.
  295. //!
  296. //! \return Returns a pointer to the base address of the channel control table.
  297. //
  298. //*****************************************************************************
  299. void *
  300. uDMAControlBaseGet(void)
  301. {
  302. //
  303. // Read the current value of the control base register, and return it to
  304. // the caller.
  305. //
  306. return((void *)HWREG(UDMA_CTLBASE));
  307. }
  308. //*****************************************************************************
  309. //
  310. //! Requests a uDMA channel to start a transfer.
  311. //!
  312. //! \param ulChannel is the channel number on which to request a uDMA transfer.
  313. //!
  314. //! This function allows software to request a uDMA channel to begin a
  315. //! transfer. This could be used for performing a memory to memory transfer,
  316. //! or if for some reason a transfer needs to be initiated by software instead
  317. //! of the peripheral associated with that channel.
  318. //!
  319. //! The \e ulChannel parameter must be one of the following:
  320. //!
  321. //! - \b UDMA_CHANNEL_UART0RX for UART 0 receive channel
  322. //! - \b UDMA_CHANNEL_UART0TX for UART 0 transmit channel
  323. //! - \b UDMA_CHANNEL_UART1RX for UART 1 receive channel
  324. //! - \b UDMA_CHANNEL_UART1TX for UART 1 transmit channel
  325. //! - \b UDMA_CHANNEL_SSI0RX for SSI 0 receive channel
  326. //! - \b UDMA_CHANNEL_SSI0TX for SSI 0 transmit channel
  327. //! - \b UDMA_CHANNEL_SSI1RX for SSI 1 receive channel
  328. //! - \b UDMA_CHANNEL_SSI1TX for SSI 1 transmit channel
  329. //! - \b UDMA_CHANNEL_SW for the software dedicated uDMA channel
  330. //!
  331. //! And for microcontrollers that have a USB peripheral:
  332. //!
  333. //! - \b UDMA_CHANNEL_USBEP1RX for USB endpoint 1 receive
  334. //! - \b UDMA_CHANNEL_USBEP1TX for USB endpoint 1 transmit
  335. //! - \b UDMA_CHANNEL_USBEP2RX for USB endpoint 2 receive
  336. //! - \b UDMA_CHANNEL_USBEP2TX for USB endpoint 2 transmit
  337. //! - \b UDMA_CHANNEL_USBEP3RX for USB endpoint 3 receive
  338. //! - \b UDMA_CHANNEL_USBEP3TX for USB endpoint 3 transmit
  339. //!
  340. //! \note If the channel is \b UDMA_CHANNEL_SW and interrupts are used, then
  341. //! the completion will be signaled on the uDMA dedicated interrupt. If a
  342. //! peripheral channel is used, then the completion will be signaled on the
  343. //! peripheral's interrupt.
  344. //!
  345. //! \return None.
  346. //
  347. //*****************************************************************************
  348. void
  349. uDMAChannelRequest(unsigned long ulChannel)
  350. {
  351. //
  352. // Check the arguments.
  353. //
  354. ASSERT(ulChannel < 32);
  355. //
  356. // Set the bit for this channel in the software uDMA request register.
  357. //
  358. HWREG(UDMA_SWREQ) = 1 << ulChannel;
  359. }
  360. //*****************************************************************************
  361. //
  362. //! Enables attributes of a uDMA channel.
  363. //!
  364. //! \param ulChannel is the channel to configure.
  365. //! \param ulAttr is a combination of attributes for the channel.
  366. //!
  367. //! The \e ulChannel parameter must be one of the following:
  368. //!
  369. //! - \b UDMA_CHANNEL_UART0RX for UART 0 receive channel
  370. //! - \b UDMA_CHANNEL_UART0TX for UART 0 transmit channel
  371. //! - \b UDMA_CHANNEL_UART1RX for UART 1 receive channel
  372. //! - \b UDMA_CHANNEL_UART1TX for UART 1 transmit channel
  373. //! - \b UDMA_CHANNEL_SSI0RX for SSI 0 receive channel
  374. //! - \b UDMA_CHANNEL_SSI0TX for SSI 0 transmit channel
  375. //! - \b UDMA_CHANNEL_SSI1RX for SSI 1 receive channel
  376. //! - \b UDMA_CHANNEL_SSI1TX for SSI 1 transmit channel
  377. //! - \b UDMA_CHANNEL_SW for the software dedicated uDMA channel
  378. //!
  379. //! And for microcontrollers that have a USB peripheral:
  380. //!
  381. //! - \b UDMA_CHANNEL_USBEP1RX for USB endpoint 1 receive
  382. //! - \b UDMA_CHANNEL_USBEP1TX for USB endpoint 1 transmit
  383. //! - \b UDMA_CHANNEL_USBEP2RX for USB endpoint 2 receive
  384. //! - \b UDMA_CHANNEL_USBEP2TX for USB endpoint 2 transmit
  385. //! - \b UDMA_CHANNEL_USBEP3RX for USB endpoint 3 receive
  386. //! - \b UDMA_CHANNEL_USBEP3TX for USB endpoint 3 transmit
  387. //!
  388. //! The \e ulAttr parameter is the logical OR of any of the following:
  389. //!
  390. //! - \b UDMA_ATTR_USEBURST is used to restrict transfers to use only a burst
  391. //! mode.
  392. //! - \b UDMA_ATTR_ALTSELECT is used to select the alternate control structure
  393. //! for this channel.
  394. //! - \b UDMA_ATTR_HIGH_PRIORITY is used to set this channel to high priority.
  395. //! - \b UDMA_ATTR_REQMASK is used to mask the hardware request signal from the
  396. //! peripheral for this channel.
  397. //!
  398. //! \return None.
  399. //
  400. //*****************************************************************************
  401. void
  402. uDMAChannelAttributeEnable(unsigned long ulChannel, unsigned long ulAttr)
  403. {
  404. //
  405. // Check the arguments.
  406. //
  407. ASSERT(ulChannel < 32);
  408. ASSERT((ulAttr & ~(UDMA_ATTR_USEBURST | UDMA_ATTR_ALTSELECT |
  409. UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK)) == 0);
  410. //
  411. // Set the useburst bit for this channel if set in ulConfig.
  412. //
  413. if(ulAttr & UDMA_ATTR_USEBURST)
  414. {
  415. HWREG(UDMA_USEBURSTSET) = 1 << ulChannel;
  416. }
  417. //
  418. // Set the alternate control select bit for this channel,
  419. // if set in ulConfig.
  420. //
  421. if(ulAttr & UDMA_ATTR_ALTSELECT)
  422. {
  423. HWREG(UDMA_ALTSET) = 1 << ulChannel;
  424. }
  425. //
  426. // Set the high priority bit for this channel, if set in ulConfig.
  427. //
  428. if(ulAttr & UDMA_ATTR_HIGH_PRIORITY)
  429. {
  430. HWREG(UDMA_PRIOSET) = 1 << ulChannel;
  431. }
  432. //
  433. // Set the request mask bit for this channel, if set in ulConfig.
  434. //
  435. if(ulAttr & UDMA_ATTR_REQMASK)
  436. {
  437. HWREG(UDMA_REQMASKSET) = 1 << ulChannel;
  438. }
  439. }
  440. //*****************************************************************************
  441. //
  442. //! Disables attributes of a uDMA channel.
  443. //!
  444. //! \param ulChannel is the channel to configure.
  445. //! \param ulAttr is a combination of attributes for the channel.
  446. //!
  447. //! This function is used to disable attributes of a uDMA channel.
  448. //!
  449. //! The \e ulChannel parameter must be one of the following:
  450. //!
  451. //! - \b UDMA_CHANNEL_UART0RX for UART 0 receive channel
  452. //! - \b UDMA_CHANNEL_UART0TX for UART 0 transmit channel
  453. //! - \b UDMA_CHANNEL_UART1RX for UART 1 receive channel
  454. //! - \b UDMA_CHANNEL_UART1TX for UART 1 transmit channel
  455. //! - \b UDMA_CHANNEL_SSI0RX for SSI 0 receive channel
  456. //! - \b UDMA_CHANNEL_SSI0TX for SSI 0 transmit channel
  457. //! - \b UDMA_CHANNEL_SSI1RX for SSI 1 receive channel
  458. //! - \b UDMA_CHANNEL_SSI1TX for SSI 1 transmit channel
  459. //! - \b UDMA_CHANNEL_SW for the software dedicated uDMA channel
  460. //!
  461. //! And for microcontrollers that have a USB peripheral:
  462. //!
  463. //! - \b UDMA_CHANNEL_USBEP1RX for USB endpoint 1 receive
  464. //! - \b UDMA_CHANNEL_USBEP1TX for USB endpoint 1 transmit
  465. //! - \b UDMA_CHANNEL_USBEP2RX for USB endpoint 2 receive
  466. //! - \b UDMA_CHANNEL_USBEP2TX for USB endpoint 2 transmit
  467. //! - \b UDMA_CHANNEL_USBEP3RX for USB endpoint 3 receive
  468. //! - \b UDMA_CHANNEL_USBEP3TX for USB endpoint 3 transmit
  469. //!
  470. //! The \e ulAttr parameter is the logical OR of any of the following:
  471. //!
  472. //! - \b UDMA_ATTR_USEBURST is used to restrict transfers to use only a burst
  473. //! mode.
  474. //! - \b UDMA_ATTR_ALTSELECT is used to select the alternate control structure
  475. //! for this channel.
  476. //! - \b UDMA_ATTR_HIGH_PRIORITY is used to set this channel to high priority.
  477. //! - \b UDMA_ATTR_REQMASK is used to mask the hardware request signal from the
  478. //! peripheral for this channel.
  479. //!
  480. //! \return None.
  481. //
  482. //*****************************************************************************
  483. void
  484. uDMAChannelAttributeDisable(unsigned long ulChannel, unsigned long ulAttr)
  485. {
  486. //
  487. // Check the arguments.
  488. //
  489. ASSERT(ulChannel < 32);
  490. ASSERT((ulAttr & ~(UDMA_ATTR_USEBURST | UDMA_ATTR_ALTSELECT |
  491. UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK)) == 0);
  492. //
  493. // Clear the useburst bit for this channel if set in ulConfig.
  494. //
  495. if(ulAttr & UDMA_ATTR_USEBURST)
  496. {
  497. HWREG(UDMA_USEBURSTCLR) = 1 << ulChannel;
  498. }
  499. //
  500. // Clear the alternate control select bit for this channel, if set in
  501. // ulConfig.
  502. //
  503. if(ulAttr & UDMA_ATTR_ALTSELECT)
  504. {
  505. HWREG(UDMA_ALTCLR) = 1 << ulChannel;
  506. }
  507. //
  508. // Clear the high priority bit for this channel, if set in ulConfig.
  509. //
  510. if(ulAttr & UDMA_ATTR_HIGH_PRIORITY)
  511. {
  512. HWREG(UDMA_PRIOCLR) = 1 << ulChannel;
  513. }
  514. //
  515. // Clear the request mask bit for this channel, if set in ulConfig.
  516. //
  517. if(ulAttr & UDMA_ATTR_REQMASK)
  518. {
  519. HWREG(UDMA_REQMASKCLR) = 1 << ulChannel;
  520. }
  521. }
  522. //*****************************************************************************
  523. //
  524. //! Gets the enabled attributes of a uDMA channel.
  525. //!
  526. //! \param ulChannel is the channel to configure.
  527. //!
  528. //! This function returns a combination of flags representing the attributes of
  529. //! the uDMA channel.
  530. //!
  531. //! The \e ulChannel parameter must be one of the following:
  532. //!
  533. //! - \b UDMA_CHANNEL_UART0RX for UART 0 receive channel
  534. //! - \b UDMA_CHANNEL_UART0TX for UART 0 transmit channel
  535. //! - \b UDMA_CHANNEL_UART1RX for UART 1 receive channel
  536. //! - \b UDMA_CHANNEL_UART1TX for UART 1 transmit channel
  537. //! - \b UDMA_CHANNEL_SSI0RX for SSI 0 receive channel
  538. //! - \b UDMA_CHANNEL_SSI0TX for SSI 0 transmit channel
  539. //! - \b UDMA_CHANNEL_SSI1RX for SSI 1 receive channel
  540. //! - \b UDMA_CHANNEL_SSI1TX for SSI 1 transmit channel
  541. //! - \b UDMA_CHANNEL_SW for the software dedicated uDMA channel
  542. //!
  543. //! And for microcontrollers that have a USB peripheral:
  544. //!
  545. //! - \b UDMA_CHANNEL_USBEP1RX for USB endpoint 1 receive
  546. //! - \b UDMA_CHANNEL_USBEP1TX for USB endpoint 1 transmit
  547. //! - \b UDMA_CHANNEL_USBEP2RX for USB endpoint 2 receive
  548. //! - \b UDMA_CHANNEL_USBEP2TX for USB endpoint 2 transmit
  549. //! - \b UDMA_CHANNEL_USBEP3RX for USB endpoint 3 receive
  550. //! - \b UDMA_CHANNEL_USBEP3TX for USB endpoint 3 transmit
  551. //!
  552. //! \return Returns the logical OR of the attributes of the uDMA channel, which
  553. //! can be any of the following:
  554. //! - \b UDMA_ATTR_USEBURST is used to restrict transfers to use only a burst
  555. //! mode.
  556. //! - \b UDMA_ATTR_ALTSELECT is used to select the alternate control structure
  557. //! for this channel.
  558. //! - \b UDMA_ATTR_HIGH_PRIORITY is used to set this channel to high priority.
  559. //! - \b UDMA_ATTR_REQMASK is used to mask the hardware request signal from the
  560. //! peripheral for this channel.
  561. //
  562. //*****************************************************************************
  563. unsigned long
  564. uDMAChannelAttributeGet(unsigned long ulChannel)
  565. {
  566. unsigned long ulAttr = 0;
  567. //
  568. // Check the arguments.
  569. //
  570. ASSERT(ulChannel < 32);
  571. //
  572. // Check to see if useburst bit is set for this channel.
  573. //
  574. if(HWREG(UDMA_USEBURSTSET) & (1 << ulChannel))
  575. {
  576. ulAttr |= UDMA_ATTR_USEBURST;
  577. }
  578. //
  579. // Check to see if the alternate control bit is set for this channel.
  580. //
  581. if(HWREG(UDMA_ALTSET) & (1 << ulChannel))
  582. {
  583. ulAttr |= UDMA_ATTR_ALTSELECT;
  584. }
  585. //
  586. // Check to see if the high priority bit is set for this channel.
  587. //
  588. if(HWREG(UDMA_PRIOSET) & (1 << ulChannel))
  589. {
  590. ulAttr |= UDMA_ATTR_HIGH_PRIORITY;
  591. }
  592. //
  593. // Check to see if the request mask bit is set for this channel.
  594. //
  595. if(HWREG(UDMA_REQMASKSET) & (1 << ulChannel))
  596. {
  597. ulAttr |= UDMA_ATTR_REQMASK;
  598. }
  599. //
  600. // Return the configuration flags.
  601. //
  602. return(ulAttr);
  603. }
  604. //*****************************************************************************
  605. //
  606. //! Sets the control parameters for a uDMA channel.
  607. //!
  608. //! \param ulChannel is the logical OR of the uDMA channel number with
  609. //! \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT.
  610. //! \param ulControl is logical OR of several control values to set the control
  611. //! parameters for the channel.
  612. //!
  613. //! This function is used to set control parameters for a uDMA transfer. These
  614. //! are typically parameters that are not changed often.
  615. //!
  616. //! The \e ulChannel parameter is one of the choices documented in the
  617. //! uDMAChannelEnable() function. It should be the logical OR of the channel
  618. //! with one of \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT to choose whether
  619. //! the primary or alternate data structure is used.
  620. //!
  621. //! The \e ulControl parameter is the logical OR of five values: the data size,
  622. //! the source address increment, the destination address increment, the
  623. //! arbitration size, and the use burst flag. The choices available for each
  624. //! of these values is described below.
  625. //!
  626. //! Choose the data size from one of \b UDMA_SIZE_8, \b UDMA_SIZE_16, or
  627. //! \b UDMA_SIZE_32 to select a data size of 8, 16, or 32 bits.
  628. //!
  629. //! Choose the source address increment from one of \b UDMA_SRC_INC_8,
  630. //! \b UDMA_SRC_INC_16, \b UDMA_SRC_INC_32, or \b UDMA_SRC_INC_NONE to select
  631. //! an address increment of 8-bit bytes, 16-bit halfwords, 32-bit words, or
  632. //! to select non-incrementing.
  633. //!
  634. //! Choose the destination address increment from one of \b UDMA_DST_INC_8,
  635. //! \b UDMA_DST_INC_16, \b UDMA_DST_INC_32, or \b UDMA_DST_INC_NONE to select
  636. //! an address increment of 8-bit bytes, 16-bit halfwords, 32-bit words, or
  637. //! to select non-incrementing.
  638. //!
  639. //! The arbitration size determines how many items are transferred before
  640. //! the uDMA controller re-arbitrates for the bus. Choose the arbitration size
  641. //! from one of \b UDMA_ARB_1, \b UDMA_ARB_2, \b UDMA_ARB_4, \b UDMA_ARB_8,
  642. //! through \b UDMA_ARB_1024 to select the arbitration size from 1 to 1024
  643. //! items, in powers of 2.
  644. //!
  645. //! The value \b UDMA_NEXT_USEBURST is used to force the channel to only
  646. //! respond to burst requests at the tail end of a scatter-gather transfer.
  647. //!
  648. //! \note The address increment cannot be smaller than the data size.
  649. //!
  650. //! \return None.
  651. //
  652. //*****************************************************************************
  653. void
  654. uDMAChannelControlSet(unsigned long ulChannel, unsigned long ulControl)
  655. {
  656. tDMAControlTable *pCtl;
  657. //
  658. // Check the arguments.
  659. //
  660. ASSERT(ulChannel < 64);
  661. ASSERT(HWREG(UDMA_CTLBASE) != 0);
  662. //
  663. // Get the base address of the control table.
  664. //
  665. pCtl = (tDMAControlTable *)HWREG(UDMA_CTLBASE);
  666. //
  667. // Get the current control word value and mask off the fields to be
  668. // changed, then OR in the new settings.
  669. //
  670. pCtl[ulChannel].ulControl = ((pCtl[ulChannel].ulControl &
  671. ~(UDMA_CHCTL_DSTINC_M |
  672. UDMA_CHCTL_DSTSIZE_M |
  673. UDMA_CHCTL_SRCINC_M |
  674. UDMA_CHCTL_SRCSIZE_M |
  675. UDMA_CHCTL_ARBSIZE_M |
  676. UDMA_CHCTL_NXTUSEBURST)) |
  677. ulControl);
  678. }
  679. //*****************************************************************************
  680. //
  681. //! Sets the transfer parameters for a uDMA channel.
  682. //!
  683. //! \param ulChannel is the logical or of the uDMA channel number with either
  684. //! \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT.
  685. //! \param ulMode is the type of uDMA transfer.
  686. //! \param pvSrcAddr is the source address for the transfer.
  687. //! \param pvDstAddr is the destination address for the transfer.
  688. //! \param ulTransferSize is the number of data items to transfer.
  689. //!
  690. //! This function is used to set the parameters for a uDMA transfer. These are
  691. //! typically parameters that are changed often. The function
  692. //! uDMAChannelControlSet() MUST be called at least once for this channel prior
  693. //! to calling this function.
  694. //!
  695. //! The \e ulChannel parameter is one of the choices documented in the
  696. //! uDMAChannelEnable() function. It should be the logical OR of the channel
  697. //! with either \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT to choose whether the
  698. //! primary or alternate data structure is used.
  699. //!
  700. //! The \e ulMode parameter should be one of the following values:
  701. //!
  702. //! - \b UDMA_MODE_STOP stops the uDMA transfer. The controller sets the mode
  703. //! to this value at the end of a transfer.
  704. //! - \b UDMA_MODE_BASIC to perform a basic transfer based on request.
  705. //! - \b UDMA_MODE_AUTO to perform a transfer that will always complete once
  706. //! started even if request is removed.
  707. //! - \b UDMA_MODE_PINGPONG to set up a transfer that switches between the
  708. //! primary and alternate control structures for the channel. This allows
  709. //! use of ping-pong buffering for uDMA transfers.
  710. //! - \b UDMA_MODE_MEM_SCATTER_GATHER to set up a memory scatter-gather
  711. //! transfer.
  712. //! - \b UDMA_MODE_PER_SCATTER_GATHER to set up a peripheral scatter-gather
  713. //! transfer.
  714. //!
  715. //! The \e pvSrcAddr and \e pvDstAddr parameters are pointers to the first
  716. //! location of the data to be transferred. These addresses should be aligned
  717. //! according to the item size. The compiler will take care of this if the
  718. //! pointers are pointing to storage of the appropriate data type.
  719. //!
  720. //! The \e ulTransferSize parameter is the number of data items, not the number
  721. //! of bytes.
  722. //!
  723. //! The two scatter/gather modes, memory and peripheral, are actually different
  724. //! depending on whether the primary or alternate control structure is
  725. //! selected. This function will look for the \b UDMA_PRI_SELECT and
  726. //! \b UDMA_ALT_SELECT flag along with the channel number and will set the
  727. //! scatter/gather mode as appropriate for the primary or alternate control
  728. //! structure.
  729. //!
  730. //! The channel must also be enabled using uDMAChannelEnable() after calling
  731. //! this function. The transfer will not begin until the channel has been set
  732. //! up and enabled. Note that the channel is automatically disabled after the
  733. //! transfer is completed, meaning that uDMAChannelEnable() must be called
  734. //! again after setting up the next transfer.
  735. //!
  736. //! \note Great care must be taken to not modify a channel control structure
  737. //! that is in use or else the results will be unpredictable, including the
  738. //! possibility of undesired data transfers to or from memory or peripherals.
  739. //! For BASIC and AUTO modes, it is safe to make changes when the channel is
  740. //! disabled, or the uDMAChannelModeGet() returns \b UDMA_MODE_STOP. For
  741. //! PINGPONG or one of the SCATTER_GATHER modes, it is safe to modify the
  742. //! primary or alternate control structure only when the other is being used.
  743. //! The uDMAChannelModeGet() function will return \b UDMA_MODE_STOP when a
  744. //! channel control structure is inactive and safe to modify.
  745. //!
  746. //! \return None.
  747. //
  748. //*****************************************************************************
  749. void
  750. uDMAChannelTransferSet(unsigned long ulChannel, unsigned long ulMode,
  751. void *pvSrcAddr, void *pvDstAddr,
  752. unsigned long ulTransferSize)
  753. {
  754. tDMAControlTable *pControlTable;
  755. unsigned long ulControl;
  756. unsigned long ulSize;
  757. unsigned long ulInc;
  758. //
  759. // Check the arguments.
  760. //
  761. ASSERT(ulChannel < 64);
  762. ASSERT(HWREG(UDMA_CTLBASE) != 0);
  763. ASSERT(ulMode <= UDMA_MODE_PER_SCATTER_GATHER);
  764. ASSERT((unsigned long)pvSrcAddr >= 0x20000000);
  765. ASSERT((unsigned long)pvDstAddr >= 0x20000000);
  766. ASSERT((ulTransferSize != 0) && (ulTransferSize <= 1024));
  767. //
  768. // Get the base address of the control table.
  769. //
  770. pControlTable = (tDMAControlTable *)HWREG(UDMA_CTLBASE);
  771. //
  772. // Get the current control word value and mask off the mode and size
  773. // fields.
  774. //
  775. ulControl = (pControlTable[ulChannel].ulControl &
  776. ~(UDMA_CHCTL_XFERSIZE_M | UDMA_CHCTL_XFERMODE_M));
  777. //
  778. // Adjust the mode if the alt control structure is selected.
  779. //
  780. if(ulChannel & UDMA_ALT_SELECT)
  781. {
  782. if((ulMode == UDMA_MODE_MEM_SCATTER_GATHER) ||
  783. (ulMode == UDMA_MODE_PER_SCATTER_GATHER))
  784. {
  785. ulMode |= UDMA_MODE_ALT_SELECT;
  786. }
  787. }
  788. //
  789. // Set the transfer size and mode in the control word (but dont write the
  790. // control word yet as it could kick off a transfer).
  791. //
  792. ulControl |= ulMode | ((ulTransferSize - 1) << 4);
  793. //
  794. // Get the data item size from the control word (set previously).
  795. //
  796. ulSize = (ulControl & UDMA_CHCTL_DSTSIZE_M) >> 28;
  797. //
  798. // Convert the transfer size to be in units of bytes. Shift (multiply) to
  799. // get the value in bytes, based on the data item size.
  800. //
  801. ulTransferSize = ulTransferSize << ulSize;
  802. //
  803. // Get the address increment value for the source, from the control word.
  804. //
  805. ulInc = (ulControl & UDMA_CHCTL_SRCINC_M);
  806. //
  807. // Compute the ending source address of the transfer. If the source
  808. // increment is set to none, then the ending address is the same as the
  809. // beginning.
  810. //
  811. if(ulInc != UDMA_SRC_INC_NONE)
  812. {
  813. pvSrcAddr = (void *)((unsigned long)pvSrcAddr + ulTransferSize - 1);
  814. }
  815. //
  816. // Load the source ending address into the control block.
  817. //
  818. pControlTable[ulChannel].pvSrcEndAddr = pvSrcAddr;
  819. //
  820. // Get the address increment value for the destination, from the control
  821. // word.
  822. //
  823. ulInc = (ulControl & UDMA_CHCTL_DSTINC_M);
  824. //
  825. // Compute the ending destination address of the transfer. If the
  826. // destination increment is set to none, then the ending address is the
  827. // same as the beginning.
  828. //
  829. if(ulInc != UDMA_DST_INC_NONE)
  830. {
  831. pvDstAddr = (void *)((unsigned long)pvDstAddr + ulTransferSize - 1);
  832. }
  833. //
  834. // Load the destination ending address into the control block.
  835. //
  836. pControlTable[ulChannel].pvDstEndAddr = pvDstAddr;
  837. //
  838. // Write the new control word value.
  839. //
  840. pControlTable[ulChannel].ulControl = ulControl;
  841. }
  842. //*****************************************************************************
  843. //
  844. //! Gets the current transfer size for a uDMA channel.
  845. //!
  846. //! \param ulChannel is the logical or of the uDMA channel number with either
  847. //! \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT.
  848. //!
  849. //! This function is used to get the uDMA transfer size for a channel. The
  850. //! transfer size is the number of items to transfer, where the size of an item
  851. //! might be 8, 16, or 32 bits. If a partial transfer has already occurred,
  852. //! then the number of remaining items will be returned. If the transfer is
  853. //! complete, then 0 will be returned.
  854. //!
  855. //! The \e ulChannel parameter is one of the choices documented in the
  856. //! uDMAChannelEnable() function. It should be the logical OR of the channel
  857. //! with either \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT to choose whether
  858. //! the primary or alternate data structure is used.
  859. //!
  860. //! \return Returns the number of items remaining to transfer.
  861. //
  862. //*****************************************************************************
  863. unsigned long
  864. uDMAChannelSizeGet(unsigned long ulChannel)
  865. {
  866. tDMAControlTable *pControlTable;
  867. unsigned long ulControl;
  868. //
  869. // Check the arguments.
  870. //
  871. ASSERT(ulChannel < 64);
  872. ASSERT(HWREG(UDMA_CTLBASE) != 0);
  873. //
  874. // Get the base address of the control table.
  875. //
  876. pControlTable = (tDMAControlTable *)HWREG(UDMA_CTLBASE);
  877. //
  878. // Get the current control word value and mask off all but the size field.
  879. //
  880. ulControl = pControlTable[ulChannel].ulControl & UDMA_CHCTL_XFERSIZE_M;
  881. //
  882. // Shift the size field and add one, then return to user.
  883. //
  884. return((ulControl >> 4) + 1);
  885. }
  886. //*****************************************************************************
  887. //
  888. //! Gets the transfer mode for a uDMA channel.
  889. //!
  890. //! \param ulChannel is the logical or of the uDMA channel number with either
  891. //! \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT.
  892. //!
  893. //! This function is used to get the transfer mode for the uDMA channel. It
  894. //! can be used to query the status of a transfer on a channel. When the
  895. //! transfer is complete the mode will be \b UDMA_MODE_STOP.
  896. //!
  897. //! The \e ulChannel parameter is one of the choices documented in the
  898. //! uDMAChannelEnable() function. It should be the logical OR of the channel
  899. //! with either \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT to choose whether the
  900. //! primary or alternate data structure is used.
  901. //!
  902. //! \return Returns the transfer mode of the specified channel and control
  903. //! structure, which will be one of the following values: \b UDMA_MODE_STOP,
  904. //! \b UDMA_MODE_BASIC, \b UDMA_MODE_AUTO, \b UDMA_MODE_PINGPONG,
  905. //! \b UDMA_MODE_MEM_SCATTER_GATHER, or \b UDMA_MODE_PER_SCATTER_GATHER.
  906. //
  907. //*****************************************************************************
  908. unsigned long
  909. uDMAChannelModeGet(unsigned long ulChannel)
  910. {
  911. tDMAControlTable *pControlTable;
  912. unsigned long ulControl;
  913. //
  914. // Check the arguments.
  915. //
  916. ASSERT(ulChannel < 64);
  917. ASSERT(HWREG(UDMA_CTLBASE) != 0);
  918. //
  919. // Get the base address of the control table.
  920. //
  921. pControlTable = (tDMAControlTable *)HWREG(UDMA_CTLBASE);
  922. //
  923. // Get the current control word value and mask off all but the mode field.
  924. //
  925. ulControl = pControlTable[ulChannel].ulControl & UDMA_CHCTL_XFERMODE_M;
  926. //
  927. // Check if scatter/gather mode, and if so, mask off the alt bit.
  928. //
  929. if(((ulControl & ~UDMA_MODE_ALT_SELECT) == UDMA_MODE_MEM_SCATTER_GATHER) ||
  930. ((ulControl & ~UDMA_MODE_ALT_SELECT) == UDMA_MODE_PER_SCATTER_GATHER))
  931. {
  932. ulControl &= ~UDMA_MODE_ALT_SELECT;
  933. }
  934. //
  935. // Return the mode to the caller.
  936. //
  937. return(ulControl);
  938. }
  939. //*****************************************************************************
  940. //
  941. //! Select the secondary peripheral for a set of uDMA channels.
  942. //!
  943. //! \param ulSecPeriphs is the logical or of the uDMA channels for which to
  944. //! use the secondary peripheral, instead of the default peripheral.
  945. //!
  946. //! This function is used to select the secondary peripheral assignment for
  947. //! a set of uDMA channels. By selecting the secondary peripheral assignment
  948. //! for a channel, the default peripheral assignment is no longer available
  949. //! for that channel.
  950. //!
  951. //! The parameter \e ulSecPeriphs can be the logical OR of any of the
  952. //! following macros. If one of the macros below is in the list passed
  953. //! to this function, then the secondary peripheral (marked as \b _SEC_)
  954. //! will be selected.
  955. //!
  956. //! - \b UDMA_DEF_USBEP1RX_SEC_UART2RX
  957. //! - \b UDMA_DEF_USBEP1TX_SEC_UART2TX
  958. //! - \b UDMA_DEF_USBEP2RX_SEC_TMR3A
  959. //! - \b UDMA_DEF_USBEP2TX_SEC_TMR3B
  960. //! - \b UDMA_DEF_USBEP3RX_SEC_TMR2A
  961. //! - \b UDMA_DEF_USBEP3TX_SEC_TMR2B
  962. //! - \b UDMA_DEF_ETH0RX_SEC_TMR2A
  963. //! - \b UDMA_DEF_ETH0TX_SEC_TMR2B
  964. //! - \b UDMA_DEF_UART0RX_SEC_UART1RX
  965. //! - \b UDMA_DEF_UART0TX_SEC_UART1TX
  966. //! - \b UDMA_DEF_SSI0RX_SEC_SSI1RX
  967. //! - \b UDMA_DEF_SSI0TX_SEC_SSI1TX
  968. //! - \b UDMA_DEF_RESERVED_SEC_UART2RX
  969. //! - \b UDMA_DEF_RESERVED_SEC_UART2TX
  970. //! - \b UDMA_DEF_ADC00_SEC_TMR2A
  971. //! - \b UDMA_DEF_ADC01_SEC_TMR2B
  972. //! - \b UDMA_DEF_ADC02_SEC_RESERVED
  973. //! - \b UDMA_DEF_ADC03_SEC_RESERVED
  974. //! - \b UDMA_DEF_TMR0A_SEC_TMR1A
  975. //! - \b UDMA_DEF_TMR0B_SEC_TMR1B
  976. //! - \b UDMA_DEF_TMR1A_SEC_GPIORX
  977. //! - \b UDMA_DEF_TMR1B_SEC_GPIOTX
  978. //! - \b UDMA_DEF_UART1RX_SEC_RESERVED
  979. //! - \b UDMA_DEF_UART1TX_SEC_RESERVED
  980. //! - \b UDMA_DEF_SSI1RX_SEC_ADC10
  981. //! - \b UDMA_DEF_SSI1TX_SEC_ADC11
  982. //! - \b UDMA_DEF_RESERVED_SEC_ADC12
  983. //! - \b UDMA_DEF_RESERVED_SEC_ADC13
  984. //! - \b UDMA_DEF_I2S0RX_SEC_RESERVED
  985. //! - \b UDMA_DEF_I2S0TX_SEC_RESERVED
  986. //!
  987. //! \return None.
  988. //
  989. //*****************************************************************************
  990. void
  991. uDMAChannelSelectSecondary(unsigned long ulSecPeriphs)
  992. {
  993. //
  994. // Select the secondary peripheral for the specified channels.
  995. //
  996. HWREG(UDMA_CHALT) |= ulSecPeriphs;
  997. }
  998. //*****************************************************************************
  999. //
  1000. //! Select the default peripheral for a set of uDMA channels.
  1001. //!
  1002. //! \param ulDefPeriphs is the logical or of the uDMA channels for which to
  1003. //! use the default peripheral, instead of the secondary peripheral.
  1004. //!
  1005. //! This function is used to select the default peripheral assignment for
  1006. //! a set of uDMA channels.
  1007. //!
  1008. //! The parameter \e ulDefPeriphs can be the logical OR of any of the
  1009. //! following macros. If one of the macros below is in the list passed
  1010. //! to this function, then the default peripheral (marked as \b _DEF_)
  1011. //! will be selected.
  1012. //!
  1013. //! - \b UDMA_DEF_USBEP1RX_SEC_UART2RX
  1014. //! - \b UDMA_DEF_USBEP1TX_SEC_UART2TX
  1015. //! - \b UDMA_DEF_USBEP2RX_SEC_TMR3A
  1016. //! - \b UDMA_DEF_USBEP2TX_SEC_TMR3B
  1017. //! - \b UDMA_DEF_USBEP3RX_SEC_TMR2A
  1018. //! - \b UDMA_DEF_USBEP3TX_SEC_TMR2B
  1019. //! - \b UDMA_DEF_ETH0RX_SEC_TMR2A
  1020. //! - \b UDMA_DEF_ETH0TX_SEC_TMR2B
  1021. //! - \b UDMA_DEF_UART0RX_SEC_UART1RX
  1022. //! - \b UDMA_DEF_UART0TX_SEC_UART1TX
  1023. //! - \b UDMA_DEF_SSI0RX_SEC_SSI1RX
  1024. //! - \b UDMA_DEF_SSI0TX_SEC_SSI1TX
  1025. //! - \b UDMA_DEF_RESERVED_SEC_UART2RX
  1026. //! - \b UDMA_DEF_RESERVED_SEC_UART2TX
  1027. //! - \b UDMA_DEF_ADC00_SEC_TMR2A
  1028. //! - \b UDMA_DEF_ADC01_SEC_TMR2B
  1029. //! - \b UDMA_DEF_ADC02_SEC_RESERVED
  1030. //! - \b UDMA_DEF_ADC03_SEC_RESERVED
  1031. //! - \b UDMA_DEF_TMR0A_SEC_TMR1A
  1032. //! - \b UDMA_DEF_TMR0B_SEC_TMR1B
  1033. //! - \b UDMA_DEF_TMR1A_SEC_GPIORX
  1034. //! - \b UDMA_DEF_TMR1B_SEC_GPIOTX
  1035. //! - \b UDMA_DEF_UART1RX_SEC_RESERVED
  1036. //! - \b UDMA_DEF_UART1TX_SEC_RESERVED
  1037. //! - \b UDMA_DEF_SSI1RX_SEC_ADC10
  1038. //! - \b UDMA_DEF_SSI1TX_SEC_ADC11
  1039. //! - \b UDMA_DEF_RESERVED_SEC_ADC12
  1040. //! - \b UDMA_DEF_RESERVED_SEC_ADC13
  1041. //! - \b UDMA_DEF_I2S0RX_SEC_RESERVED
  1042. //! - \b UDMA_DEF_I2S0TX_SEC_RESERVED
  1043. //!
  1044. //! \return None.
  1045. //
  1046. //*****************************************************************************
  1047. void
  1048. uDMAChannelSelectDefault(unsigned long ulDefPeriphs)
  1049. {
  1050. //
  1051. // Select the default peripheral for the specified channels.
  1052. //
  1053. HWREG(UDMA_CHALT) &= ~ulDefPeriphs;
  1054. }
  1055. //*****************************************************************************
  1056. //
  1057. //! Gets the uDMA controller channel interrupt status.
  1058. //!
  1059. //! This function is used to get the interrupt status of the uDMA controller.
  1060. //! The returned value is a 32-bit bit mask that indicates which channels are
  1061. //! requesting an interrupt. This function can be used from within an
  1062. //! interrupt handler to determine or confirm which uDMA channel has requested
  1063. //! an interrupt.
  1064. //!
  1065. //! \return Returns a 32-bit mask which indicates requesting uDMA channels.
  1066. //! There is a bit for each channel, and a 1 in a bit indicates that channel
  1067. //! is requesting an interrupt. Multiple bits can be set.
  1068. //
  1069. //*****************************************************************************
  1070. unsigned long
  1071. uDMAIntStatus(void)
  1072. {
  1073. return(HWREG(UDMA_CHIS));
  1074. }
  1075. //*****************************************************************************
  1076. //
  1077. //! Clears uDMA interrupt status.
  1078. //!
  1079. //! \param ulChanMask is a 32-bit mask with one bit for each uDMA channel.
  1080. //!
  1081. //! Clears bits in the uDMA interrupt status register according to which bits
  1082. //! are set in \e ulChanMask. There is one bit for each channel. If a a bit
  1083. //! is set in \e ulChanMask, then that corresponding channel's interrupt
  1084. //! status will be cleared (if it was set).
  1085. //!
  1086. //! \return None.
  1087. //
  1088. //*****************************************************************************
  1089. void
  1090. uDMAIntClear(unsigned long ulChanMask)
  1091. {
  1092. HWREG(UDMA_CHIS) = ulChanMask;
  1093. }
  1094. //*****************************************************************************
  1095. //
  1096. //! Registers an interrupt handler for the uDMA controller.
  1097. //!
  1098. //! \param ulIntChannel identifies which uDMA interrupt is to be registered.
  1099. //! \param pfnHandler is a pointer to the function to be called when the
  1100. //! interrupt is activated.
  1101. //!
  1102. //! This sets and enables the handler to be called when the uDMA controller
  1103. //! generates an interrupt. The \e ulIntChannel parameter should be one of the
  1104. //! following:
  1105. //!
  1106. //! - \b UDMA_INT_SW to register an interrupt handler to process interrupts
  1107. //! from the uDMA software channel (UDMA_CHANNEL_SW)
  1108. //! - \b UDMA_INT_ERR to register an interrupt handler to process uDMA error
  1109. //! interrupts
  1110. //!
  1111. //! \sa IntRegister() for important information about registering interrupt
  1112. //! handlers.
  1113. //!
  1114. //! \note The interrupt handler for uDMA is for transfer completion when the
  1115. //! channel UDMA_CHANNEL_SW is used, and for error interrupts. The
  1116. //! interrupts for each peripheral channel are handled through the individual
  1117. //! peripheral interrupt handlers.
  1118. //!
  1119. //! \return None.
  1120. //
  1121. //*****************************************************************************
  1122. void
  1123. uDMAIntRegister(unsigned long ulIntChannel, void (*pfnHandler)(void))
  1124. {
  1125. //
  1126. // Check the arguments.
  1127. //
  1128. ASSERT(pfnHandler);
  1129. ASSERT((ulIntChannel == UDMA_INT_SW) || (ulIntChannel == UDMA_INT_ERR));
  1130. //
  1131. // Register the interrupt handler.
  1132. //
  1133. IntRegister(ulIntChannel, pfnHandler);
  1134. //
  1135. // Enable the memory management fault.
  1136. //
  1137. IntEnable(ulIntChannel);
  1138. }
  1139. //*****************************************************************************
  1140. //
  1141. //! Unregisters an interrupt handler for the uDMA controller.
  1142. //!
  1143. //! \param ulIntChannel identifies which uDMA interrupt to unregister.
  1144. //!
  1145. //! This function will disable and clear the handler to be called for the
  1146. //! specified uDMA interrupt. The \e ulIntChannel parameter should be one of
  1147. //! \b UDMA_INT_SW or \b UDMA_INT_ERR as documented for the function
  1148. //! uDMAIntRegister().
  1149. //!
  1150. //! \sa IntRegister() for important information about registering interrupt
  1151. //! handlers.
  1152. //!
  1153. //! \return None.
  1154. //
  1155. //*****************************************************************************
  1156. void
  1157. uDMAIntUnregister(unsigned long ulIntChannel)
  1158. {
  1159. //
  1160. // Disable the interrupt.
  1161. //
  1162. IntDisable(ulIntChannel);
  1163. //
  1164. // Unregister the interrupt handler.
  1165. //
  1166. IntUnregister(ulIntChannel);
  1167. }
  1168. //*****************************************************************************
  1169. //
  1170. // Close the Doxygen group.
  1171. //! @}
  1172. //
  1173. //*****************************************************************************