eadc.h 33 KB

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