udma.c 45 KB

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