eadc.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /**************************************************************************//**
  2. * @file eadc.h
  3. * @version V1.00
  4. * $Revision: 17 $
  5. * $Date: 15/12/01 10:13a $
  6. * @brief NUC472/NUC442 EADC driver header file
  7. *
  8. * @note
  9. * Copyright (C) 2015 Nuvoton Technology Corp. All rights reserved.
  10. *****************************************************************************/
  11. #ifndef __EADC_H__
  12. #define __EADC_H__
  13. #ifdef __cplusplus
  14. extern "C"
  15. {
  16. #endif
  17. /** @addtogroup NUC472_442_Device_Driver NUC472/NUC442 Device Driver
  18. @{
  19. */
  20. /** @addtogroup NUC472_442_EADC_Driver EADC Driver
  21. @{
  22. */
  23. /** @addtogroup NUC472_442_EADC_EXPORTED_CONSTANTS EADC Exported Constants
  24. @{
  25. */
  26. /*---------------------------------------------------------------------------------------------------------*/
  27. /* EADC SAMPLE module number Definitions */
  28. /*---------------------------------------------------------------------------------------------------------*/
  29. #define EADC0_SAMPLE_MODULE0 0 /*!< EADC0 SAMPLE module 0 \hideinitializer */
  30. #define EADC0_SAMPLE_MODULE1 1 /*!< EADC0 SAMPLE module 1 \hideinitializer */
  31. #define EADC0_SAMPLE_MODULE2 2 /*!< EADC0 SAMPLE module 2 \hideinitializer */
  32. #define EADC0_SAMPLE_MODULE3 3 /*!< EADC0 SAMPLE module 3 \hideinitializer */
  33. #define EADC0_SAMPLE_MODULE4 4 /*!< EADC0 SAMPLE module 4 \hideinitializer */
  34. #define EADC0_SAMPLE_MODULE5 5 /*!< EADC0 SAMPLE module 5 \hideinitializer */
  35. #define EADC0_SAMPLE_MODULE6 6 /*!< EADC0 SAMPLE module 6 \hideinitializer */
  36. #define EADC0_SAMPLE_MODULE7 7 /*!< EADC0 SAMPLE module 7 \hideinitializer */
  37. #define EADC1_SAMPLE_MODULE0 8 /*!< EADC1 SAMPLE module 0 \hideinitializer */
  38. #define EADC1_SAMPLE_MODULE1 9 /*!< EADC1 SAMPLE module 1 \hideinitializer */
  39. #define EADC1_SAMPLE_MODULE2 10 /*!< EADC1 SAMPLE module 2 \hideinitializer */
  40. #define EADC1_SAMPLE_MODULE3 11 /*!< EADC1 SAMPLE module 3 \hideinitializer */
  41. #define EADC1_SAMPLE_MODULE4 12 /*!< EADC1 SAMPLE module 4 \hideinitializer */
  42. #define EADC1_SAMPLE_MODULE5 13 /*!< EADC1 SAMPLE module 5 \hideinitializer */
  43. #define EADC1_SAMPLE_MODULE6 14 /*!< EADC1 SAMPLE module 6 \hideinitializer */
  44. #define EADC1_SAMPLE_MODULE7 15 /*!< EADC1 SAMPLE module 7 \hideinitializer */
  45. /*---------------------------------------------------------------------------------------------------------*/
  46. /* EADC Compare SAMPLE module number Definitions */
  47. /*---------------------------------------------------------------------------------------------------------*/
  48. #define CMP_EADC0_SAMPLE_MODULE0 0 /*!< Compare EADC0 SAMPLE module 0 \hideinitializer */
  49. #define CMP_EADC0_SAMPLE_MODULE1 1 /*!< Compare EADC0 SAMPLE module 1 \hideinitializer */
  50. #define CMP_EADC0_SAMPLE_MODULE2 2 /*!< Compare EADC0 SAMPLE module 2 \hideinitializer */
  51. #define CMP_EADC0_SAMPLE_MODULE3 3 /*!< Compare EADC0 SAMPLE module 3 \hideinitializer */
  52. #define CMP_EADC1_SAMPLE_MODULE0 4 /*!< Compare EADC1 SAMPLE module 0 \hideinitializer */
  53. #define CMP_EADC1_SAMPLE_MODULE1 5 /*!< Compare EADC1 SAMPLE module 1 \hideinitializer */
  54. #define CMP_EADC1_SAMPLE_MODULE2 6 /*!< Compare EADC1 SAMPLE module 2 \hideinitializer */
  55. #define CMP_EADC1_SAMPLE_MODULE3 7 /*!< Compare EADC1 SAMPLE module 3 \hideinitializer */
  56. /*---------------------------------------------------------------------------------------------------------*/
  57. /* EADC_ADnSPCTLx Constant Definitions */
  58. /*---------------------------------------------------------------------------------------------------------*/
  59. #define EADC_SCTL_CHSEL(x) ((x) << EADC_AD0SPCTL0_CHSEL_Pos) /*!< A/D sample module channel selection \hideinitializer */
  60. #define EADC_SCTL_TRGDLYDIV(x) ((x) << EADC_AD0SPCTL0_TRGDLYDIV_Pos) /*!< A/D sample module start of conversion trigger delay clock divider selection \hideinitializer */
  61. #define EADC_SCTL_TRGDLYCNT(x) ((x) << EADC_AD0SPCTL0_TRGDLYCNT_Pos) /*!< A/D sample module start of conversion trigger delay time \hideinitializer */
  62. #define EADC_SOFTWARE_TRIGGER (0UL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< Software trigger \hideinitializer */
  63. #define EADC_STADC_TRIGGER (1UL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< External pin STADC trigger \hideinitializer */
  64. #define EADC_ADINT0_TRIGGER (2UL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< EADC ADINT0 interrupt EOC pulse trigger \hideinitializer */
  65. #define EADC_ADINT1_TRIGGER (3UL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< EADC ADINT1 interrupt EOC pulse trigger \hideinitializer */
  66. #define EADC_TIMER0_TRIGGER (4UL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< Timer0 overflow pulse trigger \hideinitializer */
  67. #define EADC_TIMER1_TRIGGER (5UL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< Timer1 overflow pulse trigger \hideinitializer */
  68. #define EADC_TIMER2_TRIGGER (6UL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< Timer2 overflow pulse trigger \hideinitializer */
  69. #define EADC_TIMER3_TRIGGER (7UL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< Timer3 overflow pulse trigger \hideinitializer */
  70. #define EADC_EPWM0CH0_TRIGGER (8UL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< EPWM0CH0 trigger \hideinitializer */
  71. #define EADC_EPWM0CH2_TRIGGER (9UL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< EPWM0CH2 trigger \hideinitializer */
  72. #define EADC_EPWM0CH4_TRIGGER (0xAUL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< EPWM0CH4 trigger \hideinitializer */
  73. #define EADC_EPWM1CH0_TRIGGER (0xBUL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< EPWM1CH0 trigger \hideinitializer */
  74. #define EADC_EPWM1CH2_TRIGGER (0xCUL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< EPWM1CH2 trigger \hideinitializer */
  75. #define EADC_EPWM1CH4_TRIGGER (0xDUL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< EPWM1CH4 trigger \hideinitializer */
  76. #define EADC_PWM0CH0_TRIGGER (0xEUL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< PWM0CH0 trigger \hideinitializer */
  77. #define EADC_PWM0CH1_TRIGGER (0xFUL << EADC_AD0SPCTL0_TRGSEL_Pos) /*!< PWM0CH1 trigger \hideinitializer */
  78. #define EADC_SPCTL_TRGDLYDIV_DIVIDER_1 (0 << EADC_AD0SPCTL0_TRGDLYDIV_Pos) /*!< Trigger delay clock frequency is ADC_CLK/1 \hideinitializer */
  79. #define EADC_SPCTL_TRGDLYDIV_DIVIDER_2 (0x1UL << EADC_AD0SPCTL0_TRGDLYDIV_Pos) /*!< Trigger delay clock frequency is ADC_CLK/2 \hideinitializer */
  80. #define EADC_SPCTL_TRGDLYDIV_DIVIDER_4 (0x2UL << EADC_AD0SPCTL0_TRGDLYDIV_Pos) /*!< Trigger delay clock frequency is ADC_CLK/4 \hideinitializer */
  81. #define EADC_SPCTL_TRGDLYDIV_DIVIDER_16 (0x3UL << EADC_AD0SPCTL0_TRGDLYDIV_Pos) /*!< Trigger delay clock frequency is ADC_CLK/16 \hideinitializer */
  82. /*---------------------------------------------------------------------------------------------------------*/
  83. /* EADC_CMP Constant Definitions */
  84. /*---------------------------------------------------------------------------------------------------------*/
  85. #define EADC_CMP_CMPCOND_LESS_THAN (0UL << EADC_CMP0_CMPCOND_Pos) /*!< The compare condition is "less than" \hideinitializer */
  86. #define EADC_CMP_CMPCOND_GREATER_OR_EQUAL (1UL << EADC_CMP0_CMPCOND_Pos) /*!< The compare condition is "greater than or equal to" \hideinitializer */
  87. #define EADC_CMP_ADCMPIE_ENABLE (EADC_CMP0_ADCMPIE_Msk) /*!< A/D result compare interrupt enable \hideinitializer */
  88. #define EADC_CMP_ADCMPIE_DISABLE (~EADC_CMP0_ADCMPIE_Msk) /*!< A/D result compare interrupt disable \hideinitializer */
  89. /*---------------------------------------------------------------------------------------------------------*/
  90. /* EADC PWM Trigger Condition Definitions */
  91. /*---------------------------------------------------------------------------------------------------------*/
  92. #define EADC0_TRIGGEREN0 0 /*!< A/D trigger condition for SAMPLE00 \hideinitializer */
  93. #define EADC0_TRIGGEREN1 1 /*!< A/D trigger condition for SAMPLE01 \hideinitializer */
  94. #define EADC0_TRIGGEREN2 2 /*!< A/D trigger condition for SAMPLE02 \hideinitializer */
  95. #define EADC0_TRIGGEREN3 3 /*!< A/D trigger condition for SAMPLE03 \hideinitializer */
  96. #define EADC1_TRIGGEREN0 4 /*!< A/D trigger condition for SAMPLE10 \hideinitializer */
  97. #define EADC1_TRIGGEREN1 5 /*!< A/D trigger condition for SAMPLE11 \hideinitializer */
  98. #define EADC1_TRIGGEREN2 6 /*!< A/D trigger condition for SAMPLE12 \hideinitializer */
  99. #define EADC1_TRIGGEREN3 7 /*!< A/D trigger condition for SAMPLE13 \hideinitializer */
  100. /*---------------------------------------------------------------------------------------------------------*/
  101. /* EADC Channel selection Definitions */
  102. /*---------------------------------------------------------------------------------------------------------*/
  103. #define EADC0_CH0 0 /*!< Select EADC0 channel 0 for EADC0 SAMPLE Module \hideinitializer */
  104. #define EADC0_CH1 1 /*!< Select EADC0 channel 1 for EADC0 SAMPLE Module \hideinitializer */
  105. #define EADC0_CH2 2 /*!< Select EADC0 channel 2 for EADC0 SAMPLE Module \hideinitializer */
  106. #define EADC0_CH3 3 /*!< Select EADC0 channel 3 for EADC0 SAMPLE Module \hideinitializer */
  107. #define EADC0_CH4 4 /*!< Select EADC0 channel 4 for EADC0 SAMPLE Module \hideinitializer */
  108. #define EADC0_CH5 5 /*!< Select EADC0 channel 5 for EADC0 SAMPLE Module \hideinitializer */
  109. #define EADC0_CH6 6 /*!< Select EADC0 channel 6 for EADC0 SAMPLE Module \hideinitializer */
  110. #define EADC0_CH7 7 /*!< Select EADC0 channel 7 for EADC0 SAMPLE Module \hideinitializer */
  111. #define EADC0_VBG 8 /*!< Select EADC0 VBG for EADC0 SAMPLE Module \hideinitializer */
  112. #define EADC0_VTEMP 9 /*!< Select EADC0 VTEMP for EADC0 SAMPLE Module \hideinitializer */
  113. #define EADC0_AVSS 10 /*!< Select EADC0 AVSS for EADC0 SAMPLE Module \hideinitializer */
  114. #define EADC0_OP0 11 /*!< Select EADC0 OP0 for EADC0 SAMPLE Module \hideinitializer */
  115. #define EADC1_CH0 0 /*!< Select EADC1 channel 0 for EADC1 SAMPLE Module \hideinitializer */
  116. #define EADC1_CH1 1 /*!< Select EADC1 channel 1 for EADC1 SAMPLE Module \hideinitializer */
  117. #define EADC1_CH2 2 /*!< Select EADC1 channel 2 for EADC1 SAMPLE Module \hideinitializer */
  118. #define EADC1_CH3 3 /*!< Select EADC1 channel 3 for EADC1 SAMPLE Module \hideinitializer */
  119. #define EADC1_CH4 4 /*!< Select EADC1 channel 4 for EADC1 SAMPLE Module \hideinitializer */
  120. #define EADC1_CH5 5 /*!< Select EADC1 channel 5 for EADC1 SAMPLE Module \hideinitializer */
  121. #define EADC1_CH6 6 /*!< Select EADC1 channel 6 for EADC1 SAMPLE Module \hideinitializer */
  122. #define EADC1_CH7 7 /*!< Select EADC1 channel 7 for EADC1 SAMPLE Module \hideinitializer */
  123. #define EADC1_OP1 8 /*!< Select EADC1 OP1 for EADC1 SAMPLE Module \hideinitializer */
  124. /*@}*/ /* end of group NUC472_442_EADC_EXPORTED_CONSTANTS */
  125. /** @addtogroup NUC472_442_EADC_EXPORTED_FUNCTIONS EADC Exported Functions
  126. @{
  127. */
  128. /*---------------------------------------------------------------------------------------------------------*/
  129. /* EADC Macro Definitions */
  130. /*---------------------------------------------------------------------------------------------------------*/
  131. /**
  132. * @brief Power down EADC module
  133. * @param[in] eadc Base address of EADC module
  134. * @return None
  135. * \hideinitializer
  136. */
  137. #define EADC_POWER_DOWN(eadc) (EADC->CTL &= ~EADC_CTL_ADCEN_Msk)
  138. /**
  139. * @brief Power on EADC module
  140. * @param[in] eadc Base address of EADC module
  141. * @return None
  142. * \hideinitializer
  143. */
  144. #define EADC_POWER_ON(eadc) (EADC->CTL |= EADC_CTL_ADCEN_Msk)
  145. /**
  146. * @brief A/D Converter Control Circuits Reset.
  147. * @param[in] eadc Base address of EADC module.
  148. * @return None
  149. * @details ADCRST bit (EADC_CT[1]) remains 1 during EADC reset, when EADC reset end, the ADCRST bit is automatically cleared to 0.
  150. * \hideinitializer
  151. */
  152. #define EADC_CONV_RESET(eadc) ((eadc)->CTL |= EADC_CTL_ADCRST_Msk)
  153. /**
  154. * @brief Enable double buffer mode.
  155. * @param[in] eadc Base address of EADC module.
  156. * @param[in] u32ModuleNum Decides the sample module number, valid values are:
  157. * - \ref EADC0_SAMPLE_MODULE0 : EADC0 SAMPLE module 0
  158. * - \ref EADC0_SAMPLE_MODULE1 : EADC0 SAMPLE module 1
  159. * - \ref EADC0_SAMPLE_MODULE2 : EADC0 SAMPLE module 2
  160. * - \ref EADC0_SAMPLE_MODULE3 : EADC0 SAMPLE module 3
  161. * - \ref EADC1_SAMPLE_MODULE0 : EADC1 SAMPLE module 0
  162. * - \ref EADC1_SAMPLE_MODULE1 : EADC1 SAMPLE module 1
  163. * - \ref EADC1_SAMPLE_MODULE2 : EADC1 SAMPLE module 2
  164. * - \ref EADC1_SAMPLE_MODULE3 : EADC1 SAMPLE module 3
  165. * @return None
  166. * @details The EADC controller supports a double buffer mode in eadc0/1 sample module 0~3.
  167. * \hideinitializer
  168. */
  169. #define EADC_ENABLE_DOUBLE_BUFFER(eadc, u32ModuleNum) ((eadc)->DBMEN |= (1 << u32ModuleNum))
  170. /**
  171. * @brief Disable double buffer mode.
  172. * @param[in] eadc Base address of EADC module..
  173. * @param[in] u32ModuleNum Decides the sample module number, valid values are:
  174. * - \ref EADC0_SAMPLE_MODULE0 : EADC0 SAMPLE module 0
  175. * - \ref EADC0_SAMPLE_MODULE1 : EADC0 SAMPLE module 1
  176. * - \ref EADC0_SAMPLE_MODULE2 : EADC0 SAMPLE module 2
  177. * - \ref EADC0_SAMPLE_MODULE3 : EADC0 SAMPLE module 3
  178. * - \ref EADC1_SAMPLE_MODULE0 : EADC1 SAMPLE module 0
  179. * - \ref EADC1_SAMPLE_MODULE1 : EADC1 SAMPLE module 1
  180. * - \ref EADC1_SAMPLE_MODULE2 : EADC1 SAMPLE module 2
  181. * - \ref EADC1_SAMPLE_MODULE3 : EADC1 SAMPLE module 3
  182. * @return None
  183. * @details Sample has one sample result register.
  184. * \hideinitializer
  185. */
  186. #define EADC_DISABLE_DOUBLE_BUFFER(eadc, u32ModuleNum) ((eadc)->DBMEN &= ~(1 << u32ModuleNum))
  187. /**
  188. * @brief Enable the interrupt.
  189. * @param[in] eadc Base address of EADC module.
  190. * @param[in] u32Mask Decides the combination of interrupt enable bits. Each bit corresponds to a interrupt enable.
  191. * This parameter decides which interrupts will be enabled. Bit 0 is ADCIEN0, bit 1 is ADCIEN1..., bit 3 is ADCIEN3.
  192. * @return None
  193. * @details The A/D converter generates a conversion end ADIFn (EADC_STATUS1[n]) upon the end of specific sample module A/D conversion.
  194. * If ADCIENn bit (EADC_CTL[n+2]) is set then conversion end interrupt request ADINTn is generated (n=0~3).
  195. * \hideinitializer
  196. */
  197. #define EADC_ENABLE_INT(eadc, u32Mask) ((eadc)->CTL |= ((u32Mask) << EADC_CTL_ADCIEN0_Pos))
  198. /**
  199. * @brief Disable the interrupt.
  200. * @param[in] eadc Base address of EADC module.
  201. * @param[in] u32Mask Decides the combination of interrupt enable bits. Each bit corresponds to a interrupt enable.
  202. * This parameter decides which interrupts will be disabled. Bit 0 is ADCIEN0, bit 1 is ADCIEN1..., bit 3 is ADCIEN3.
  203. * @return None
  204. * @details Specific sample module A/D ADINT0 interrupt function Disabled.
  205. * \hideinitializer
  206. */
  207. #define EADC_DISABLE_INT(eadc, u32Mask) ((eadc)->CTL &= ~((u32Mask) << EADC_CTL_ADCIEN0_Pos))
  208. /**
  209. * @brief Enable the sample module interrupt.
  210. * @param[in] eadc Base address of EADC module.
  211. * @param[in] u32IntSel Decides which interrupt source will be used, valid value are from 0 to 3.
  212. * @param[in] u32ModuleMask the combination of sample module interrupt enable bits. Each bit corresponds to a sample module interrupt enable.
  213. * This parameter decides which sample module interrupts will be enabled, valid range are between 1~0xFFFF.
  214. * @return None
  215. * @details There are 4 EADC interrupts ADINT0~3, and each of these interrupts has its own interrupt vector address.
  216. * \hideinitializer
  217. */
  218. #define EADC_ENABLE_SAMPLE_MODULE_INT(eadc, u32IntSel, u32ModuleMask) ((eadc)->INTSRC[(u32IntSel)] |= (u32ModuleMask))
  219. /**
  220. * @brief Disable the sample module interrupt.
  221. * @param[in] eadc Base address of EADC module.
  222. * @param[in] u32IntSel Decides which interrupt source will be used, valid value are from 0 to 3.
  223. * @param[in] u32ModuleMask the combination of sample module interrupt enable bits. Each bit corresponds to a sample module interrupt enable.
  224. * This parameter decides which sample module interrupts will be disabled, valid range are between 1~0xFFFF.
  225. * @return None
  226. * @details There are 4 EADC interrupts ADINT0~3, and each of these interrupts has its own interrupt vector address.
  227. * \hideinitializer
  228. */
  229. #define EADC_DISABLE_SAMPLE_MODULE_INT(eadc, u32IntSel, u32ModuleMask) ((eadc)->INTSRC[(u32IntSel)] &= ~(u32ModuleMask))
  230. /**
  231. * @brief Start the A/D conversion.
  232. * @param[in] eadc Base address of EADC module.
  233. * @param[in] u32ModuleMask The combination of sample module. Each bit corresponds to a sample module.
  234. * This parameter decides which sample module will be conversion, valid range are between 1~0xFFFF.
  235. * Bit 0 is sample module 0, bit 1 is sample module 1..., bit 15 is sample module 15.
  236. * @return None
  237. * @details After write EADC_SWTRG register to start EADC conversion, the EADC_PENDSTS register will show which SAMPLE will conversion.
  238. * \hideinitializer
  239. */
  240. #define EADC_START_CONV(eadc, u32ModuleMask) ((eadc)->SWTRG = (u32ModuleMask))
  241. /**
  242. * @brief Get the conversion pending flag.
  243. * @param[in] eadc Base address of EADC module.
  244. * @return Return the conversion pending sample module.
  245. * @return None
  246. * @details This STPFn(EADC_PENDSTS[15:0]) bit remains 1 during pending state, when the respective EADC conversion is end,
  247. * the STPFn (n=0~15) bit is automatically cleared to 0.
  248. * \hideinitializer
  249. */
  250. #define EADC_GET_PENDING_CONV(eadc) ((eadc)->PENDSTS)
  251. /**
  252. * @brief Get the conversion data of the user-specified sample module.
  253. * @param[in] eadc Base address of EADC module.
  254. * @param[in] u32ModuleNum Decides the sample module number, valid values are:
  255. * - \ref EADC0_SAMPLE_MODULE0 : EADC0 SAMPLE module 0
  256. * - \ref EADC0_SAMPLE_MODULE1 : EADC0 SAMPLE module 1
  257. * - \ref EADC0_SAMPLE_MODULE2 : EADC0 SAMPLE module 2
  258. * - \ref EADC0_SAMPLE_MODULE3 : EADC0 SAMPLE module 3
  259. * - \ref EADC0_SAMPLE_MODULE4 : EADC0 SAMPLE module 4
  260. * - \ref EADC0_SAMPLE_MODULE5 : EADC0 SAMPLE module 5
  261. * - \ref EADC0_SAMPLE_MODULE6 : EADC0 SAMPLE module 6
  262. * - \ref EADC0_SAMPLE_MODULE7 : EADC0 SAMPLE module 7
  263. * - \ref EADC1_SAMPLE_MODULE0 : EADC1 SAMPLE module 0
  264. * - \ref EADC1_SAMPLE_MODULE1 : EADC1 SAMPLE module 1
  265. * - \ref EADC1_SAMPLE_MODULE2 : EADC1 SAMPLE module 2
  266. * - \ref EADC1_SAMPLE_MODULE3 : EADC1 SAMPLE module 3
  267. * - \ref EADC1_SAMPLE_MODULE4 : EADC1 SAMPLE module 4
  268. * - \ref EADC1_SAMPLE_MODULE5 : EADC1 SAMPLE module 5
  269. * - \ref EADC1_SAMPLE_MODULE6 : EADC1 SAMPLE module 6
  270. * - \ref EADC1_SAMPLE_MODULE7 : EADC1 SAMPLE module 7
  271. * @return Return the conversion data of the user-specified sample module.
  272. * @details This macro is used to read RESULT bit (EADC_ADxDATn[11:0], x=0~1, n=0~7) field to get conversion data.
  273. * \hideinitializer
  274. */
  275. #define EADC_GET_CONV_DATA(eadc, u32ModuleNum) (*(__IO uint32_t *)(&((eadc)->AD0DAT0) + (u32ModuleNum)) & EADC_AD0DAT0_RESULT_Msk)
  276. /**
  277. * @brief Get the data overrun flag of the user-specified sample module.
  278. * @param[in] eadc Base address of EADC module.
  279. * @param[in] u32ModuleMask The combination of data overrun status bits. Each bit corresponds to a data overrun status, valid range are between 1~0x7FFFF.
  280. * @return Return the data overrun flag of the user-specified sample module.
  281. * @details This macro is used to read OV bit (EADC_STATUS0[31:16]) field to get data overrun status.
  282. * \hideinitializer
  283. */
  284. #define EADC_GET_DATA_OVERRUN_FLAG(eadc, u32ModuleMask) (((eadc)->STATUS0 >> EADC_STATUS0_OV_Pos) & (u32ModuleMask))
  285. /**
  286. * @brief Get the data valid flag of the user-specified sample module.
  287. * @param[in] eadc Base address of EADC module.
  288. * @param[in] u32ModuleMask The combination of data valid status bits. Each bit corresponds to a data valid status, valid range are between 1~0x7FFFF.
  289. * @return Return the data valid flag of the user-specified sample module.
  290. * @details This macro is used to read VALID bit of EADC_STATUS0[15:0] to get data valid status.
  291. * \hideinitializer
  292. */
  293. #define EADC_GET_DATA_VALID_FLAG(eadc, u32ModuleMask) (((eadc)->STATUS0 & EADC_STATUS0_VALID_Msk) & (u32ModuleMask))
  294. /**
  295. * @brief Get the double data of the user-specified sample module.
  296. * @param[in] eadc Base address of EADC module.
  297. * @param[in] u32ModuleNum Decides the sample module number, valid values are:
  298. * - \ref EADC0_SAMPLE_MODULE0 : EADC0 SAMPLE module 0
  299. * - \ref EADC0_SAMPLE_MODULE1 : EADC0 SAMPLE module 1
  300. * - \ref EADC0_SAMPLE_MODULE2 : EADC0 SAMPLE module 2
  301. * - \ref EADC0_SAMPLE_MODULE3 : EADC0 SAMPLE module 3
  302. * - \ref EADC1_SAMPLE_MODULE0 : EADC1 SAMPLE module 0
  303. * - \ref EADC1_SAMPLE_MODULE1 : EADC1 SAMPLE module 1
  304. * - \ref EADC1_SAMPLE_MODULE2 : EADC1 SAMPLE module 2
  305. * - \ref EADC1_SAMPLE_MODULE3 : EADC1 SAMPLE module 3
  306. * @return Return the double data of the user-specified sample module.
  307. * @details This macro is used to read RESULT bit (EADC_ADxDDATn[11:0], x=0~1, n=0~3) field to get conversion data.
  308. * \hideinitializer
  309. */
  310. #define EADC_GET_DOUBLE_DATA(eadc, u32ModuleNum) (*(__IO uint32_t *)(&((eadc)->AD0DDAT0) + (u32ModuleNum)) & EADC_AD0DDAT0_RESULT_Msk)
  311. /**
  312. * @brief Get the user-specified interrupt flags.
  313. * @param[in] eadc Base address of EADC module.
  314. * @param[in] u32Mask The combination of interrupt status bits. Each bit corresponds to a interrupt status.
  315. * Bit 0 is ADIF0, bit 1 is ADIF1..., bit 3 is ADIF3.
  316. * Bit 4 is ADCMPO0, bit 5 is ADCMPO1, bit 6 is ADCMPF0, bit 7 is ADCMPF1.
  317. * @return Return the user-specified interrupt flags.
  318. * @details This macro is used to get the user-specified interrupt flags.
  319. * \hideinitializer
  320. */
  321. #define EADC_GET_INT_FLAG(eadc, u32Mask) ((eadc)->STATUS1 & (u32Mask))
  322. /**
  323. * @brief Get the user-specified sample module overrun flags.
  324. * @param[in] eadc Base address of EADC module.
  325. * @param[in] u32ModuleMask The combination of sample module overrun status bits. Each bit corresponds to a sample module overrun status, valid range are between 1~0xFFFF.
  326. * @return Return the user-specified sample module overrun flags.
  327. * @details This macro is used to get the user-specified sample module overrun flags.
  328. * \hideinitializer
  329. */
  330. #define EADC_GET_SAMPLE_MODULE_OV_FLAG(eadc, u32ModuleMask) (((eadc)->STATUS0 >> EADC_STATUS0_OV_Pos) & u32ModuleMask)
  331. /**
  332. * @brief Clear the selected interrupt status bits.
  333. * @param[in] eadc Base address of EADC module.
  334. * @param[in] u32Mask The combination of compare interrupt status bits. Each bit corresponds to a compare interrupt status.
  335. * Bit 0 is ADIF0, bit 1 is ADIF1..., bit 3 is ADIF3.
  336. * Bit 4 is ADCMPO0, bit 5 is ADCMPO1, bit 6 is ADCMPF0, bit 7 is ADCMPF1.
  337. * @return None
  338. * @details This macro is used to clear clear the selected interrupt status bits.
  339. * \hideinitializer
  340. */
  341. #define EADC_CLR_INT_FLAG(eadc, u32Mask) ((eadc)->STATUS1 = (u32Mask))
  342. /**
  343. * @brief Check all sample module A/D result data register overrun flags.
  344. * @param[in] eadc Base address of EADC module.
  345. * @retval 0 None of sample module data register overrun flag is set to 1.
  346. * @retval 1 Any one of sample module data register overrun flag is set to 1.
  347. * @details The AOV bit (EADC_STATUS1[27]) will keep 1 when any one of sample module data register overrun flag OVn (EADC_ADxDATn[16]) is set to 1.
  348. * \hideinitializer
  349. */
  350. #define EADC_IS_DATA_OV(eadc) (((eadc)->STATUS1 & EADC_STATUS1_AOV_Msk) >> EADC_STATUS1_AOV_Pos)
  351. /**
  352. * @brief Check all sample module A/D result data register valid flags.
  353. * @param[in] eadc Base address of EADC module.
  354. * @retval 0 None of sample module data register valid flag is set to 1.
  355. * @retval 1 Any one of sample module data register valid flag is set to 1.
  356. * @details The AVALID bit (EADC_STATUS1[26]) will keep 1 when any one of sample module data register valid flag VALIDn (EADC_ADxDATn[17]) is set to 1.
  357. * \hideinitializer
  358. */
  359. #define EADC_IS_DATA_VALID(eadc) (((eadc)->STATUS1 & EADC_STATUS1_AVALID_Msk) >> EADC_STATUS1_AVALID_Pos)
  360. /**
  361. * @brief Check all A/D sample module start of conversion overrun flags.
  362. * @param[in] eadc Base address of EADC module.
  363. * @retval 0 None of sample module event overrun flag is set to 1.
  364. * @retval 1 Any one of sample module event overrun flag is set to 1.
  365. * @details The STOVF bit (EADC_STATUS1[25]) will keep 1 when any one of sample module event overrun flag SPOVFn (EADC_OVSTS[n]) is set to 1.
  366. * \hideinitializer
  367. */
  368. #define EADC_IS_SAMPLE_MODULE_OV(eadc) (((eadc)->STATUS1 & EADC_STATUS1_STOVF_Msk) >> EADC_STATUS1_STOVF_Pos)
  369. /**
  370. * @brief Check all A/D interrupt flag overrun bits.
  371. * @param[in] eadc Base address of EADC module.
  372. * @retval 0 None of ADINT interrupt flag is overwritten to 1.
  373. * @retval 1 Any one of ADINT interrupt flag is overwritten to 1.
  374. * @details The ADOVIF bit (EADC_STATUS1[24]) will keep 1 when any one of ADINT interrupt flag ADFOVn (EADC_ADIFOV[3:0]) is overwritten to 1.
  375. * \hideinitializer
  376. */
  377. #define EADC_IS_INT_FLAG_OV(eadc) (((eadc)->STATUS1 & EADC_STATUS1_ADOVIF_Msk) >> EADC_STATUS1_ADOVIF_Pos)
  378. /**
  379. * @brief Get the busy state of EADC.
  380. * @param[in] eadc Base address of EADC module.
  381. * @param[in] converter Which converter, it should be 0 or 1.
  382. * @retval 0 Idle state.
  383. * @retval 1 Busy state.
  384. * @details This macro is used to read BUSY0(EADC_STATUS1[8]) or BUSY1(EADC_STATUS1[16]) to get busy state.
  385. * \hideinitializer
  386. */
  387. #define EADC_IS_BUSY(eadc, converter) (((((eadc)->STATUS1 >> (EADC_STATUS1_BUSY0_Pos + (8 * converter)))) & EADC_STATUS1_BUSY0_Msk) )
  388. /**
  389. * @brief Configure the comparator 0 and enable it.
  390. * @param[in] eadc Base address of EADC module.
  391. * @param[in] u32ModuleNum specifies the compare sample module, valid values are:
  392. * - \ref CMP_EADC0_SAMPLE_MODULE0 : EADC0 SAMPLE module 0
  393. * - \ref CMP_EADC0_SAMPLE_MODULE1 : EADC0 SAMPLE module 1
  394. * - \ref CMP_EADC0_SAMPLE_MODULE2 : EADC0 SAMPLE module 2
  395. * - \ref CMP_EADC0_SAMPLE_MODULE3 : EADC0 SAMPLE module 3
  396. * - \ref CMP_EADC1_SAMPLE_MODULE0 : EADC1 SAMPLE module 0
  397. * - \ref CMP_EADC1_SAMPLE_MODULE1 : EADC1 SAMPLE module 1
  398. * - \ref CMP_EADC1_SAMPLE_MODULE2 : EADC1 SAMPLE module 2
  399. * - \ref CMP_EADC1_SAMPLE_MODULE3 : EADC1 SAMPLE module 3
  400. * @param[in] u32Condition specifies the compare condition. Valid values are:
  401. * - \ref EADC_CMP_CMPCOND_LESS_THAN :The compare condition is "less than the compare value"
  402. * - \ref EADC_CMP_CMPCOND_GREATER_OR_EQUAL :The compare condition is "greater than or equal to the compare value
  403. * @param[in] u16CMPData specifies the compare value, valid range are between 0~0xFFF.
  404. * @param[in] u32MatchCount specifies the match count setting, valid range are between 0~0xF.
  405. * @return None
  406. * @details For example, ADC_ENABLE_CMP0(EADC, 5, ADC_ADCMPR_CMPCOND_GREATER_OR_EQUAL, 0x800, 10, EADC_CMP_CMPWEN_DISABLE, EADC_CMP_ADCMPIE_ENABLE);
  407. * Means EADC will assert comparator 0 flag if sample module 5 conversion result is greater or
  408. * equal to 0x800 for 10 times continuously, and a compare interrupt request is generated.
  409. * \hideinitializer
  410. */
  411. #define EADC_ENABLE_CMP0(eadc,\
  412. u32ModuleNum,\
  413. u32Condition,\
  414. u16CMPData,\
  415. u32MatchCount) ((eadc)->CMP[0] |=(((u32ModuleNum) << EADC_CMP0_CMPSPL_Pos)|\
  416. (u32Condition) |\
  417. ((u16CMPData) << EADC_CMP0_CMPDAT_Pos)| \
  418. (((u32MatchCount) - 1) << EADC_CMP0_CMPMCNT_Pos)|\
  419. EADC_CMP0_ADCMPEN_Msk))
  420. /**
  421. * @brief Configure the comparator 1 and enable it.
  422. * @param[in] eadc Base address of EADC module.
  423. * @param[in] u32ModuleNum specifies the compare sample module, valid values are:
  424. * - \ref CMP_EADC0_SAMPLE_MODULE0 : EADC0 SAMPLE module 0
  425. * - \ref CMP_EADC0_SAMPLE_MODULE1 : EADC0 SAMPLE module 1
  426. * - \ref CMP_EADC0_SAMPLE_MODULE2 : EADC0 SAMPLE module 2
  427. * - \ref CMP_EADC0_SAMPLE_MODULE3 : EADC0 SAMPLE module 3
  428. * - \ref CMP_EADC1_SAMPLE_MODULE0 : EADC1 SAMPLE module 0
  429. * - \ref CMP_EADC1_SAMPLE_MODULE1 : EADC1 SAMPLE module 1
  430. * - \ref CMP_EADC1_SAMPLE_MODULE2 : EADC1 SAMPLE module 2
  431. * - \ref CMP_EADC1_SAMPLE_MODULE3 : EADC1 SAMPLE module 3
  432. * @param[in] u32Condition specifies the compare condition. Valid values are:
  433. * - \ref EADC_CMP_CMPCOND_LESS_THAN :The compare condition is "less than the compare value"
  434. * - \ref EADC_CMP_CMPCOND_GREATER_OR_EQUAL :The compare condition is "greater than or equal to the compare value
  435. * @param[in] u16CMPData specifies the compare value, valid range are between 0~0xFFF.
  436. * @param[in] u32MatchCount specifies the match count setting, valid range are between 0~0xF.
  437. * @return None
  438. * @details For example, ADC_ENABLE_CMP1(EADC, 5, ADC_ADCMPR_CMPCOND_GREATER_OR_EQUAL, 0x800, 10, EADC_CMP_ADCMPIE_ENABLE);
  439. * Means EADC will assert comparator 1 flag if sample module 5 conversion result is greater or
  440. * equal to 0x800 for 10 times continuously, and a compare interrupt request is generated.
  441. * \hideinitializer
  442. */
  443. #define EADC_ENABLE_CMP1(eadc,\
  444. u32ModuleNum,\
  445. u32Condition,\
  446. u16CMPData,\
  447. u32MatchCount) ((eadc)->CMP[1] |=(((u32ModuleNum) << EADC_CMP1_CMPSPL_Pos)|\
  448. (u32Condition) |\
  449. ((u16CMPData) << EADC_CMP1_CMPDAT_Pos)| \
  450. (((u32MatchCount) - 1) << EADC_CMP1_CMPMCNT_Pos)|\
  451. EADC_CMP1_ADCMPEN_Msk))
  452. /**
  453. * @brief Enable the compare interrupt.
  454. * @param[in] eadc Base address of EADC module.
  455. * @param[in] u32CMP Specifies the compare register, valid value are 0 and 1.
  456. * @return None
  457. * @details If the compare function is enabled and the compare condition matches the setting of CMPCOND (EADC_CMPn[2], n=0~1)
  458. * and CMPMCNT (EADC_CMPn[11:8], n=0~1), ADCMPFn (EADC_STATUS1[7:6], n=0~1) will be asserted, in the meanwhile,
  459. * if ADCMPIE is set to 1, a compare interrupt request is generated.
  460. * \hideinitializer
  461. */
  462. #define EADC_ENABLE_CMP_INT(eadc, u32CMP) ((eadc)->CMP[(u32CMP)] |= EADC_CMP0_ADCMPIE_Msk)
  463. /**
  464. * @brief Disable the compare interrupt.
  465. * @param[in] eadc Base address of EADC module.
  466. * @param[in] u32CMP Specifies the compare register, valid value are 0 and 1.
  467. * @return None
  468. * @details This macro is used to disable the compare interrupt.
  469. * \hideinitializer
  470. */
  471. #define EADC_DISABLE_CMP_INT(eadc, u32CMP) ((eadc)->CMP[(u32CMP)] &= ~EADC_CMP0_ADCMPIE_Msk)
  472. /**
  473. * @brief Disable comparator 0.
  474. * @param[in] eadc Base address of EADC module.
  475. * @return None
  476. * @details This macro is used to disable comparator 0.
  477. * \hideinitializer
  478. */
  479. #define EADC_DISABLE_CMP0(eadc) ((eadc)->CMP[0] = 0)
  480. /**
  481. * @brief Disable comparator 1.
  482. * @param[in] eadc Base address of EADC module.
  483. * @return None
  484. * @details This macro is used to disable comparator 1.
  485. * \hideinitializer
  486. */
  487. #define EADC_DISABLE_CMP1(eadc) ((eadc)->CMP[1] = 0)
  488. /**
  489. * @brief Enable simultaneous mode.
  490. * @param[in] eadc Base address of EADC module.
  491. * @param[in] u32ModuleMask The combination of sample module. Each bit corresponds to a sample module.
  492. * This parameter decides which sample module will be set to simultaneous mode, valid range are between 1~0xFF.
  493. * Bit 0 is sample module 0, bit 1 is sample module 1..., bit 7 is sample module 7.
  494. * @return None
  495. * @details This macro is used to set selected sample modules to be simultaneous mode.
  496. * \hideinitializer
  497. */
  498. #define EADC_ENABLE_SIMULTANEOUS(eadc,u32ModuleMask) ((eadc)->SIMUSEL |= (u32ModuleMask))
  499. /**
  500. * @brief Disable simultaneous mode.
  501. * @param[in] eadc Base address of EADC module.
  502. * @param[in] u32ModuleMask The combination of sample module. Each bit corresponds to a sample module.
  503. * This parameter decides which sample module will be set to disable simultaneous mode, valid range are between 1~0xFF.
  504. * Bit 0 is sample module 0, bit 1 is sample module 1..., bit 7 is sample module 7.
  505. * @return None
  506. * @details This macro is used to set selected sample modules to disable simultaneous mode.
  507. * \hideinitializer
  508. */
  509. #define EADC_DISABLE_SIMULTANEOUS(eadc,u32ModuleMask) ((eadc)->SIMUSEL &= ~(u32ModuleMask))
  510. /**
  511. * @brief Enable PWM and EPWM trigger trigger EADC condition.
  512. * @param[in] eadc Base address of EADC module.
  513. * @param[in] u32ADTriggerModuleNum Decides the sample module number, valid values are:
  514. * - \ref EADC0_TRIGGEREN0 : AD trigger condition for SAMPLE00
  515. * - \ref EADC0_TRIGGEREN1 : AD trigger condition for SAMPLE01
  516. * - \ref EADC0_TRIGGEREN2 : AD trigger condition for SAMPLE02
  517. * - \ref EADC0_TRIGGEREN3 : AD trigger condition for SAMPLE03
  518. * - \ref EADC1_TRIGGEREN0 : AD trigger condition for SAMPLE10
  519. * - \ref EADC1_TRIGGEREN1 : AD trigger condition for SAMPLE11
  520. * - \ref EADC1_TRIGGEREN2 : AD trigger condition for SAMPLE12
  521. * - \ref EADC1_TRIGGEREN3 : AD trigger condition for SAMPLE13
  522. * @param[in] u32TriggerMask Decides the PWM and EPWM trigger EADC condition, valid range are between 0~0xFFFFFFFF.
  523. * @return None
  524. * @details This macro is used to enable PWM and EPWM trigger EADC condition.
  525. */
  526. #define EADC_EnablePWMTriggerCondition(eadc,u32ADTriggerModuleNum,u32TriggerMask) (*(__IO uint32_t *)(&(eadc)->AD0TRGEN0 + (u32ADTriggerModuleNum)) |= (u32TriggerMask))
  527. /**
  528. * @brief Disable PWM and EPWM trigger trigger EADC condition.
  529. * @param[in] eadc Base address of EADC module.
  530. * @param[in] u32ADTriggerModuleNum Decides the sample module number, valid values are:
  531. * - \ref EADC0_TRIGGEREN0 : AD trigger condition for SAMPLE00
  532. * - \ref EADC0_TRIGGEREN1 : AD trigger condition for SAMPLE01
  533. * - \ref EADC0_TRIGGEREN2 : AD trigger condition for SAMPLE02
  534. * - \ref EADC0_TRIGGEREN3 : AD trigger condition for SAMPLE03
  535. * - \ref EADC1_TRIGGEREN0 : AD trigger condition for SAMPLE10
  536. * - \ref EADC1_TRIGGEREN1 : AD trigger condition for SAMPLE11
  537. * - \ref EADC1_TRIGGEREN2 : AD trigger condition for SAMPLE12
  538. * - \ref EADC1_TRIGGEREN3 : AD trigger condition for SAMPLE13
  539. * @param[in] u32TriggerMask Decides the PWM and EPWM trigger EADC condition, valid range are between 0~0xFFFFFFFF.
  540. * @return None
  541. * @details This macro is used to disable PWM and EPWM trigger EADC condition.
  542. */
  543. #define EADC_DisablePWMTriggerCondition(eadc,u32ADTriggerModuleNum,u32TriggerMask) (*(__IO uint32_t *)(&(eadc)->AD0TRGEN0 + (u32ADTriggerModuleNum)) |= (u32TriggerMask))
  544. /*---------------------------------------------------------------------------------------------------------*/
  545. /* Define EADC functions prototype */
  546. /*---------------------------------------------------------------------------------------------------------*/
  547. void EADC_Open(EADC_T *eadc, uint32_t u32InputMode);
  548. void EADC_Close(EADC_T *eadc);
  549. void EADC_ConfigSampleModule(EADC_T *eadc, \
  550. uint32_t u32ModuleNum, \
  551. uint32_t u32TriggerSource, \
  552. uint32_t u32Channel);
  553. void EADC_SetTriggerDelayTime(EADC_T *eadc, \
  554. uint32_t u32ModuleNum, \
  555. uint32_t u32TriggerDelayTime, \
  556. uint32_t u32DelayClockDivider);
  557. void EADC_SetExtendSampleTime(EADC_T *eadc, uint32_t u32ModuleNum, uint32_t u32ExtendSampleTime);
  558. /*@}*/ /* end of group NUC472_442_EADC_EXPORTED_FUNCTIONS */
  559. /*@}*/ /* end of group NUC472_442_EADC_Driver */
  560. /*@}*/ /* end of group NUC472_442_Device_Driver */
  561. #ifdef __cplusplus
  562. }
  563. #endif
  564. #endif //__EADC_H__
  565. /*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/