udma.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382
  1. //*****************************************************************************
  2. //
  3. // udma.c - Driver for the micro-DMA controller.
  4. //
  5. // Copyright (c) 2007-2020 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.2.0.295 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 INT_UDMA to register an interrupt handler to process interrupts
  995. //! from the uDMA software channel (UDMA_CHANNEL_SW)
  996. //! - \b INT_UDMAERR 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. //
  1018. // Register the interrupt handler.
  1019. //
  1020. IntRegister(ui32IntChannel, pfnHandler);
  1021. //
  1022. // Enable the memory management fault.
  1023. //
  1024. IntEnable(ui32IntChannel);
  1025. }
  1026. //*****************************************************************************
  1027. //
  1028. //! Unregisters an interrupt handler for the uDMA controller.
  1029. //!
  1030. //! \param ui32IntChannel identifies which uDMA interrupt to unregister.
  1031. //!
  1032. //! This function disables and unregisters the handler to be called for the
  1033. //! specified uDMA interrupt. The \e ui32IntChannel parameter should be one of
  1034. //! \b INT_UDMA or \b INT_UDMAERR as documented for the function
  1035. //! uDMAIntRegister().
  1036. //!
  1037. //! \sa IntRegister() for important information about registering interrupt
  1038. //! handlers.
  1039. //!
  1040. //! \return None.
  1041. //
  1042. //*****************************************************************************
  1043. void
  1044. uDMAIntUnregister(uint32_t ui32IntChannel)
  1045. {
  1046. //
  1047. // Disable the interrupt.
  1048. //
  1049. IntDisable(ui32IntChannel);
  1050. //
  1051. // Unregister the interrupt handler.
  1052. //
  1053. IntUnregister(ui32IntChannel);
  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. //! \note This function is only available on devices that have the DMA Channel
  1066. //! Interrupt Status Register (DMACHIS). Please consult the data sheet for
  1067. //! your part.
  1068. //!
  1069. //! \return Returns a 32-bit mask which indicates requesting uDMA channels.
  1070. //! There is a bit for each channel and a 1 indicates that the channel
  1071. //! is requesting an interrupt. Multiple bits can be set.
  1072. //
  1073. //*****************************************************************************
  1074. uint32_t
  1075. uDMAIntStatus(void)
  1076. {
  1077. //
  1078. // Return the value of the uDMA interrupt status register
  1079. //
  1080. return(HWREG(UDMA_CHIS));
  1081. }
  1082. //*****************************************************************************
  1083. //
  1084. //! Clears uDMA interrupt status.
  1085. //!
  1086. //! \param ui32ChanMask is a 32-bit mask with one bit for each uDMA channel.
  1087. //!
  1088. //! This function clears bits in the uDMA interrupt status register according
  1089. //! to which bits are set in \e ui32ChanMask. There is one bit for each
  1090. //! channel. If a a bit is set in \e ui32ChanMask, then that corresponding
  1091. //! channel's interrupt status is cleared (if it was set).
  1092. //!
  1093. //! \note This function is only available on devices that have the DMA Channel
  1094. //! Interrupt Status Register (DMACHIS). Please consult the data sheet for
  1095. //! your part. Devices without the DMACHIS register have uDMA done status in
  1096. //! the interrupt registers in the peripheral memory maps.
  1097. //!
  1098. //! \return None.
  1099. //
  1100. //*****************************************************************************
  1101. void
  1102. uDMAIntClear(uint32_t ui32ChanMask)
  1103. {
  1104. //
  1105. // Clear the requested bits in the uDMA interrupt status register
  1106. //
  1107. HWREG(UDMA_CHIS) = ui32ChanMask;
  1108. }
  1109. //*****************************************************************************
  1110. //
  1111. //! Assigns a peripheral mapping for a uDMA channel.
  1112. //!
  1113. //! \param ui32Mapping is a macro specifying the peripheral assignment for
  1114. //! a channel.
  1115. //!
  1116. //! This function assigns a peripheral mapping to a uDMA channel. It is
  1117. //! used to select which peripheral is used for a uDMA channel. The parameter
  1118. //! \e ui32Mapping should be one of the macros named \b UDMA_CHn_tttt from the
  1119. //! header file \e udma.h. For example, to assign uDMA channel 0 to the
  1120. //! UART2 RX channel, the parameter should be the macro \b UDMA_CH0_UART2RX.
  1121. //!
  1122. //! Please consult the Tiva data sheet for a table showing all the
  1123. //! possible peripheral assignments for the uDMA channels for a particular
  1124. //! device.
  1125. //!
  1126. //! \note This function is only available on devices that have the DMA Channel
  1127. //! Map Select registers (DMACHMAP0-3). Please consult the data sheet for
  1128. //! your part.
  1129. //!
  1130. //! \return None.
  1131. //
  1132. //*****************************************************************************
  1133. void
  1134. uDMAChannelAssign(uint32_t ui32Mapping)
  1135. {
  1136. uint32_t ui32MapReg;
  1137. uint_fast8_t ui8MapShift;
  1138. uint_fast8_t ui8ChannelNum;
  1139. //
  1140. // Check the parameters
  1141. //
  1142. ASSERT((ui32Mapping & 0xffffff00) < 0x00090000);
  1143. //
  1144. // Extract the channel number and map encoding value from the parameter.
  1145. //
  1146. ui8ChannelNum = ui32Mapping & 0xff;
  1147. ui32Mapping = ui32Mapping >> 16;
  1148. //
  1149. // Find the uDMA channel mapping register and shift value to use for this
  1150. // channel
  1151. //
  1152. ui32MapReg = UDMA_CHMAP0 + (uint32_t)((ui8ChannelNum / 8) * 4);
  1153. ui8MapShift = (ui8ChannelNum % 8) * 4;
  1154. //
  1155. // Set the channel map encoding for this channel
  1156. //
  1157. HWREG(ui32MapReg) = (HWREG(ui32MapReg) & ~(0xf << ui8MapShift)) |
  1158. ui32Mapping << ui8MapShift;
  1159. }
  1160. //*****************************************************************************
  1161. //
  1162. // The following functions are deprecated. Use uDMAChannelAssign() instead
  1163. // to accomplish the same end.
  1164. //
  1165. //*****************************************************************************
  1166. #ifndef DEPRECATED
  1167. //*****************************************************************************
  1168. //
  1169. //! Selects the secondary peripheral for a set of uDMA channels.
  1170. //!
  1171. //! \param ui32SecPeriphs is the logical OR of the uDMA channels for which to
  1172. //! use the secondary peripheral, instead of the default peripheral.
  1173. //!
  1174. //! This function is used to select the secondary peripheral assignment for a
  1175. //! set of uDMA channels. By selecting the secondary peripheral assignment for
  1176. //! a channel, the default peripheral assignment is no longer available for
  1177. //! that channel.
  1178. //!
  1179. //! The parameter \e ui32SecPeriphs can be the logical OR of any of the
  1180. //! following macros. If one of the macros below is in the list passed to this
  1181. //! function, then the secondary peripheral (marked as \b _SEC_) is selected.
  1182. //!
  1183. //! - \b UDMA_DEF_USBEP1RX_SEC_UART2RX
  1184. //! - \b UDMA_DEF_USBEP1TX_SEC_UART2TX
  1185. //! - \b UDMA_DEF_USBEP2RX_SEC_TMR3A
  1186. //! - \b UDMA_DEF_USBEP2TX_SEC_TMR3B
  1187. //! - \b UDMA_DEF_USBEP3RX_SEC_TMR2A
  1188. //! - \b UDMA_DEF_USBEP3TX_SEC_TMR2B
  1189. //! - \b UDMA_DEF_ETH0RX_SEC_TMR2A
  1190. //! - \b UDMA_DEF_ETH0TX_SEC_TMR2B
  1191. //! - \b UDMA_DEF_UART0RX_SEC_UART1RX
  1192. //! - \b UDMA_DEF_UART0TX_SEC_UART1TX
  1193. //! - \b UDMA_DEF_SSI0RX_SEC_SSI1RX
  1194. //! - \b UDMA_DEF_SSI0TX_SEC_SSI1TX
  1195. //! - \b UDMA_DEF_RESERVED_SEC_UART2RX
  1196. //! - \b UDMA_DEF_RESERVED_SEC_UART2TX
  1197. //! - \b UDMA_DEF_ADC00_SEC_TMR2A
  1198. //! - \b UDMA_DEF_ADC01_SEC_TMR2B
  1199. //! - \b UDMA_DEF_ADC02_SEC_RESERVED
  1200. //! - \b UDMA_DEF_ADC03_SEC_RESERVED
  1201. //! - \b UDMA_DEF_TMR0A_SEC_TMR1A
  1202. //! - \b UDMA_DEF_TMR0B_SEC_TMR1B
  1203. //! - \b UDMA_DEF_TMR1A_SEC_EPI0RX
  1204. //! - \b UDMA_DEF_TMR1B_SEC_EPI0TX
  1205. //! - \b UDMA_DEF_UART1RX_SEC_RESERVED
  1206. //! - \b UDMA_DEF_UART1TX_SEC_RESERVED
  1207. //! - \b UDMA_DEF_SSI1RX_SEC_ADC10
  1208. //! - \b UDMA_DEF_SSI1TX_SEC_ADC11
  1209. //! - \b UDMA_DEF_RESERVED_SEC_ADC12
  1210. //! - \b UDMA_DEF_RESERVED_SEC_ADC13
  1211. //! - \b UDMA_DEF_I2S0RX_SEC_RESERVED
  1212. //! - \b UDMA_DEF_I2S0TX_SEC_RESERVED
  1213. //!
  1214. //! \return None.
  1215. //
  1216. //*****************************************************************************
  1217. void
  1218. uDMAChannelSelectSecondary(uint32_t ui32SecPeriphs)
  1219. {
  1220. //
  1221. // Select the secondary peripheral for the specified channels.
  1222. //
  1223. HWREG(UDMA_CHASGN) |= ui32SecPeriphs;
  1224. }
  1225. //*****************************************************************************
  1226. //
  1227. //! Selects the default peripheral for a set of uDMA channels.
  1228. //!
  1229. //! \param ui32DefPeriphs is the logical OR of the uDMA channels for which to
  1230. //! use the default peripheral, instead of the secondary peripheral.
  1231. //!
  1232. //! This function is used to select the default peripheral assignment for a set
  1233. //! of uDMA channels.
  1234. //!
  1235. //! The parameter \e ui32DefPeriphs can be the logical OR of any of the
  1236. //! following macros. If one of the macros below is in the list passed to this
  1237. //! function, then the default peripheral (marked as \b _DEF_) is selected.
  1238. //!
  1239. //! - \b UDMA_DEF_USBEP1RX_SEC_UART2RX
  1240. //! - \b UDMA_DEF_USBEP1TX_SEC_UART2TX
  1241. //! - \b UDMA_DEF_USBEP2RX_SEC_TMR3A
  1242. //! - \b UDMA_DEF_USBEP2TX_SEC_TMR3B
  1243. //! - \b UDMA_DEF_USBEP3RX_SEC_TMR2A
  1244. //! - \b UDMA_DEF_USBEP3TX_SEC_TMR2B
  1245. //! - \b UDMA_DEF_ETH0RX_SEC_TMR2A
  1246. //! - \b UDMA_DEF_ETH0TX_SEC_TMR2B
  1247. //! - \b UDMA_DEF_UART0RX_SEC_UART1RX
  1248. //! - \b UDMA_DEF_UART0TX_SEC_UART1TX
  1249. //! - \b UDMA_DEF_SSI0RX_SEC_SSI1RX
  1250. //! - \b UDMA_DEF_SSI0TX_SEC_SSI1TX
  1251. //! - \b UDMA_DEF_RESERVED_SEC_UART2RX
  1252. //! - \b UDMA_DEF_RESERVED_SEC_UART2TX
  1253. //! - \b UDMA_DEF_ADC00_SEC_TMR2A
  1254. //! - \b UDMA_DEF_ADC01_SEC_TMR2B
  1255. //! - \b UDMA_DEF_ADC02_SEC_RESERVED
  1256. //! - \b UDMA_DEF_ADC03_SEC_RESERVED
  1257. //! - \b UDMA_DEF_TMR0A_SEC_TMR1A
  1258. //! - \b UDMA_DEF_TMR0B_SEC_TMR1B
  1259. //! - \b UDMA_DEF_TMR1A_SEC_EPI0RX
  1260. //! - \b UDMA_DEF_TMR1B_SEC_EPI0TX
  1261. //! - \b UDMA_DEF_UART1RX_SEC_RESERVED
  1262. //! - \b UDMA_DEF_UART1TX_SEC_RESERVED
  1263. //! - \b UDMA_DEF_SSI1RX_SEC_ADC10
  1264. //! - \b UDMA_DEF_SSI1TX_SEC_ADC11
  1265. //! - \b UDMA_DEF_RESERVED_SEC_ADC12
  1266. //! - \b UDMA_DEF_RESERVED_SEC_ADC13
  1267. //! - \b UDMA_DEF_I2S0RX_SEC_RESERVED
  1268. //! - \b UDMA_DEF_I2S0TX_SEC_RESERVED
  1269. //!
  1270. //! \return None.
  1271. //
  1272. //*****************************************************************************
  1273. void
  1274. uDMAChannelSelectDefault(uint32_t ui32DefPeriphs)
  1275. {
  1276. //
  1277. // Select the default peripheral for the specified channels.
  1278. //
  1279. HWREG(UDMA_CHASGN) &= ~ui32DefPeriphs;
  1280. }
  1281. #endif
  1282. //*****************************************************************************
  1283. //
  1284. // Close the Doxygen group.
  1285. //! @}
  1286. //
  1287. //*****************************************************************************