udma.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384
  1. //*****************************************************************************
  2. //
  3. // udma.c - Driver for the micro-DMA controller.
  4. //
  5. // Copyright (c) 2007-2014 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. // This is part of revision 2.1.0.12573 of the Tiva Peripheral Driver Library.
  37. //
  38. //*****************************************************************************
  39. //*****************************************************************************
  40. //
  41. //! \addtogroup udma_api
  42. //! @{
  43. //
  44. //*****************************************************************************
  45. #include <stdbool.h>
  46. #include <stdint.h>
  47. #include "inc/hw_sysctl.h"
  48. #include "inc/hw_types.h"
  49. #include "inc/hw_udma.h"
  50. #include "driverlib/debug.h"
  51. #include "driverlib/interrupt.h"
  52. #include "driverlib/udma.h"
  53. //*****************************************************************************
  54. //
  55. //! Enables the uDMA controller for use.
  56. //!
  57. //! This function enables the uDMA controller. The uDMA controller must be
  58. //! enabled before it can be configured and used.
  59. //!
  60. //! \return None.
  61. //
  62. //*****************************************************************************
  63. void
  64. uDMAEnable(void)
  65. {
  66. //
  67. // Set the master enable bit in the config register.
  68. //
  69. HWREG(UDMA_CFG) = UDMA_CFG_MASTEN;
  70. }
  71. //*****************************************************************************
  72. //
  73. //! Disables the uDMA controller for use.
  74. //!
  75. //! This function disables the uDMA controller. Once disabled, the uDMA
  76. //! controller cannot operate until re-enabled with uDMAEnable().
  77. //!
  78. //! \return None.
  79. //
  80. //*****************************************************************************
  81. void
  82. uDMADisable(void)
  83. {
  84. //
  85. // Clear the master enable bit in the config register.
  86. //
  87. HWREG(UDMA_CFG) = 0;
  88. }
  89. //*****************************************************************************
  90. //
  91. //! Gets the uDMA error status.
  92. //!
  93. //! This function returns the uDMA error status. It should be called from
  94. //! within the uDMA error interrupt handler to determine if a uDMA error
  95. //! occurred.
  96. //!
  97. //! \return Returns non-zero if a uDMA error is pending.
  98. //
  99. //*****************************************************************************
  100. uint32_t
  101. uDMAErrorStatusGet(void)
  102. {
  103. //
  104. // Return the uDMA error status.
  105. //
  106. return(HWREG(UDMA_ERRCLR));
  107. }
  108. //*****************************************************************************
  109. //
  110. //! Clears the uDMA error interrupt.
  111. //!
  112. //! This function clears a pending uDMA error interrupt. This function should
  113. //! be called from within the uDMA error interrupt handler to clear the
  114. //! interrupt.
  115. //!
  116. //! \return None.
  117. //
  118. //*****************************************************************************
  119. void
  120. uDMAErrorStatusClear(void)
  121. {
  122. //
  123. // Clear the uDMA error interrupt.
  124. //
  125. HWREG(UDMA_ERRCLR) = 1;
  126. }
  127. //*****************************************************************************
  128. //
  129. //! Enables a uDMA channel for operation.
  130. //!
  131. //! \param ui32ChannelNum is the channel number to enable.
  132. //!
  133. //! This function enables a specific uDMA channel for use. This function must
  134. //! be used to enable a channel before it can be used to perform a uDMA
  135. //! transfer.
  136. //!
  137. //! When a uDMA transfer is completed, the channel is automatically disabled by
  138. //! the uDMA controller. Therefore, this function should be called prior to
  139. //! starting up any new transfer.
  140. //!
  141. //! \return None.
  142. //
  143. //*****************************************************************************
  144. void
  145. uDMAChannelEnable(uint32_t ui32ChannelNum)
  146. {
  147. //
  148. // Check the arguments.
  149. //
  150. ASSERT((ui32ChannelNum & 0xffff) < 32);
  151. //
  152. // Set the bit for this channel in the enable set register.
  153. //
  154. HWREG(UDMA_ENASET) = 1 << (ui32ChannelNum & 0x1f);
  155. }
  156. //*****************************************************************************
  157. //
  158. //! Disables a uDMA channel for operation.
  159. //!
  160. //! \param ui32ChannelNum is the channel number to disable.
  161. //!
  162. //! This function disables a specific uDMA channel. Once disabled, a channel
  163. //! cannot respond to uDMA transfer requests until re-enabled via
  164. //! uDMAChannelEnable().
  165. //!
  166. //! \return None.
  167. //
  168. //*****************************************************************************
  169. void
  170. uDMAChannelDisable(uint32_t ui32ChannelNum)
  171. {
  172. //
  173. // Check the arguments.
  174. //
  175. ASSERT((ui32ChannelNum & 0xffff) < 32);
  176. //
  177. // Set the bit for this channel in the enable clear register.
  178. //
  179. HWREG(UDMA_ENACLR) = 1 << (ui32ChannelNum & 0x1f);
  180. }
  181. //*****************************************************************************
  182. //
  183. //! Checks if a uDMA channel is enabled for operation.
  184. //!
  185. //! \param ui32ChannelNum is the channel number to check.
  186. //!
  187. //! This function checks to see if a specific uDMA channel is enabled. This
  188. //! function can be used to check the status of a transfer, as the channel is
  189. //! automatically disabled at the end of a transfer.
  190. //!
  191. //! \return Returns \b true if the channel is enabled, \b false if disabled.
  192. //
  193. //*****************************************************************************
  194. bool
  195. uDMAChannelIsEnabled(uint32_t ui32ChannelNum)
  196. {
  197. //
  198. // Check the arguments.
  199. //
  200. ASSERT((ui32ChannelNum & 0xffff) < 32);
  201. //
  202. // AND the specified channel bit with the enable register and return the
  203. // result.
  204. //
  205. return((HWREG(UDMA_ENASET) & (1 << (ui32ChannelNum & 0x1f))) ? true :
  206. false);
  207. }
  208. //*****************************************************************************
  209. //
  210. //! Sets the base address for the channel control table.
  211. //!
  212. //! \param psControlTable is a pointer to the 1024-byte-aligned base address
  213. //! of the uDMA channel control table.
  214. //!
  215. //! This function configures the base address of the channel control table.
  216. //! This table resides in system memory and holds control information for each
  217. //! uDMA channel. The table must be aligned on a 1024-byte boundary. The base
  218. //! address must be configured before any of the channel functions can be used.
  219. //!
  220. //! The size of the channel control table depends on the number of uDMA
  221. //! channels and the transfer modes that are used. Refer to the introductory
  222. //! text and the microcontroller datasheet for more information about the
  223. //! channel control table.
  224. //!
  225. //! \return None.
  226. //
  227. //*****************************************************************************
  228. void
  229. uDMAControlBaseSet(void *psControlTable)
  230. {
  231. //
  232. // Check the arguments.
  233. //
  234. ASSERT(((uint32_t)psControlTable & ~0x3FF) ==
  235. (uint32_t)psControlTable);
  236. ASSERT((uint32_t)psControlTable >= 0x20000000);
  237. //
  238. // Program the base address into the register.
  239. //
  240. HWREG(UDMA_CTLBASE) = (uint32_t)psControlTable;
  241. }
  242. //*****************************************************************************
  243. //
  244. //! Gets the base address for the channel control table.
  245. //!
  246. //! This function gets the base address of the channel control table. This
  247. //! table resides in system memory and holds control information for each uDMA
  248. //! channel.
  249. //!
  250. //! \return Returns a pointer to the base address of the channel control table.
  251. //
  252. //*****************************************************************************
  253. void *
  254. uDMAControlBaseGet(void)
  255. {
  256. //
  257. // Read the current value of the control base register and return it to
  258. // the caller.
  259. //
  260. return((void *)HWREG(UDMA_CTLBASE));
  261. }
  262. //*****************************************************************************
  263. //
  264. //! Gets the base address for the channel control table alternate structures.
  265. //!
  266. //! This function gets the base address of the second half of the channel
  267. //! control table that holds the alternate control structures for each channel.
  268. //!
  269. //! \return Returns a pointer to the base address of the second half of the
  270. //! channel control table.
  271. //
  272. //*****************************************************************************
  273. void *
  274. uDMAControlAlternateBaseGet(void)
  275. {
  276. //
  277. // Read the current value of the control base register and return it to
  278. // the caller.
  279. //
  280. return((void *)HWREG(UDMA_ALTBASE));
  281. }
  282. //*****************************************************************************
  283. //
  284. //! Requests a uDMA channel to start a transfer.
  285. //!
  286. //! \param ui32ChannelNum is the channel number on which to request a uDMA
  287. //! transfer.
  288. //!
  289. //! This function allows software to request a uDMA channel to begin a
  290. //! transfer. This function could be used for performing a memory-to-memory
  291. //! transfer, or if for some reason a transfer needs to be initiated by
  292. //! software instead of the peripheral associated with that channel.
  293. //!
  294. //! \note If the channel is \b UDMA_CHANNEL_SW and interrupts are used, then
  295. //! the completion is signaled on the uDMA dedicated interrupt. If a
  296. //! peripheral channel is used, then the completion is signaled on the
  297. //! peripheral's interrupt.
  298. //!
  299. //! \return None.
  300. //
  301. //*****************************************************************************
  302. void
  303. uDMAChannelRequest(uint32_t ui32ChannelNum)
  304. {
  305. //
  306. // Check the arguments.
  307. //
  308. ASSERT((ui32ChannelNum & 0xffff) < 32);
  309. //
  310. // Set the bit for this channel in the software uDMA request register.
  311. //
  312. HWREG(UDMA_SWREQ) = 1 << (ui32ChannelNum & 0x1f);
  313. }
  314. //*****************************************************************************
  315. //
  316. //! Enables attributes of a uDMA channel.
  317. //!
  318. //! \param ui32ChannelNum is the channel to configure.
  319. //! \param ui32Attr is a combination of attributes for the channel.
  320. //!
  321. //! This function is used to enable attributes of a uDMA channel.
  322. //!
  323. //! The \e ui32Attr parameter is the logical OR of any of the following:
  324. //!
  325. //! - \b UDMA_ATTR_USEBURST is used to restrict transfers to use only burst
  326. //! mode.
  327. //! - \b UDMA_ATTR_ALTSELECT is used to select the alternate control structure
  328. //! for this channel (it is very unlikely that this flag should be used).
  329. //! - \b UDMA_ATTR_HIGH_PRIORITY is used to set this channel to high priority.
  330. //! - \b UDMA_ATTR_REQMASK is used to mask the hardware request signal from the
  331. //! peripheral for this channel.
  332. //!
  333. //! \return None.
  334. //
  335. //*****************************************************************************
  336. void
  337. uDMAChannelAttributeEnable(uint32_t ui32ChannelNum, uint32_t ui32Attr)
  338. {
  339. //
  340. // Check the arguments.
  341. //
  342. ASSERT((ui32ChannelNum & 0xffff) < 32);
  343. ASSERT((ui32Attr & ~(UDMA_ATTR_USEBURST | UDMA_ATTR_ALTSELECT |
  344. UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK)) == 0);
  345. //
  346. // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
  347. // passed as the ui32ChannelNum parameter, extract just the channel number
  348. // from this parameter.
  349. //
  350. ui32ChannelNum &= 0x1f;
  351. //
  352. // Set the useburst bit for this channel if set in ui32Config.
  353. //
  354. if(ui32Attr & UDMA_ATTR_USEBURST)
  355. {
  356. HWREG(UDMA_USEBURSTSET) = 1 << ui32ChannelNum;
  357. }
  358. //
  359. // Set the alternate control select bit for this channel,
  360. // if set in ui32Config.
  361. //
  362. if(ui32Attr & UDMA_ATTR_ALTSELECT)
  363. {
  364. HWREG(UDMA_ALTSET) = 1 << ui32ChannelNum;
  365. }
  366. //
  367. // Set the high priority bit for this channel, if set in ui32Config.
  368. //
  369. if(ui32Attr & UDMA_ATTR_HIGH_PRIORITY)
  370. {
  371. HWREG(UDMA_PRIOSET) = 1 << ui32ChannelNum;
  372. }
  373. //
  374. // Set the request mask bit for this channel, if set in ui32Config.
  375. //
  376. if(ui32Attr & UDMA_ATTR_REQMASK)
  377. {
  378. HWREG(UDMA_REQMASKSET) = 1 << ui32ChannelNum;
  379. }
  380. }
  381. //*****************************************************************************
  382. //
  383. //! Disables attributes of a uDMA channel.
  384. //!
  385. //! \param ui32ChannelNum is the channel to configure.
  386. //! \param ui32Attr is a combination of attributes for the channel.
  387. //!
  388. //! This function is used to disable attributes of a uDMA channel.
  389. //!
  390. //! The \e ui32Attr parameter is the logical OR of any of the following:
  391. //!
  392. //! - \b UDMA_ATTR_USEBURST is used to restrict transfers to use only burst
  393. //! mode.
  394. //! - \b UDMA_ATTR_ALTSELECT is used to select the alternate control structure
  395. //! for this channel.
  396. //! - \b UDMA_ATTR_HIGH_PRIORITY is used to set this channel to high priority.
  397. //! - \b UDMA_ATTR_REQMASK is used to mask the hardware request signal from the
  398. //! peripheral for this channel.
  399. //!
  400. //! \return None.
  401. //
  402. //*****************************************************************************
  403. void
  404. uDMAChannelAttributeDisable(uint32_t ui32ChannelNum, uint32_t ui32Attr)
  405. {
  406. //
  407. // Check the arguments.
  408. //
  409. ASSERT((ui32ChannelNum & 0xffff) < 32);
  410. ASSERT((ui32Attr & ~(UDMA_ATTR_USEBURST | UDMA_ATTR_ALTSELECT |
  411. UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK)) == 0);
  412. //
  413. // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
  414. // passed as the ui32ChannelNum parameter, extract just the channel number
  415. // from this parameter.
  416. //
  417. ui32ChannelNum &= 0x1f;
  418. //
  419. // Clear the useburst bit for this channel if set in ui32Config.
  420. //
  421. if(ui32Attr & UDMA_ATTR_USEBURST)
  422. {
  423. HWREG(UDMA_USEBURSTCLR) = 1 << ui32ChannelNum;
  424. }
  425. //
  426. // Clear the alternate control select bit for this channel, if set in
  427. // ui32Config.
  428. //
  429. if(ui32Attr & UDMA_ATTR_ALTSELECT)
  430. {
  431. HWREG(UDMA_ALTCLR) = 1 << ui32ChannelNum;
  432. }
  433. //
  434. // Clear the high priority bit for this channel, if set in ui32Config.
  435. //
  436. if(ui32Attr & UDMA_ATTR_HIGH_PRIORITY)
  437. {
  438. HWREG(UDMA_PRIOCLR) = 1 << ui32ChannelNum;
  439. }
  440. //
  441. // Clear the request mask bit for this channel, if set in ui32Config.
  442. //
  443. if(ui32Attr & UDMA_ATTR_REQMASK)
  444. {
  445. HWREG(UDMA_REQMASKCLR) = 1 << ui32ChannelNum;
  446. }
  447. }
  448. //*****************************************************************************
  449. //
  450. //! Gets the enabled attributes of a uDMA channel.
  451. //!
  452. //! \param ui32ChannelNum is the channel to configure.
  453. //!
  454. //! This function returns a combination of flags representing the attributes of
  455. //! the uDMA channel.
  456. //!
  457. //! \return Returns the logical OR of the attributes of the uDMA channel, which
  458. //! can be any of the following:
  459. //! - \b UDMA_ATTR_USEBURST is used to restrict transfers to use only burst
  460. //! mode.
  461. //! - \b UDMA_ATTR_ALTSELECT is used to select the alternate control structure
  462. //! for this channel.
  463. //! - \b UDMA_ATTR_HIGH_PRIORITY is used to set this channel to high priority.
  464. //! - \b UDMA_ATTR_REQMASK is used to mask the hardware request signal from the
  465. //! peripheral for this channel.
  466. //
  467. //*****************************************************************************
  468. uint32_t
  469. uDMAChannelAttributeGet(uint32_t ui32ChannelNum)
  470. {
  471. uint32_t ui32Attr = 0;
  472. //
  473. // Check the arguments.
  474. //
  475. ASSERT((ui32ChannelNum & 0xffff) < 32);
  476. //
  477. // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
  478. // passed as the ui32ChannelNum parameter, extract just the channel number
  479. // from this parameter.
  480. //
  481. ui32ChannelNum &= 0x1f;
  482. //
  483. // Check to see if useburst bit is set for this channel.
  484. //
  485. if(HWREG(UDMA_USEBURSTSET) & (1 << ui32ChannelNum))
  486. {
  487. ui32Attr |= UDMA_ATTR_USEBURST;
  488. }
  489. //
  490. // Check to see if the alternate control bit is set for this channel.
  491. //
  492. if(HWREG(UDMA_ALTSET) & (1 << ui32ChannelNum))
  493. {
  494. ui32Attr |= UDMA_ATTR_ALTSELECT;
  495. }
  496. //
  497. // Check to see if the high priority bit is set for this channel.
  498. //
  499. if(HWREG(UDMA_PRIOSET) & (1 << ui32ChannelNum))
  500. {
  501. ui32Attr |= UDMA_ATTR_HIGH_PRIORITY;
  502. }
  503. //
  504. // Check to see if the request mask bit is set for this channel.
  505. //
  506. if(HWREG(UDMA_REQMASKSET) & (1 << ui32ChannelNum))
  507. {
  508. ui32Attr |= UDMA_ATTR_REQMASK;
  509. }
  510. //
  511. // Return the configuration flags.
  512. //
  513. return(ui32Attr);
  514. }
  515. //*****************************************************************************
  516. //
  517. //! Sets the control parameters for a uDMA channel control structure.
  518. //!
  519. //! \param ui32ChannelStructIndex is the logical OR of the uDMA channel number
  520. //! with \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT.
  521. //! \param ui32Control is logical OR of several control values to set the
  522. //! control parameters for the channel.
  523. //!
  524. //! This function is used to set control parameters for a uDMA transfer. These
  525. //! parameters are typically not changed often.
  526. //!
  527. //! The \e ui32ChannelStructIndex parameter should be the logical OR of the
  528. //! channel number with one of \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT to
  529. //! choose whether the primary or alternate data structure is used.
  530. //!
  531. //! The \e ui32Control parameter is the logical OR of five values: the data
  532. //! size, the source address increment, the destination address increment, the
  533. //! arbitration size, and the use burst flag. The choices available for each
  534. //! of these values is described below.
  535. //!
  536. //! Choose the data size from one of \b UDMA_SIZE_8, \b UDMA_SIZE_16, or
  537. //! \b UDMA_SIZE_32 to select a data size of 8, 16, or 32 bits.
  538. //!
  539. //! Choose the source address increment from one of \b UDMA_SRC_INC_8,
  540. //! \b UDMA_SRC_INC_16, \b UDMA_SRC_INC_32, or \b UDMA_SRC_INC_NONE to select
  541. //! an address increment of 8-bit bytes, 16-bit half-words, 32-bit words, or
  542. //! to select non-incrementing.
  543. //!
  544. //! Choose the destination address increment from one of \b UDMA_DST_INC_8,
  545. //! \b UDMA_DST_INC_16, \b UDMA_DST_INC_32, or \b UDMA_DST_INC_NONE to select
  546. //! an address increment of 8-bit bytes, 16-bit half-words, 32-bit words, or
  547. //! to select non-incrementing.
  548. //!
  549. //! The arbitration size determines how many items are transferred before
  550. //! the uDMA controller re-arbitrates for the bus. Choose the arbitration size
  551. //! from one of \b UDMA_ARB_1, \b UDMA_ARB_2, \b UDMA_ARB_4, \b UDMA_ARB_8,
  552. //! through \b UDMA_ARB_1024 to select the arbitration size from 1 to 1024
  553. //! items, in powers of 2.
  554. //!
  555. //! The value \b UDMA_NEXT_USEBURST is used to force the channel to only
  556. //! respond to burst requests at the tail end of a scatter-gather transfer.
  557. //!
  558. //! \note The address increment cannot be smaller than the data size.
  559. //!
  560. //! \return None.
  561. //
  562. //*****************************************************************************
  563. void
  564. uDMAChannelControlSet(uint32_t ui32ChannelStructIndex, uint32_t ui32Control)
  565. {
  566. tDMAControlTable *psCtl;
  567. //
  568. // Check the arguments.
  569. //
  570. ASSERT((ui32ChannelStructIndex & 0xffff) < 64);
  571. ASSERT(HWREG(UDMA_CTLBASE) != 0);
  572. //
  573. // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
  574. // passed as the ui32ChannelStructIndex parameter, extract just the channel
  575. // index from this parameter.
  576. //
  577. ui32ChannelStructIndex &= 0x3f;
  578. //
  579. // Get the base address of the control table.
  580. //
  581. psCtl = (tDMAControlTable *)HWREG(UDMA_CTLBASE);
  582. //
  583. // Get the current control word value and mask off the fields to be
  584. // changed, then OR in the new settings.
  585. //
  586. psCtl[ui32ChannelStructIndex].ui32Control =
  587. ((psCtl[ui32ChannelStructIndex].ui32Control &
  588. ~(UDMA_CHCTL_DSTINC_M |
  589. UDMA_CHCTL_DSTSIZE_M |
  590. UDMA_CHCTL_SRCINC_M |
  591. UDMA_CHCTL_SRCSIZE_M |
  592. UDMA_CHCTL_ARBSIZE_M |
  593. UDMA_CHCTL_NXTUSEBURST)) |
  594. ui32Control);
  595. }
  596. //*****************************************************************************
  597. //
  598. //! Sets the transfer parameters for a uDMA channel control structure.
  599. //!
  600. //! \param ui32ChannelStructIndex is the logical OR of the uDMA channel number
  601. //! with either \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT.
  602. //! \param ui32Mode is the type of uDMA transfer.
  603. //! \param pvSrcAddr is the source address for the transfer.
  604. //! \param pvDstAddr is the destination address for the transfer.
  605. //! \param ui32TransferSize is the number of data items to transfer.
  606. //!
  607. //! This function is used to configure the parameters for a uDMA transfer.
  608. //! These parameters are not typically changed often. The function
  609. //! uDMAChannelControlSet() MUST be called at least once for this channel prior
  610. //! to calling this function.
  611. //!
  612. //! The \e ui32ChannelStructIndex parameter should be the logical OR of the
  613. //! channel number with one of \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT to
  614. //! choose whether the primary or alternate data structure is used.
  615. //!
  616. //! The \e ui32Mode parameter should be one of the following values:
  617. //!
  618. //! - \b UDMA_MODE_STOP stops the uDMA transfer. The controller sets the mode
  619. //! to this value at the end of a transfer.
  620. //! - \b UDMA_MODE_BASIC to perform a basic transfer based on request.
  621. //! - \b UDMA_MODE_AUTO to perform a transfer that always completes once
  622. //! started even if the request is removed.
  623. //! - \b UDMA_MODE_PINGPONG to set up a transfer that switches between the
  624. //! primary and alternate control structures for the channel. This mode
  625. //! allows use of ping-pong buffering for uDMA transfers.
  626. //! - \b UDMA_MODE_MEM_SCATTER_GATHER to set up a memory scatter-gather
  627. //! transfer.
  628. //! - \b UDMA_MODE_PER_SCATTER_GATHER to set up a peripheral scatter-gather
  629. //! transfer.
  630. //!
  631. //! The \e pvSrcAddr and \e pvDstAddr parameters are pointers to the first
  632. //! location of the data to be transferred. These addresses should be aligned
  633. //! according to the item size. The compiler takes care of this alignment if
  634. //! the pointers are pointing to storage of the appropriate data type.
  635. //!
  636. //! The \e ui32TransferSize parameter is the number of data items, not the
  637. //! number of bytes.
  638. //!
  639. //! The two scatter-gather modes, memory and peripheral, are actually different
  640. //! depending on whether the primary or alternate control structure is
  641. //! selected. This function looks for the \b UDMA_PRI_SELECT and
  642. //! \b UDMA_ALT_SELECT flag along with the channel number and sets the
  643. //! scatter-gather mode as appropriate for the primary or alternate control
  644. //! structure.
  645. //!
  646. //! The channel must also be enabled using uDMAChannelEnable() after calling
  647. //! this function. The transfer does not begin until the channel has been
  648. //! configured and enabled. Note that the channel is automatically disabled
  649. //! after the transfer is completed, meaning that uDMAChannelEnable() must be
  650. //! called again after setting up the next transfer.
  651. //!
  652. //! \note Great care must be taken to not modify a channel control structure
  653. //! that is in use or else the results are unpredictable, including the
  654. //! possibility of undesired data transfers to or from memory or peripherals.
  655. //! For BASIC and AUTO modes, it is safe to make changes when the channel is
  656. //! disabled, or the uDMAChannelModeGet() returns \b UDMA_MODE_STOP. For
  657. //! PINGPONG or one of the SCATTER_GATHER modes, it is safe to modify the
  658. //! primary or alternate control structure only when the other is being used.
  659. //! The uDMAChannelModeGet() function returns \b UDMA_MODE_STOP when a
  660. //! channel control structure is inactive and safe to modify.
  661. //!
  662. //! \return None.
  663. //
  664. //*****************************************************************************
  665. void
  666. uDMAChannelTransferSet(uint32_t ui32ChannelStructIndex, uint32_t ui32Mode,
  667. void *pvSrcAddr, void *pvDstAddr,
  668. uint32_t ui32TransferSize)
  669. {
  670. tDMAControlTable *psControlTable;
  671. uint32_t ui32Control;
  672. uint32_t ui32Inc;
  673. uint32_t ui32BufferBytes;
  674. //
  675. // Check the arguments.
  676. //
  677. ASSERT((ui32ChannelStructIndex & 0xffff) < 64);
  678. ASSERT(HWREG(UDMA_CTLBASE) != 0);
  679. ASSERT(ui32Mode <= UDMA_MODE_PER_SCATTER_GATHER);
  680. ASSERT((uint32_t)pvSrcAddr >= 0x20000000);
  681. ASSERT((uint32_t)pvDstAddr >= 0x20000000);
  682. ASSERT((ui32TransferSize != 0) && (ui32TransferSize <= 1024));
  683. //
  684. // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
  685. // passed as the ui32ChannelStructIndex parameter, extract just the channel
  686. // index from this parameter.
  687. //
  688. ui32ChannelStructIndex &= 0x3f;
  689. //
  690. // Get the base address of the control table.
  691. //
  692. psControlTable = (tDMAControlTable *)HWREG(UDMA_CTLBASE);
  693. //
  694. // Get the current control word value and mask off the mode and size
  695. // fields.
  696. //
  697. ui32Control = (psControlTable[ui32ChannelStructIndex].ui32Control &
  698. ~(UDMA_CHCTL_XFERSIZE_M | UDMA_CHCTL_XFERMODE_M));
  699. //
  700. // Adjust the mode if the alt control structure is selected.
  701. //
  702. if(ui32ChannelStructIndex & UDMA_ALT_SELECT)
  703. {
  704. if((ui32Mode == UDMA_MODE_MEM_SCATTER_GATHER) ||
  705. (ui32Mode == UDMA_MODE_PER_SCATTER_GATHER))
  706. {
  707. ui32Mode |= UDMA_MODE_ALT_SELECT;
  708. }
  709. }
  710. //
  711. // Set the transfer size and mode in the control word (but don't write the
  712. // control word yet as it could kick off a transfer).
  713. //
  714. ui32Control |= ui32Mode | ((ui32TransferSize - 1) << 4);
  715. //
  716. // Get the address increment value for the source, from the control word.
  717. //
  718. ui32Inc = (ui32Control & UDMA_CHCTL_SRCINC_M);
  719. //
  720. // Compute the ending source address of the transfer. If the source
  721. // increment is set to none, then the ending address is the same as the
  722. // beginning.
  723. //
  724. if(ui32Inc != UDMA_SRC_INC_NONE)
  725. {
  726. ui32Inc = ui32Inc >> 26;
  727. ui32BufferBytes = ui32TransferSize << ui32Inc;
  728. pvSrcAddr = (void *)((uint32_t)pvSrcAddr + ui32BufferBytes - 1);
  729. }
  730. //
  731. // Load the source ending address into the control block.
  732. //
  733. psControlTable[ui32ChannelStructIndex].pvSrcEndAddr = pvSrcAddr;
  734. //
  735. // Get the address increment value for the destination, from the control
  736. // word.
  737. //
  738. ui32Inc = ui32Control & UDMA_CHCTL_DSTINC_M;
  739. //
  740. // Compute the ending destination address of the transfer. If the
  741. // destination increment is set to none, then the ending address is the
  742. // same as the beginning.
  743. //
  744. if(ui32Inc != UDMA_DST_INC_NONE)
  745. {
  746. //
  747. // There is a special case if this is setting up a scatter-gather
  748. // transfer. The destination pointer must point to the end of
  749. // the alternate structure for this channel instead of calculating
  750. // the end of the buffer in the normal way.
  751. //
  752. if((ui32Mode == UDMA_MODE_MEM_SCATTER_GATHER) ||
  753. (ui32Mode == UDMA_MODE_PER_SCATTER_GATHER))
  754. {
  755. pvDstAddr =
  756. (void *)&psControlTable[ui32ChannelStructIndex |
  757. UDMA_ALT_SELECT].ui32Spare;
  758. }
  759. //
  760. // Not a scatter-gather transfer, calculate end pointer normally.
  761. //
  762. else
  763. {
  764. ui32Inc = ui32Inc >> 30;
  765. ui32BufferBytes = ui32TransferSize << ui32Inc;
  766. pvDstAddr = (void *)((uint32_t)pvDstAddr + ui32BufferBytes - 1);
  767. }
  768. }
  769. //
  770. // Load the destination ending address into the control block.
  771. //
  772. psControlTable[ui32ChannelStructIndex].pvDstEndAddr = pvDstAddr;
  773. //
  774. // Write the new control word value.
  775. //
  776. psControlTable[ui32ChannelStructIndex].ui32Control = ui32Control;
  777. }
  778. //*****************************************************************************
  779. //
  780. //! Configures a uDMA channel for scatter-gather mode.
  781. //!
  782. //! \param ui32ChannelNum is the uDMA channel number.
  783. //! \param ui32TaskCount is the number of scatter-gather tasks to execute.
  784. //! \param pvTaskList is a pointer to the beginning of the scatter-gather
  785. //! task list.
  786. //! \param ui32IsPeriphSG is a flag to indicate it is a peripheral
  787. //! scatter-gather transfer (else it is memory scatter-gather transfer)
  788. //!
  789. //! This function is used to configure a channel for scatter-gather mode.
  790. //! The caller must have already set up a task list and must pass a pointer to
  791. //! the start of the task list as the \e pvTaskList parameter. The
  792. //! \e ui32TaskCount parameter is the count of tasks in the task list, not the
  793. //! size of the task list. The flag \e bIsPeriphSG should be used to indicate
  794. //! if scatter-gather should be configured for peripheral or memory
  795. //! operation.
  796. //!
  797. //! \sa uDMATaskStructEntry
  798. //!
  799. //! \return None.
  800. //
  801. //*****************************************************************************
  802. void
  803. uDMAChannelScatterGatherSet(uint32_t ui32ChannelNum, uint32_t ui32TaskCount,
  804. void *pvTaskList, uint32_t ui32IsPeriphSG)
  805. {
  806. tDMAControlTable *psControlTable;
  807. tDMAControlTable *psTaskTable;
  808. //
  809. // Check the parameters
  810. //
  811. ASSERT((ui32ChannelNum & 0xffff) < 32);
  812. ASSERT(HWREG(UDMA_CTLBASE) != 0);
  813. ASSERT(pvTaskList != 0);
  814. ASSERT(ui32TaskCount <= 1024);
  815. ASSERT(ui32TaskCount != 0);
  816. //
  817. // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
  818. // passed as the ui32ChannelNum parameter, extract just the channel number
  819. // from this parameter.
  820. //
  821. ui32ChannelNum &= 0x1f;
  822. //
  823. // Get the base address of the control table.
  824. //
  825. psControlTable = (tDMAControlTable *)HWREG(UDMA_CTLBASE);
  826. //
  827. // Get a handy pointer to the task list
  828. //
  829. psTaskTable = (tDMAControlTable *)pvTaskList;
  830. //
  831. // Compute the ending address for the source pointer. This address is the
  832. // last element of the last task in the task table
  833. //
  834. psControlTable[ui32ChannelNum].pvSrcEndAddr =
  835. &psTaskTable[ui32TaskCount - 1].ui32Spare;
  836. //
  837. // Compute the ending address for the destination pointer. This address
  838. // is the end of the alternate structure for this channel.
  839. //
  840. psControlTable[ui32ChannelNum].pvDstEndAddr =
  841. &psControlTable[ui32ChannelNum | UDMA_ALT_SELECT].ui32Spare;
  842. //
  843. // Compute the control word. Most configurable items are fixed for
  844. // scatter-gather. Item and increment sizes are all 32-bit and arb
  845. // size must be 4. The count is the number of items in the task list
  846. // times 4 (4 words per task).
  847. //
  848. psControlTable[ui32ChannelNum].ui32Control =
  849. (UDMA_CHCTL_DSTINC_32 | UDMA_CHCTL_DSTSIZE_32 |
  850. UDMA_CHCTL_SRCINC_32 | UDMA_CHCTL_SRCSIZE_32 |
  851. UDMA_CHCTL_ARBSIZE_4 |
  852. (((ui32TaskCount * 4) - 1) << UDMA_CHCTL_XFERSIZE_S) |
  853. (ui32IsPeriphSG ? UDMA_CHCTL_XFERMODE_PER_SG :
  854. UDMA_CHCTL_XFERMODE_MEM_SG));
  855. //
  856. // Scatter-gather operations can leave the alt bit set. So if doing
  857. // back to back scatter-gather transfers, the second attempt may not
  858. // work correctly because the alt bit is set. Therefore, clear the
  859. // alt bit here to ensure that it is always cleared before a new SG
  860. // transfer is started.
  861. //
  862. HWREG(UDMA_ALTCLR) = 1 << ui32ChannelNum;
  863. }
  864. //*****************************************************************************
  865. //
  866. //! Gets the current transfer size for a uDMA channel control structure.
  867. //!
  868. //! \param ui32ChannelStructIndex is the logical OR of the uDMA channel number
  869. //! with either \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT.
  870. //!
  871. //! This function is used to get the uDMA transfer size for a channel. The
  872. //! transfer size is the number of items to transfer, where the size of an item
  873. //! might be 8, 16, or 32 bits. If a partial transfer has already occurred,
  874. //! then the number of remaining items is returned. If the transfer is
  875. //! complete, then 0 is returned.
  876. //!
  877. //! \return Returns the number of items remaining to transfer.
  878. //
  879. //*****************************************************************************
  880. uint32_t
  881. uDMAChannelSizeGet(uint32_t ui32ChannelStructIndex)
  882. {
  883. tDMAControlTable *psControlTable;
  884. uint32_t ui32Control;
  885. //
  886. // Check the arguments.
  887. //
  888. ASSERT((ui32ChannelStructIndex & 0xffff) < 64);
  889. ASSERT(HWREG(UDMA_CTLBASE) != 0);
  890. //
  891. // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
  892. // passed as the ui32ChannelStructIndex parameter, extract just the channel
  893. // index from this parameter.
  894. //
  895. ui32ChannelStructIndex &= 0x3f;
  896. //
  897. // Get the base address of the control table.
  898. //
  899. psControlTable = (tDMAControlTable *)HWREG(UDMA_CTLBASE);
  900. //
  901. // Get the current control word value and mask off all but the size field
  902. // and the mode field.
  903. //
  904. ui32Control = (psControlTable[ui32ChannelStructIndex].ui32Control &
  905. (UDMA_CHCTL_XFERSIZE_M | UDMA_CHCTL_XFERMODE_M));
  906. //
  907. // If the size field and mode field are 0 then the transfer is finished
  908. // and there are no more items to transfer
  909. //
  910. if(ui32Control == 0)
  911. {
  912. return(0);
  913. }
  914. //
  915. // Otherwise, if either the size field or more field is non-zero, then
  916. // not all the items have been transferred.
  917. //
  918. else
  919. {
  920. //
  921. // Shift the size field and add one, then return to user.
  922. //
  923. return((ui32Control >> 4) + 1);
  924. }
  925. }
  926. //*****************************************************************************
  927. //
  928. //! Gets the transfer mode for a uDMA channel control structure.
  929. //!
  930. //! \param ui32ChannelStructIndex is the logical OR of the uDMA channel number
  931. //! with either \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT.
  932. //!
  933. //! This function is used to get the transfer mode for the uDMA channel and
  934. //! to query the status of a transfer on a channel. When the transfer is
  935. //! complete the mode is \b UDMA_MODE_STOP.
  936. //!
  937. //! \return Returns the transfer mode of the specified channel and control
  938. //! structure, which is one of the following values: \b UDMA_MODE_STOP,
  939. //! \b UDMA_MODE_BASIC, \b UDMA_MODE_AUTO, \b UDMA_MODE_PINGPONG,
  940. //! \b UDMA_MODE_MEM_SCATTER_GATHER, or \b UDMA_MODE_PER_SCATTER_GATHER.
  941. //
  942. //*****************************************************************************
  943. uint32_t
  944. uDMAChannelModeGet(uint32_t ui32ChannelStructIndex)
  945. {
  946. tDMAControlTable *psControlTable;
  947. uint32_t ui32Control;
  948. //
  949. // Check the arguments.
  950. //
  951. ASSERT((ui32ChannelStructIndex & 0xffff) < 64);
  952. ASSERT(HWREG(UDMA_CTLBASE) != 0);
  953. //
  954. // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
  955. // passed as the ui32ChannelStructIndex parameter, extract just the channel
  956. // index from this parameter.
  957. //
  958. ui32ChannelStructIndex &= 0x3f;
  959. //
  960. // Get the base address of the control table.
  961. //
  962. psControlTable = (tDMAControlTable *)HWREG(UDMA_CTLBASE);
  963. //
  964. // Get the current control word value and mask off all but the mode field.
  965. //
  966. ui32Control = (psControlTable[ui32ChannelStructIndex].ui32Control &
  967. UDMA_CHCTL_XFERMODE_M);
  968. //
  969. // Check if scatter/gather mode, and if so, mask off the alt bit.
  970. //
  971. if(((ui32Control & ~UDMA_MODE_ALT_SELECT) ==
  972. UDMA_MODE_MEM_SCATTER_GATHER) ||
  973. ((ui32Control & ~UDMA_MODE_ALT_SELECT) == UDMA_MODE_PER_SCATTER_GATHER))
  974. {
  975. ui32Control &= ~UDMA_MODE_ALT_SELECT;
  976. }
  977. //
  978. // Return the mode to the caller.
  979. //
  980. return(ui32Control);
  981. }
  982. //*****************************************************************************
  983. //
  984. //! Registers an interrupt handler for the uDMA controller.
  985. //!
  986. //! \param ui32IntChannel identifies which uDMA interrupt is to be registered.
  987. //! \param pfnHandler is a pointer to the function to be called when the
  988. //! interrupt is activated.
  989. //!
  990. //! This function registers and enables the handler to be called when the uDMA
  991. //! controller generates an interrupt. The \e ui32IntChannel parameter should
  992. //! be one of the following:
  993. //!
  994. //! - \b UDMA_INT_SW to register an interrupt handler to process interrupts
  995. //! from the uDMA software channel (UDMA_CHANNEL_SW)
  996. //! - \b UDMA_INT_ERR to register an interrupt handler to process uDMA error
  997. //! interrupts
  998. //!
  999. //! \sa IntRegister() for important information about registering interrupt
  1000. //! handlers.
  1001. //!
  1002. //! \note The interrupt handler for the uDMA is for transfer completion when
  1003. //! the channel UDMA_CHANNEL_SW is used and for error interrupts. The
  1004. //! interrupts for each peripheral channel are handled through the individual
  1005. //! peripheral interrupt handlers.
  1006. //!
  1007. //! \return None.
  1008. //
  1009. //*****************************************************************************
  1010. void
  1011. uDMAIntRegister(uint32_t ui32IntChannel, void (*pfnHandler)(void))
  1012. {
  1013. //
  1014. // Check the arguments.
  1015. //
  1016. ASSERT(pfnHandler);
  1017. ASSERT((ui32IntChannel == UDMA_INT_SW) ||
  1018. (ui32IntChannel == UDMA_INT_ERR));
  1019. //
  1020. // Register the interrupt handler.
  1021. //
  1022. IntRegister(ui32IntChannel, pfnHandler);
  1023. //
  1024. // Enable the memory management fault.
  1025. //
  1026. IntEnable(ui32IntChannel);
  1027. }
  1028. //*****************************************************************************
  1029. //
  1030. //! Unregisters an interrupt handler for the uDMA controller.
  1031. //!
  1032. //! \param ui32IntChannel identifies which uDMA interrupt to unregister.
  1033. //!
  1034. //! This function disables and unregisters the handler to be called for the
  1035. //! specified uDMA interrupt. The \e ui32IntChannel parameter should be one of
  1036. //! \b UDMA_INT_SW or \b UDMA_INT_ERR as documented for the function
  1037. //! uDMAIntRegister().
  1038. //!
  1039. //! \sa IntRegister() for important information about registering interrupt
  1040. //! handlers.
  1041. //!
  1042. //! \return None.
  1043. //
  1044. //*****************************************************************************
  1045. void
  1046. uDMAIntUnregister(uint32_t ui32IntChannel)
  1047. {
  1048. //
  1049. // Disable the interrupt.
  1050. //
  1051. IntDisable(ui32IntChannel);
  1052. //
  1053. // Unregister the interrupt handler.
  1054. //
  1055. IntUnregister(ui32IntChannel);
  1056. }
  1057. //*****************************************************************************
  1058. //
  1059. //! Gets the uDMA controller channel interrupt status.
  1060. //!
  1061. //! This function is used to get the interrupt status of the uDMA controller.
  1062. //! The returned value is a 32-bit bit mask that indicates which channels are
  1063. //! requesting an interrupt. This function can be used from within an
  1064. //! interrupt handler to determine or confirm which uDMA channel has requested
  1065. //! an interrupt.
  1066. //!
  1067. //! \note This function is only available on devices that have the DMA Channel
  1068. //! Interrupt Status Register (DMACHIS). Please consult the data sheet for
  1069. //! your part.
  1070. //!
  1071. //! \return Returns a 32-bit mask which indicates requesting uDMA channels.
  1072. //! There is a bit for each channel and a 1 indicates that the channel
  1073. //! is requesting an interrupt. Multiple bits can be set.
  1074. //
  1075. //*****************************************************************************
  1076. uint32_t
  1077. uDMAIntStatus(void)
  1078. {
  1079. //
  1080. // Return the value of the uDMA interrupt status register
  1081. //
  1082. return(HWREG(UDMA_CHIS));
  1083. }
  1084. //*****************************************************************************
  1085. //
  1086. //! Clears uDMA interrupt status.
  1087. //!
  1088. //! \param ui32ChanMask is a 32-bit mask with one bit for each uDMA channel.
  1089. //!
  1090. //! This function clears bits in the uDMA interrupt status register according
  1091. //! to which bits are set in \e ui32ChanMask. There is one bit for each
  1092. //! channel. If a a bit is set in \e ui32ChanMask, then that corresponding
  1093. //! channel's interrupt status is cleared (if it was set).
  1094. //!
  1095. //! \note This function is only available on devices that have the DMA Channel
  1096. //! Interrupt Status Register (DMACHIS). Please consult the data sheet for
  1097. //! your part. Devices without the DMACHIS register have uDMA done status in
  1098. //! the interrupt registers in the peripheral memory maps.
  1099. //!
  1100. //! \return None.
  1101. //
  1102. //*****************************************************************************
  1103. void
  1104. uDMAIntClear(uint32_t ui32ChanMask)
  1105. {
  1106. //
  1107. // Clear the requested bits in the uDMA interrupt status register
  1108. //
  1109. HWREG(UDMA_CHIS) = ui32ChanMask;
  1110. }
  1111. //*****************************************************************************
  1112. //
  1113. //! Assigns a peripheral mapping for a uDMA channel.
  1114. //!
  1115. //! \param ui32Mapping is a macro specifying the peripheral assignment for
  1116. //! a channel.
  1117. //!
  1118. //! This function assigns a peripheral mapping to a uDMA channel. It is
  1119. //! used to select which peripheral is used for a uDMA channel. The parameter
  1120. //! \e ui32Mapping should be one of the macros named \b UDMA_CHn_tttt from the
  1121. //! header file \e udma.h. For example, to assign uDMA channel 0 to the
  1122. //! UART2 RX channel, the parameter should be the macro \b UDMA_CH0_UART2RX.
  1123. //!
  1124. //! Please consult the Tiva data sheet for a table showing all the
  1125. //! possible peripheral assignments for the uDMA channels for a particular
  1126. //! device.
  1127. //!
  1128. //! \note This function is only available on devices that have the DMA Channel
  1129. //! Map Select registers (DMACHMAP0-3). Please consult the data sheet for
  1130. //! your part.
  1131. //!
  1132. //! \return None.
  1133. //
  1134. //*****************************************************************************
  1135. void
  1136. uDMAChannelAssign(uint32_t ui32Mapping)
  1137. {
  1138. uint32_t ui32MapReg;
  1139. uint_fast8_t ui8MapShift;
  1140. uint_fast8_t ui8ChannelNum;
  1141. //
  1142. // Check the parameters
  1143. //
  1144. ASSERT((ui32Mapping & 0xffffff00) < 0x00050000);
  1145. //
  1146. // Extract the channel number and map encoding value from the parameter.
  1147. //
  1148. ui8ChannelNum = ui32Mapping & 0xff;
  1149. ui32Mapping = ui32Mapping >> 16;
  1150. //
  1151. // Find the uDMA channel mapping register and shift value to use for this
  1152. // channel
  1153. //
  1154. ui32MapReg = UDMA_CHMAP0 + (uint32_t)((ui8ChannelNum / 8) * 4);
  1155. ui8MapShift = (ui8ChannelNum % 8) * 4;
  1156. //
  1157. // Set the channel map encoding for this channel
  1158. //
  1159. HWREG(ui32MapReg) = (HWREG(ui32MapReg) & ~(0xf << ui8MapShift)) |
  1160. ui32Mapping << ui8MapShift;
  1161. }
  1162. //*****************************************************************************
  1163. //
  1164. // The following functions are deprecated. Use uDMAChannelAssign() instead
  1165. // to accomplish the same end.
  1166. //
  1167. //*****************************************************************************
  1168. #ifndef DEPRECATED
  1169. //*****************************************************************************
  1170. //
  1171. //! Selects the secondary peripheral for a set of uDMA channels.
  1172. //!
  1173. //! \param ui32SecPeriphs is the logical OR of the uDMA channels for which to
  1174. //! use the secondary peripheral, instead of the default peripheral.
  1175. //!
  1176. //! This function is used to select the secondary peripheral assignment for a
  1177. //! set of uDMA channels. By selecting the secondary peripheral assignment for
  1178. //! a channel, the default peripheral assignment is no longer available for
  1179. //! that channel.
  1180. //!
  1181. //! The parameter \e ui32SecPeriphs can be the logical OR of any of the
  1182. //! following macros. If one of the macros below is in the list passed to this
  1183. //! function, then the secondary peripheral (marked as \b _SEC_) is selected.
  1184. //!
  1185. //! - \b UDMA_DEF_USBEP1RX_SEC_UART2RX
  1186. //! - \b UDMA_DEF_USBEP1TX_SEC_UART2TX
  1187. //! - \b UDMA_DEF_USBEP2RX_SEC_TMR3A
  1188. //! - \b UDMA_DEF_USBEP2TX_SEC_TMR3B
  1189. //! - \b UDMA_DEF_USBEP3RX_SEC_TMR2A
  1190. //! - \b UDMA_DEF_USBEP3TX_SEC_TMR2B
  1191. //! - \b UDMA_DEF_ETH0RX_SEC_TMR2A
  1192. //! - \b UDMA_DEF_ETH0TX_SEC_TMR2B
  1193. //! - \b UDMA_DEF_UART0RX_SEC_UART1RX
  1194. //! - \b UDMA_DEF_UART0TX_SEC_UART1TX
  1195. //! - \b UDMA_DEF_SSI0RX_SEC_SSI1RX
  1196. //! - \b UDMA_DEF_SSI0TX_SEC_SSI1TX
  1197. //! - \b UDMA_DEF_RESERVED_SEC_UART2RX
  1198. //! - \b UDMA_DEF_RESERVED_SEC_UART2TX
  1199. //! - \b UDMA_DEF_ADC00_SEC_TMR2A
  1200. //! - \b UDMA_DEF_ADC01_SEC_TMR2B
  1201. //! - \b UDMA_DEF_ADC02_SEC_RESERVED
  1202. //! - \b UDMA_DEF_ADC03_SEC_RESERVED
  1203. //! - \b UDMA_DEF_TMR0A_SEC_TMR1A
  1204. //! - \b UDMA_DEF_TMR0B_SEC_TMR1B
  1205. //! - \b UDMA_DEF_TMR1A_SEC_EPI0RX
  1206. //! - \b UDMA_DEF_TMR1B_SEC_EPI0TX
  1207. //! - \b UDMA_DEF_UART1RX_SEC_RESERVED
  1208. //! - \b UDMA_DEF_UART1TX_SEC_RESERVED
  1209. //! - \b UDMA_DEF_SSI1RX_SEC_ADC10
  1210. //! - \b UDMA_DEF_SSI1TX_SEC_ADC11
  1211. //! - \b UDMA_DEF_RESERVED_SEC_ADC12
  1212. //! - \b UDMA_DEF_RESERVED_SEC_ADC13
  1213. //! - \b UDMA_DEF_I2S0RX_SEC_RESERVED
  1214. //! - \b UDMA_DEF_I2S0TX_SEC_RESERVED
  1215. //!
  1216. //! \return None.
  1217. //
  1218. //*****************************************************************************
  1219. void
  1220. uDMAChannelSelectSecondary(uint32_t ui32SecPeriphs)
  1221. {
  1222. //
  1223. // Select the secondary peripheral for the specified channels.
  1224. //
  1225. HWREG(UDMA_CHASGN) |= ui32SecPeriphs;
  1226. }
  1227. //*****************************************************************************
  1228. //
  1229. //! Selects the default peripheral for a set of uDMA channels.
  1230. //!
  1231. //! \param ui32DefPeriphs is the logical OR of the uDMA channels for which to
  1232. //! use the default peripheral, instead of the secondary peripheral.
  1233. //!
  1234. //! This function is used to select the default peripheral assignment for a set
  1235. //! of uDMA channels.
  1236. //!
  1237. //! The parameter \e ui32DefPeriphs can be the logical OR of any of the
  1238. //! following macros. If one of the macros below is in the list passed to this
  1239. //! function, then the default peripheral (marked as \b _DEF_) is selected.
  1240. //!
  1241. //! - \b UDMA_DEF_USBEP1RX_SEC_UART2RX
  1242. //! - \b UDMA_DEF_USBEP1TX_SEC_UART2TX
  1243. //! - \b UDMA_DEF_USBEP2RX_SEC_TMR3A
  1244. //! - \b UDMA_DEF_USBEP2TX_SEC_TMR3B
  1245. //! - \b UDMA_DEF_USBEP3RX_SEC_TMR2A
  1246. //! - \b UDMA_DEF_USBEP3TX_SEC_TMR2B
  1247. //! - \b UDMA_DEF_ETH0RX_SEC_TMR2A
  1248. //! - \b UDMA_DEF_ETH0TX_SEC_TMR2B
  1249. //! - \b UDMA_DEF_UART0RX_SEC_UART1RX
  1250. //! - \b UDMA_DEF_UART0TX_SEC_UART1TX
  1251. //! - \b UDMA_DEF_SSI0RX_SEC_SSI1RX
  1252. //! - \b UDMA_DEF_SSI0TX_SEC_SSI1TX
  1253. //! - \b UDMA_DEF_RESERVED_SEC_UART2RX
  1254. //! - \b UDMA_DEF_RESERVED_SEC_UART2TX
  1255. //! - \b UDMA_DEF_ADC00_SEC_TMR2A
  1256. //! - \b UDMA_DEF_ADC01_SEC_TMR2B
  1257. //! - \b UDMA_DEF_ADC02_SEC_RESERVED
  1258. //! - \b UDMA_DEF_ADC03_SEC_RESERVED
  1259. //! - \b UDMA_DEF_TMR0A_SEC_TMR1A
  1260. //! - \b UDMA_DEF_TMR0B_SEC_TMR1B
  1261. //! - \b UDMA_DEF_TMR1A_SEC_EPI0RX
  1262. //! - \b UDMA_DEF_TMR1B_SEC_EPI0TX
  1263. //! - \b UDMA_DEF_UART1RX_SEC_RESERVED
  1264. //! - \b UDMA_DEF_UART1TX_SEC_RESERVED
  1265. //! - \b UDMA_DEF_SSI1RX_SEC_ADC10
  1266. //! - \b UDMA_DEF_SSI1TX_SEC_ADC11
  1267. //! - \b UDMA_DEF_RESERVED_SEC_ADC12
  1268. //! - \b UDMA_DEF_RESERVED_SEC_ADC13
  1269. //! - \b UDMA_DEF_I2S0RX_SEC_RESERVED
  1270. //! - \b UDMA_DEF_I2S0TX_SEC_RESERVED
  1271. //!
  1272. //! \return None.
  1273. //
  1274. //*****************************************************************************
  1275. void
  1276. uDMAChannelSelectDefault(uint32_t ui32DefPeriphs)
  1277. {
  1278. //
  1279. // Select the default peripheral for the specified channels.
  1280. //
  1281. HWREG(UDMA_CHASGN) &= ~ui32DefPeriphs;
  1282. }
  1283. #endif
  1284. //*****************************************************************************
  1285. //
  1286. // Close the Doxygen group.
  1287. //! @}
  1288. //
  1289. //*****************************************************************************