udma.c 46 KB

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