hw_adc.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * @brief ADC ROM API declarations and functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2014
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef _HW_ADC_H
  32. #define _HW_ADC_H
  33. /*******************
  34. * INCLUDE FILES *
  35. ********************/
  36. #include <stdint.h>
  37. #if defined( __CC_ARM )
  38. #pragma anon_unions
  39. #endif
  40. /*******************
  41. * EXPORTED MACROS *
  42. ********************/
  43. /*********************
  44. * EXPORTED TYPEDEFS *
  45. **********************/
  46. // ------------------------------------------------------------------------------------------------
  47. // ----- ADC -----
  48. // ------------------------------------------------------------------------------------------------
  49. /**
  50. * @brief Product name title=UM10462 Chapter title=LPC11U1x ADC Modification date=3/16/2011 Major revision=0 Minor revision=3 (ADC)
  51. */
  52. typedef struct { /*!< (@ 0x40000000) ADC Structure */
  53. volatile uint32_t CTRL; /*!< (@ 0x40000000) A/D Control Register */
  54. volatile uint32_t INPUTSEL; /*!< (@ 0x40000004) A/D Input Control Register */
  55. union {
  56. volatile uint32_t SEQ_CTRL[2];
  57. struct {
  58. volatile uint32_t SEQA_CTRL; /*!< (@ 0x40000008) A/D SEQA Ctrl Register */
  59. volatile uint32_t SEQB_CTRL; /*!< (@ 0x4000000C) A/D SEQB Ctrl Register */
  60. };
  61. };
  62. union {
  63. const volatile uint32_t SEQ_GDAT[2];
  64. struct {
  65. const volatile uint32_t SEQA_GDAT; /*!< (@ 0x40000010) A/D SEQA Global Data Register */
  66. const volatile uint32_t SEQB_GDAT; /*!< (@ 0x40000014) A/D SEQB Global Data Register */
  67. };
  68. };
  69. uint32_t Reserved[2];
  70. union {
  71. const volatile uint32_t DAT[12]; /*!< (@ 0x40000020) A/D Channel Data Register*/
  72. struct {
  73. const volatile uint32_t DAT0; /*!< (@ 0x40000020) A/D Channel Data Register 0*/
  74. const volatile uint32_t DAT1; /*!< (@ 0x40000024) A/D Channel Data Register 1*/
  75. const volatile uint32_t DAT2; /*!< (@ 0x40000028) A/D Channel Data Register 2*/
  76. const volatile uint32_t DAT3; /*!< (@ 0x4000002C) A/D Channel Data Register 3*/
  77. const volatile uint32_t DAT4; /*!< (@ 0x40000030) A/D Channel Data Register 4*/
  78. const volatile uint32_t DAT5; /*!< (@ 0x40000034) A/D Channel Data Register 5*/
  79. const volatile uint32_t DAT6; /*!< (@ 0x40000038) A/D Channel Data Register 6*/
  80. const volatile uint32_t DAT7; /*!< (@ 0x4000003C) A/D Channel Data Register 7*/
  81. const volatile uint32_t DAT8; /*!< (@ 0x40000040) A/D Channel Data Register 8*/
  82. const volatile uint32_t DAT9; /*!< (@ 0x40000044) A/D Channel Data Register 9*/
  83. const volatile uint32_t DAT10; /*!< (@ 0x40000048) A/D Channel Data Register 10*/
  84. const volatile uint32_t DAT11; /*!< (@ 0x4000004C) A/D Channel Data Register 11*/
  85. };
  86. };
  87. union {
  88. volatile uint32_t THR_LOW[2];
  89. struct {
  90. volatile uint32_t THR0_LOW; /*!< (@ 0x40000050) A/D Low Threhold Register 0. */
  91. volatile uint32_t THR1_LOW; /*!< (@ 0x40000054) A/D Low Threhold Register 1. */
  92. };
  93. };
  94. union {
  95. volatile uint32_t THR_HIGH[2];
  96. struct {
  97. volatile uint32_t THR0_HIGH; /*!< (@ 0x40000058) A/D High Threhold Register 0. */
  98. volatile uint32_t THR1_HIGH; /*!< (@ 0x4000005C) A/D High Threhold Register 1. */
  99. };
  100. };
  101. volatile uint32_t CHAN_THRSEL; /*!< (@ 0x40000060) A/D Channel Threhold Select Register. */
  102. volatile uint32_t INTEN; /*!< (@ 0x40000064) A/D Interrupt Enable Register. */
  103. volatile uint32_t FLAGS; /*!< (@ 0x40000068) A/D Interrupt Request Flags Register. */
  104. volatile uint32_t STARTUP; /*!< (@ 0x4000006C) A/D Startup Register. */
  105. volatile uint32_t CALIBR; /*!< (@ 0x40000070) A/D Calibration Register. */
  106. } ADC_REGS_T;
  107. /** Maximum sample rate in Hz (12-bit conversions) */
  108. #define ADC_MAX_CHANNEL_NUM 12
  109. /**
  110. * @brief ADC register support bitfields and mask
  111. */
  112. /** ADC Control register bit fields */
  113. #define ADC_CR_CLKDIV_MASK (0xFF << 0) /*!< Mask for Clock divider value */
  114. #define ADC_CR_CLKDIV_BITPOS (0) /*!< Bit position for Clock divider value */
  115. #define ADC_CR_ASYNC_MODE (1 << 8)
  116. #define ADC_CR_RESOL_MASK (0x3 << 9) /*!< Two-bit mask for resolution */
  117. #define ADC_CR_RESOL(n) ((n) << 9) /*!< 2-bits, 6(0x0),8(0x1),10(0x2),12(0x3)-bit mode enable bit */
  118. #define ADC_CR_RESOL_BITPOS (9)
  119. #define ADC_CR_BYPASS (1 << 11) /*!< Bypass mode */
  120. #define ADC_CR_TSAMP_MASK (0x7 << 12) /*!< Three-bit mask for Sample time */
  121. /**
  122. * @brief ADC resolution bits 9 and 10
  123. */
  124. typedef enum _ADC_RESOL_T {
  125. ADC_RESOL_6BIT = 0,
  126. ADC_RESOL_8BIT,
  127. ADC_RESOL_10BIT,
  128. ADC_RESOL_12BIT,
  129. } ADC_RESOL_T;
  130. /* ADC input Select register */
  131. #define ADC_INPUTSEL_PIN (0x0 << 0)
  132. #define ADC_INPUTSEL_CORE_VOL (0x1 << 0)
  133. #define ADC_INPUTSEL_INTERNAL_VOL (0x2 << 0)
  134. #define ADC_INPUTSEL_TEMP_VOL (0x3 << 0)
  135. /** ADC Sequence Control register bit fields */
  136. #define ADC_SEQ_CTRL_CHANSEL(n) (1 << (n)) /*!< Channel select macro */
  137. #define ADC_SEQ_CTRL_CHANSEL_BITPOS(n) ((n) << 0) /*!< Channel select macro */
  138. #define ADC_SEQ_CTRL_CHANSEL_MASK (0xFFF) /*!< Channel select mask */
  139. /** SEQ_CTRL register bit fields */
  140. #define ADC_SEQ_CTRL_TRIGGER(n) ((n) << 12)
  141. #define ADC_SEQ_CTRL_TRIGGER_MASK (0x1F << 12)
  142. #define ADC_SEQ_CTRL_HWTRIG_POLPOS (1 << 18) /*!< HW trigger polarity - positive edge */
  143. #define ADC_SEQ_CTRL_HWTRIG_SYNCBYPASS (1 << 19) /*!< HW trigger bypass synchronisation */
  144. #define ADC_SEQ_CTRL_START (1 << 26) /*!< Start conversion enable bit */
  145. #define ADC_SEQ_CTRL_BURST (1 << 27) /*!< Repeated conversion enable bit */
  146. #define ADC_SEQ_CTRL_SINGLESTEP (1 << 28) /*!< Single step enable bit */
  147. #define ADC_SEQ_CTRL_LOWPRIO (1 << 29) /*!< High priority enable bit (regardless of name) */
  148. #define ADC_SEQ_CTRL_MODE_EOS (1 << 30) /*!< Mode End of sequence enable bit */
  149. #define ADC_SEQ_CTRL_SEQ_ENA (1UL << 31) /*!< Sequence enable bit */
  150. /** ADC global data register bit fields */
  151. #define ADC_SEQ_GDAT_RESULT_MASK (0xFFF << 4) /*!< Result value mask */
  152. #define ADC_SEQ_GDAT_RESULT_BITPOS (4) /*!< Result start bit position */
  153. #define ADC_SEQ_GDAT_THCMPRANGE_MASK (0x3 << 16) /*!< Comparion range mask */
  154. #define ADC_SEQ_GDAT_THCMPRANGE_BITPOS (16) /*!< Comparison range bit position */
  155. #define ADC_SEQ_GDAT_THCMPCROSS_MASK (0x3 << 18) /*!< Comparion cross mask */
  156. #define ADC_SEQ_GDAT_THCMPCROSS_BITPOS (18) /*!< Comparison cross bit position */
  157. #define ADC_SEQ_GDAT_CHAN_MASK (0xF << 26) /*!< Channel number mask */
  158. #define ADC_SEQ_GDAT_CHAN_BITPOS (26) /*!< Channel number bit position */
  159. #define ADC_SEQ_GDAT_OVERRUN (1 << 30) /*!< Overrun bit */
  160. #define ADC_SEQ_GDAT_DATAVALID (1UL << 31) /*!< Data valid bit */
  161. /** ADC Data register bit fields */
  162. #define ADC_DR_RESULT(n) ((((n) >> 4) & 0xFFF)) /*!< Macro for getting the ADC data value */
  163. #define ADC_DRTHR_RESULT(n) ((((n) >> 4) & 0xFFFF)) /*!< Macro for getting the ADC data value along with Threshold */
  164. #define ADC_DR_THCMPRANGE_MASK (0x3 << 16) /*!< Comparion range mask */
  165. #define ADC_DR_THCMPRANGE_BITPOS (16) /*!< Comparison range bit position */
  166. #define ADC_DR_THCMPRANGE(n) (((n) >> ADC_DR_THCMPRANGE_BITPOS) & 0x3)
  167. #define ADC_DR_THCMPCROSS_MASK (0x3 << 18) /*!< Comparion cross mask */
  168. #define ADC_DR_THCMPCROSS_BITPOS (18) /*!< Comparison cross bit position */
  169. #define ADC_DR_THCMPCROSS(n) (((n) >> ADC_DR_THCMPCROSS_BITPOS) & 0x3)
  170. #define ADC_DR_CHAN_MASK (0xF << 26) /*!< Channel number mask */
  171. #define ADC_DR_CHAN_BITPOS (26) /*!< Channel number bit position */
  172. #define ADC_DR_CHANNEL(n) (((n) >> ADC_DR_CHAN_BITPOS) & 0xF) /*!< Channel number bit position */
  173. #define ADC_DR_OVERRUN (1 << 30) /*!< Overrun bit */
  174. #define ADC_DR_DATAVALID (1UL << 31) /*!< Data valid bit */
  175. #define ADC_DR_DONE(n) (((n) >> 31))
  176. /** ADC low/high Threshold register bit fields */
  177. #define ADC_THR_VAL_MASK (0xFFF << 4) /*!< Threshold value bit mask */
  178. #define ADC_THR_VAL_POS (4) /*!< Threshold value bit position */
  179. /** ADC Threshold select register bit fields */
  180. #define ADC_THRSEL_CHAN_SEL_THR1(n) (1 << (n)) /*!< Select THR1 register for channel n */
  181. /** ADC Interrupt Enable register bit fields */
  182. #define ADC_INTEN_SEQA_ENABLE (1 << 0) /*!< Sequence A Interrupt enable bit */
  183. #define ADC_INTEN_SEQB_ENABLE (1 << 1) /*!< Sequence B Interrupt enable bit */
  184. #define ADC_INTEN_SEQN_ENABLE(seq) (1 << (seq)) /*!< Sequence A/B Interrupt enable bit */
  185. #define ADC_INTEN_OVRRUN_ENABLE (1 << 2) /*!< Overrun Interrupt enable bit */
  186. #define ADC_INTEN_CMP_DISBALE (0) /*!< Disable comparison interrupt value */
  187. #define ADC_INTEN_CMP_OUTSIDETH (1) /*!< Outside threshold interrupt value */
  188. #define ADC_INTEN_CMP_CROSSTH (2) /*!< Crossing threshold interrupt value */
  189. #define ADC_INTEN_CMP_MASK (3) /*!< Comparison interrupt value mask */
  190. #define ADC_INTEN_CMP_ENABLE(isel, ch) (((isel) & ADC_INTEN_CMP_MASK) << ((2 * (ch)) + 3)) /*!< Interrupt selection for channel */
  191. /** ADC Flags register bit fields */
  192. #define ADC_FLAGS_THCMP_MASK(ch) (1 << (ch)) /*!< Threshold comparison status for channel */
  193. #define ADC_FLAGS_OVRRUN_MASK(ch) (1 << (12 + (ch))) /*!< Overrun status for channel */
  194. #define ADC_FLAGS_SEQA_OVRRUN_MASK (1 << 24) /*!< Seq A Overrun status */
  195. #define ADC_FLAGS_SEQB_OVRRUN_MASK (1 << 25) /*!< Seq B Overrun status */
  196. #define ADC_FLAGS_SEQN_OVRRUN_MASK(seq) (1 << (24 + (seq))) /*!< Seq A/B Overrun status */
  197. #define ADC_FLAGS_SEQA_INT_MASK (1 << 28) /*!< Seq A Interrupt status */
  198. #define ADC_FLAGS_SEQB_INT_MASK (1 << 29) /*!< Seq B Interrupt status */
  199. #define ADC_FLAGS_SEQN_INT_MASK(seq) (1 << (28 + (seq)))/*!< Seq A/B Interrupt status */
  200. #define ADC_FLAGS_THCMP_INT_MASK (1 << 30) /*!< Threshold comparison Interrupt status */
  201. #define ADC_FLAGS_OVRRUN_INT_MASK (1UL << 31) /*!< Overrun Interrupt status */
  202. /** ADC Startup register bit fields */
  203. #define ADC_STARTUP_ENABLE (0x1 << 0)
  204. #define ADC_STARTUP_INIT (0x1 << 1)
  205. /* ADC Calibration register definition */
  206. #define ADC_CALIB (0x1 << 0)
  207. #define ADC_CALREQD (0x1 << 1)
  208. /* Depending on the mode you are running: the slowest case is using interrupt and end of conversion while BURST mode is enabled.
  209. For interrupt and end of sequence, the clock can be set faster. */
  210. #endif /* _HW_ADCD_H Do not add any thing below this line */