nu_eadc.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /**************************************************************************//**
  2. * @file nu_eadc.h
  3. * @version V0.10
  4. * @brief EADC driver header file
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. * @copyright (C) 2021 Nuvoton Technology Corp. All rights reserved.
  8. *****************************************************************************/
  9. #ifndef __NU_EADC_H__
  10. #define __NU_EADC_H__
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. /** @addtogroup Standard_Driver Standard Driver
  16. @{
  17. */
  18. /** @addtogroup EADC_Driver EADC Driver
  19. @{
  20. */
  21. /** @addtogroup EADC_EXPORTED_CONSTANTS EADC Exported Constants
  22. @{
  23. */
  24. /*---------------------------------------------------------------------------------------------------------*/
  25. /* EADC_CTL Constant Definitions */
  26. /*---------------------------------------------------------------------------------------------------------*/
  27. #define EADC_CTL_DIFFEN_SINGLE_END (0UL<<EADC_CTL_DIFFEN_Pos) /*!< Single-end input mode \hideinitializer */
  28. #define EADC_CTL_DIFFEN_DIFFERENTIAL (1UL<<EADC_CTL_DIFFEN_Pos) /*!< Differential input mode \hideinitializer */
  29. #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 */
  30. #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 */
  31. /*---------------------------------------------------------------------------------------------------------*/
  32. /* EADC_SCTL Constant Definitions */
  33. /*---------------------------------------------------------------------------------------------------------*/
  34. #define EADC_SCTL_CHSEL(x) ((x) << EADC_SCTL_CHSEL_Pos) /*!< A/D sample module channel selection \hideinitializer */
  35. #define EADC_SCTL_TRGDLYDIV(x) ((x) << EADC_SCTL_TRGDLYDIV_Pos) /*!< A/D sample module start of conversion trigger delay clock divider selection \hideinitializer */
  36. #define EADC_SCTL_TRGDLYCNT(x) ((x) << EADC_SCTL_TRGDLYCNT_Pos) /*!< A/D sample module start of conversion trigger delay time \hideinitializer */
  37. #define EADC_SOFTWARE_TRIGGER (0UL<<EADC_SCTL_TRGSEL_Pos) /*!< Software trigger \hideinitializer */
  38. #define EADC_FALLING_EDGE_TRIGGER (EADC_SCTL_EXTFEN_Msk | (1UL<<EADC_SCTL_TRGSEL_Pos)) /*!< STADC pin falling edge trigger \hideinitializer */
  39. #define EADC_RISING_EDGE_TRIGGER (EADC_SCTL_EXTREN_Msk | (1UL<<EADC_SCTL_TRGSEL_Pos)) /*!< STADC pin rising edge trigger \hideinitializer */
  40. #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 */
  41. #define EADC_ADINT0_TRIGGER (2UL<<EADC_SCTL_TRGSEL_Pos) /*!< ADC ADINT0 interrupt EOC pulse trigger \hideinitializer */
  42. #define EADC_ADINT1_TRIGGER (3UL<<EADC_SCTL_TRGSEL_Pos) /*!< ADC ADINT1 interrupt EOC pulse trigger \hideinitializer */
  43. #define EADC_TIMER0_TRIGGER (4UL<<EADC_SCTL_TRGSEL_Pos) /*!< Timer0 overflow pulse trigger \hideinitializer */
  44. #define EADC_TIMER1_TRIGGER (5UL<<EADC_SCTL_TRGSEL_Pos) /*!< Timer1 overflow pulse trigger \hideinitializer */
  45. #define EADC_TIMER2_TRIGGER (6UL<<EADC_SCTL_TRGSEL_Pos) /*!< Timer2 overflow pulse trigger \hideinitializer */
  46. #define EADC_TIMER3_TRIGGER (7UL<<EADC_SCTL_TRGSEL_Pos) /*!< Timer3 overflow pulse trigger \hideinitializer */
  47. #define EADC_EPWM0TG0_TRIGGER (8UL<<EADC_SCTL_TRGSEL_Pos) /*!< EPWM0TG0 trigger \hideinitializer */
  48. #define EADC_EPWM0TG1_TRIGGER (9UL<<EADC_SCTL_TRGSEL_Pos) /*!< EPWM0TG1 trigger \hideinitializer */
  49. #define EADC_EPWM0TG2_TRIGGER (0xAUL<<EADC_SCTL_TRGSEL_Pos) /*!< EPWM0TG2 trigger \hideinitializer */
  50. #define EADC_EPWM0TG3_TRIGGER (0xBUL<<EADC_SCTL_TRGSEL_Pos) /*!< EPWM0TG3 trigger \hideinitializer */
  51. #define EADC_EPWM0TG4_TRIGGER (0xCUL<<EADC_SCTL_TRGSEL_Pos) /*!< EPWM0TG4 trigger \hideinitializer */
  52. #define EADC_EPWM0TG5_TRIGGER (0xDUL<<EADC_SCTL_TRGSEL_Pos) /*!< EPWM0TG5 trigger \hideinitializer */
  53. #define EADC_EPWM1TG0_TRIGGER (0xEUL<<EADC_SCTL_TRGSEL_Pos) /*!< EPWM1TG0 trigger \hideinitializer */
  54. #define EADC_EPWM1TG1_TRIGGER (0xFUL<<EADC_SCTL_TRGSEL_Pos) /*!< EPWM1TG1 trigger \hideinitializer */
  55. #define EADC_EPWM1TG2_TRIGGER (0x10UL<<EADC_SCTL_TRGSEL_Pos) /*!< EPWM1TG2 trigger \hideinitializer */
  56. #define EADC_EPWM1TG3_TRIGGER (0x11UL<<EADC_SCTL_TRGSEL_Pos) /*!< EPWM1TG3 trigger \hideinitializer */
  57. #define EADC_EPWM1TG4_TRIGGER (0x12UL<<EADC_SCTL_TRGSEL_Pos) /*!< EPWM1TG4 trigger \hideinitializer */
  58. #define EADC_EPWM1TG5_TRIGGER (0x13UL<<EADC_SCTL_TRGSEL_Pos) /*!< EPWM1TG5 trigger \hideinitializer */
  59. #define EADC_BPWM0TG_TRIGGER (0x14UL<<EADC_SCTL_TRGSEL_Pos) /*!< BPWM0TG trigger \hideinitializer */
  60. #define EADC_BPWM1TG_TRIGGER (0x15UL<<EADC_SCTL_TRGSEL_Pos) /*!< BPWM1TG trigger \hideinitializer */
  61. #define EADC_SCTL_TRGDLYDIV_DIVIDER_1 (0UL<<EADC_SCTL_TRGDLYDIV_Pos) /*!< Trigger delay clock frequency is ADC_CLK/1 \hideinitializer */
  62. #define EADC_SCTL_TRGDLYDIV_DIVIDER_2 (0x1UL<<EADC_SCTL_TRGDLYDIV_Pos) /*!< Trigger delay clock frequency is ADC_CLK/2 \hideinitializer */
  63. #define EADC_SCTL_TRGDLYDIV_DIVIDER_4 (0x2UL<<EADC_SCTL_TRGDLYDIV_Pos) /*!< Trigger delay clock frequency is ADC_CLK/4 \hideinitializer */
  64. #define EADC_SCTL_TRGDLYDIV_DIVIDER_16 (0x3UL<<EADC_SCTL_TRGDLYDIV_Pos) /*!< Trigger delay clock frequency is ADC_CLK/16 \hideinitializer */
  65. /*---------------------------------------------------------------------------------------------------------*/
  66. /* EADC_CMP Constant Definitions */
  67. /*---------------------------------------------------------------------------------------------------------*/
  68. #define EADC_CMP_CMPCOND_LESS_THAN (0UL<<EADC_CMP_CMPCOND_Pos) /*!< The compare condition is "less than" \hideinitializer */
  69. #define EADC_CMP_CMPCOND_GREATER_OR_EQUAL (1UL<<EADC_CMP_CMPCOND_Pos) /*!< The compare condition is "greater than or equal to" \hideinitializer */
  70. #define EADC_CMP_CMPWEN_ENABLE (EADC_CMP_CMPWEN_Msk) /*!< Compare window mode enable \hideinitializer */
  71. #define EADC_CMP_CMPWEN_DISABLE (~EADC_CMP_CMPWEN_Msk) /*!< Compare window mode disable \hideinitializer */
  72. #define EADC_CMP_ADCMPIE_ENABLE (EADC_CMP_ADCMPIE_Msk) /*!< A/D result compare interrupt enable \hideinitializer */
  73. #define EADC_CMP_ADCMPIE_DISABLE (~EADC_CMP_ADCMPIE_Msk) /*!< A/D result compare interrupt disable \hideinitializer */
  74. /*---------------------------------------------------------------------------------------------------------*/
  75. /* EADC_MnCTL1 Constant Definitions */
  76. /*---------------------------------------------------------------------------------------------------------*/
  77. #define EADC_MCTL1_ACU_1 (0x0UL<<EADC_MCTL1_ACU_Pos) /*!< Accumulated 1 time \hideinitializer */
  78. #define EADC_MCTL1_ACU_2 (0x1UL<<EADC_MCTL1_ACU_Pos) /*!< Accumulated 2 times \hideinitializer */
  79. #define EADC_MCTL1_ACU_4 (0x2UL<<EADC_MCTL1_ACU_Pos) /*!< Accumulated 4 times \hideinitializer */
  80. #define EADC_MCTL1_ACU_8 (0x3UL<<EADC_MCTL1_ACU_Pos) /*!< Accumulated 8 times \hideinitializer */
  81. #define EADC_MCTL1_ACU_16 (0x4UL<<EADC_MCTL1_ACU_Pos) /*!< Accumulated 16 times \hideinitializer */
  82. #define EADC_MCTL1_ACU_32 (0x5UL<<EADC_MCTL1_ACU_Pos) /*!< Accumulated 32 times \hideinitializer */
  83. #define EADC_MCTL1_ACU_64 (0x6UL<<EADC_MCTL1_ACU_Pos) /*!< Accumulated 64 times \hideinitializer */
  84. #define EADC_MCTL1_ACU_128 (0x7UL<<EADC_MCTL1_ACU_Pos) /*!< Accumulated 128 times \hideinitializer */
  85. #define EADC_MCTL1_ACU_256 (0x8UL<<EADC_MCTL1_ACU_Pos) /*!< Accumulated 256 times \hideinitializer */
  86. /*--------------------------------------------------------------------------------------------------*/
  87. /* Define Error Code */
  88. /*--------------------------------------------------------------------------------------------------*/
  89. #define EADC_TIMEOUT_ERR (-1) /*!< EADC operation abort due to timeout error \hideinitializer */
  90. /*@}*/ /* end of group EADC_EXPORTED_CONSTANTS */
  91. extern int32_t g_EADC_i32ErrCode;
  92. /** @addtogroup EADC_EXPORTED_FUNCTIONS EADC Exported Functions
  93. @{
  94. */
  95. /*---------------------------------------------------------------------------------------------------------*/
  96. /* EADC Macro Definitions */
  97. /*---------------------------------------------------------------------------------------------------------*/
  98. /**
  99. * @brief A/D Converter Control Circuits Reset.
  100. * @param[in] eadc The pointer of the specified EADC module.
  101. * @return None
  102. * @details ADCRST bit (EADC_CTL[1]) remains 1 during EADC reset, when EADC reset end, the ADCRST bit is automatically cleared to 0.
  103. * \hideinitializer
  104. */
  105. #define EADC_CONV_RESET(eadc) ((eadc)->CTL |= EADC_CTL_ADCRST_Msk)
  106. /**
  107. * @brief Enable Sample Module PDMA transfer.
  108. * @param[in] eadc The pointer of the specified EADC module.
  109. * @param[in] u32ModuleMask the combination of sample module interrupt status bits. Each bit corresponds to a sample module interrupt status.
  110. * This parameter decides which sample module interrupts will be disabled, valid range are between 1~0x7FFFF.
  111. * @return None
  112. * @details When A/D conversion is completed, the converted data is loaded into EADC_DATn (n: 0 ~ 18) register,
  113. * user can enable this bit to generate a PDMA data transfer request.
  114. * \hideinitializer
  115. */
  116. #define EADC_ENABLE_SAMPLE_MODULE_PDMA(eadc, u32ModuleMask) ((eadc)->PDMACTL |= u32ModuleMask)
  117. /**
  118. * @brief Disable Sample Module PDMA transfer.
  119. * @param[in] eadc The pointer of the specified EADC module.
  120. * @param[in] u32ModuleMask the combination of sample module interrupt status bits. Each bit corresponds to a sample module interrupt status.
  121. * This parameter decides which sample module interrupts will be disabled, valid range are between 1~0x7FFFF.
  122. * @return None
  123. * @details This macro is used to disable sample module PDMA transfer.
  124. * \hideinitializer
  125. */
  126. #define EADC_DISABLE_SAMPLE_MODULE_PDMA(eadc, u32ModuleMask) ((eadc)->PDMACTL &= (~u32ModuleMask))
  127. /**
  128. * @brief Enable double buffer mode.
  129. * @param[in] eadc The pointer of the specified EADC module.
  130. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 3.
  131. * @return None
  132. * @details The EADC controller supports a double buffer mode in sample module 0~3.
  133. * If user enable DBMEN (EADC_SCTLn[23], n=0~3), the double buffer mode will enable.
  134. * \hideinitializer
  135. */
  136. #define EADC_ENABLE_DOUBLE_BUFFER(eadc, u32ModuleNum) ((eadc)->SCTL[(u32ModuleNum)] |= EADC_SCTL_DBMEN_Msk)
  137. /**
  138. * @brief Disable double buffer mode.
  139. * @param[in] eadc The pointer of the specified EADC module.
  140. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 3.
  141. * @return None
  142. * @details Sample has one sample result register.
  143. * \hideinitializer
  144. */
  145. #define EADC_DISABLE_DOUBLE_BUFFER(eadc, u32ModuleNum) ((eadc)->SCTL[(u32ModuleNum)] &= ~EADC_SCTL_DBMEN_Msk)
  146. /**
  147. * @brief Set ADIFn at A/D end of conversion.
  148. * @param[in] eadc The pointer of the specified EADC module.
  149. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 15.
  150. * @return None
  151. * @details The A/D converter generates ADIFn (EADC_STATUS2[3:0], n=0~3) at the start of conversion.
  152. * \hideinitializer
  153. */
  154. #define EADC_ENABLE_INT_POSITION(eadc, u32ModuleNum) ((eadc)->SCTL[(u32ModuleNum)] |= EADC_SCTL_INTPOS_Msk)
  155. /**
  156. * @brief Set ADIFn at A/D start of conversion.
  157. * @param[in] eadc The pointer of the specified EADC module.
  158. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 15.
  159. * @return None
  160. * @details The A/D converter generates ADIFn (EADC_STATUS2[3:0], n=0~3) at the end of conversion.
  161. * \hideinitializer
  162. */
  163. #define EADC_DISABLE_INT_POSITION(eadc, u32ModuleNum) ((eadc)->SCTL[(u32ModuleNum)] &= ~EADC_SCTL_INTPOS_Msk)
  164. /**
  165. * @brief Enable the interrupt.
  166. * @param[in] eadc The pointer of the specified EADC module.
  167. * @param[in] u32Mask Decides the combination of interrupt status bits. Each bit corresponds to a interrupt status.
  168. * This parameter decides which interrupts will be enabled. Bit 0 is ADCIEN0, bit 1 is ADCIEN1..., bit 3 is ADCIEN3.
  169. * @return None
  170. * @details The A/D converter generates a conversion end ADIFn (EADC_STATUS2[n]) upon the end of specific sample module A/D conversion.
  171. * If ADCIENn bit (EADC_CTL[n+2]) is set then conversion end interrupt request ADINTn is generated (n=0~3).
  172. * \hideinitializer
  173. */
  174. #define EADC_ENABLE_INT(eadc, u32Mask) ((eadc)->CTL |= ((u32Mask) << EADC_CTL_ADCIEN0_Pos))
  175. /**
  176. * @brief Disable the interrupt.
  177. * @param[in] eadc The pointer of the specified EADC module.
  178. * @param[in] u32Mask Decides the combination of interrupt status bits. Each bit corresponds to a interrupt status.
  179. * This parameter decides which interrupts will be disabled. Bit 0 is ADCIEN0, bit 1 is ADCIEN1..., bit 3 is ADCIEN3.
  180. * @return None
  181. * @details Specific sample module A/D ADINT0 interrupt function Disabled.
  182. * \hideinitializer
  183. */
  184. #define EADC_DISABLE_INT(eadc, u32Mask) ((eadc)->CTL &= ~((u32Mask) << EADC_CTL_ADCIEN0_Pos))
  185. /**
  186. * @brief Enable the sample module interrupt.
  187. * @param[in] eadc The pointer of the specified EADC module.
  188. * @param[in] u32IntSel Decides which interrupt source will be used, valid value are from 0 to 3.
  189. * @param[in] u32ModuleMask the combination of sample module interrupt status bits. Each bit corresponds to a sample module interrupt status.
  190. * This parameter decides which sample module interrupts will be enabled, valid range are between 1~0x7FFFF.
  191. * @return None
  192. * @details There are 4 EADC interrupts ADINT0~3, and each of these interrupts has its own interrupt vector address.
  193. * \hideinitializer
  194. */
  195. #define EADC_ENABLE_SAMPLE_MODULE_INT(eadc, u32IntSel, u32ModuleMask) ((eadc)->INTSRC[(u32IntSel)] |= (u32ModuleMask))
  196. /**
  197. * @brief Disable the sample module interrupt.
  198. * @param[in] eadc The pointer of the specified EADC module.
  199. * @param[in] u32IntSel Decides which interrupt source will be used, valid value are from 0 to 3.
  200. * @param[in] u32ModuleMask the combination of sample module interrupt status bits. Each bit corresponds to a sample module interrupt status.
  201. * This parameter decides which sample module interrupts will be disabled, valid range are between 1~0x7FFFF.
  202. * @return None
  203. * @details There are 4 EADC interrupts ADINT0~3, and each of these interrupts has its own interrupt vector address.
  204. * \hideinitializer
  205. */
  206. #define EADC_DISABLE_SAMPLE_MODULE_INT(eadc, u32IntSel, u32ModuleMask) ((eadc)->INTSRC[(u32IntSel)] &= (uint32_t)(~(u32ModuleMask)))
  207. /**
  208. * @brief Set the input mode output format.
  209. * @param[in] eadc The pointer of the specified EADC module.
  210. * @param[in] u32Format Decides the output format. Valid values are:
  211. * - \ref EADC_CTL_DMOF_STRAIGHT_BINARY :Select the straight binary format as the output format of the conversion result.
  212. * - \ref EADC_CTL_DMOF_TWOS_COMPLEMENT :Select the 2's complement format as the output format of the conversion result.
  213. * @return None
  214. * @details The macro is used to set A/D input mode output format.
  215. * \hideinitializer
  216. */
  217. #define EADC_SET_DMOF(eadc, u32Format) ((eadc)->CTL = ((eadc)->CTL & ~EADC_CTL_DMOF_Msk) | (u32Format))
  218. /**
  219. * @brief Start the A/D conversion.
  220. * @param[in] eadc The pointer of the specified EADC module.
  221. * @param[in] u32ModuleMask The combination of sample module. Each bit corresponds to a sample module.
  222. * This parameter decides which sample module will be conversion, valid range are between 1~0x7FFFF.
  223. * Bit 0 is sample module 0, bit 1 is sample module 1..., bit 18 is sample module 18.
  224. * @return None
  225. * @details After write EADC_SWTRG register to start EADC conversion, the EADC_PENDSTS register will show which SAMPLE will conversion.
  226. * \hideinitializer
  227. */
  228. #define EADC_START_CONV(eadc, u32ModuleMask) ((eadc)->SWTRG = (u32ModuleMask))
  229. /**
  230. * @brief Cancel the conversion for sample module.
  231. * @param[in] eadc The pointer of the specified EADC module.
  232. * @param[in] u32ModuleMask The combination of sample module. Each bit corresponds to a sample module.
  233. * This parameter decides which sample module will stop the conversion, valid range are between 1~0x7FFFF.
  234. * Bit 0 is sample module 0, bit 1 is sample module 1..., bit 18 is sample module18.
  235. * @return None
  236. * @details If user want to disable the conversion of the sample module, user can write EADC_PENDSTS register to clear it.
  237. * \hideinitializer
  238. */
  239. #define EADC_STOP_CONV(eadc, u32ModuleMask) ((eadc)->PENDSTS = (u32ModuleMask))
  240. /**
  241. * @brief Get the conversion pending flag.
  242. * @param[in] eadc The pointer of the specified EADC module.
  243. * @return Return the conversion pending sample module.
  244. * @details This STPFn(EADC_PENDSTS[18:0]) bit remains 1 during pending state, when the respective ADC conversion is end,
  245. * the STPFn (n=0~18) bit is automatically cleared to 0.
  246. * \hideinitializer
  247. */
  248. #define EADC_GET_PENDING_CONV(eadc) ((eadc)->PENDSTS)
  249. /**
  250. * @brief Get the conversion data of the user-specified sample module.
  251. * @param[in] eadc The pointer of the specified EADC module.
  252. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 18.
  253. * @return Return the conversion data of the user-specified sample module.
  254. * @details This macro is used to read RESULT bit (EADC_DATn[15:0], n=0~18) field to get conversion data.
  255. * \hideinitializer
  256. */
  257. #define EADC_GET_CONV_DATA(eadc, u32ModuleNum) ((eadc)->DAT[(u32ModuleNum)] & EADC_DAT_RESULT_Msk)
  258. /**
  259. * @brief Get the data overrun flag of the user-specified sample module.
  260. * @param[in] eadc The pointer of the specified EADC module.
  261. * @param[in] u32ModuleMask The combination of data overrun status bits. Each bit corresponds to a data overrun status, valid range are between 1~0x7FFFF.
  262. * @return Return the data overrun flag of the user-specified sample module.
  263. * @details This macro is used to read OV bit (EADC_STATUS0[31:16], EADC_STATUS1[18:16]) field to get data overrun status.
  264. * \hideinitializer
  265. */
  266. #define EADC_GET_DATA_OVERRUN_FLAG(eadc, u32ModuleMask) ((((eadc)->STATUS0 >> EADC_STATUS0_OV_Pos) | ((eadc)->STATUS1 & EADC_STATUS1_OV_Msk)) & (u32ModuleMask))
  267. /**
  268. * @brief Get the data valid flag of the user-specified sample module.
  269. * @param[in] eadc The pointer of the specified EADC module.
  270. * @param[in] u32ModuleMask The combination of data valid status bits. Each bit corresponds to a data valid status, valid range are between 1~0x7FFFF.
  271. * @return Return the data valid flag of the user-specified sample module.
  272. * @details This macro is used to read VALID bit (EADC_STATUS0[15:0], EADC_STATUS1[2:0]) field to get data valid status.
  273. * \hideinitializer
  274. */
  275. #define EADC_GET_DATA_VALID_FLAG(eadc, u32ModuleMask) ((((eadc)->STATUS0 & EADC_STATUS0_VALID_Msk) | (((eadc)->STATUS1 & EADC_STATUS1_VALID_Msk) << 16)) & (u32ModuleMask))
  276. /**
  277. * @brief Get the double data of the user-specified sample module.
  278. * @param[in] eadc The pointer of the specified EADC module.
  279. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 18.
  280. * @return Return the double data of the user-specified sample module.
  281. * @details This macro is used to read RESULT bit (EADC_DDATn[15:0], n=0~3) field to get conversion data.
  282. * \hideinitializer
  283. */
  284. #define EADC_GET_DOUBLE_DATA(eadc, u32ModuleNum) ((eadc)->DDAT[(u32ModuleNum)] & EADC_DDAT0_RESULT_Msk)
  285. /**
  286. * @brief Get the user-specified interrupt flags.
  287. * @param[in] eadc The pointer of the specified EADC module.
  288. * @param[in] u32Mask The combination of interrupt status bits. Each bit corresponds to a interrupt status.
  289. * Bit 0 is ADIF0, bit 1 is ADIF1..., bit 3 is ADIF3.
  290. * Bit 4 is ADCMPF0, bit 5 is ADCMPF1..., bit 7 is ADCMPF3.
  291. * @return Return the user-specified interrupt flags.
  292. * @details This macro is used to get the user-specified interrupt flags.
  293. * \hideinitializer
  294. */
  295. #define EADC_GET_INT_FLAG(eadc, u32Mask) ((eadc)->STATUS2 & (u32Mask))
  296. /**
  297. * @brief Get the user-specified sample module overrun flags.
  298. * @param[in] eadc The pointer of the specified EADC module.
  299. * @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.
  300. * @return Return the user-specified sample module overrun flags.
  301. * @details This macro is used to get the user-specified sample module overrun flags.
  302. * \hideinitializer
  303. */
  304. #define EADC_GET_SAMPLE_MODULE_OV_FLAG(eadc, u32ModuleMask) ((eadc)->OVSTS & (u32ModuleMask))
  305. /**
  306. * @brief Clear the selected interrupt status bits.
  307. * @param[in] eadc The pointer of the specified EADC module.
  308. * @param[in] u32Mask The combination of compare interrupt status bits. Each bit corresponds to a compare interrupt status.
  309. * Bit 0 is ADIF0, bit 1 is ADIF1..., bit 3 is ADIF3.
  310. * Bit 4 is ADCMPF0, bit 5 is ADCMPF1..., bit 7 is ADCMPF3.
  311. * @return None
  312. * @details This macro is used to clear clear the selected interrupt status bits.
  313. * \hideinitializer
  314. */
  315. #define EADC_CLR_INT_FLAG(eadc, u32Mask) ((eadc)->STATUS2 = (u32Mask))
  316. /**
  317. * @brief Clear the selected sample module overrun status bits.
  318. * @param[in] eadc The pointer of the specified EADC module.
  319. * @param[in] u32ModuleMask The combination of sample module overrun status bits. Each bit corresponds to a sample module overrun status.
  320. * Bit 0 is SPOVF0, bit 1 is SPOVF1..., bit 18 is SPOVF18.
  321. * @return None
  322. * @details This macro is used to clear the selected sample module overrun status bits.
  323. * \hideinitializer
  324. */
  325. #define EADC_CLR_SAMPLE_MODULE_OV_FLAG(eadc, u32ModuleMask) ((eadc)->OVSTS = (u32ModuleMask))
  326. /**
  327. * @brief Check all sample module A/D result data register overrun flags.
  328. * @param[in] eadc The pointer of the specified EADC module.
  329. * @retval 0 None of sample module data register overrun flag is set to 1.
  330. * @retval 1 Any one of sample module data register overrun flag is set to 1.
  331. * @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.
  332. * \hideinitializer
  333. */
  334. #define EADC_IS_DATA_OV(eadc) (((eadc)->STATUS2 & EADC_STATUS2_AOV_Msk) >> EADC_STATUS2_AOV_Pos)
  335. /**
  336. * @brief Check all sample module A/D result data register valid flags.
  337. * @param[in] eadc The pointer of the specified EADC module.
  338. * @retval 0 None of sample module data register valid flag is set to 1.
  339. * @retval 1 Any one of sample module data register valid flag is set to 1.
  340. * @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.
  341. * \hideinitializer
  342. */
  343. #define EADC_IS_DATA_VALID(eadc) (((eadc)->STATUS2 & EADC_STATUS2_AVALID_Msk) >> EADC_STATUS2_AVALID_Pos)
  344. /**
  345. * @brief Check all A/D sample module start of conversion overrun flags.
  346. * @param[in] eadc The pointer of the specified EADC module.
  347. * @retval 0 None of sample module event overrun flag is set to 1.
  348. * @retval 1 Any one of sample module event overrun flag is set to 1.
  349. * @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.
  350. * \hideinitializer
  351. */
  352. #define EADC_IS_SAMPLE_MODULE_OV(eadc) (((eadc)->STATUS2 & EADC_STATUS2_STOVF_Msk) >> EADC_STATUS2_STOVF_Pos)
  353. /**
  354. * @brief Check all A/D interrupt flag overrun bits.
  355. * @param[in] eadc The pointer of the specified EADC module.
  356. * @retval 0 None of ADINT interrupt flag is overwritten to 1.
  357. * @retval 1 Any one of ADINT interrupt flag is overwritten to 1.
  358. * @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.
  359. * \hideinitializer
  360. */
  361. #define EADC_IS_INT_FLAG_OV(eadc) (((eadc)->STATUS2 & EADC_STATUS2_ADOVIF_Msk) >> EADC_STATUS2_ADOVIF_Pos)
  362. /**
  363. * @brief Get the busy state of EADC.
  364. * @param[in] eadc The pointer of the specified EADC module.
  365. * @retval 0 Idle state.
  366. * @retval 1 Busy state.
  367. * @details This macro is used to read BUSY bit (EADC_STATUS2[23]) to get busy state.
  368. * \hideinitializer
  369. */
  370. #define EADC_IS_BUSY(eadc) (((eadc)->STATUS2 & EADC_STATUS2_BUSY_Msk) >> EADC_STATUS2_BUSY_Pos)
  371. /**
  372. * @brief Configure the comparator 0 and enable it.
  373. * @param[in] eadc The pointer of the specified EADC module.
  374. * @param[in] u32ModuleNum specifies the compare sample module, valid value are from 0 to 18.
  375. * @param[in] u32Condition specifies the compare condition. Valid values are:
  376. * - \ref EADC_CMP_CMPCOND_LESS_THAN :The compare condition is "less than the compare value"
  377. * - \ref EADC_CMP_CMPCOND_GREATER_OR_EQUAL :The compare condition is "greater than or equal to the compare value
  378. * @param[in] u16CMPData specifies the compare value, valid range are between 0~0xFFF.
  379. * @param[in] u32MatchCount specifies the match count setting, valid range are between 0~0xF.
  380. * @return None
  381. * @details For example, ADC_ENABLE_CMP0(EADC, 5, ADC_ADCMPR_CMPCOND_GREATER_OR_EQUAL, 0x800, 10, EADC_CMP_CMPWEN_DISABLE, EADC_CMP_ADCMPIE_ENABLE);
  382. * Means EADC will assert comparator 0 flag if sample module 5 conversion result is greater or
  383. * equal to 0x800 for 10 times continuously, and a compare interrupt request is generated.
  384. * \hideinitializer
  385. */
  386. #define EADC_ENABLE_CMP0(eadc,\
  387. u32ModuleNum,\
  388. u32Condition,\
  389. u16CMPData,\
  390. u32MatchCount) ((eadc)->CMP[0] = (((eadc)->CMP[0] & ~(EADC_CMP_CMPSPL_Msk|EADC_CMP_CMPCOND_Msk|EADC_CMP_CMPDAT_Msk|EADC_CMP_CMPMCNT_Msk))|\
  391. (((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 1 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_CMP1(EADC, 5, ADC_ADCMPR_CMPCOND_GREATER_OR_EQUAL, 0x800, 10, EADC_CMP_ADCMPIE_ENABLE);
  407. * Means EADC will assert comparator 1 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_CMP1(eadc,\
  412. u32ModuleNum,\
  413. u32Condition,\
  414. u16CMPData,\
  415. u32MatchCount) ((eadc)->CMP[1] = (((eadc)->CMP[1] & ~(EADC_CMP_CMPSPL_Msk|EADC_CMP_CMPCOND_Msk|EADC_CMP_CMPDAT_Msk|EADC_CMP_CMPMCNT_Msk))|\
  416. (((u32ModuleNum) << EADC_CMP_CMPSPL_Pos)|\
  417. (u32Condition) |\
  418. ((u16CMPData) << EADC_CMP_CMPDAT_Pos)| \
  419. (((u32MatchCount) - 1) << EADC_CMP_CMPMCNT_Pos)|\
  420. EADC_CMP_ADCMPEN_Msk)))
  421. /**
  422. * @brief Configure the comparator 2 and enable it.
  423. * @param[in] eadc The pointer of the specified EADC module.
  424. * @param[in] u32ModuleNum specifies the compare sample module, valid value are from 0 to 18.
  425. * @param[in] u32Condition specifies the compare condition. Valid values are:
  426. * - \ref EADC_CMP_CMPCOND_LESS_THAN :The compare condition is "less than the compare value"
  427. * - \ref EADC_CMP_CMPCOND_GREATER_OR_EQUAL :The compare condition is "greater than or equal to the compare value
  428. * @param[in] u16CMPData specifies the compare value, valid range are between 0~0xFFF.
  429. * @param[in] u32MatchCount specifies the match count setting, valid range are between 0~0xF.
  430. * @return None
  431. * @details For example, ADC_ENABLE_CMP2(EADC, 5, ADC_ADCMPR_CMPCOND_GREATER_OR_EQUAL, 0x800, 10, EADC_CMP_CMPWEN_DISABLE, EADC_CMP_ADCMPIE_ENABLE);
  432. * Means EADC will assert comparator 2 flag if sample module 5 conversion result is greater or
  433. * equal to 0x800 for 10 times continuously, and a compare interrupt request is generated.
  434. * \hideinitializer
  435. */
  436. #define EADC_ENABLE_CMP2(eadc,\
  437. u32ModuleNum,\
  438. u32Condition,\
  439. u16CMPData,\
  440. u32MatchCount) ((eadc)->CMP[2] = (((eadc)->CMP[2] & ~(EADC_CMP_CMPSPL_Msk|EADC_CMP_CMPCOND_Msk|EADC_CMP_CMPDAT_Msk|EADC_CMP_CMPMCNT_Msk))|\
  441. (((u32ModuleNum) << EADC_CMP_CMPSPL_Pos)|\
  442. (u32Condition) |\
  443. ((u16CMPData) << EADC_CMP_CMPDAT_Pos)| \
  444. (((u32MatchCount) - 1) << EADC_CMP_CMPMCNT_Pos)|\
  445. EADC_CMP_ADCMPEN_Msk)))
  446. /**
  447. * @brief Configure the comparator 3 and enable it.
  448. * @param[in] eadc The pointer of the specified EADC module.
  449. * @param[in] u32ModuleNum specifies the compare sample module, valid value are from 0 to 18.
  450. * @param[in] u32Condition specifies the compare condition. Valid values are:
  451. * - \ref EADC_CMP_CMPCOND_LESS_THAN :The compare condition is "less than the compare value"
  452. * - \ref EADC_CMP_CMPCOND_GREATER_OR_EQUAL :The compare condition is "greater than or equal to the compare value
  453. * @param[in] u16CMPData specifies the compare value, valid range are between 0~0xFFF.
  454. * @param[in] u32MatchCount specifies the match count setting, valid range are between 1~0xF.
  455. * @return None
  456. * @details For example, ADC_ENABLE_CMP3(EADC, 5, ADC_ADCMPR_CMPCOND_GREATER_OR_EQUAL, 0x800, 10, EADC_CMP_ADCMPIE_ENABLE);
  457. * Means EADC will assert comparator 3 flag if sample module 5 conversion result is greater or
  458. * equal to 0x800 for 10 times continuously, and a compare interrupt request is generated.
  459. * \hideinitializer
  460. */
  461. #define EADC_ENABLE_CMP3(eadc,\
  462. u32ModuleNum,\
  463. u32Condition,\
  464. u16CMPData,\
  465. u32MatchCount) ((eadc)->CMP[3] = (((eadc)->CMP[3] & ~(EADC_CMP_CMPSPL_Msk|EADC_CMP_CMPCOND_Msk|EADC_CMP_CMPDAT_Msk|EADC_CMP_CMPMCNT_Msk))|\
  466. (((u32ModuleNum) << EADC_CMP_CMPSPL_Pos)|\
  467. (u32Condition) |\
  468. ((u16CMPData) << EADC_CMP_CMPDAT_Pos)| \
  469. (((u32MatchCount) - 1) << EADC_CMP_CMPMCNT_Pos)|\
  470. EADC_CMP_ADCMPEN_Msk)))
  471. /**
  472. * @brief Enable the compare window mode.
  473. * @param[in] eadc The pointer of the specified EADC module.
  474. * @param[in] u32CMP Specifies the compare register, valid value are 0 and 2.
  475. * @return None
  476. * @details ADCMPF0 (EADC_STATUS2[4]) will be set when both EADC_CMP0 and EADC_CMP1 compared condition matched.
  477. * \hideinitializer
  478. */
  479. #define EADC_ENABLE_CMP_WINDOW_MODE(eadc, u32CMP) ((eadc)->CMP[(u32CMP)] |= EADC_CMP_CMPWEN_Msk)
  480. /**
  481. * @brief Disable the compare window mode.
  482. * @param[in] eadc The pointer of the specified EADC module.
  483. * @param[in] u32CMP Specifies the compare register, valid value are 0 and 2.
  484. * @return None
  485. * @details ADCMPF2 (EADC_STATUS2[6]) will be set when both EADC_CMP2 and EADC_CMP3 compared condition matched.
  486. * \hideinitializer
  487. */
  488. #define EADC_DISABLE_CMP_WINDOW_MODE(eadc, u32CMP) ((eadc)->CMP[(u32CMP)] &= ~EADC_CMP_CMPWEN_Msk)
  489. /**
  490. * @brief Enable the compare interrupt.
  491. * @param[in] eadc The pointer of the specified EADC module.
  492. * @param[in] u32CMP Specifies the compare register, valid value are from 0 to 3.
  493. * @return None
  494. * @details If the compare function is enabled and the compare condition matches the setting of CMPCOND (EADC_CMPn[2], n=0~3)
  495. * and CMPMCNT (EADC_CMPn[11:8], n=0~3), ADCMPFn (EADC_STATUS2[7:4], n=0~3) will be asserted, in the meanwhile,
  496. * if ADCMPIE is set to 1, a compare interrupt request is generated.
  497. * \hideinitializer
  498. */
  499. #define EADC_ENABLE_CMP_INT(eadc, u32CMP) ((eadc)->CMP[(u32CMP)] |= EADC_CMP_ADCMPIE_Msk)
  500. /**
  501. * @brief Disable the compare interrupt.
  502. * @param[in] eadc The pointer of the specified EADC module.
  503. * @param[in] u32CMP Specifies the compare register, valid value are from 0 to 3.
  504. * @return None
  505. * @details This macro is used to disable the compare interrupt.
  506. * \hideinitializer
  507. */
  508. #define EADC_DISABLE_CMP_INT(eadc, u32CMP) ((eadc)->CMP[(u32CMP)] &= ~EADC_CMP_ADCMPIE_Msk)
  509. /**
  510. * @brief Disable comparator 0.
  511. * @param[in] eadc The pointer of the specified EADC module.
  512. * @return None
  513. * @details This macro is used to disable comparator 0.
  514. * \hideinitializer
  515. */
  516. #define EADC_DISABLE_CMP0(eadc) ((eadc)->CMP[0] = 0UL)
  517. /**
  518. * @brief Disable comparator 1.
  519. * @param[in] eadc The pointer of the specified EADC module.
  520. * @return None
  521. * @details This macro is used to disable comparator 1.
  522. * \hideinitializer
  523. */
  524. #define EADC_DISABLE_CMP1(eadc) ((eadc)->CMP[1] = 0UL)
  525. /**
  526. * @brief Disable comparator 2.
  527. * @param[in] eadc The pointer of the specified EADC module.
  528. * @return None
  529. * @details This macro is used to disable comparator 2.
  530. * \hideinitializer
  531. */
  532. #define EADC_DISABLE_CMP2(eadc) ((eadc)->CMP[2] = 0UL)
  533. /**
  534. * @brief Disable comparator 3.
  535. * @param[in] eadc The pointer of the specified EADC module.
  536. * @return None
  537. * @details This macro is used to disable comparator 3.
  538. * \hideinitializer
  539. */
  540. #define EADC_DISABLE_CMP3(eadc) ((eadc)->CMP[3] = 0UL)
  541. /**
  542. * @brief Enable conversion result left alignment.
  543. * @param[in] eadc The pointer of the specified EADC module.
  544. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 23.
  545. * @return None
  546. * @details The 12-bit conversion result will be left aligned and stored in EADC_DATn[15:4] (n=0~23).
  547. * \hideinitializer
  548. */
  549. #define EADC_ENABLE_LEFT_ALIGN(eadc, u32ModuleNum) ((((eadc)->MCTL1[(u32ModuleNum)])) |= EADC_MCTL1_ALIGN_Msk)
  550. /**
  551. * @brief Disable conversion result left alignment.
  552. * @param[in] eadc The pointer of the specified EADC module.
  553. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 23.
  554. * @return None
  555. * @details The 12-bit conversion result will be right aligned and stored in EADC_DATn[11:0] (n=0~23).
  556. * \hideinitializer
  557. */
  558. #define EADC_DISABLE_LEFT_ALIGN(eadc, u32ModuleNum) ((((eadc)->MCTL1[(u32ModuleNum)])) &= (~EADC_MCTL1_ALIGN_Msk))
  559. /**
  560. * @brief Enable average mode.
  561. * @param[in] eadc The pointer of the specified EADC module.
  562. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 23.
  563. * @return None
  564. * @details Conversion results in data register will be averaged.
  565. * @note This average mode needs to work with accumulated mode that configured by ACU (EADC_MnCTL1[7:4], n=0~23) bit field.
  566. * \hideinitializer
  567. */
  568. #define EADC_ENABLE_AVG(eadc, u32ModuleNum) ((((eadc)->MCTL1[(u32ModuleNum)])) |= EADC_MCTL1_AVG_Msk)
  569. /**
  570. * @brief Disable average mode.
  571. * @param[in] eadc The pointer of the specified EADC module.
  572. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 23.
  573. * @return None
  574. * @details Conversion results in data register will not be averaged.
  575. * \hideinitializer
  576. */
  577. #define EADC_DISABLE_AVG(eadc, u32ModuleNum) ((((eadc)->MCTL1[(u32ModuleNum)])) &= (~EADC_MCTL1_AVG_Msk))
  578. /**
  579. * @brief Configure the Accumulation feature and enable it.
  580. * @param[in] eadc The pointer of the specified EADC module.
  581. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 23.
  582. * @param[in] u16ACUNum specifies the number of accumulation, valid values are
  583. * - \ref EADC_MCTL1_ACU_1 : 1 conversion result will be accumulated.
  584. * - \ref EADC_MCTL1_ACU_2 : 2 conversion result will be accumulated.
  585. * - \ref EADC_MCTL1_ACU_4 : 4 conversion result will be accumulated.
  586. * - \ref EADC_MCTL1_ACU_8 : 8 conversion result will be accumulated.
  587. * - \ref EADC_MCTL1_ACU_16 : 16 conversion result will be accumulated.
  588. * - \ref EADC_MCTL1_ACU_32 : 32 conversion result will be accumulated. The result is right shift 1 bit to fit within the available 16-bit register size.
  589. * - \ref EADC_MCTL1_ACU_64 : 64 conversion result will be accumulated. The result is right shift 2 bits to fit within the available 16-bit register size.
  590. * - \ref EADC_MCTL1_ACU_128 : 128 conversion result will be accumulated. The result is right shift 3 bits to fit within the available 16-bit register size.
  591. * - \ref EADC_MCTL1_ACU_256 : 256 conversion result will be accumulated. The result is right shift 4 bits to fit within the available 16-bit register size.
  592. * @return None
  593. * @details When accumulating more than 16 samples, the result will be too large to match the
  594. * 16-bit RESULT register size (EADC_DATn[15:0]. To avoid overflow, the result is
  595. * right shifted automatically to fit within the available 16-bit register size.
  596. * The number of automatic right shifts is specified in parameter list above.
  597. * \hideinitializer
  598. */
  599. #define EADC_ENABLE_ACU(eadc,\
  600. u32ModuleNum,\
  601. u16ACUNum) ((((eadc)->MCTL1[(u32ModuleNum)])) = (((((eadc)->MCTL1[(u32ModuleNum)])) & (~EADC_MCTL1_ACU_Msk)) |\
  602. (u16ACUNum)))
  603. /**
  604. * @brief Disable the Accumulation feature.
  605. * @param[in] eadc The pointer of the specified EADC module.
  606. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 23.
  607. * @return None
  608. * \hideinitializer
  609. */
  610. #define EADC_DISABLE_ACU(eadc, u32ModuleNum) ((((eadc)->MCTL1[(u32ModuleNum)])) &= (~EADC_MCTL1_ACU_Msk))
  611. /**
  612. * @brief Set start of conversion interrupt delay cycle.
  613. * @param[in] eadc The pointer of the specified EADC module.
  614. * @param[in] u32IntSel Decides which interrupt source will be used, valid value are from 0 to 3.
  615. * @param[in] u32DelayCycle Decides the interrupt delay cycle, valid value are from 0 to 15.
  616. * @return None
  617. * @details Select EADC start of conversion interrupt ADINT0 to ADINT3 delay cycle(s).
  618. * @note This function is workable only when any one of INTPOS (EADC_SCTLx[5]), x=0~15 is set.
  619. * \hideinitializer
  620. */
  621. #define EADC_SET_INT_DELAY(eadc, u32IntSel, u32DelayCycle) ((eadc)->CTL = ((eadc)->CTL & ~(0xFUL << (EADC_CTL_INTDELAY0_Pos + ((u32IntSel) << 2)))) | \
  622. ((u32DelayCycle) << (EADC_CTL_INTDELAY0_Pos + ((u32IntSel) << 2))))
  623. /**
  624. * @brief Enable comparetor to trigger EPWM brake.
  625. * @param[in] eadc The pointer of the specified EADC module.
  626. * @param[in] u32CmpSel Decides which comparator will be used, valid value are from 0 to 3.
  627. * @return None
  628. * @details Enable EADC comparator 0 to 3 can trigger EPWM brake.
  629. * \hideinitializer
  630. */
  631. #define EADC_ENABLE_CMP_TRIGGER_BRAKE(eadc, u32CmpSel) ((eadc)->CTL1 |= (1UL << (EADC_CTL1_CMP0TRG_Pos + (u32CmpSel))))
  632. /**
  633. * @brief Disable comparetor to trigger EPWM brake.
  634. * @param[in] eadc The pointer of the specified EADC module.
  635. * @param[in] u32CmpSel Decides which comparator will be disabled, valid value are from 0 to 3.
  636. * @return None
  637. * @details Disable EADC comparator 0 to 3 trigger EPWM brake.
  638. * \hideinitializer
  639. */
  640. #define EADC_DISABLE_CMP_TRIGGER_BRAKE(eadc, u32CmpSel) ((eadc)->CTL1 &= (~(1UL << (EADC_CTL1_CMP0TRG_Pos + (u32CmpSel)))))
  641. /*---------------------------------------------------------------------------------------------------------*/
  642. /* Define EADC functions prototype */
  643. /*---------------------------------------------------------------------------------------------------------*/
  644. void EADC_Open(EADC_T *eadc, uint32_t u32InputMode);
  645. void EADC_Close(EADC_T *eadc);
  646. void EADC_ConfigSampleModule(EADC_T *eadc, uint32_t u32ModuleNum, uint32_t u32TriggerSrc, uint32_t u32Channel);
  647. void EADC_SetTriggerDelayTime(EADC_T *eadc, uint32_t u32ModuleNum, uint32_t u32TriggerDelayTime, uint32_t u32DelayClockDivider);
  648. void EADC_SetExtendSampleTime(EADC_T *eadc, uint32_t u32ModuleNum, uint32_t u32ExtendSampleTime);
  649. /*@}*/ /* end of group EADC_EXPORTED_FUNCTIONS */
  650. /*@}*/ /* end of group EADC_Driver */
  651. /*@}*/ /* end of group Standard_Driver */
  652. #ifdef __cplusplus
  653. }
  654. #endif
  655. #endif /* __NU_EADC_H__ */