adc.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. //*****************************************************************************
  2. //
  3. // adc.h - ADC headers for using the ADC driver functions.
  4. //
  5. // Copyright (c) 2005-2020 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. // This is part of revision 2.2.0.295 of the Tiva Peripheral Driver Library.
  37. //
  38. //*****************************************************************************
  39. #ifndef __DRIVERLIB_ADC_H__
  40. #define __DRIVERLIB_ADC_H__
  41. //*****************************************************************************
  42. //
  43. // If building with a C++ compiler, make all of the definitions in this header
  44. // have a C binding.
  45. //
  46. //*****************************************************************************
  47. #ifdef __cplusplus
  48. extern "C"
  49. {
  50. #endif
  51. //*****************************************************************************
  52. //
  53. // Values that can be passed to ADCSequenceConfigure as the ui32Trigger
  54. // parameter.
  55. //
  56. //*****************************************************************************
  57. #define ADC_TRIGGER_PROCESSOR 0x00000000 // Processor event
  58. #define ADC_TRIGGER_COMP0 0x00000001 // Analog comparator 0 event
  59. #define ADC_TRIGGER_COMP1 0x00000002 // Analog comparator 1 event
  60. #define ADC_TRIGGER_COMP2 0x00000003 // Analog comparator 2 event
  61. #define ADC_TRIGGER_EXTERNAL 0x00000004 // External event
  62. #define ADC_TRIGGER_TIMER 0x00000005 // Timer event
  63. #define ADC_TRIGGER_PWM0 0x00000006 // PWM0 event
  64. #define ADC_TRIGGER_PWM1 0x00000007 // PWM1 event
  65. #define ADC_TRIGGER_PWM2 0x00000008 // PWM2 event
  66. #define ADC_TRIGGER_PWM3 0x00000009 // PWM3 event
  67. #define ADC_TRIGGER_NEVER 0x0000000E // Never Trigger
  68. #define ADC_TRIGGER_ALWAYS 0x0000000F // Always event
  69. #define ADC_TRIGGER_PWM_MOD0 0x00000000 // PWM triggers from PWM0
  70. #define ADC_TRIGGER_PWM_MOD1 0x00000010 // PWM triggers from PWM1
  71. //*****************************************************************************
  72. //
  73. // Values that can be passed to ADCSequenceStepConfigure as the ui32Config
  74. // parameter.
  75. //
  76. //*****************************************************************************
  77. #define ADC_CTL_TS 0x00000080 // Temperature sensor select
  78. #define ADC_CTL_IE 0x00000040 // Interrupt enable
  79. #define ADC_CTL_END 0x00000020 // Sequence end select
  80. #define ADC_CTL_D 0x00000010 // Differential select
  81. #define ADC_CTL_CH0 0x00000000 // Input channel 0
  82. #define ADC_CTL_CH1 0x00000001 // Input channel 1
  83. #define ADC_CTL_CH2 0x00000002 // Input channel 2
  84. #define ADC_CTL_CH3 0x00000003 // Input channel 3
  85. #define ADC_CTL_CH4 0x00000004 // Input channel 4
  86. #define ADC_CTL_CH5 0x00000005 // Input channel 5
  87. #define ADC_CTL_CH6 0x00000006 // Input channel 6
  88. #define ADC_CTL_CH7 0x00000007 // Input channel 7
  89. #define ADC_CTL_CH8 0x00000008 // Input channel 8
  90. #define ADC_CTL_CH9 0x00000009 // Input channel 9
  91. #define ADC_CTL_CH10 0x0000000A // Input channel 10
  92. #define ADC_CTL_CH11 0x0000000B // Input channel 11
  93. #define ADC_CTL_CH12 0x0000000C // Input channel 12
  94. #define ADC_CTL_CH13 0x0000000D // Input channel 13
  95. #define ADC_CTL_CH14 0x0000000E // Input channel 14
  96. #define ADC_CTL_CH15 0x0000000F // Input channel 15
  97. #define ADC_CTL_CH16 0x00000100 // Input channel 16
  98. #define ADC_CTL_CH17 0x00000101 // Input channel 17
  99. #define ADC_CTL_CH18 0x00000102 // Input channel 18
  100. #define ADC_CTL_CH19 0x00000103 // Input channel 19
  101. #define ADC_CTL_CH20 0x00000104 // Input channel 20
  102. #define ADC_CTL_CH21 0x00000105 // Input channel 21
  103. #define ADC_CTL_CH22 0x00000106 // Input channel 22
  104. #define ADC_CTL_CH23 0x00000107 // Input channel 23
  105. #define ADC_CTL_CMP0 0x00080000 // Select Comparator 0
  106. #define ADC_CTL_CMP1 0x00090000 // Select Comparator 1
  107. #define ADC_CTL_CMP2 0x000A0000 // Select Comparator 2
  108. #define ADC_CTL_CMP3 0x000B0000 // Select Comparator 3
  109. #define ADC_CTL_CMP4 0x000C0000 // Select Comparator 4
  110. #define ADC_CTL_CMP5 0x000D0000 // Select Comparator 5
  111. #define ADC_CTL_CMP6 0x000E0000 // Select Comparator 6
  112. #define ADC_CTL_CMP7 0x000F0000 // Select Comparator 7
  113. #define ADC_CTL_SHOLD_4 0x00000000 // Sample and hold 4 ADC clocks
  114. #define ADC_CTL_SHOLD_8 0x00200000 // Sample and hold 8 ADC clocks
  115. #define ADC_CTL_SHOLD_16 0x00400000 // Sample and hold 16 ADC clocks
  116. #define ADC_CTL_SHOLD_32 0x00600000 // Sample and hold 32 ADC clocks
  117. #define ADC_CTL_SHOLD_64 0x00800000 // Sample and hold 64 ADC clocks
  118. #define ADC_CTL_SHOLD_128 0x00A00000 // Sample and hold 128 ADC clocks
  119. #define ADC_CTL_SHOLD_256 0x00C00000 // Sample and hold 256 ADC clocks
  120. //*****************************************************************************
  121. //
  122. // Values that can be passed to ADCComparatorConfigure as part of the
  123. // ui32Config parameter.
  124. //
  125. //*****************************************************************************
  126. #define ADC_COMP_TRIG_NONE 0x00000000 // Trigger Disabled
  127. #define ADC_COMP_TRIG_LOW_ALWAYS \
  128. 0x00001000 // Trigger Low Always
  129. #define ADC_COMP_TRIG_LOW_ONCE 0x00001100 // Trigger Low Once
  130. #define ADC_COMP_TRIG_LOW_HALWAYS \
  131. 0x00001200 // Trigger Low Always (Hysteresis)
  132. #define ADC_COMP_TRIG_LOW_HONCE 0x00001300 // Trigger Low Once (Hysteresis)
  133. #define ADC_COMP_TRIG_MID_ALWAYS \
  134. 0x00001400 // Trigger Mid Always
  135. #define ADC_COMP_TRIG_MID_ONCE 0x00001500 // Trigger Mid Once
  136. #define ADC_COMP_TRIG_HIGH_ALWAYS \
  137. 0x00001C00 // Trigger High Always
  138. #define ADC_COMP_TRIG_HIGH_ONCE 0x00001D00 // Trigger High Once
  139. #define ADC_COMP_TRIG_HIGH_HALWAYS \
  140. 0x00001E00 // Trigger High Always (Hysteresis)
  141. #define ADC_COMP_TRIG_HIGH_HONCE \
  142. 0x00001F00 // Trigger High Once (Hysteresis)
  143. #define ADC_COMP_INT_NONE 0x00000000 // Interrupt Disabled
  144. #define ADC_COMP_INT_LOW_ALWAYS \
  145. 0x00000010 // Interrupt Low Always
  146. #define ADC_COMP_INT_LOW_ONCE 0x00000011 // Interrupt Low Once
  147. #define ADC_COMP_INT_LOW_HALWAYS \
  148. 0x00000012 // Interrupt Low Always
  149. // (Hysteresis)
  150. #define ADC_COMP_INT_LOW_HONCE 0x00000013 // Interrupt Low Once (Hysteresis)
  151. #define ADC_COMP_INT_MID_ALWAYS \
  152. 0x00000014 // Interrupt Mid Always
  153. #define ADC_COMP_INT_MID_ONCE 0x00000015 // Interrupt Mid Once
  154. #define ADC_COMP_INT_HIGH_ALWAYS \
  155. 0x0000001C // Interrupt High Always
  156. #define ADC_COMP_INT_HIGH_ONCE 0x0000001D // Interrupt High Once
  157. #define ADC_COMP_INT_HIGH_HALWAYS \
  158. 0x0000001E // Interrupt High Always
  159. // (Hysteresis)
  160. #define ADC_COMP_INT_HIGH_HONCE \
  161. 0x0000001F // Interrupt High Once (Hysteresis)
  162. //*****************************************************************************
  163. //
  164. // Values that can be used to modify the sequence number passed to
  165. // ADCProcessorTrigger in order to get cross-module synchronous processor
  166. // triggers.
  167. //
  168. //*****************************************************************************
  169. #define ADC_TRIGGER_WAIT 0x08000000 // Wait for the synchronous trigger
  170. #define ADC_TRIGGER_SIGNAL 0x80000000 // Signal the synchronous trigger
  171. //*****************************************************************************
  172. //
  173. // Values that can be passed to ADCPhaseDelaySet as the ui32Phase parameter and
  174. // returned from ADCPhaseDelayGet.
  175. //
  176. //*****************************************************************************
  177. #define ADC_PHASE_0 0x00000000 // 0 degrees
  178. #define ADC_PHASE_22_5 0x00000001 // 22.5 degrees
  179. #define ADC_PHASE_45 0x00000002 // 45 degrees
  180. #define ADC_PHASE_67_5 0x00000003 // 67.5 degrees
  181. #define ADC_PHASE_90 0x00000004 // 90 degrees
  182. #define ADC_PHASE_112_5 0x00000005 // 112.5 degrees
  183. #define ADC_PHASE_135 0x00000006 // 135 degrees
  184. #define ADC_PHASE_157_5 0x00000007 // 157.5 degrees
  185. #define ADC_PHASE_180 0x00000008 // 180 degrees
  186. #define ADC_PHASE_202_5 0x00000009 // 202.5 degrees
  187. #define ADC_PHASE_225 0x0000000A // 225 degrees
  188. #define ADC_PHASE_247_5 0x0000000B // 247.5 degrees
  189. #define ADC_PHASE_270 0x0000000C // 270 degrees
  190. #define ADC_PHASE_292_5 0x0000000D // 292.5 degrees
  191. #define ADC_PHASE_315 0x0000000E // 315 degrees
  192. #define ADC_PHASE_337_5 0x0000000F // 337.5 degrees
  193. //*****************************************************************************
  194. //
  195. // Values that can be passed to ADCReferenceSet as the ui32Ref parameter.
  196. //
  197. //*****************************************************************************
  198. #define ADC_REF_INT 0x00000000 // Internal reference
  199. #define ADC_REF_EXT_3V 0x00000001 // External 3V reference
  200. //*****************************************************************************
  201. //
  202. // Values that can be passed to ADCIntDisableEx(), ADCIntEnableEx(),
  203. // ADCIntClearEx() and ADCIntStatusEx().
  204. //
  205. //*****************************************************************************
  206. #define ADC_INT_SS0 0x00000001
  207. #define ADC_INT_SS1 0x00000002
  208. #define ADC_INT_SS2 0x00000004
  209. #define ADC_INT_SS3 0x00000008
  210. #define ADC_INT_DMA_SS0 0x00000100
  211. #define ADC_INT_DMA_SS1 0x00000200
  212. #define ADC_INT_DMA_SS2 0x00000400
  213. #define ADC_INT_DMA_SS3 0x00000800
  214. #define ADC_INT_DCON_SS0 0x00010000
  215. #define ADC_INT_DCON_SS1 0x00020000
  216. #define ADC_INT_DCON_SS2 0x00040000
  217. #define ADC_INT_DCON_SS3 0x00080000
  218. //*****************************************************************************
  219. //
  220. // Values that can be passed to ADCClockConfigSet() and ADCClockConfigGet().
  221. //
  222. //*****************************************************************************
  223. #define ADC_CLOCK_RATE_FULL 0x00000070
  224. #define ADC_CLOCK_RATE_HALF 0x00000050
  225. #define ADC_CLOCK_RATE_FOURTH 0x00000030
  226. #define ADC_CLOCK_RATE_EIGHTH 0x00000010
  227. #define ADC_CLOCK_SRC_PLL 0x00000000
  228. #define ADC_CLOCK_SRC_PIOSC 0x00000001
  229. #define ADC_CLOCK_SRC_ALTCLK 0x00000001
  230. #define ADC_CLOCK_SRC_MOSC 0x00000002
  231. //*****************************************************************************
  232. //
  233. // Prototypes for the APIs.
  234. //
  235. //*****************************************************************************
  236. extern void ADCIntRegister(uint32_t ui32Base, uint32_t ui32SequenceNum,
  237. void (*pfnHandler)(void));
  238. extern void ADCIntUnregister(uint32_t ui32Base, uint32_t ui32SequenceNum);
  239. extern void ADCIntDisable(uint32_t ui32Base, uint32_t ui32SequenceNum);
  240. extern void ADCIntEnable(uint32_t ui32Base, uint32_t ui32SequenceNum);
  241. extern uint32_t ADCIntStatus(uint32_t ui32Base, uint32_t ui32SequenceNum,
  242. bool bMasked);
  243. extern void ADCIntClear(uint32_t ui32Base, uint32_t ui32SequenceNum);
  244. extern void ADCSequenceEnable(uint32_t ui32Base, uint32_t ui32SequenceNum);
  245. extern void ADCSequenceDisable(uint32_t ui32Base, uint32_t ui32SequenceNum);
  246. extern void ADCSequenceConfigure(uint32_t ui32Base, uint32_t ui32SequenceNum,
  247. uint32_t ui32Trigger, uint32_t ui32Priority);
  248. extern void ADCSequenceStepConfigure(uint32_t ui32Base,
  249. uint32_t ui32SequenceNum,
  250. uint32_t ui32Step, uint32_t ui32Config);
  251. extern int32_t ADCSequenceOverflow(uint32_t ui32Base,
  252. uint32_t ui32SequenceNum);
  253. extern void ADCSequenceOverflowClear(uint32_t ui32Base,
  254. uint32_t ui32SequenceNum);
  255. extern int32_t ADCSequenceUnderflow(uint32_t ui32Base,
  256. uint32_t ui32SequenceNum);
  257. extern void ADCSequenceUnderflowClear(uint32_t ui32Base,
  258. uint32_t ui32SequenceNum);
  259. extern int32_t ADCSequenceDataGet(uint32_t ui32Base, uint32_t ui32SequenceNum,
  260. uint32_t *pui32Buffer);
  261. extern void ADCProcessorTrigger(uint32_t ui32Base, uint32_t ui32SequenceNum);
  262. extern void ADCSoftwareOversampleConfigure(uint32_t ui32Base,
  263. uint32_t ui32SequenceNum,
  264. uint32_t ui32Factor);
  265. extern void ADCSoftwareOversampleStepConfigure(uint32_t ui32Base,
  266. uint32_t ui32SequenceNum,
  267. uint32_t ui32Step,
  268. uint32_t ui32Config);
  269. extern void ADCSoftwareOversampleDataGet(uint32_t ui32Base,
  270. uint32_t ui32SequenceNum,
  271. uint32_t *pui32Buffer,
  272. uint32_t ui32Count);
  273. extern void ADCHardwareOversampleConfigure(uint32_t ui32Base,
  274. uint32_t ui32Factor);
  275. extern void ADCClockConfigSet(uint32_t ui32Base, uint32_t ui32Config,
  276. uint32_t ui32ClockDiv);
  277. extern uint32_t ADCClockConfigGet(uint32_t ui32Base, uint32_t *pui32ClockDiv);
  278. extern void ADCComparatorConfigure(uint32_t ui32Base, uint32_t ui32Comp,
  279. uint32_t ui32Config);
  280. extern void ADCComparatorRegionSet(uint32_t ui32Base, uint32_t ui32Comp,
  281. uint32_t ui32LowRef, uint32_t ui32HighRef);
  282. extern void ADCComparatorReset(uint32_t ui32Base, uint32_t ui32Comp,
  283. bool bTrigger, bool bInterrupt);
  284. extern void ADCComparatorIntDisable(uint32_t ui32Base,
  285. uint32_t ui32SequenceNum);
  286. extern void ADCComparatorIntEnable(uint32_t ui32Base,
  287. uint32_t ui32SequenceNum);
  288. extern uint32_t ADCComparatorIntStatus(uint32_t ui32Base);
  289. extern void ADCComparatorIntClear(uint32_t ui32Base, uint32_t ui32Status);
  290. extern void ADCIntDisableEx(uint32_t ui32Base, uint32_t ui32IntFlags);
  291. extern void ADCIntEnableEx(uint32_t ui32Base, uint32_t ui32IntFlags);
  292. extern uint32_t ADCIntStatusEx(uint32_t ui32Base, bool bMasked);
  293. extern void ADCIntClearEx(uint32_t ui32Base, uint32_t ui32IntFlags);
  294. extern void ADCSequenceDMAEnable(uint32_t ui32Base, uint32_t ui32SequenceNum);
  295. extern void ADCSequenceDMADisable(uint32_t ui32Base, uint32_t ui32SequenceNum);
  296. extern bool ADCBusy(uint32_t ui32Base);
  297. extern void ADCReferenceSet(uint32_t ui32Base, uint32_t ui32Ref);
  298. extern uint32_t ADCReferenceGet(uint32_t ui32Base);
  299. extern void ADCPhaseDelaySet(uint32_t ui32Base, uint32_t ui32Phase);
  300. extern uint32_t ADCPhaseDelayGet(uint32_t ui32Base);
  301. extern void ADCSampleRateSet(uint32_t ui32Base, uint32_t ui32ADCClock,
  302. uint32_t ui32Rate);
  303. extern uint32_t ADCSampleRateGet(uint32_t ui32Base);
  304. //*****************************************************************************
  305. //
  306. // Mark the end of the C bindings section for C++ compilers.
  307. //
  308. //*****************************************************************************
  309. #ifdef __cplusplus
  310. }
  311. #endif
  312. #endif // __DRIVERLIB_ADC_H__