adc.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. //*****************************************************************************
  2. //
  3. // adc.c
  4. //
  5. // Driver for the ADC module.
  6. //
  7. // Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
  8. //
  9. //
  10. // Redistribution and use in source and binary forms, with or without
  11. // modification, are permitted provided that the following conditions
  12. // are met:
  13. //
  14. // Redistributions of source code must retain the above copyright
  15. // notice, this list of conditions and the following disclaimer.
  16. //
  17. // Redistributions in binary form must reproduce the above copyright
  18. // notice, this list of conditions and the following disclaimer in the
  19. // documentation and/or other materials provided with the
  20. // distribution.
  21. //
  22. // Neither the name of Texas Instruments Incorporated nor the names of
  23. // its contributors may be used to endorse or promote products derived
  24. // from this software without specific prior written permission.
  25. //
  26. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  29. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  30. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  31. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  32. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  33. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  34. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  35. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  36. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. //
  38. //*****************************************************************************
  39. //*****************************************************************************
  40. //
  41. //! \addtogroup ADC_Analog_to_Digital_Converter_api
  42. //! @{
  43. //
  44. //*****************************************************************************
  45. #include "inc/hw_types.h"
  46. #include "inc/hw_memmap.h"
  47. #include "inc/hw_ints.h"
  48. #include "inc/hw_adc.h"
  49. #include "inc/hw_apps_config.h"
  50. #include "interrupt.h"
  51. #include "adc.h"
  52. //*****************************************************************************
  53. //
  54. //! Enables the ADC
  55. //!
  56. //! \param ulBase is the base address of the ADC
  57. //!
  58. //! This function sets the ADC global enable
  59. //!
  60. //! \return None.
  61. //
  62. //*****************************************************************************
  63. void ADCEnable(unsigned long ulBase)
  64. {
  65. //
  66. // Set the global enable bit in the control register.
  67. //
  68. HWREG(ulBase + ADC_O_ADC_CTRL) |= 0x1;
  69. }
  70. //*****************************************************************************
  71. //
  72. //! Disable the ADC
  73. //!
  74. //! \param ulBase is the base address of the ADC
  75. //!
  76. //! This function clears the ADC global enable
  77. //!
  78. //! \return None.
  79. //
  80. //*****************************************************************************
  81. void ADCDisable(unsigned long ulBase)
  82. {
  83. //
  84. // Clear the global enable bit in the control register.
  85. //
  86. HWREG(ulBase + ADC_O_ADC_CTRL) &= ~0x1 ;
  87. }
  88. //*****************************************************************************
  89. //
  90. //! Enables specified ADC channel
  91. //!
  92. //! \param ulBase is the base address of the ADC
  93. //! \param ulChannel is one of the valid ADC channels
  94. //!
  95. //! This function enables specified ADC channel and configures the
  96. //! pin as analog pin.
  97. //!
  98. //! \return None.
  99. //
  100. //*****************************************************************************
  101. void ADCChannelEnable(unsigned long ulBase, unsigned long ulChannel)
  102. {
  103. unsigned long ulCh;
  104. ulCh = (ulChannel == ADC_CH_0)? 0x02 :
  105. (ulChannel == ADC_CH_1)? 0x04 :
  106. (ulChannel == ADC_CH_2)? 0x08 : 0x10;
  107. HWREG(ulBase + ADC_O_ADC_CH_ENABLE) |= ulCh;
  108. }
  109. //*****************************************************************************
  110. //
  111. //! Disables specified ADC channel
  112. //!
  113. //! \param ulBase is the base address of the ADC
  114. //! \param ulChannel is one of the valid ADC channelsber
  115. //!
  116. //! This function disables specified ADC channel.
  117. //!
  118. //! \return None.
  119. //
  120. //*****************************************************************************
  121. void ADCChannelDisable(unsigned long ulBase, unsigned long ulChannel)
  122. {
  123. unsigned long ulCh;
  124. ulCh = (ulChannel == ADC_CH_0)? 0x02 :
  125. (ulChannel == ADC_CH_1)? 0x04 :
  126. (ulChannel == ADC_CH_2)? 0x08 : 0x10;
  127. HWREG(ulBase + ADC_O_ADC_CH_ENABLE) &= ~ulCh;
  128. }
  129. //*****************************************************************************
  130. //
  131. //! Enables and registers ADC interrupt handler for specified channel
  132. //!
  133. //! \param ulBase is the base address of the ADC
  134. //! \param ulChannel is one of the valid ADC channels
  135. //! \param pfnHandler is a pointer to the function to be called when the
  136. //! ADC channel interrupt occurs.
  137. //!
  138. //! This function enables and registers ADC interrupt handler for specified
  139. //! channel. Individual interrupt for each channel should be enabled using
  140. //! \sa ADCIntEnable(). It is the interrupt handler's responsibility to clear
  141. //! the interrupt source.
  142. //!
  143. //! The parameter \e ulChannel should be one of the following
  144. //!
  145. //! - \b ADC_CH_0 for channel 0
  146. //! - \b ADC_CH_1 for channel 1
  147. //! - \b ADC_CH_2 for channel 2
  148. //! - \b ADC_CH_3 for channel 3
  149. //!
  150. //! \return None.
  151. //
  152. //*****************************************************************************
  153. void ADCIntRegister(unsigned long ulBase, unsigned long ulChannel,
  154. void (*pfnHandler)(void))
  155. {
  156. unsigned long ulIntNo;
  157. //
  158. // Get the interrupt number associted with the specified channel
  159. //
  160. ulIntNo = (ulChannel == ADC_CH_0)? INT_ADCCH0 :
  161. (ulChannel == ADC_CH_1)? INT_ADCCH1 :
  162. (ulChannel == ADC_CH_2)? INT_ADCCH2 : INT_ADCCH3;
  163. //
  164. // Register the interrupt handler
  165. //
  166. IntRegister(ulIntNo,pfnHandler);
  167. //
  168. // Enable ADC interrupt
  169. //
  170. IntEnable(ulIntNo);
  171. }
  172. //*****************************************************************************
  173. //
  174. //! Disables and unregisters ADC interrupt handler for specified channel
  175. //!
  176. //! \param ulBase is the base address of the ADC
  177. //! \param ulChannel is one of the valid ADC channels
  178. //!
  179. //! This function disables and unregisters ADC interrupt handler for specified
  180. //! channel. This function also masks off the interrupt in the interrupt
  181. //! controller so that the interrupt handler no longer is called.
  182. //!
  183. //! The parameter \e ulChannel should be one of the following
  184. //!
  185. //! - \b ADC_CH_0 for channel 0
  186. //! - \b ADC_CH_1 for channel 1
  187. //! - \b ADC_CH_2 for channel 2
  188. //! - \b ADC_CH_3 for channel 3
  189. //!
  190. //! \return None.
  191. //
  192. //*****************************************************************************
  193. void ADCIntUnregister(unsigned long ulBase, unsigned long ulChannel)
  194. {
  195. unsigned long ulIntNo;
  196. //
  197. // Get the interrupt number associted with the specified channel
  198. //
  199. ulIntNo = (ulChannel == ADC_CH_0)? INT_ADCCH0 :
  200. (ulChannel == ADC_CH_1)? INT_ADCCH1 :
  201. (ulChannel == ADC_CH_2)? INT_ADCCH2 : INT_ADCCH3;
  202. //
  203. // Disable ADC interrupt
  204. //
  205. IntDisable(ulIntNo);
  206. //
  207. // Unregister the interrupt handler
  208. //
  209. IntUnregister(ulIntNo);
  210. }
  211. //*****************************************************************************
  212. //
  213. //! Enables individual interrupt sources for specified channel
  214. //!
  215. //!
  216. //! \param ulBase is the base address of the ADC
  217. //! \param ulChannel is one of the valid ADC channels
  218. //! \param ulIntFlags is the bit mask of the interrupt sources to be enabled.
  219. //!
  220. //! This function enables the indicated ADC interrupt sources. Only the
  221. //! sources that are enabled can be reflected to the processor interrupt;
  222. //! disabled sources have no effect on the processor.
  223. //!
  224. //! The parameter \e ulChannel should be one of the following
  225. //!
  226. //! - \b ADC_CH_0 for channel 0
  227. //! - \b ADC_CH_1 for channel 1
  228. //! - \b ADC_CH_2 for channel 2
  229. //! - \b ADC_CH_3 for channel 3
  230. //!
  231. //! The \e ulIntFlags parameter is the logical OR of any of the following:
  232. //! - \b ADC_DMA_DONE for DMA done
  233. //! - \b ADC_FIFO_OVERFLOW for FIFO over flow
  234. //! - \b ADC_FIFO_UNDERFLOW for FIFO under flow
  235. //! - \b ADC_FIFO_EMPTY for FIFO empty
  236. //! - \b ADC_FIFO_FULL for FIFO full
  237. //!
  238. //! \return None.
  239. //
  240. //*****************************************************************************
  241. void ADCIntEnable(unsigned long ulBase, unsigned long ulChannel,
  242. unsigned long ulIntFlags)
  243. {
  244. unsigned long ulOffset;
  245. unsigned long ulDmaMsk;
  246. //
  247. // Enable DMA Done interrupt
  248. //
  249. if(ulIntFlags & ADC_DMA_DONE)
  250. {
  251. ulDmaMsk = (ulChannel == ADC_CH_0)?0x00001000:
  252. (ulChannel == ADC_CH_1)?0x00002000:
  253. (ulChannel == ADC_CH_2)?0x00004000:0x00008000;
  254. HWREG(APPS_CONFIG_BASE + APPS_CONFIG_O_DMA_DONE_INT_MASK_CLR) = ulDmaMsk;
  255. }
  256. ulIntFlags = ulIntFlags & 0x0F;
  257. //
  258. // Get the interrupt enable register offset for specified channel
  259. //
  260. ulOffset = ADC_O_adc_ch0_irq_en + ulChannel;
  261. //
  262. // Unmask the specified interrupts
  263. //
  264. HWREG(ulBase + ulOffset) |= (ulIntFlags & 0xf);
  265. }
  266. //*****************************************************************************
  267. //
  268. //! Disables individual interrupt sources for specified channel
  269. //!
  270. //!
  271. //! \param ulBase is the base address of the ADC.
  272. //! \param ulChannel is one of the valid ADC channels
  273. //! \param ulIntFlags is the bit mask of the interrupt sources to be enabled.
  274. //!
  275. //! This function disables the indicated ADC interrupt sources. Only the
  276. //! sources that are enabled can be reflected to the processor interrupt;
  277. //! disabled sources have no effect on the processor.
  278. //!
  279. //! The parameters\e ulIntFlags and \e ulChannel should be as explained in
  280. //! ADCIntEnable().
  281. //!
  282. //! \return None.
  283. //
  284. //*****************************************************************************
  285. void ADCIntDisable(unsigned long ulBase, unsigned long ulChannel,
  286. unsigned long ulIntFlags)
  287. {
  288. unsigned long ulOffset;
  289. unsigned long ulDmaMsk;
  290. //
  291. // Disable DMA Done interrupt
  292. //
  293. if(ulIntFlags & ADC_DMA_DONE)
  294. {
  295. ulDmaMsk = (ulChannel == ADC_CH_0)?0x00001000:
  296. (ulChannel == ADC_CH_1)?0x00002000:
  297. (ulChannel == ADC_CH_2)?0x00004000:0x00008000;
  298. HWREG(APPS_CONFIG_BASE + APPS_CONFIG_O_DMA_DONE_INT_MASK_SET) = ulDmaMsk;
  299. }
  300. //
  301. // Get the interrupt enable register offset for specified channel
  302. //
  303. ulOffset = ADC_O_adc_ch0_irq_en + ulChannel;
  304. //
  305. // Unmask the specified interrupts
  306. //
  307. HWREG(ulBase + ulOffset) &= ~ulIntFlags;
  308. }
  309. //*****************************************************************************
  310. //
  311. //! Gets the current channel interrupt status
  312. //!
  313. //! \param ulBase is the base address of the ADC
  314. //! \param ulChannel is one of the valid ADC channels
  315. //!
  316. //! This function returns the interrupt status of the specified ADC channel.
  317. //!
  318. //! The parameter \e ulChannel should be as explained in \sa ADCIntEnable().
  319. //!
  320. //! \return Return the ADC channel interrupt status, enumerated as a bit
  321. //! field of values described in ADCIntEnable()
  322. //
  323. //*****************************************************************************
  324. unsigned long ADCIntStatus(unsigned long ulBase, unsigned long ulChannel)
  325. {
  326. unsigned long ulOffset;
  327. unsigned long ulDmaMsk;
  328. unsigned long ulIntStatus;
  329. //
  330. // Get DMA Done interrupt status
  331. //
  332. ulDmaMsk = (ulChannel == ADC_CH_0)?0x00001000:
  333. (ulChannel == ADC_CH_1)?0x00002000:
  334. (ulChannel == ADC_CH_2)?0x00004000:0x00008000;
  335. ulIntStatus = HWREG(APPS_CONFIG_BASE +
  336. APPS_CONFIG_O_DMA_DONE_INT_STS_MASKED)& ulDmaMsk;
  337. //
  338. // Get the interrupt enable register offset for specified channel
  339. //
  340. ulOffset = ADC_O_adc_ch0_irq_status + ulChannel;
  341. //
  342. // Read ADC interrupt status
  343. //
  344. ulIntStatus |= HWREG(ulBase + ulOffset) & 0xf;
  345. //
  346. // Return the current interrupt status
  347. //
  348. return(ulIntStatus);
  349. }
  350. //*****************************************************************************
  351. //
  352. //! Clears the current channel interrupt sources
  353. //!
  354. //! \param ulBase is the base address of the ADC
  355. //! \param ulChannel is one of the valid ADC channels
  356. //! \param ulIntFlags is the bit mask of the interrupt sources to be cleared.
  357. //!
  358. //! This function clears individual interrupt source for the specified
  359. //! ADC channel.
  360. //!
  361. //! The parameter \e ulChannel should be as explained in \sa ADCIntEnable().
  362. //!
  363. //! \return None.
  364. //
  365. //*****************************************************************************
  366. void ADCIntClear(unsigned long ulBase, unsigned long ulChannel,
  367. unsigned long ulIntFlags)
  368. {
  369. unsigned long ulOffset;
  370. unsigned long ulDmaMsk;
  371. //
  372. // Clear DMA Done interrupt
  373. //
  374. if(ulIntFlags & ADC_DMA_DONE)
  375. {
  376. ulDmaMsk = (ulChannel == ADC_CH_0)?0x00001000:
  377. (ulChannel == ADC_CH_1)?0x00002000:
  378. (ulChannel == ADC_CH_2)?0x00004000:0x00008000;
  379. HWREG(APPS_CONFIG_BASE + APPS_CONFIG_O_DMA_DONE_INT_ACK) = ulDmaMsk;
  380. }
  381. //
  382. // Get the interrupt enable register offset for specified channel
  383. //
  384. ulOffset = ADC_O_adc_ch0_irq_status + ulChannel;
  385. //
  386. // Clear the specified interrupts
  387. //
  388. HWREG(ulBase + ulOffset) = (ulIntFlags & ~(ADC_DMA_DONE));
  389. }
  390. //*****************************************************************************
  391. //
  392. //! Enables the ADC DMA operation for specified channel
  393. //!
  394. //! \param ulBase is the base address of the ADC
  395. //! \param ulChannel is one of the valid ADC channels
  396. //!
  397. //! This function enables the DMA operation for specified ADC channel
  398. //!
  399. //! The parameter \e ulChannel should be one of the following
  400. //!
  401. //! - \b ADC_CH_0 for channel 0
  402. //! - \b ADC_CH_1 for channel 1
  403. //! - \b ADC_CH_2 for channel 2
  404. //! - \b ADC_CH_3 for channel 3
  405. //!
  406. //! \return None.
  407. //
  408. //*****************************************************************************
  409. void ADCDMAEnable(unsigned long ulBase, unsigned long ulChannel)
  410. {
  411. unsigned long ulBitMask;
  412. //
  413. // Get the bit mask for enabling DMA for specified channel
  414. //
  415. ulBitMask = (ulChannel == ADC_CH_0)?0x01:
  416. (ulChannel == ADC_CH_1)?0x04:
  417. (ulChannel == ADC_CH_2)?0x10:0x40;
  418. //
  419. // Enable DMA request for the specified channel
  420. //
  421. HWREG(ulBase + ADC_O_adc_dma_mode_en) |= ulBitMask;
  422. }
  423. //*****************************************************************************
  424. //
  425. //! Disables the ADC DMA operation for specified channel
  426. //!
  427. //! \param ulBase is the base address of the ADC
  428. //! \param ulChannel is one of the valid ADC channels
  429. //!
  430. //! This function disables the DMA operation for specified ADC channel
  431. //!
  432. //! The parameter \e ulChannel should be one of the following
  433. //!
  434. //! - \b ADC_CH_0 for channel 0
  435. //! - \b ADC_CH_1 for channel 1
  436. //! - \b ADC_CH_2 for channel 2
  437. //! - \b ADC_CH_3 for channel 3
  438. //!
  439. //! \return None.
  440. //
  441. //*****************************************************************************
  442. void ADCDMADisable(unsigned long ulBase, unsigned long ulChannel)
  443. {
  444. unsigned long ulBitMask;
  445. //
  446. // Get the bit mask for disabling DMA for specified channel
  447. //
  448. ulBitMask = (ulChannel == ADC_CH_0)?0x01:
  449. (ulChannel == ADC_CH_1)?0x04:
  450. (ulChannel == ADC_CH_2)?0x10:0x40;
  451. //
  452. // Disable DMA request for the specified channel
  453. //
  454. HWREG(ulBase + ADC_O_adc_dma_mode_en) &= ~ulBitMask;
  455. }
  456. //*****************************************************************************
  457. //
  458. //! Configures the ADC internal timer
  459. //!
  460. //! \param ulBase is the base address of the ADC
  461. //! \param ulValue is wrap arround value of the timer
  462. //!
  463. //! This function Configures the ADC internal timer. The ADC timer is a 17 bit
  464. //! used to timestamp the ADC data samples internally.
  465. //! User can read the timestamp along with the sample from the FIFO register(s).
  466. //! Each sample in the FIFO contains 14 bit actual data and 18 bit timestamp
  467. //!
  468. //! The parameter \e ulValue can take any value between 0 - 2^17
  469. //!
  470. //! \returns None.
  471. //
  472. //*****************************************************************************
  473. void ADCTimerConfig(unsigned long ulBase, unsigned long ulValue)
  474. {
  475. unsigned long ulReg;
  476. //
  477. // Read the currrent config
  478. //
  479. ulReg = HWREG(ulBase + ADC_O_adc_timer_configuration);
  480. //
  481. // Mask and set timer count field
  482. //
  483. ulReg = ((ulReg & ~0x1FFFF) | (ulValue & 0x1FFFF));
  484. //
  485. // Set the timer count value
  486. //
  487. HWREG(ulBase + ADC_O_adc_timer_configuration) = ulReg;
  488. }
  489. //*****************************************************************************
  490. //
  491. //! Resets ADC internal timer
  492. //!
  493. //! \param ulBase is the base address of the ADC
  494. //!
  495. //! This function resets 17-bit ADC internal timer
  496. //!
  497. //! \returns None.
  498. //
  499. //*****************************************************************************
  500. void ADCTimerReset(unsigned long ulBase)
  501. {
  502. //
  503. // Reset the timer
  504. //
  505. HWREG(ulBase + ADC_O_adc_timer_configuration) |= (1 << 24);
  506. }
  507. //*****************************************************************************
  508. //
  509. //! Enables ADC internal timer
  510. //!
  511. //! \param ulBase is the base address of the ADC
  512. //!
  513. //! This function enables 17-bit ADC internal timer
  514. //!
  515. //! \returns None.
  516. //
  517. //*****************************************************************************
  518. void ADCTimerEnable(unsigned long ulBase)
  519. {
  520. //
  521. // Enable the timer
  522. //
  523. HWREG(ulBase + ADC_O_adc_timer_configuration) |= (1 << 25);
  524. }
  525. //*****************************************************************************
  526. //
  527. //! Disables ADC internal timer
  528. //!
  529. //! \param ulBase is the base address of the ADC
  530. //!
  531. //! This function disables 17-bit ADC internal timer
  532. //!
  533. //! \returns None.
  534. //
  535. //*****************************************************************************
  536. void ADCTimerDisable(unsigned long ulBase)
  537. {
  538. //
  539. // Disable the timer
  540. //
  541. HWREG(ulBase + ADC_O_adc_timer_configuration) &= ~(1 << 25);
  542. }
  543. //*****************************************************************************
  544. //
  545. //! Gets the current value of ADC internal timer
  546. //!
  547. //! \param ulBase is the base address of the ADC
  548. //!
  549. //! This function the current value of 17-bit ADC internal timer
  550. //!
  551. //! \returns Return the current value of ADC internal timer.
  552. //
  553. //*****************************************************************************
  554. unsigned long ADCTimerValueGet(unsigned long ulBase)
  555. {
  556. return(HWREG(ulBase + ADC_O_adc_timer_current_count));
  557. }
  558. //*****************************************************************************
  559. //
  560. //! Gets the current FIFO level for specified ADC channel
  561. //!
  562. //! \param ulBase is the base address of the ADC
  563. //! \param ulChannel is one of the valid ADC channels.
  564. //!
  565. //! This function returns the current FIFO level for specified ADC channel.
  566. //!
  567. //! The parameter \e ulChannel should be one of the following
  568. //!
  569. //! - \b ADC_CH_0 for channel 0
  570. //! - \b ADC_CH_1 for channel 1
  571. //! - \b ADC_CH_2 for channel 2
  572. //! - \b ADC_CH_3 for channel 3
  573. //!
  574. //! \returns Return the current FIFO level for specified channel
  575. //
  576. //*****************************************************************************
  577. unsigned char ADCFIFOLvlGet(unsigned long ulBase, unsigned long ulChannel)
  578. {
  579. unsigned long ulOffset;
  580. //
  581. // Get the fifo level register offset for specified channel
  582. //
  583. ulOffset = ADC_O_adc_ch0_fifo_lvl + ulChannel;
  584. //
  585. // Return FIFO level
  586. //
  587. return(HWREG(ulBase + ulOffset) & 0x7);
  588. }
  589. //*****************************************************************************
  590. //
  591. //! Reads FIFO for specified ADC channel
  592. //!
  593. //! \param ulBase is the base address of the ADC
  594. //! \param ulChannel is one of the valid ADC channels.
  595. //!
  596. //! This function returns one data sample from the channel fifo as specified by
  597. //! \e ulChannel parameter.
  598. //!
  599. //! The parameter \e ulChannel should be one of the following
  600. //!
  601. //! - \b ADC_CH_0 for channel 0
  602. //! - \b ADC_CH_1 for channel 1
  603. //! - \b ADC_CH_2 for channel 2
  604. //! - \b ADC_CH_3 for channel 3
  605. //!
  606. //! \returns Return one data sample from the channel fifo.
  607. //
  608. //*****************************************************************************
  609. unsigned long ADCFIFORead(unsigned long ulBase, unsigned long ulChannel)
  610. {
  611. unsigned long ulOffset;
  612. //
  613. // Get the fifo register offset for specified channel
  614. //
  615. ulOffset = ADC_O_channel0FIFODATA + ulChannel;
  616. //
  617. // Return FIFO level
  618. //
  619. return(HWREG(ulBase + ulOffset));
  620. }
  621. //*****************************************************************************
  622. //
  623. // Close the Doxygen group.
  624. //! @}
  625. //
  626. //*****************************************************************************