eadc.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /**************************************************************************//**
  2. * @file eadc.h
  3. * @version V0.10
  4. * @brief M480 series EADC driver header file
  5. *
  6. * @copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.
  7. *****************************************************************************/
  8. #ifndef __EADC_H__
  9. #define __EADC_H__
  10. #ifdef __cplusplus
  11. extern "C"
  12. {
  13. #endif
  14. /** @addtogroup Standard_Driver Standard Driver
  15. @{
  16. */
  17. /** @addtogroup EADC_Driver EADC Driver
  18. @{
  19. */
  20. /** @addtogroup EADC_EXPORTED_CONSTANTS EADC Exported Constants
  21. @{
  22. */
  23. /*---------------------------------------------------------------------------------------------------------*/
  24. /* EADC_CTL Constant Definitions */
  25. /*---------------------------------------------------------------------------------------------------------*/
  26. #define EADC_CTL_DIFFEN_SINGLE_END (0UL<<EADC_CTL_DIFFEN_Pos) /*!< Single-end input mode \hideinitializer */
  27. #define EADC_CTL_DIFFEN_DIFFERENTIAL (1UL<<EADC_CTL_DIFFEN_Pos) /*!< Differential input mode \hideinitializer */
  28. #define EADC_CTL_DMOF_STRAIGHT_BINARY (0UL<<EADC_CTL_DMOF_Pos) /*!< Select the straight binary format as the output format of the conversion result \hideinitializer */
  29. #define EADC_CTL_DMOF_TWOS_COMPLEMENT (1UL<<EADC_CTL_DMOF_Pos) /*!< Select the 2's complement format as the output format of the conversion result \hideinitializer */
  30. /*---------------------------------------------------------------------------------------------------------*/
  31. /* EADC_SCTL Constant Definitions */
  32. /*---------------------------------------------------------------------------------------------------------*/
  33. #define EADC_SCTL_CHSEL(x) ((x) << EADC_SCTL_CHSEL_Pos) /*!< A/D sample module channel selection \hideinitializer */
  34. #define EADC_SCTL_TRGDLYDIV(x) ((x) << EADC_SCTL_TRGDLYDIV_Pos) /*!< A/D sample module start of conversion trigger delay clock divider selection \hideinitializer */
  35. #define EADC_SCTL_TRGDLYCNT(x) ((x) << EADC_SCTL_TRGDLYCNT_Pos) /*!< A/D sample module start of conversion trigger delay time \hideinitializer */
  36. #define EADC_SOFTWARE_TRIGGER (0UL<<EADC_SCTL_TRGSEL_Pos) /*!< Software trigger \hideinitializer */
  37. #define EADC_FALLING_EDGE_TRIGGER (EADC_SCTL_EXTFEN_Msk | (1UL<<EADC_SCTL_TRGSEL_Pos)) /*!< STADC pin falling edge trigger \hideinitializer */
  38. #define EADC_RISING_EDGE_TRIGGER (EADC_SCTL_EXTREN_Msk | (1UL<<EADC_SCTL_TRGSEL_Pos)) /*!< STADC pin rising edge trigger \hideinitializer */
  39. #define EADC_FALLING_RISING_EDGE_TRIGGER (EADC_SCTL_EXTFEN_Msk | EADC_SCTL_EXTREN_Msk | (1UL<<EADC_SCTL_TRGSEL_Pos)) /*!< STADC pin both falling and rising edge trigger \hideinitializer */
  40. #define EADC_ADINT0_TRIGGER (2UL<<EADC_SCTL_TRGSEL_Pos) /*!< ADC ADINT0 interrupt EOC pulse trigger \hideinitializer */
  41. #define EADC_ADINT1_TRIGGER (3UL<<EADC_SCTL_TRGSEL_Pos) /*!< ADC ADINT1 interrupt EOC pulse trigger \hideinitializer */
  42. #define EADC_TIMER0_TRIGGER (4UL<<EADC_SCTL_TRGSEL_Pos) /*!< Timer0 overflow pulse trigger \hideinitializer */
  43. #define EADC_TIMER1_TRIGGER (5UL<<EADC_SCTL_TRGSEL_Pos) /*!< Timer1 overflow pulse trigger \hideinitializer */
  44. #define EADC_TIMER2_TRIGGER (6UL<<EADC_SCTL_TRGSEL_Pos) /*!< Timer2 overflow pulse trigger \hideinitializer */
  45. #define EADC_TIMER3_TRIGGER (7UL<<EADC_SCTL_TRGSEL_Pos) /*!< Timer3 overflow pulse trigger \hideinitializer */
  46. #define EADC_PWM0TG0_TRIGGER (8UL<<EADC_SCTL_TRGSEL_Pos) /*!< PWM0TG0 trigger \hideinitializer */
  47. #define EADC_PWM0TG1_TRIGGER (9UL<<EADC_SCTL_TRGSEL_Pos) /*!< PWM0TG1 trigger \hideinitializer */
  48. #define EADC_PWM0TG2_TRIGGER (0xAUL<<EADC_SCTL_TRGSEL_Pos) /*!< PWM0TG2 trigger \hideinitializer */
  49. #define EADC_PWM0TG3_TRIGGER (0xBUL<<EADC_SCTL_TRGSEL_Pos) /*!< PWM0TG3 trigger \hideinitializer */
  50. #define EADC_PWM0TG4_TRIGGER (0xCUL<<EADC_SCTL_TRGSEL_Pos) /*!< PWM0TG4 trigger \hideinitializer */
  51. #define EADC_PWM0TG5_TRIGGER (0xDUL<<EADC_SCTL_TRGSEL_Pos) /*!< PWM0TG5 trigger \hideinitializer */
  52. #define EADC_PWM1TG0_TRIGGER (0xEUL<<EADC_SCTL_TRGSEL_Pos) /*!< PWM1TG0 trigger \hideinitializer */
  53. #define EADC_PWM1TG1_TRIGGER (0xFUL<<EADC_SCTL_TRGSEL_Pos) /*!< PWM1TG1 trigger \hideinitializer */
  54. #define EADC_PWM1TG2_TRIGGER (0x10UL<<EADC_SCTL_TRGSEL_Pos) /*!< PWM1TG2 trigger \hideinitializer */
  55. #define EADC_PWM1TG3_TRIGGER (0x11UL<<EADC_SCTL_TRGSEL_Pos) /*!< PWM1TG3 trigger \hideinitializer */
  56. #define EADC_PWM1TG4_TRIGGER (0x12UL<<EADC_SCTL_TRGSEL_Pos) /*!< PWM1TG4 trigger \hideinitializer */
  57. #define EADC_PWM1TG5_TRIGGER (0x13UL<<EADC_SCTL_TRGSEL_Pos) /*!< PWM1TG5 trigger \hideinitializer */
  58. #define EADC_SCTL_TRGDLYDIV_DIVIDER_1 (0<<EADC_SCTL_TRGDLYDIV_Pos) /*!< Trigger delay clock frequency is ADC_CLK/1 \hideinitializer */
  59. #define EADC_SCTL_TRGDLYDIV_DIVIDER_2 (0x1UL<<EADC_SCTL_TRGDLYDIV_Pos) /*!< Trigger delay clock frequency is ADC_CLK/2 \hideinitializer */
  60. #define EADC_SCTL_TRGDLYDIV_DIVIDER_4 (0x2UL<<EADC_SCTL_TRGDLYDIV_Pos) /*!< Trigger delay clock frequency is ADC_CLK/4 \hideinitializer */
  61. #define EADC_SCTL_TRGDLYDIV_DIVIDER_16 (0x3UL<<EADC_SCTL_TRGDLYDIV_Pos) /*!< Trigger delay clock frequency is ADC_CLK/16 \hideinitializer */
  62. /*---------------------------------------------------------------------------------------------------------*/
  63. /* EADC_CMP Constant Definitions */
  64. /*---------------------------------------------------------------------------------------------------------*/
  65. #define EADC_CMP_CMPCOND_LESS_THAN (0UL<<EADC_CMP_CMPCOND_Pos) /*!< The compare condition is "less than" \hideinitializer */
  66. #define EADC_CMP_CMPCOND_GREATER_OR_EQUAL (1UL<<EADC_CMP_CMPCOND_Pos) /*!< The compare condition is "greater than or equal to" \hideinitializer */
  67. #define EADC_CMP_CMPWEN_ENABLE (EADC_CMP_CMPWEN_Msk) /*!< Compare window mode enable \hideinitializer */
  68. #define EADC_CMP_CMPWEN_DISABLE (~EADC_CMP_CMPWEN_Msk) /*!< Compare window mode disable \hideinitializer */
  69. #define EADC_CMP_ADCMPIE_ENABLE (EADC_CMP_ADCMPIE_Msk) /*!< A/D result compare interrupt enable \hideinitializer */
  70. #define EADC_CMP_ADCMPIE_DISABLE (~EADC_CMP_ADCMPIE_Msk) /*!< A/D result compare interrupt disable \hideinitializer */
  71. /*@}*/ /* end of group EADC_EXPORTED_CONSTANTS */
  72. /** @addtogroup EADC_EXPORTED_FUNCTIONS EADC Exported Functions
  73. @{
  74. */
  75. /*---------------------------------------------------------------------------------------------------------*/
  76. /* EADC Macro Definitions */
  77. /*---------------------------------------------------------------------------------------------------------*/
  78. /**
  79. * @brief A/D Converter Control Circuits Reset.
  80. * @param[in] eadc The pointer of the specified EADC module.
  81. * @return None
  82. * @details ADCRST bit (EADC_CT[1]) remains 1 during ADC reset, when ADC reset end, the ADCRST bit is automatically cleared to 0.
  83. * \hideinitializer
  84. */
  85. #define EADC_CONV_RESET(eadc) ((eadc)->CTL |= EADC_CTL_ADCRST_Msk)
  86. /**
  87. * @brief Enable PDMA transfer.
  88. * @param[in] eadc The pointer of the specified EADC module.
  89. * @return None
  90. * @details When A/D conversion is completed, the converted data is loaded into EADC_DATn (n: 0 ~ 18) register,
  91. * user can enable this bit to generate a PDMA data transfer request.
  92. * @note When set PDMAEN bit (EADC_CTL[11]), user must set ADINTENn (EADC_CTL[5:2], n=0~3) = 0 to disable interrupt.
  93. * \hideinitializer
  94. */
  95. #define EADC_ENABLE_PDMA(eadc) ((eadc)->CTL |= EADC_CTL_PDMAEN_Msk)
  96. /**
  97. * @brief Disable PDMA transfer.
  98. * @param[in] eadc The pointer of the specified EADC module.
  99. * @return None
  100. * @details This macro is used to disable PDMA transfer.
  101. * \hideinitializer
  102. */
  103. #define EADC_DISABLE_PDMA(eadc) ((eadc)->CTL &= (~EADC_CTL_PDMAEN_Msk))
  104. /**
  105. * @brief Enable double buffer mode.
  106. * @param[in] eadc The pointer of the specified EADC module.
  107. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 3.
  108. * @return None
  109. * @details The ADC controller supports a double buffer mode in sample module 0~3.
  110. * If user enable DBMEN (EADC_SCTLn[23], n=0~3), the double buffer mode will enable.
  111. * \hideinitializer
  112. */
  113. #define EADC_ENABLE_DOUBLE_BUFFER(eadc, u32ModuleNum) ((eadc)->SCTL[(u32ModuleNum)] |= EADC_SCTL_DBMEN_Msk)
  114. /**
  115. * @brief Disable double buffer mode.
  116. * @param[in] eadc The pointer of the specified EADC module.
  117. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 3.
  118. * @return None
  119. * @details Sample has one sample result register.
  120. * \hideinitializer
  121. */
  122. #define EADC_DISABLE_DOUBLE_BUFFER(eadc, u32ModuleNum) ((eadc)->SCTL[(u32ModuleNum)] &= ~EADC_SCTL_DBMEN_Msk)
  123. /**
  124. * @brief Set ADIFn at A/D end of conversion.
  125. * @param[in] eadc The pointer of the specified EADC module.
  126. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 15.
  127. * @return None
  128. * @details The A/D converter generates ADIFn (EADC_STATUS2[3:0], n=0~3) at the start of conversion.
  129. * \hideinitializer
  130. */
  131. #define EADC_ENABLE_INT_POSITION(eadc, u32ModuleNum) ((eadc)->SCTL[(u32ModuleNum)] |= EADC_SCTL_INTPOS_Msk)
  132. /**
  133. * @brief Set ADIFn at A/D start of conversion.
  134. * @param[in] eadc The pointer of the specified EADC module.
  135. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 15.
  136. * @return None
  137. * @details The A/D converter generates ADIFn (EADC_STATUS2[3:0], n=0~3) at the end of conversion.
  138. * \hideinitializer
  139. */
  140. #define EADC_DISABLE_INT_POSITION(eadc, u32ModuleNum) ((eadc)->SCTL[(u32ModuleNum)] &= ~EADC_SCTL_INTPOS_Msk)
  141. /**
  142. * @brief Enable the interrupt.
  143. * @param[in] eadc The pointer of the specified EADC module.
  144. * @param[in] u32Mask Decides the combination of interrupt status bits. Each bit corresponds to a interrupt status.
  145. * This parameter decides which interrupts will be enabled. Bit 0 is ADCIEN0, bit 1 is ADCIEN1..., bit 3 is ADCIEN3.
  146. * @return None
  147. * @details The A/D converter generates a conversion end ADIFn (EADC_STATUS2[n]) upon the end of specific sample module A/D conversion.
  148. * If ADCIENn bit (EADC_CTL[n+2]) is set then conversion end interrupt request ADINTn is generated (n=0~3).
  149. * \hideinitializer
  150. */
  151. #define EADC_ENABLE_INT(eadc, u32Mask) ((eadc)->CTL |= ((u32Mask) << EADC_CTL_ADCIEN0_Pos))
  152. /**
  153. * @brief Disable the interrupt.
  154. * @param[in] eadc The pointer of the specified EADC module.
  155. * @param[in] u32Mask Decides the combination of interrupt status bits. Each bit corresponds to a interrupt status.
  156. * This parameter decides which interrupts will be disabled. Bit 0 is ADCIEN0, bit 1 is ADCIEN1..., bit 3 is ADCIEN3.
  157. * @return None
  158. * @details Specific sample module A/D ADINT0 interrupt function Disabled.
  159. * \hideinitializer
  160. */
  161. #define EADC_DISABLE_INT(eadc, u32Mask) ((eadc)->CTL &= ~((u32Mask) << EADC_CTL_ADCIEN0_Pos))
  162. /**
  163. * @brief Enable the sample module interrupt.
  164. * @param[in] eadc The pointer of the specified EADC module.
  165. * @param[in] u32IntSel Decides which interrupt source will be used, valid value are from 0 to 3.
  166. * @param[in] u32ModuleMask the combination of sample module interrupt status bits. Each bit corresponds to a sample module interrupt status.
  167. * This parameter decides which sample module interrupts will be enabled, valid range are between 1~0x7FFFF.
  168. * @return None
  169. * @details There are 4 ADC interrupts ADINT0~3, and each of these interrupts has its own interrupt vector address.
  170. * \hideinitializer
  171. */
  172. #define EADC_ENABLE_SAMPLE_MODULE_INT(eadc, u32IntSel, u32ModuleMask) ((eadc)->INTSRC[(u32IntSel)] |= (u32ModuleMask))
  173. /**
  174. * @brief Disable the sample module interrupt.
  175. * @param[in] eadc The pointer of the specified EADC module.
  176. * @param[in] u32IntSel Decides which interrupt source will be used, valid value are from 0 to 3.
  177. * @param[in] u32ModuleMask the combination of sample module interrupt status bits. Each bit corresponds to a sample module interrupt status.
  178. * This parameter decides which sample module interrupts will be disabled, valid range are between 1~0x7FFFF.
  179. * @return None
  180. * @details There are 4 ADC interrupts ADINT0~3, and each of these interrupts has its own interrupt vector address.
  181. * \hideinitializer
  182. */
  183. #define EADC_DISABLE_SAMPLE_MODULE_INT(eadc, u32IntSel, u32ModuleMask) ((eadc)->INTSRC[(u32IntSel)] &= ~(u32ModuleMask))
  184. /**
  185. * @brief Set the input mode output format.
  186. * @param[in] eadc The pointer of the specified EADC module.
  187. * @param[in] u32Format Decides the output format. Valid values are:
  188. * - EADC_CTL_DMOF_STRAIGHT_BINARY :Select the straight binary format as the output format of the conversion result.
  189. * - EADC_CTL_DMOF_TWOS_COMPLEMENT :Select the 2's complement format as the output format of the conversion result.
  190. * @return None
  191. * @details The macro is used to set A/D input mode output format.
  192. * \hideinitializer
  193. */
  194. #define EADC_SET_DMOF(eadc, u32Format) ((eadc)->CTL = ((eadc)->CTL & ~EADC_CTL_DMOF_Msk) | (u32Format))
  195. /**
  196. * @brief Start the A/D conversion.
  197. * @param[in] eadc The pointer of the specified EADC module.
  198. * @param[in] u32ModuleMask The combination of sample module. Each bit corresponds to a sample module.
  199. * This parameter decides which sample module will be conversion, valid range are between 1~0x7FFFF.
  200. * Bit 0 is sample module 0, bit 1 is sample module 1..., bit 18 is sample module 18.
  201. * @return None
  202. * @details After write EADC_SWTRG register to start ADC conversion, the EADC_PENDSTS register will show which SAMPLE will conversion.
  203. * \hideinitializer
  204. */
  205. #define EADC_START_CONV(eadc, u32ModuleMask) ((eadc)->SWTRG = (u32ModuleMask))
  206. /**
  207. * @brief Cancel the conversion for sample module.
  208. * @param[in] eadc The pointer of the specified EADC module.
  209. * @param[in] u32ModuleMask The combination of sample module. Each bit corresponds to a sample module.
  210. * This parameter decides which sample module will stop the conversion, valid range are between 1~0x7FFFF.
  211. * Bit 0 is sample module 0, bit 1 is sample module 1..., bit 18 is sample module18.
  212. * @return None
  213. * @details If user want to disable the conversion of the sample module, user can write EADC_PENDSTS register to clear it.
  214. * \hideinitializer
  215. */
  216. #define EADC_STOP_CONV(eadc, u32ModuleMask) ((eadc)->PENDSTS = (u32ModuleMask))
  217. /**
  218. * @brief Get the conversion pending flag.
  219. * @param[in] eadc The pointer of the specified EADC module.
  220. * @return Return the conversion pending sample module.
  221. * @details This STPFn(EADC_PENDSTS[18:0]) bit remains 1 during pending state, when the respective ADC conversion is end,
  222. * the STPFn (n=0~18) bit is automatically cleared to 0.
  223. * \hideinitializer
  224. */
  225. #define EADC_GET_PENDING_CONV(eadc) ((eadc)->PENDSTS)
  226. /**
  227. * @brief Get the conversion data of the user-specified sample module.
  228. * @param[in] eadc The pointer of the specified EADC module.
  229. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 18.
  230. * @return Return the conversion data of the user-specified sample module.
  231. * @details This macro is used to read RESULT bit (EADC_DATn[15:0], n=0~18) field to get conversion data.
  232. * \hideinitializer
  233. */
  234. #define EADC_GET_CONV_DATA(eadc, u32ModuleNum) ((eadc)->DAT[(u32ModuleNum)] & EADC_DAT_RESULT_Msk)
  235. /**
  236. * @brief Get the data overrun flag of the user-specified sample module.
  237. * @param[in] eadc The pointer of the specified EADC module.
  238. * @param[in] u32ModuleMask The combination of data overrun status bits. Each bit corresponds to a data overrun status, valid range are between 1~0x7FFFF.
  239. * @return Return the data overrun flag of the user-specified sample module.
  240. * @details This macro is used to read OV bit (EADC_STATUS0[31:16], EADC_STATUS1[18:16]) field to get data overrun status.
  241. * \hideinitializer
  242. */
  243. #define EADC_GET_DATA_OVERRUN_FLAG(eadc, u32ModuleMask) ((((eadc)->STATUS0 >> EADC_STATUS0_OV_Pos) | ((eadc)->STATUS1 & EADC_STATUS1_OV_Msk)) & (u32ModuleMask))
  244. /**
  245. * @brief Get the data valid flag of the user-specified sample module.
  246. * @param[in] eadc The pointer of the specified EADC module.
  247. * @param[in] u32ModuleMask The combination of data valid status bits. Each bit corresponds to a data valid status, valid range are between 1~0x7FFFF.
  248. * @return Return the data valid flag of the user-specified sample module.
  249. * @details This macro is used to read VALID bit (EADC_STATUS0[15:0], EADC_STATUS1[2:0]) field to get data valid status.
  250. * \hideinitializer
  251. */
  252. #define EADC_GET_DATA_VALID_FLAG(eadc, u32ModuleMask) ((((eadc)->STATUS0 & EADC_STATUS0_VALID_Msk) | (((eadc)->STATUS1 & EADC_STATUS1_VALID_Msk) << 16)) & (u32ModuleMask))
  253. /**
  254. * @brief Get the double data of the user-specified sample module.
  255. * @param[in] eadc The pointer of the specified EADC module.
  256. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 18.
  257. * @return Return the double data of the user-specified sample module.
  258. * @details This macro is used to read RESULT bit (EADC_DDATn[15:0], n=0~3) field to get conversion data.
  259. * \hideinitializer
  260. */
  261. #define EADC_GET_DOUBLE_DATA(eadc, u32ModuleNum) ((eadc)->DDAT[(u32ModuleNum)] & EADC_DDAT0_RESULT_Msk)
  262. /**
  263. * @brief Get the user-specified interrupt flags.
  264. * @param[in] eadc The pointer of the specified EADC module.
  265. * @param[in] u32Mask The combination of interrupt status bits. Each bit corresponds to a interrupt status.
  266. * Bit 0 is ADIF0, bit 1 is ADIF1..., bit 3 is ADIF3.
  267. * Bit 4 is ADCMPF0, bit 5 is ADCMPF1..., bit 7 is ADCMPF3.
  268. * @return Return the user-specified interrupt flags.
  269. * @details This macro is used to get the user-specified interrupt flags.
  270. * \hideinitializer
  271. */
  272. #define EADC_GET_INT_FLAG(eadc, u32Mask) ((eadc)->STATUS2 & (u32Mask))
  273. /**
  274. * @brief Get the user-specified sample module overrun flags.
  275. * @param[in] eadc The pointer of the specified EADC module.
  276. * @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~0x7FFFF.
  277. * @return Return the user-specified sample module overrun flags.
  278. * @details This macro is used to get the user-specified sample module overrun flags.
  279. * \hideinitializer
  280. */
  281. #define EADC_GET_SAMPLE_MODULE_OV_FLAG(eadc, u32ModuleMask) ((eadc)->OVSTS & (u32ModuleMask))
  282. /**
  283. * @brief Clear the selected interrupt status bits.
  284. * @param[in] eadc The pointer of the specified EADC module.
  285. * @param[in] u32Mask The combination of compare interrupt status bits. Each bit corresponds to a compare interrupt status.
  286. * Bit 0 is ADIF0, bit 1 is ADIF1..., bit 3 is ADIF3.
  287. * Bit 4 is ADCMPF0, bit 5 is ADCMPF1..., bit 7 is ADCMPF3.
  288. * @return None
  289. * @details This macro is used to clear clear the selected interrupt status bits.
  290. * \hideinitializer
  291. */
  292. #define EADC_CLR_INT_FLAG(eadc, u32Mask) ((eadc)->STATUS2 = (u32Mask))
  293. /**
  294. * @brief Clear the selected sample module overrun status bits.
  295. * @param[in] eadc The pointer of the specified EADC module.
  296. * @param[in] u32ModuleMask The combination of sample module overrun status bits. Each bit corresponds to a sample module overrun status.
  297. * Bit 0 is SPOVF0, bit 1 is SPOVF1..., bit 18 is SPOVF18.
  298. * @return None
  299. * @details This macro is used to clear the selected sample module overrun status bits.
  300. * \hideinitializer
  301. */
  302. #define EADC_CLR_SAMPLE_MODULE_OV_FLAG(eadc, u32ModuleMask) ((eadc)->OVSTS = (u32ModuleMask))
  303. /**
  304. * @brief Check all sample module A/D result data register overrun flags.
  305. * @param[in] eadc The pointer of the specified EADC module.
  306. * @retval 0 None of sample module data register overrun flag is set to 1.
  307. * @retval 1 Any one of sample module data register overrun flag is set to 1.
  308. * @details The AOV bit (EADC_STATUS2[27]) will keep 1 when any one of sample module data register overrun flag OVn (EADC_DATn[16]) is set to 1.
  309. * \hideinitializer
  310. */
  311. #define EADC_IS_DATA_OV(eadc) (((eadc)->STATUS2 & EADC_STATUS2_AOV_Msk) >> EADC_STATUS2_AOV_Pos)
  312. /**
  313. * @brief Check all sample module A/D result data register valid flags.
  314. * @param[in] eadc The pointer of the specified EADC module.
  315. * @retval 0 None of sample module data register valid flag is set to 1.
  316. * @retval 1 Any one of sample module data register valid flag is set to 1.
  317. * @details The AVALID bit (EADC_STATUS2[26]) will keep 1 when any one of sample module data register valid flag VALIDn (EADC_DATn[17]) is set to 1.
  318. * \hideinitializer
  319. */
  320. #define EADC_IS_DATA_VALID(eadc) (((eadc)->STATUS2 & EADC_STATUS2_AVALID_Msk) >> EADC_STATUS2_AVALID_Pos)
  321. /**
  322. * @brief Check all A/D sample module start of conversion overrun flags.
  323. * @param[in] eadc The pointer of the specified EADC module.
  324. * @retval 0 None of sample module event overrun flag is set to 1.
  325. * @retval 1 Any one of sample module event overrun flag is set to 1.
  326. * @details The STOVF bit (EADC_STATUS2[25]) will keep 1 when any one of sample module event overrun flag SPOVFn (EADC_OVSTS[n]) is set to 1.
  327. * \hideinitializer
  328. */
  329. #define EADC_IS_SAMPLE_MODULE_OV(eadc) (((eadc)->STATUS2 & EADC_STATUS2_STOVF_Msk) >> EADC_STATUS2_STOVF_Pos)
  330. /**
  331. * @brief Check all A/D interrupt flag overrun bits.
  332. * @param[in] eadc The pointer of the specified EADC module.
  333. * @retval 0 None of ADINT interrupt flag is overwritten to 1.
  334. * @retval 1 Any one of ADINT interrupt flag is overwritten to 1.
  335. * @details The ADOVIF bit (EADC_STATUS2[24]) will keep 1 when any one of ADINT interrupt flag ADOVIFn (EADC_STATUS2[11:8]) is overwritten to 1.
  336. * \hideinitializer
  337. */
  338. #define EADC_IS_INT_FLAG_OV(eadc) (((eadc)->STATUS2 & EADC_STATUS2_ADOVIF_Msk) >> EADC_STATUS2_ADOVIF_Pos)
  339. /**
  340. * @brief Get the busy state of EADC.
  341. * @param[in] eadc The pointer of the specified EADC module.
  342. * @retval 0 Idle state.
  343. * @retval 1 Busy state.
  344. * @details This macro is used to read BUSY bit (EADC_STATUS2[23]) to get busy state.
  345. * \hideinitializer
  346. */
  347. #define EADC_IS_BUSY(eadc) (((eadc)->STATUS2 & EADC_STATUS2_BUSY_Msk) >> EADC_STATUS2_BUSY_Pos)
  348. /**
  349. * @brief Configure the comparator 0 and enable it.
  350. * @param[in] eadc The pointer of the specified EADC module.
  351. * @param[in] u32ModuleNum specifies the compare sample module, valid value are from 0 to 18.
  352. * @param[in] u32Condition specifies the compare condition. Valid values are:
  353. * - \ref EADC_CMP_CMPCOND_LESS_THAN :The compare condition is "less than the compare value"
  354. * - \ref EADC_CMP_CMPCOND_GREATER_OR_EQUAL :The compare condition is "greater than or equal to the compare value
  355. * @param[in] u16CMPData specifies the compare value, valid range are between 0~0xFFF.
  356. * @param[in] u32MatchCount specifies the match count setting, valid range are between 0~0xF.
  357. * @return None
  358. * @details For example, ADC_ENABLE_CMP0(EADC, 5, ADC_ADCMPR_CMPCOND_GREATER_OR_EQUAL, 0x800, 10, EADC_CMP_CMPWEN_DISABLE, EADC_CMP_ADCMPIE_ENABLE);
  359. * Means EADC will assert comparator 0 flag if sample module 5 conversion result is greater or
  360. * equal to 0x800 for 10 times continuously, and a compare interrupt request is generated.
  361. * \hideinitializer
  362. */
  363. #define EADC_ENABLE_CMP0(eadc,\
  364. u32ModuleNum,\
  365. u32Condition,\
  366. u16CMPData,\
  367. u32MatchCount) ((eadc)->CMP[0] |=(((u32ModuleNum) << EADC_CMP_CMPSPL_Pos)|\
  368. (u32Condition) |\
  369. ((u16CMPData) << EADC_CMP_CMPDAT_Pos)| \
  370. (((u32MatchCount) - 1) << EADC_CMP_CMPMCNT_Pos)|\
  371. EADC_CMP_ADCMPEN_Msk))
  372. /**
  373. * @brief Configure the comparator 1 and enable it.
  374. * @param[in] eadc The pointer of the specified EADC module.
  375. * @param[in] u32ModuleNum specifies the compare sample module, valid value are from 0 to 18.
  376. * @param[in] u32Condition specifies the compare condition. Valid values are:
  377. * - \ref EADC_CMP_CMPCOND_LESS_THAN :The compare condition is "less than the compare value"
  378. * - \ref EADC_CMP_CMPCOND_GREATER_OR_EQUAL :The compare condition is "greater than or equal to the compare value
  379. * @param[in] u16CMPData specifies the compare value, valid range are between 0~0xFFF.
  380. * @param[in] u32MatchCount specifies the match count setting, valid range are between 0~0xF.
  381. * @return None
  382. * @details For example, ADC_ENABLE_CMP1(EADC, 5, ADC_ADCMPR_CMPCOND_GREATER_OR_EQUAL, 0x800, 10, EADC_CMP_ADCMPIE_ENABLE);
  383. * Means EADC will assert comparator 1 flag if sample module 5 conversion result is greater or
  384. * equal to 0x800 for 10 times continuously, and a compare interrupt request is generated.
  385. * \hideinitializer
  386. */
  387. #define EADC_ENABLE_CMP1(eadc,\
  388. u32ModuleNum,\
  389. u32Condition,\
  390. u16CMPData,\
  391. u32MatchCount) ((eadc)->CMP[1] |=(((u32ModuleNum) << EADC_CMP_CMPSPL_Pos)|\
  392. (u32Condition) |\
  393. ((u16CMPData) << EADC_CMP_CMPDAT_Pos)| \
  394. (((u32MatchCount) - 1) << EADC_CMP_CMPMCNT_Pos)|\
  395. EADC_CMP_ADCMPEN_Msk))
  396. /**
  397. * @brief Configure the comparator 2 and enable it.
  398. * @param[in] eadc The pointer of the specified EADC module.
  399. * @param[in] u32ModuleNum specifies the compare sample module, valid value are from 0 to 18.
  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_CMP2(EADC, 5, ADC_ADCMPR_CMPCOND_GREATER_OR_EQUAL, 0x800, 10, EADC_CMP_CMPWEN_DISABLE, EADC_CMP_ADCMPIE_ENABLE);
  407. * Means EADC will assert comparator 2 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_CMP2(eadc,\
  412. u32ModuleNum,\
  413. u32Condition,\
  414. u16CMPData,\
  415. u32MatchCount) ((eadc)->CMP[2] |=(((u32ModuleNum) << EADC_CMP_CMPSPL_Pos)|\
  416. (u32Condition) |\
  417. ((u16CMPData) << EADC_CMP_CMPDAT_Pos)| \
  418. (((u32MatchCount) - 1) << EADC_CMP_CMPMCNT_Pos)|\
  419. EADC_CMP_ADCMPEN_Msk))
  420. /**
  421. * @brief Configure the comparator 3 and enable it.
  422. * @param[in] eadc The pointer of the specified EADC module.
  423. * @param[in] u32ModuleNum specifies the compare sample module, valid value are from 0 to 18.
  424. * @param[in] u32Condition specifies the compare condition. Valid values are:
  425. * - \ref EADC_CMP_CMPCOND_LESS_THAN :The compare condition is "less than the compare value"
  426. * - \ref EADC_CMP_CMPCOND_GREATER_OR_EQUAL :The compare condition is "greater than or equal to the compare value
  427. * @param[in] u16CMPData specifies the compare value, valid range are between 0~0xFFF.
  428. * @param[in] u32MatchCount specifies the match count setting, valid range are between 1~0xF.
  429. * @return None
  430. * @details For example, ADC_ENABLE_CMP3(EADC, 5, ADC_ADCMPR_CMPCOND_GREATER_OR_EQUAL, 0x800, 10, EADC_CMP_ADCMPIE_ENABLE);
  431. * Means EADC will assert comparator 3 flag if sample module 5 conversion result is greater or
  432. * equal to 0x800 for 10 times continuously, and a compare interrupt request is generated.
  433. * \hideinitializer
  434. */
  435. #define EADC_ENABLE_CMP3(eadc,\
  436. u32ModuleNum,\
  437. u32Condition,\
  438. u16CMPData,\
  439. u32MatchCount) ((eadc)->CMP[3] |=(((u32ModuleNum) << EADC_CMP_CMPSPL_Pos)|\
  440. (u32Condition) |\
  441. ((u16CMPData) << EADC_CMP_CMPDAT_Pos)| \
  442. (((u32MatchCount) - 1) << EADC_CMP_CMPMCNT_Pos)|\
  443. EADC_CMP_ADCMPEN_Msk))
  444. /**
  445. * @brief Enable the compare window mode.
  446. * @param[in] eadc The pointer of the specified EADC module.
  447. * @param[in] u32CMP Specifies the compare register, valid value are 0 and 2.
  448. * @return None
  449. * @details ADCMPF0 (EADC_STATUS2[4]) will be set when both EADC_CMP0 and EADC_CMP1 compared condition matched.
  450. * \hideinitializer
  451. */
  452. #define EADC_ENABLE_CMP_WINDOW_MODE(eadc, u32CMP) ((eadc)->CMP[(u32CMP)] |= EADC_CMP_CMPWEN_Msk)
  453. /**
  454. * @brief Disable the compare window mode.
  455. * @param[in] eadc The pointer of the specified EADC module.
  456. * @param[in] u32CMP Specifies the compare register, valid value are 0 and 2.
  457. * @return None
  458. * @details ADCMPF2 (EADC_STATUS2[6]) will be set when both EADC_CMP2 and EADC_CMP3 compared condition matched.
  459. * \hideinitializer
  460. */
  461. #define EADC_DISABLE_CMP_WINDOW_MODE(eadc, u32CMP) ((eadc)->CMP[(u32CMP)] &= ~EADC_CMP_CMPWEN_Msk)
  462. /**
  463. * @brief Enable the compare interrupt.
  464. * @param[in] eadc The pointer of the specified EADC module.
  465. * @param[in] u32CMP Specifies the compare register, valid value are from 0 to 3.
  466. * @return None
  467. * @details If the compare function is enabled and the compare condition matches the setting of CMPCOND (EADC_CMPn[2], n=0~3)
  468. * and CMPMCNT (EADC_CMPn[11:8], n=0~3), ADCMPFn (EADC_STATUS2[7:4], n=0~3) will be asserted, in the meanwhile,
  469. * if ADCMPIE is set to 1, a compare interrupt request is generated.
  470. * \hideinitializer
  471. */
  472. #define EADC_ENABLE_CMP_INT(eadc, u32CMP) ((eadc)->CMP[(u32CMP)] |= EADC_CMP_ADCMPIE_Msk)
  473. /**
  474. * @brief Disable the compare interrupt.
  475. * @param[in] eadc The pointer of the specified EADC module.
  476. * @param[in] u32CMP Specifies the compare register, valid value are from 0 to 3.
  477. * @return None
  478. * @details This macro is used to disable the compare interrupt.
  479. * \hideinitializer
  480. */
  481. #define EADC_DISABLE_CMP_INT(eadc, u32CMP) ((eadc)->CMP[(u32CMP)] &= ~EADC_CMP_ADCMPIE_Msk)
  482. /**
  483. * @brief Disable comparator 0.
  484. * @param[in] eadc The pointer of the specified EADC module.
  485. * @return None
  486. * @details This macro is used to disable comparator 0.
  487. * \hideinitializer
  488. */
  489. #define EADC_DISABLE_CMP0(eadc) ((eadc)->CMP[0] = 0)
  490. /**
  491. * @brief Disable comparator 1.
  492. * @param[in] eadc The pointer of the specified EADC module.
  493. * @return None
  494. * @details This macro is used to disable comparator 1.
  495. * \hideinitializer
  496. */
  497. #define EADC_DISABLE_CMP1(eadc) ((eadc)->CMP[1] = 0)
  498. /**
  499. * @brief Disable comparator 2.
  500. * @param[in] eadc The pointer of the specified EADC module.
  501. * @return None
  502. * @details This macro is used to disable comparator 2.
  503. * \hideinitializer
  504. */
  505. #define EADC_DISABLE_CMP2(eadc) ((eadc)->CMP[2] = 0)
  506. /**
  507. * @brief Disable comparator 3.
  508. * @param[in] eadc The pointer of the specified EADC module.
  509. * @return None
  510. * @details This macro is used to disable comparator 3.
  511. * \hideinitializer
  512. */
  513. #define EADC_DISABLE_CMP3(eadc) ((eadc)->CMP[3] = 0)
  514. /*---------------------------------------------------------------------------------------------------------*/
  515. /* Define EADC functions prototype */
  516. /*---------------------------------------------------------------------------------------------------------*/
  517. void EADC_Open(EADC_T *eadc, uint32_t u32InputMode);
  518. void EADC_Close(EADC_T *eadc);
  519. void EADC_ConfigSampleModule(EADC_T *eadc, uint32_t u32ModuleNum, uint32_t u32TriggerSrc, uint32_t u32Channel);
  520. void EADC_SetTriggerDelayTime(EADC_T *eadc, uint32_t u32ModuleNum, uint32_t u32TriggerDelayTime, uint32_t u32DelayClockDivider);
  521. void EADC_SetExtendSampleTime(EADC_T *eadc, uint32_t u32ModuleNum, uint32_t u32ExtendSampleTime);
  522. /*@}*/ /* end of group EADC_EXPORTED_FUNCTIONS */
  523. /*@}*/ /* end of group EADC_Driver */
  524. /*@}*/ /* end of group Standard_Driver */
  525. #ifdef __cplusplus
  526. }
  527. #endif
  528. #endif /* __EADC_H__ */
  529. /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/