epi.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. //*****************************************************************************
  2. //
  3. // epi.c - Driver for the EPI module.
  4. //
  5. // Copyright (c) 2008-2009 Luminary Micro, Inc. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
  9. // exclusively on LMI's microcontroller products.
  10. //
  11. // The software is owned by LMI and/or its suppliers, and is protected under
  12. // applicable copyright laws. All rights are reserved. You may not combine
  13. // this software with "viral" open-source software in order to form a larger
  14. // program. Any use in violation of the foregoing restrictions may subject
  15. // the user to criminal sanctions under applicable laws, as well as to civil
  16. // liability for the breach of the terms and conditions of this license.
  17. //
  18. // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
  19. // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  20. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
  21. // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
  22. // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  23. //
  24. // This is part of revision 4694 of the Stellaris Peripheral Driver Library.
  25. //
  26. //*****************************************************************************
  27. #include "inc/hw_epi.h"
  28. #include "inc/hw_ints.h"
  29. #include "inc/hw_memmap.h"
  30. #include "inc/hw_types.h"
  31. #include "driverlib/debug.h"
  32. #include "driverlib/epi.h"
  33. #include "driverlib/interrupt.h"
  34. //*****************************************************************************
  35. //
  36. //! \addtogroup epi_api
  37. //! @{
  38. //
  39. //*****************************************************************************
  40. //*****************************************************************************
  41. //
  42. //! Sets the usage mode of the EPI module.
  43. //!
  44. //! \param ulBase is the EPI module base address.
  45. //! \param ulMode is the usage mode of the EPI module.
  46. //!
  47. //! This functions sets the operating mode of the EPI module. The parameter
  48. //! \e ulMode must be one of the following:
  49. //!
  50. //! - \b EPI_MODE_NONE - non-moded operation
  51. //! - \b EPI_MODE_SDRAM - use with SDRAM device
  52. //! - \b EPI_MODE_HB8 - use with host-bus 8-bit interface
  53. //! - \b EPI_MODE_DISABLE - disable the EPI module
  54. //!
  55. //! Selection of any of the above modes will enable the EPI module, except
  56. //! for \b EPI_MODE_DISABLE which should be used to disable the module.
  57. //!
  58. //! \return None.
  59. //
  60. //*****************************************************************************
  61. void
  62. EPIModeSet(unsigned long ulBase, unsigned long ulMode)
  63. {
  64. //
  65. // Check the arguments.
  66. //
  67. ASSERT(ulBase == EPI0_BASE);
  68. ASSERT((ulMode == EPI_MODE_NONE) ||
  69. (ulMode == EPI_MODE_SDRAM) ||
  70. (ulMode == EPI_MODE_HB8) ||
  71. (ulMode == EPI_MODE_DISABLE));
  72. //
  73. // Write the mode word to the register.
  74. //
  75. HWREG(ulBase + EPI_O_CFG) = ulMode;
  76. }
  77. //*****************************************************************************
  78. //
  79. //! Sets the clock divider for the EPI module.
  80. //!
  81. //! \param ulBase is the EPI module base address.
  82. //! \param ulDivider is the value of the clock divider to be applied to
  83. //! the external interface (0-65535).
  84. //!
  85. //! This functions sets the clock divider that will be used to determine the
  86. //! clock rate of the external interface. The value is the number of high
  87. //! and low ticks of the system clock per external bus clock. A value of 0
  88. //! means that the system clock is used without any reduction. The system
  89. //! clock will be divided by the value of \e ulDivider multiplied by 2. A
  90. //! value of 1 gives a divider of 2, and value of 2 gives a divider of 4, a
  91. //! value of 3 gives a divider of 6, and so on.
  92. //!
  93. //! \return None.
  94. //
  95. //*****************************************************************************
  96. void
  97. EPIDividerSet(unsigned long ulBase, unsigned long ulDivider)
  98. {
  99. //
  100. // Check the arguments.
  101. //
  102. ASSERT(ulBase == EPI0_BASE);
  103. //
  104. // Write the divider value to the register.
  105. //
  106. HWREG(ulBase + EPI_O_BAUD) = ulDivider;
  107. }
  108. //*****************************************************************************
  109. //
  110. //! Configures the SDRAM mode of operation.
  111. //!
  112. //! \param ulBase is the EPI module base address.
  113. //! \param ulConfig is the SDRAM interface configuration.
  114. //! \param ulRefresh is the refresh count in core clocks (0-2047).
  115. //!
  116. //! This function is used to configure the SDRAM interface, when the SDRAM
  117. //! mode is chosen with the function EPIModeSet(). The parameter \e ulConfig
  118. //! is the logical OR of several sets of choices:
  119. //!
  120. //! The processor core frequency must be specified with one of the following:
  121. //!
  122. //! - \b EPI_SDRAM_CORE_FREQ_0_15 - core clock is 0 MHz < clk <= 15 MHz
  123. //! - \b EPI_SDRAM_CORE_FREQ_15_30 - core clock is 15 MHz < clk <= 30 MHz
  124. //! - \b EPI_SDRAM_CORE_FREQ_30_50 - core clock is 30 MHz < clk <= 50 MHz
  125. //! - \b EPI_SDRAM_CORE_FREQ_50_100 - core clock is 50 MHz < clk <= 100 MHz
  126. //!
  127. //! The low power mode is specified with one of the following:
  128. //!
  129. //! - \b EPI_SDRAM_LOW_POWER - enter low power, self-refresh state
  130. //! - \b EPI_SDRAM_FULL_POWER - normal operating state
  131. //!
  132. //! The SDRAM device size is specified with one of the following:
  133. //!
  134. //! - \b EPI_SDRAM_SIZE_64MBIT - 64 Mbit device (8 MB)
  135. //! - \b EPI_SDRAM_SIZE_128MBIT - 128 Mbit device (16 MB)
  136. //! - \b EPI_SDRAM_SIZE_256MBIT - 256 Mbit device (32 MB)
  137. //! - \b EPI_SDRAM_SIZE_512MBIT - 512 Mbit device (64 MB)
  138. //!
  139. //! The parameter \e ulRefresh sets the refresh counter in units of core
  140. //! clock ticks. It is an 11-bit value with a range of 0 - 2047 counts.
  141. //!
  142. //! \return None.
  143. //
  144. //*****************************************************************************
  145. void
  146. EPIConfigSDRAMSet(unsigned long ulBase, unsigned long ulConfig,
  147. unsigned long ulRefresh)
  148. {
  149. //
  150. // Check the arguments.
  151. //
  152. ASSERT(ulBase == EPI0_BASE);
  153. ASSERT(ulRefresh < 2048);
  154. //
  155. // Fill in the refresh count field of the configuration word.
  156. //
  157. ulConfig &= ~EPI_SDRAMCFG_RFSH_M;
  158. ulConfig |= ulRefresh << EPI_SDRAMCFG_RFSH_S;
  159. //
  160. // Write the SDRAM configuration register.
  161. //
  162. HWREG(ulBase + EPI_O_SDRAMCFG) = ulConfig;
  163. }
  164. //*****************************************************************************
  165. //
  166. //! Configures the interface for Host-bus 8 operation.
  167. //!
  168. //! \param ulBase is the EPI module base address.
  169. //! \param ulConfig is the interface configuration.
  170. //! \param ulMaxWait is the maximum number of external clocks to wait
  171. //! if a FIFO ready signal is holding off the transaction.
  172. //!
  173. //! This function is used to configure the interface when used in Host-bus 8
  174. //! operation as chosen with the function EPIModeSet(). The parameter
  175. //! \e ulConfig is the logical OR of any of the following:
  176. //!
  177. //! - one of \b EPI_HB8_MODE_ADMUX, \b EPI_HB8_MODE_ADDEMUX,
  178. //! \b EPI_HB8_MODE_SRAM, or \b EPI_HB8_MODE_FIFO to select the HB8 mode
  179. //! - \b EPI_HB8_USE_TXEMPTY - enable TXEMPTY signal with FIFO
  180. //! - \b EPI_HB8_USE_RXFULL - enable RXFULL signal with FIFO
  181. //! - \b EPI_HB8_WRHIGH - use active high write strobe, otherwise it is
  182. //! active low
  183. //! - \b EPI_HB8_RDHIGH - use active high read strobe, otherwise it is
  184. //! active low
  185. //! - one of \b EPI_HB8_WRWAIT_0, \b EPI_HB8_WRWAIT_1, \b EPI_HB8_WRWAIT_2,
  186. //! or \b EPI_HB8_WRWAIT_3 to select the number of write wait states (default
  187. //! is 0 wait states)
  188. //! - one of \b EPI_HB8_RDWAIT_0, \b EPI_HB8_RDWAIT_1, \b EPI_HB8_RDWAIT_2,
  189. //! or \b EPI_HB8_RDWAIT_3 to select the number of read wait states (default
  190. //! is 0 wait states)
  191. //!
  192. //! The parameter \e ulMaxWait is used if the FIFO mode is chosen. If a
  193. //! FIFO is used along with RXFULL or TXEMPTY ready signals, then this
  194. //! parameter determines the maximum number of clocks to wait when the
  195. //! transaction is being held off by by the FIFO using one of these ready
  196. //! signals. A value of 0 means to wait forever.
  197. //!
  198. //! \return None.
  199. //
  200. //*****************************************************************************
  201. void
  202. EPIConfigHB8Set(unsigned long ulBase, unsigned long ulConfig,
  203. unsigned long ulMaxWait)
  204. {
  205. //
  206. // Check the arguments.
  207. //
  208. ASSERT(ulBase == EPI0_BASE);
  209. ASSERT(ulMaxWait < 256);
  210. //
  211. // Fill in the max wait field of the configuration word.
  212. //
  213. ulConfig &= ~EPI_HB8CFG_MAXWAIT_M;
  214. ulConfig |= ulMaxWait << EPI_HB8CFG_MAXWAIT_S;
  215. //
  216. // Write the non-moded configuration register.
  217. //
  218. HWREG(ulBase + EPI_O_HB8CFG) = ulConfig;
  219. }
  220. //*****************************************************************************
  221. //
  222. //! Configures the interface for non-moded operation.
  223. //!
  224. //! \param ulBase is the EPI module base address.
  225. //! \param ulConfig is the interface configuration.
  226. //! \param ulFrameCount is the frame size in clocks, if the frame signal
  227. //! is used (0-15).
  228. //! \param ulMaxWait is the maximum number of external clocks to wait
  229. //! when the external clock enable is holding off the transaction (0-255).
  230. //!
  231. //! This function is used to configure the interface when used in non-moded
  232. //! operation as chosen with the function EPIModeSet(). The parameter
  233. //! \e ulConfig is the logical OR of any of the following:
  234. //!
  235. //! - \b EPI_NONMODE_CLKPIN - interface clock is output on a pin
  236. //! - \b EPI_NONMODE_CLKSTOP - clock is stopped when there is no transaction,
  237. //! otherwise it is free-running
  238. //! - \b EPI_NONMODE_CLKENA - enable the clock enable input from the device
  239. //! - \b EPI_NONMODE_FRAMEPIN - framing signal is emitted on a pin
  240. //! - \b EPI_NONMODE_FRAME50 - framing signal is 50/50 duty cycle, otherwise it
  241. //! is a pulse
  242. //! - \b EPI_NONMODE_READWRITE - read and write strobes are emitted on pins
  243. //! - \b EPI_NONMODE_WRITE2CYCLE - a two cycle write is used, otherwise a
  244. //! single-cycle write is used
  245. //! - \b EPI_NONMODE_READ2CYCLE - a two cycle read is used, otherwise a
  246. //! single-cycle read is used
  247. //! - \b EPI_NONMODE_ASIZE_NONE, \b EPI_NONMODE_ASIZE_4,
  248. //! \b EPI_NONMODE_ASIZE_12, or \b EPI_NONMODE_ASIZE_20 to choose no address
  249. //! bus, or and address bus size of 4, 12, or 20 bits
  250. //! - \b EPI_NONMODE_DSIZE_8, \b EPI_NONMODE_DSIZE_16,
  251. //! \b EPI_NONMODE_DSIZE_24, or \b EPI_NONMODE_DSIZE_32 to select a data bus
  252. //! size of 8, 16, 24, or 32 bits
  253. //!
  254. //! The parameter \e ulFrameCount is the number of clocks used to form the
  255. //! framing signal, if the framing signal is used. The behavior depends on
  256. //! whether the frame signal is a pulse or a 50/50 duty cycle. This value
  257. //! is not used if the framing signal is not enabled with the option
  258. //! \b EPI_NONMMODE_FRAMEPIN.
  259. //!
  260. //! The parameter \e ulMaxWait is used if the external clock enable is turned
  261. //! on with the \b EPI_NONMODE_CLKENA option is used. In the case that
  262. //! external clock enable is used, this parameter determines the maximum
  263. //! number of clocks to wait when the external clock enable signal is holding
  264. //! off a transaction. A value of 0 means to wait forever. If a non-zero
  265. //! value is used and exceeded, an interrupt will occur and the transaction
  266. //! aborted.
  267. //!
  268. //! \return None.
  269. //
  270. //*****************************************************************************
  271. void
  272. EPIConfigNoModeSet(unsigned long ulBase, unsigned long ulConfig,
  273. unsigned long ulFrameCount, unsigned long ulMaxWait)
  274. {
  275. //
  276. // Check the arguments.
  277. //
  278. ASSERT(ulBase == EPI0_BASE);
  279. ASSERT(ulFrameCount < 16);
  280. ASSERT(ulMaxWait < 256);
  281. //
  282. // Fill in the frame count field of the configuration word.
  283. //
  284. ulConfig &= ~EPI_GPCFG_FRMCNT_M;
  285. ulConfig |= ulFrameCount << EPI_GPCFG_FRMCNT_S;
  286. //
  287. // Fill in the max wait field of the configuration word.
  288. //
  289. ulConfig &= ~EPI_GPCFG_MAXWAIT_M;
  290. ulConfig |= ulMaxWait << EPI_GPCFG_MAXWAIT_S;
  291. //
  292. // Write the non-moded configuration register.
  293. //
  294. HWREG(ulBase + EPI_O_GPCFG) = ulConfig;
  295. }
  296. //*****************************************************************************
  297. //
  298. //! Configures the address map for the external interface.
  299. //!
  300. //! \param ulBase is the EPI module base address.
  301. //! \param ulMap is the address mapping configuration.
  302. //!
  303. //! This function is used to configure the address mapping for the external
  304. //! interface. This determines the base address of the external memory or
  305. //! device within the processor peripheral and/or memory space.
  306. //!
  307. //! The parameter \e ulMap is the logical OR of the following:
  308. //!
  309. //! - \b EPI_ADDR_PER_SIZE_256B, \b EPI_ADDR_PER_SIZE_64KB,
  310. //! \b EPI_ADDR_PER_SIZE_16MB, or \b EPI_ADDR_PER_SIZE_512MB to choose a
  311. //! peripheral address space of 256 bytes, 64 Kbytes, 16 Mbytes or 512 Mbytes
  312. //! - \b EPI_ADDR_PER_BASE_NONE, \b EPI_ADDR_PER_BASE_A, or
  313. //! \b EPI_ADDR_PER_BASE_C to choose the base address of the peripheral
  314. //! space as none, 0xA0000000, or 0xC0000000
  315. //! - \b EPI_ADDR_RAM_SIZE_256B, \b EPI_ADDR_RAM_SIZE_64KB,
  316. //! \b EPI_ADDR_RAM_SIZE_16MB, or \b EPI_ADDR_RAM_SIZE_512MB to choose a
  317. //! RAM address space of 256 bytes, 64 Kbytes, 16 Mbytes or 512 Mbytes
  318. //! - \b EPI_ADDR_RAM_BASE_NONE, \b EPI_ADDR_RAM_BASE_6, or
  319. //! \b EPI_ADDR_RAM_BASE_8 to choose the base address of the RAM space
  320. //! as none, 0x60000000, or 0x80000000
  321. //!
  322. //! \return None.
  323. //
  324. //*****************************************************************************
  325. void
  326. EPIAddressMapSet(unsigned long ulBase, unsigned long ulMap)
  327. {
  328. //
  329. // Check the arguments.
  330. //
  331. ASSERT(ulBase == EPI0_BASE);
  332. ASSERT(ulMap < 0x100);
  333. //
  334. // Set the value of the address mapping register.
  335. //
  336. HWREG(ulBase + EPI_O_ADDRMAP) = ulMap;
  337. }
  338. //*****************************************************************************
  339. //
  340. //! Configures a non-blocking read transaction.
  341. //!
  342. //! \param ulBase is the EPI module base address.
  343. //! \param ulChannel is the read channel (0 or 1).
  344. //! \param ulDataSize is the size of the data items to read.
  345. //! \param ulAddress is the starting address to read.
  346. //!
  347. //! This function is used to configure a non-blocking read channel for a
  348. //! transaction. Two channels are available which can be used in a ping-pong
  349. //! method for continuous reading. It is not necessary to use both channels
  350. //! to perform a non-blocking read.
  351. //!
  352. //! The parameter \e ulDataSize is one of \b EPI_NBCONFIG_SIZE_8,
  353. //! \b EPI_NBCONFIG_SIZE_16, or \b EPI_NBCONFIG_SIZE_32 for 8-bit, 16-bit,
  354. //! or 32-bit sized data transfers.
  355. //!
  356. //! The parameter \e ulAddress is the starting address for the read, relative
  357. //! to the external device. The start of the device is address 0.
  358. //!
  359. //! Once configured, the non-blocking read is started by calling
  360. //! EPINonBlockingReadStart(). If the addresses to be read from the device
  361. //! are in a sequence, it is not necessary to call this function multiple
  362. //! times. Until it is changed, the EPI module will remember the last address
  363. //! that was used for a non-blocking read (per channel).
  364. //!
  365. //! \return None.
  366. //
  367. //*****************************************************************************
  368. void
  369. EPINonBlockingReadConfigure(unsigned long ulBase, unsigned long ulChannel,
  370. unsigned long ulDataSize, unsigned long ulAddress)
  371. {
  372. unsigned long ulOffset;
  373. //
  374. // Check the arguments.
  375. //
  376. ASSERT(ulBase == EPI0_BASE);
  377. ASSERT(ulChannel < 2);
  378. ASSERT(ulDataSize < 4);
  379. ASSERT(ulAddress < 0x20000000);
  380. //
  381. // Compute the offset needed to select the correct channel regs.
  382. //
  383. ulOffset = ulChannel * (EPI_O_RSIZE1 - EPI_O_RSIZE0);
  384. //
  385. // Write the data size register for the channel.
  386. //
  387. HWREG(ulBase + EPI_O_RSIZE0 + ulOffset) = ulDataSize;
  388. //
  389. // Write the starting address register for the channel.
  390. //
  391. HWREG(ulBase + EPI_O_RADDR0 + ulOffset) = ulAddress;
  392. }
  393. //*****************************************************************************
  394. //
  395. //! Starts a non-blocking read transaction.
  396. //!
  397. //! \param ulBase is the EPI module base address.
  398. //! \param ulChannel is the read channel (0 or 1).
  399. //! \param ulCount is the number of items to read (1-4095).
  400. //!
  401. //! This function starts a non-blocking read that was previously configured
  402. //! with the function EPINonBlockingReadConfigure(). Once this function is
  403. //! called, the EPI module will begin reading data from the external device
  404. //! into the read FIFO. The EPI will stop reading when the FIFO fills up
  405. //! and resume reading when the application drains the FIFO, until the
  406. //! total specified count of data items has been read.
  407. //!
  408. //! Once a read transaction is completed and the FIFO drained, another
  409. //! transaction can be started from the next address by calling this
  410. //! function again.
  411. //!
  412. //! \return None.
  413. //
  414. //*****************************************************************************
  415. void
  416. EPINonBlockingReadStart(unsigned long ulBase, unsigned long ulChannel,
  417. unsigned long ulCount)
  418. {
  419. unsigned long ulOffset;
  420. //
  421. // Check the arguments.
  422. //
  423. ASSERT(ulBase == EPI0_BASE);
  424. ASSERT(ulChannel < 2);
  425. ASSERT(ulCount < 4096);
  426. //
  427. // Compute the offset needed to select the correct channel regs.
  428. //
  429. ulOffset = ulChannel * (EPI_O_RPSTD1 - EPI_O_RPSTD0);
  430. //
  431. // Write to the read count register.
  432. //
  433. HWREG(ulBase + EPI_O_RPSTD0 + ulOffset) = ulCount;
  434. }
  435. //*****************************************************************************
  436. //
  437. //! Stops a non-blocking read transaction.
  438. //!
  439. //! \param ulBase is the EPI module base address.
  440. //! \param ulChannel is the read channel (0 or 1).
  441. //!
  442. //! This function cancels a non-blocking read transaction that is already
  443. //! in progress.
  444. //!
  445. //! \return None.
  446. //
  447. //*****************************************************************************
  448. void
  449. EPINonBlockingReadStop(unsigned long ulBase, unsigned long ulChannel)
  450. {
  451. unsigned long ulOffset;
  452. //
  453. // Check the arguments.
  454. //
  455. ASSERT(ulBase == EPI0_BASE);
  456. ASSERT(ulChannel < 2);
  457. //
  458. // Compute the offset needed to select the correct channel regs.
  459. //
  460. ulOffset = ulChannel * (EPI_O_RPSTD1 - EPI_O_RPSTD0);
  461. //
  462. // Write a 0 to the read count register, which will cancel the transaction.
  463. //
  464. HWREG(ulBase + EPI_O_RPSTD0 + ulOffset) = 0;
  465. }
  466. //*****************************************************************************
  467. //
  468. //! Get the count remaining for a non-blocking transaction.
  469. //!
  470. //! \param ulBase is the EPI module base address.
  471. //! \param ulChannel is the read channel (0 or 1).
  472. //!
  473. //! This function gets the remaining count of items for a non-blocking read
  474. //! transaction.
  475. //!
  476. //! \return The number of items remaining in the non-blocking read transaction.
  477. //
  478. //*****************************************************************************
  479. unsigned long
  480. EPINonBlockingReadCount(unsigned long ulBase, unsigned long ulChannel)
  481. {
  482. unsigned long ulOffset;
  483. //
  484. // Check the arguments.
  485. //
  486. ASSERT(ulBase == EPI0_BASE);
  487. ASSERT(ulChannel < 2);
  488. //
  489. // Compute the offset needed to select the correct channel regs.
  490. //
  491. ulOffset = ulChannel * (EPI_O_RPSTD1 - EPI_O_RPSTD0);
  492. //
  493. // Read the count remaining and return the value to the caller.
  494. //
  495. return(HWREG(ulBase + EPI_O_RPSTD0 + ulOffset));
  496. }
  497. //*****************************************************************************
  498. //
  499. //! Get the count of items available in the read FIFO.
  500. //!
  501. //! \param ulBase is the EPI module base address.
  502. //!
  503. //! This function gets the number of items that are available to read in
  504. //! the read FIFO. The read FIFO is filled by a non-blocking read transaction
  505. //! which is configured by the functions EPINonBlockingReadConfigure() and
  506. //! EPINonBlockingReadStart().
  507. //!
  508. //! \return The number of items available to read in the read FIFO.
  509. //
  510. //*****************************************************************************
  511. unsigned long
  512. EPINonBlockingReadAvail(unsigned long ulBase)
  513. {
  514. //
  515. // Check the arguments.
  516. //
  517. ASSERT(ulBase == EPI0_BASE);
  518. //
  519. // Read the FIFO count and return it to the caller.
  520. //
  521. return(HWREG(ulBase + EPI_O_RFIFOCNT));
  522. }
  523. //*****************************************************************************
  524. //
  525. //! Read available data from the read FIFO, as 32-bit data items.
  526. //!
  527. //! \param ulBase is the EPI module base address.
  528. //! \param ulCount is the maximum count of items to read.
  529. //! \param pulBuf is the caller supplied buffer where the read data should
  530. //! be stored.
  531. //!
  532. //! This function reads 32-bit data items from the read FIFO and stores
  533. //! the values in a caller supplied buffer. The function will read and store
  534. //! data from the FIFO until there is no more data in the FIFO or the maximum
  535. //! count is reached as specified in the parameter \e ulCount. The actual
  536. //! count of items will be returned.
  537. //!
  538. //! \return The number of items read from the FIFO.
  539. //
  540. //*****************************************************************************
  541. unsigned long
  542. EPINonBlockingReadGet32(unsigned long ulBase, unsigned long ulCount,
  543. unsigned long *pulBuf)
  544. {
  545. unsigned long ulCountRead = 0;
  546. //
  547. // Check the arguments.
  548. //
  549. ASSERT(ulBase == EPI0_BASE);
  550. ASSERT(ulCount < 4096);
  551. ASSERT(pulBuf);
  552. //
  553. // Read from the FIFO while there are any items to read, and
  554. // the callers specified count is not exceeded.
  555. //
  556. while(HWREG(ulBase + EPI_O_RFIFOCNT) && ulCount--)
  557. {
  558. //
  559. // Read from the FIFO and store in the caller supplied buffer.
  560. //
  561. *pulBuf = HWREG(ulBase + EPI_O_READFIFO);
  562. //
  563. // Update the caller's buffer pointer and the count of items read.
  564. //
  565. pulBuf++;
  566. ulCountRead++;
  567. }
  568. //
  569. // Return the count of items read to the caller.
  570. //
  571. return(ulCountRead);
  572. }
  573. //*****************************************************************************
  574. //
  575. //! Read available data from the read FIFO, as 16-bit data items.
  576. //!
  577. //! \param ulBase is the EPI module base address.
  578. //! \param ulCount is the maximum count of items to read.
  579. //! \param pusBuf is the caller supplied buffer where the read data should
  580. //! be stored.
  581. //!
  582. //! This function reads 16-bit data items from the read FIFO and stores
  583. //! the values in a caller supplied buffer. The function will read and store
  584. //! data from the FIFO until there is no more data in the FIFO or the maximum
  585. //! count is reached as specified in the parameter \e ulCount. The actual
  586. //! count of items will be returned.
  587. //!
  588. //! \return The number of items read from the FIFO.
  589. //
  590. //*****************************************************************************
  591. unsigned long
  592. EPINonBlockingReadGet16(unsigned long ulBase, unsigned long ulCount,
  593. unsigned short *pusBuf)
  594. {
  595. unsigned long ulCountRead = 0;
  596. //
  597. // Check the arguments.
  598. //
  599. ASSERT(ulBase == EPI0_BASE);
  600. ASSERT(ulCount < 4096);
  601. ASSERT(pusBuf);
  602. //
  603. // Read from the FIFO while there are any items to read, and
  604. // the callers specified count is not exceeded.
  605. //
  606. while(HWREG(ulBase + EPI_O_RFIFOCNT) && ulCount--)
  607. {
  608. //
  609. // Read from the FIFO and store in the caller supplied buffer.
  610. //
  611. *pusBuf = (unsigned short)HWREG(ulBase + EPI_O_READFIFO);
  612. //
  613. // Update the caller's buffer pointer and the count of items read.
  614. //
  615. pusBuf++;
  616. ulCountRead++;
  617. }
  618. //
  619. // Return the count of items read to the caller.
  620. //
  621. return(ulCountRead);
  622. }
  623. //*****************************************************************************
  624. //
  625. //! Read available data from the read FIFO, as 8-bit data items.
  626. //!
  627. //! \param ulBase is the EPI module base address.
  628. //! \param ulCount is the maximum count of items to read.
  629. //! \param pucBuf is the caller supplied buffer where the read data should
  630. //! be stored.
  631. //!
  632. //! This function reads 8-bit data items from the read FIFO and stores
  633. //! the values in a caller supplied buffer. The function will read and store
  634. //! data from the FIFO until there is no more data in the FIFO or the maximum
  635. //! count is reached as specified in the parameter \e ulCount. The actual
  636. //! count of items will be returned.
  637. //!
  638. //! \return The number of items read from the FIFO.
  639. //
  640. //*****************************************************************************
  641. unsigned long
  642. EPINonBlockingReadGet8(unsigned long ulBase, unsigned long ulCount,
  643. unsigned char *pucBuf)
  644. {
  645. unsigned long ulCountRead = 0;
  646. //
  647. // Check the arguments.
  648. //
  649. ASSERT(ulBase == EPI0_BASE);
  650. ASSERT(ulCount < 4096);
  651. ASSERT(pucBuf);
  652. //
  653. // Read from the FIFO while there are any items to read, and
  654. // the callers specified count is not exceeded.
  655. //
  656. while(HWREG(ulBase + EPI_O_RFIFOCNT) && ulCount--)
  657. {
  658. //
  659. // Read from the FIFO and store in the caller supplied buffer.
  660. //
  661. *pucBuf = (unsigned char)HWREG(ulBase + EPI_O_READFIFO);
  662. //
  663. // Update the caller's buffer pointer and the count of items read.
  664. //
  665. pucBuf++;
  666. ulCountRead++;
  667. }
  668. //
  669. // Return the count of items read to the caller.
  670. //
  671. return(ulCountRead);
  672. }
  673. //*****************************************************************************
  674. //
  675. //! Configures the read FIFO.
  676. //!
  677. //! \param ulBase is the EPI module base address.
  678. //! \param ulConfig is the FIFO configuration.
  679. //!
  680. //! This function configures the FIFO trigger levels and error
  681. //! generation. The parameter \e ulConfig is the logical OR of the
  682. //! following:
  683. //!
  684. //! - \b EPI_FIFO_CONFIG_WTFULLERR - enables an error interrupt when a write is
  685. //! attempted and the write FIFO is full
  686. //! - \b EPI_FIFO_CONFIG_RSTALLERR - enables an error interrupt when a read is
  687. //! stalled due to an interleaved write or other reason
  688. //! - \b EPI_FIFO_CONFIG_TX_EMPTY, \b EPI_FIFO_CONFIG_TX_1_4,
  689. //! \b EPI_FIFO_CONFIG_TX_1_2, or \b EPI_FIFO_CONFIG_TX_3_4 to set the
  690. //! TX FIFO trigger level to empty, 1/4, 1/2, or 3/4 level
  691. //! - \b EPI_FIFO_CONFIG_RX_1_8, \b EPI_FIFO_CONFIG_RX_1_4,
  692. //! \b EPI_FIFO_CONFIG_RX_1_2, \b EPI_FIFO_CONFIG_RX_3_4,
  693. //! \b EPI_FIFO_CONFIG_RX_7_8, or \b EPI_FIFO_CONFIG_RX_FULL to set the
  694. //! RX FIFO trigger level to 1/8, 1/4, 1/2, 3/4, 7/8 or full level
  695. //!
  696. //! \return None.
  697. //
  698. //*****************************************************************************
  699. void
  700. EPIFIFOConfig(unsigned long ulBase, unsigned long ulConfig)
  701. {
  702. //
  703. // Check the arguments.
  704. //
  705. ASSERT(ulBase == EPI0_BASE);
  706. ASSERT(ulConfig == (ulConfig & 0x00030077));
  707. //
  708. // Load the configuration into the FIFO config reg.
  709. //
  710. HWREG(ulBase + EPI_O_FIFOLVL) = ulConfig;
  711. }
  712. //*****************************************************************************
  713. //
  714. //! Reads the number of empty slots in the write transaction FIFO.
  715. //!
  716. //! \param ulBase is the EPI module base address.
  717. //!
  718. //! This function returns the number of slots available in the transaction
  719. //! FIFO. It can be used in a polling method to avoid attempting a write
  720. //! that would stall.
  721. //!
  722. //! \return The number of empty slots in the transaction FIFO.
  723. //
  724. //*****************************************************************************
  725. unsigned long
  726. EPINonBlockingWriteCount(unsigned long ulBase)
  727. {
  728. //
  729. // Check the arguments.
  730. //
  731. ASSERT(ulBase == EPI0_BASE);
  732. //
  733. // Read the FIFO count and return it to the caller.
  734. //
  735. return(HWREG(ulBase + EPI_O_WFIFOCNT));
  736. }
  737. //*****************************************************************************
  738. //
  739. //! Enables EPI interrupt sources.
  740. //!
  741. //! \param ulBase is the EPI module base address.
  742. //! \param ulIntFlags is a bit mask of the interrupt sources to be enabled.
  743. //!
  744. //! This function enables the specified EPI sources to generate interrupts.
  745. //! The \e ulIntFlags parameter can be the logical OR of any of the following
  746. //! values:
  747. //!
  748. //! - \b EPI_INT_TXREQ - transmit FIFO is below the trigger level
  749. //! - \b EPI_INT_RXREQ - read FIFO is above the trigger level
  750. //! - \b EPI_INT_ERR - an error condition occurred
  751. //!
  752. //! \return Returns None.
  753. //
  754. //*****************************************************************************
  755. void
  756. EPIIntEnable(unsigned long ulBase, unsigned long ulIntFlags)
  757. {
  758. //
  759. // Check the arguments.
  760. //
  761. ASSERT(ulBase == EPI0_BASE);
  762. ASSERT(ulIntFlags < 16);
  763. //
  764. // Write the interrupt flags mask to the mask register.
  765. //
  766. HWREG(ulBase + EPI_O_IM) |= ulIntFlags;
  767. }
  768. //*****************************************************************************
  769. //
  770. //! Disables EPI interrupt sources.
  771. //!
  772. //! \param ulBase is the EPI module base address.
  773. //! \param ulIntFlags is a bit mask of the interrupt sources to be disabled.
  774. //!
  775. //! This function disables the specified EPI sources for interrupt
  776. //! generation. The \e ulIntFlags parameter can be the logical OR
  777. //! of any of the following values: \b EPI_INT_RXREQ, \b EPI_INT_TXREQ, or
  778. //! \b I2S_INT_ERR.
  779. //!
  780. //! \return Returns None.
  781. //
  782. //*****************************************************************************
  783. void
  784. EPIIntDisable(unsigned long ulBase, unsigned long ulIntFlags)
  785. {
  786. //
  787. // Check the arguments.
  788. //
  789. ASSERT(ulBase == EPI0_BASE);
  790. ASSERT(ulIntFlags < 16);
  791. //
  792. // Write the interrupt flags mask to the mask register.
  793. //
  794. HWREG(ulBase + EPI_O_IM) &= ~ulIntFlags;
  795. }
  796. //*****************************************************************************
  797. //
  798. //! Gets the EPI interrupt status.
  799. //!
  800. //! \param ulBase is the EPI module base address.
  801. //! \param bMasked is set \b true to get the masked interrupt status, or
  802. //! \b false to get the raw interrupt status.
  803. //!
  804. //! This function returns the EPI interrupt status. It can return either
  805. //! the raw or masked interrupt status.
  806. //!
  807. //! \return Returns the masked or raw EPI interrupt status, as a bit field
  808. //! of any of the following values: \b EPI_INT_TXREQ, \b EPI_INT_RXREQ,
  809. //! or \b EPI_INT_ERR
  810. //
  811. //*****************************************************************************
  812. unsigned long
  813. EPIIntStatus(unsigned long ulBase, tBoolean bMasked)
  814. {
  815. //
  816. // Check the arguments.
  817. //
  818. ASSERT(ulBase == EPI0_BASE);
  819. //
  820. // Return either the interrupt status or the raw interrupt status as
  821. // requested.
  822. //
  823. if(bMasked)
  824. {
  825. return(HWREG(ulBase + EPI_O_MIS));
  826. }
  827. else
  828. {
  829. return(HWREG(ulBase + EPI_O_RIS));
  830. }
  831. }
  832. //*****************************************************************************
  833. //
  834. //! Gets the EPI error interrupt status.
  835. //!
  836. //! \param ulBase is the EPI module base address.
  837. //!
  838. //! This function returns the error status of the EPI. If the return value of
  839. //! the function EPIIntStatus() has the flag \b EPI_INT_ERR set, then this
  840. //! function can be used to determine the cause of the error.
  841. //!
  842. //! This function returns a bit mask of error flags, which can be the logical
  843. //! OR of any of the following:
  844. //!
  845. //! - \b EPI_INT_ERR_WTFULL - occurs when a write stalled when the transaction
  846. //! FIFO was full
  847. //! - \b EPI_INT_ERR_RSTALL - occurs when a read stalled
  848. //! - \b EPI_INT_ERR_TIMEOUT - occurs when the external clock enable held
  849. //! off a transaction longer than the configured maximum wait time
  850. //!
  851. //! \return Returns the interrupt error flags as the logical OR of any of
  852. //! the following: \b EPI_INT_ERR_WTFULL, \b EPI_INT_ERR_RSTALL, or
  853. //! \b EPI_INT_ERR_TIMEOUT.
  854. //
  855. //*****************************************************************************
  856. unsigned long
  857. EPIIntErrorStatus(unsigned long ulBase)
  858. {
  859. //
  860. // Check the arguments.
  861. //
  862. ASSERT(ulBase == EPI0_BASE);
  863. //
  864. // Read the error status and return to caller.
  865. //
  866. return(HWREG(ulBase + EPI_O_EISC));
  867. }
  868. //*****************************************************************************
  869. //
  870. //! Clears pending EPI error sources.
  871. //!
  872. //! \param ulBase is the EPI module base address.
  873. //! \param ulErrFlags is a bit mask of the error sources to be cleared.
  874. //!
  875. //! This function clears the specified pending EPI errors. The \e ulErrFlags
  876. //! parameter can be the logical OR of any of the following values:
  877. //! \b EPI_INT_ERR_WTFULL, \b EPI_INT_ERR_RSTALL, or \b EPI_INT_ERR_TIMEOUT.
  878. //!
  879. //! \return Returns None.
  880. //
  881. //*****************************************************************************
  882. void
  883. EPIIntErrorClear(unsigned long ulBase, unsigned long ulErrFlags)
  884. {
  885. //
  886. // Check the arguments.
  887. //
  888. ASSERT(ulBase == EPI0_BASE);
  889. ASSERT(ulErrFlags < 16);
  890. //
  891. // Write the error flags to the register to clear the pending errors.
  892. //
  893. HWREG(ulBase + EPI_O_EISC) = ulErrFlags;
  894. }
  895. //*****************************************************************************
  896. //
  897. //! Registers an interrupt handler for the EPI module.
  898. //!
  899. //! \param ulBase is the EPI module base address.
  900. //! \param pfnHandler is a pointer to the function to be called when the
  901. //! interrupt is activated.
  902. //!
  903. //! This sets and enables the handler to be called when the EPI module
  904. //! generates an interrupt. Specific EPI interrupts must still be enabled
  905. //! with the EPIIntEnable() function.
  906. //!
  907. //! \sa IntRegister() for important information about registering interrupt
  908. //! handlers.
  909. //!
  910. //! \return None.
  911. //
  912. //*****************************************************************************
  913. void
  914. EPIIntRegister(unsigned long ulBase, void (*pfnHandler)(void))
  915. {
  916. //
  917. // Check the arguments.
  918. //
  919. ASSERT(ulBase == EPI0_BASE);
  920. ASSERT(pfnHandler);
  921. //
  922. // Register the interrupt handler.
  923. //
  924. IntRegister(INT_EPI0, pfnHandler);
  925. //
  926. // Enable the EPI interface interrupt.
  927. //
  928. IntEnable(INT_EPI0);
  929. }
  930. //*****************************************************************************
  931. //
  932. //! Unregisters an interrupt handler for the EPI module.
  933. //!
  934. //! \param ulBase is the EPI module base address.
  935. //!
  936. //! This function will disable and clear the handler to be called when the
  937. //! EPI interrupt occurs.
  938. //!
  939. //! \sa IntRegister() for important information about registering interrupt
  940. //! handlers.
  941. //!
  942. //! \return None.
  943. //
  944. //*****************************************************************************
  945. void
  946. EPIIntUnregister(unsigned long ulBase)
  947. {
  948. //
  949. // Check the arguments.
  950. //
  951. ASSERT(ulBase == EPI0_BASE);
  952. //
  953. // Disable the EPI interface interrupt.
  954. //
  955. IntDisable(INT_EPI0);
  956. //
  957. // Unregister the interrupt handler.
  958. //
  959. IntUnregister(INT_EPI0);
  960. }
  961. //*****************************************************************************
  962. //
  963. // Close the Doxygen group.
  964. //! @}
  965. //
  966. //*****************************************************************************