nu_eadc.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /**************************************************************************//**
  2. * @file nu_eadc.h
  3. * @version V0.10
  4. * @brief M480 series EADC driver header file
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. * @copyright (C) 2016-2020 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 (0<<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. /*@}*/ /* end of group EADC_EXPORTED_CONSTANTS */
  75. /** @addtogroup EADC_EXPORTED_FUNCTIONS EADC Exported Functions
  76. @{
  77. */
  78. /*---------------------------------------------------------------------------------------------------------*/
  79. /* EADC Macro Definitions */
  80. /*---------------------------------------------------------------------------------------------------------*/
  81. /**
  82. * @brief A/D Converter Control Circuits Reset.
  83. * @param[in] eadc The pointer of the specified EADC module.
  84. * @return None
  85. * @details ADCRST bit (EADC_CT[1]) remains 1 during ADC reset, when ADC reset end, the ADCRST bit is automatically cleared to 0.
  86. * \hideinitializer
  87. */
  88. #define EADC_CONV_RESET(eadc) ((eadc)->CTL |= EADC_CTL_ADCRST_Msk)
  89. /**
  90. * @brief Enable PDMA transfer.
  91. * @param[in] eadc The pointer of the specified EADC module.
  92. * @return None
  93. * @details When A/D conversion is completed, the converted data is loaded into EADC_DATn (n: 0 ~ 18) register,
  94. * user can enable this bit to generate a PDMA data transfer request.
  95. * @note When set PDMAEN bit (EADC_CTL[11]), user must set ADINTENn (EADC_CTL[5:2], n=0~3) = 0 to disable interrupt.
  96. * \hideinitializer
  97. */
  98. #define EADC_ENABLE_PDMA(eadc) ((eadc)->CTL |= EADC_CTL_PDMAEN_Msk)
  99. /**
  100. * @brief Disable PDMA transfer.
  101. * @param[in] eadc The pointer of the specified EADC module.
  102. * @return None
  103. * @details This macro is used to disable PDMA transfer.
  104. * \hideinitializer
  105. */
  106. #define EADC_DISABLE_PDMA(eadc) ((eadc)->CTL &= (~EADC_CTL_PDMAEN_Msk))
  107. /**
  108. * @brief Enable Sample Module PDMA transfer.
  109. * @param[in] eadc The pointer of the specified EADC module.
  110. * @param[in] u32ModuleMask the combination of sample module interrupt status bits. Each bit corresponds to a sample module interrupt status.
  111. * This parameter decides which sample module interrupts will be disabled, valid range are between 1~0x7FFFF.
  112. * @return None
  113. * @details When A/D conversion is completed, the converted data is loaded into EADC_DATn (n: 0 ~ 18) register,
  114. * user can enable this bit to generate a PDMA data transfer request.
  115. * \hideinitializer
  116. */
  117. #define EADC_ENABLE_SAMPLE_MODULE_PDMA(eadc, u32ModuleMask) ((eadc)->PDMACTL |= u32ModuleMask)
  118. /**
  119. * @brief Disable Sample Module PDMA transfer.
  120. * @param[in] eadc The pointer of the specified EADC module.
  121. * @param[in] u32ModuleMask the combination of sample module interrupt status bits. Each bit corresponds to a sample module interrupt status.
  122. * This parameter decides which sample module interrupts will be disabled, valid range are between 1~0x7FFFF.
  123. * @return None
  124. * @details This macro is used to disable sample module PDMA transfer.
  125. * \hideinitializer
  126. */
  127. #define EADC_DISABLE_SAMPLE_MODULE_PDMA(eadc, u32ModuleMask) ((eadc)->PDMACTL &= (~u32ModuleMask))
  128. /**
  129. * @brief Enable double buffer mode.
  130. * @param[in] eadc The pointer of the specified EADC module.
  131. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 3.
  132. * @return None
  133. * @details The ADC controller supports a double buffer mode in sample module 0~3.
  134. * If user enable DBMEN (EADC_SCTLn[23], n=0~3), the double buffer mode will enable.
  135. * \hideinitializer
  136. */
  137. #define EADC_ENABLE_DOUBLE_BUFFER(eadc, u32ModuleNum) ((eadc)->SCTL[(u32ModuleNum)] |= EADC_SCTL_DBMEN_Msk)
  138. /**
  139. * @brief Disable double buffer mode.
  140. * @param[in] eadc The pointer of the specified EADC module.
  141. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 3.
  142. * @return None
  143. * @details Sample has one sample result register.
  144. * \hideinitializer
  145. */
  146. #define EADC_DISABLE_DOUBLE_BUFFER(eadc, u32ModuleNum) ((eadc)->SCTL[(u32ModuleNum)] &= ~EADC_SCTL_DBMEN_Msk)
  147. /**
  148. * @brief Set ADIFn at A/D end of conversion.
  149. * @param[in] eadc The pointer of the specified EADC module.
  150. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 15.
  151. * @return None
  152. * @details The A/D converter generates ADIFn (EADC_STATUS2[3:0], n=0~3) at the start of conversion.
  153. * \hideinitializer
  154. */
  155. #define EADC_ENABLE_INT_POSITION(eadc, u32ModuleNum) ((eadc)->SCTL[(u32ModuleNum)] |= EADC_SCTL_INTPOS_Msk)
  156. /**
  157. * @brief Set ADIFn at A/D start of conversion.
  158. * @param[in] eadc The pointer of the specified EADC module.
  159. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 15.
  160. * @return None
  161. * @details The A/D converter generates ADIFn (EADC_STATUS2[3:0], n=0~3) at the end of conversion.
  162. * \hideinitializer
  163. */
  164. #define EADC_DISABLE_INT_POSITION(eadc, u32ModuleNum) ((eadc)->SCTL[(u32ModuleNum)] &= ~EADC_SCTL_INTPOS_Msk)
  165. /**
  166. * @brief Enable the interrupt.
  167. * @param[in] eadc The pointer of the specified EADC module.
  168. * @param[in] u32Mask Decides the combination of interrupt status bits. Each bit corresponds to a interrupt status.
  169. * This parameter decides which interrupts will be enabled. Bit 0 is ADCIEN0, bit 1 is ADCIEN1..., bit 3 is ADCIEN3.
  170. * @return None
  171. * @details The A/D converter generates a conversion end ADIFn (EADC_STATUS2[n]) upon the end of specific sample module A/D conversion.
  172. * If ADCIENn bit (EADC_CTL[n+2]) is set then conversion end interrupt request ADINTn is generated (n=0~3).
  173. * \hideinitializer
  174. */
  175. #define EADC_ENABLE_INT(eadc, u32Mask) ((eadc)->CTL |= ((u32Mask) << EADC_CTL_ADCIEN0_Pos))
  176. /**
  177. * @brief Disable the interrupt.
  178. * @param[in] eadc The pointer of the specified EADC module.
  179. * @param[in] u32Mask Decides the combination of interrupt status bits. Each bit corresponds to a interrupt status.
  180. * This parameter decides which interrupts will be disabled. Bit 0 is ADCIEN0, bit 1 is ADCIEN1..., bit 3 is ADCIEN3.
  181. * @return None
  182. * @details Specific sample module A/D ADINT0 interrupt function Disabled.
  183. * \hideinitializer
  184. */
  185. #define EADC_DISABLE_INT(eadc, u32Mask) ((eadc)->CTL &= ~((u32Mask) << EADC_CTL_ADCIEN0_Pos))
  186. /**
  187. * @brief Enable the sample module interrupt.
  188. * @param[in] eadc The pointer of the specified EADC module.
  189. * @param[in] u32IntSel Decides which interrupt source will be used, valid value are from 0 to 3.
  190. * @param[in] u32ModuleMask the combination of sample module interrupt status bits. Each bit corresponds to a sample module interrupt status.
  191. * This parameter decides which sample module interrupts will be enabled, valid range are between 1~0x7FFFF.
  192. * @return None
  193. * @details There are 4 ADC interrupts ADINT0~3, and each of these interrupts has its own interrupt vector address.
  194. * \hideinitializer
  195. */
  196. #define EADC_ENABLE_SAMPLE_MODULE_INT(eadc, u32IntSel, u32ModuleMask) ((eadc)->INTSRC[(u32IntSel)] |= (u32ModuleMask))
  197. /**
  198. * @brief Disable the sample module interrupt.
  199. * @param[in] eadc The pointer of the specified EADC module.
  200. * @param[in] u32IntSel Decides which interrupt source will be used, valid value are from 0 to 3.
  201. * @param[in] u32ModuleMask the combination of sample module interrupt status bits. Each bit corresponds to a sample module interrupt status.
  202. * This parameter decides which sample module interrupts will be disabled, valid range are between 1~0x7FFFF.
  203. * @return None
  204. * @details There are 4 ADC interrupts ADINT0~3, and each of these interrupts has its own interrupt vector address.
  205. * \hideinitializer
  206. */
  207. #define EADC_DISABLE_SAMPLE_MODULE_INT(eadc, u32IntSel, u32ModuleMask) ((eadc)->INTSRC[(u32IntSel)] &= ~(u32ModuleMask))
  208. /**
  209. * @brief Set the input mode output format.
  210. * @param[in] eadc The pointer of the specified EADC module.
  211. * @param[in] u32Format Decides the output format. Valid values are:
  212. * - EADC_CTL_DMOF_STRAIGHT_BINARY :Select the straight binary format as the output format of the conversion result.
  213. * - EADC_CTL_DMOF_TWOS_COMPLEMENT :Select the 2's complement format as the output format of the conversion result.
  214. * @return None
  215. * @details The macro is used to set A/D input mode output format.
  216. * \hideinitializer
  217. */
  218. #define EADC_SET_DMOF(eadc, u32Format) ((eadc)->CTL = ((eadc)->CTL & ~EADC_CTL_DMOF_Msk) | (u32Format))
  219. /**
  220. * @brief Start the A/D conversion.
  221. * @param[in] eadc The pointer of the specified EADC module.
  222. * @param[in] u32ModuleMask The combination of sample module. Each bit corresponds to a sample module.
  223. * This parameter decides which sample module will be conversion, valid range are between 1~0x7FFFF.
  224. * Bit 0 is sample module 0, bit 1 is sample module 1..., bit 18 is sample module 18.
  225. * @return None
  226. * @details After write EADC_SWTRG register to start ADC conversion, the EADC_PENDSTS register will show which SAMPLE will conversion.
  227. * \hideinitializer
  228. */
  229. #define EADC_START_CONV(eadc, u32ModuleMask) ((eadc)->SWTRG = (u32ModuleMask))
  230. /**
  231. * @brief Cancel the conversion for sample module.
  232. * @param[in] eadc The pointer of the specified EADC module.
  233. * @param[in] u32ModuleMask The combination of sample module. Each bit corresponds to a sample module.
  234. * This parameter decides which sample module will stop the conversion, valid range are between 1~0x7FFFF.
  235. * Bit 0 is sample module 0, bit 1 is sample module 1..., bit 18 is sample module18.
  236. * @return None
  237. * @details If user want to disable the conversion of the sample module, user can write EADC_PENDSTS register to clear it.
  238. * \hideinitializer
  239. */
  240. #define EADC_STOP_CONV(eadc, u32ModuleMask) ((eadc)->PENDSTS = (u32ModuleMask))
  241. /**
  242. * @brief Get the conversion pending flag.
  243. * @param[in] eadc The pointer of the specified EADC module.
  244. * @return Return the conversion pending sample module.
  245. * @details This STPFn(EADC_PENDSTS[18:0]) bit remains 1 during pending state, when the respective ADC conversion is end,
  246. * the STPFn (n=0~18) bit is automatically cleared to 0.
  247. * \hideinitializer
  248. */
  249. #define EADC_GET_PENDING_CONV(eadc) ((eadc)->PENDSTS)
  250. /**
  251. * @brief Get the conversion 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 conversion data of the user-specified sample module.
  255. * @details This macro is used to read RESULT bit (EADC_DATn[15:0], n=0~18) field to get conversion data.
  256. * \hideinitializer
  257. */
  258. #define EADC_GET_CONV_DATA(eadc, u32ModuleNum) ((eadc)->DAT[(u32ModuleNum)] & EADC_DAT_RESULT_Msk)
  259. /**
  260. * @brief Get the data overrun flag of the user-specified sample module.
  261. * @param[in] eadc The pointer of the specified EADC module.
  262. * @param[in] u32ModuleMask The combination of data overrun status bits. Each bit corresponds to a data overrun status, valid range are between 1~0x7FFFF.
  263. * @return Return the data overrun flag of the user-specified sample module.
  264. * @details This macro is used to read OV bit (EADC_STATUS0[31:16], EADC_STATUS1[18:16]) field to get data overrun status.
  265. * \hideinitializer
  266. */
  267. #define EADC_GET_DATA_OVERRUN_FLAG(eadc, u32ModuleMask) ((((eadc)->STATUS0 >> EADC_STATUS0_OV_Pos) | ((eadc)->STATUS1 & EADC_STATUS1_OV_Msk)) & (u32ModuleMask))
  268. /**
  269. * @brief Get the data valid flag of the user-specified sample module.
  270. * @param[in] eadc The pointer of the specified EADC module.
  271. * @param[in] u32ModuleMask The combination of data valid status bits. Each bit corresponds to a data valid status, valid range are between 1~0x7FFFF.
  272. * @return Return the data valid flag of the user-specified sample module.
  273. * @details This macro is used to read VALID bit (EADC_STATUS0[15:0], EADC_STATUS1[2:0]) field to get data valid status.
  274. * \hideinitializer
  275. */
  276. #define EADC_GET_DATA_VALID_FLAG(eadc, u32ModuleMask) ((((eadc)->STATUS0 & EADC_STATUS0_VALID_Msk) | (((eadc)->STATUS1 & EADC_STATUS1_VALID_Msk) << 16)) & (u32ModuleMask))
  277. /**
  278. * @brief Get the double data of the user-specified sample module.
  279. * @param[in] eadc The pointer of the specified EADC module.
  280. * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 18.
  281. * @return Return the double data of the user-specified sample module.
  282. * @details This macro is used to read RESULT bit (EADC_DDATn[15:0], n=0~3) field to get conversion data.
  283. * \hideinitializer
  284. */
  285. #define EADC_GET_DOUBLE_DATA(eadc, u32ModuleNum) ((eadc)->DDAT[(u32ModuleNum)] & EADC_DDAT0_RESULT_Msk)
  286. /**
  287. * @brief Get the user-specified interrupt flags.
  288. * @param[in] eadc The pointer of the specified EADC module.
  289. * @param[in] u32Mask The combination of interrupt status bits. Each bit corresponds to a interrupt status.
  290. * Bit 0 is ADIF0, bit 1 is ADIF1..., bit 3 is ADIF3.
  291. * Bit 4 is ADCMPF0, bit 5 is ADCMPF1..., bit 7 is ADCMPF3.
  292. * @return Return the user-specified interrupt flags.
  293. * @details This macro is used to get the user-specified interrupt flags.
  294. * \hideinitializer
  295. */
  296. #define EADC_GET_INT_FLAG(eadc, u32Mask) ((eadc)->STATUS2 & (u32Mask))
  297. /**
  298. * @brief Get the user-specified sample module overrun flags.
  299. * @param[in] eadc The pointer of the specified EADC module.
  300. * @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.
  301. * @return Return the user-specified sample module overrun flags.
  302. * @details This macro is used to get the user-specified sample module overrun flags.
  303. * \hideinitializer
  304. */
  305. #define EADC_GET_SAMPLE_MODULE_OV_FLAG(eadc, u32ModuleMask) ((eadc)->OVSTS & (u32ModuleMask))
  306. /**
  307. * @brief Clear the selected interrupt status bits.
  308. * @param[in] eadc The pointer of the specified EADC module.
  309. * @param[in] u32Mask The combination of compare interrupt status bits. Each bit corresponds to a compare interrupt status.
  310. * Bit 0 is ADIF0, bit 1 is ADIF1..., bit 3 is ADIF3.
  311. * Bit 4 is ADCMPF0, bit 5 is ADCMPF1..., bit 7 is ADCMPF3.
  312. * @return None
  313. * @details This macro is used to clear clear the selected interrupt status bits.
  314. * \hideinitializer
  315. */
  316. #define EADC_CLR_INT_FLAG(eadc, u32Mask) ((eadc)->STATUS2 = (u32Mask))
  317. /**
  318. * @brief Clear the selected sample module overrun status bits.
  319. * @param[in] eadc The pointer of the specified EADC module.
  320. * @param[in] u32ModuleMask The combination of sample module overrun status bits. Each bit corresponds to a sample module overrun status.
  321. * Bit 0 is SPOVF0, bit 1 is SPOVF1..., bit 18 is SPOVF18.
  322. * @return None
  323. * @details This macro is used to clear the selected sample module overrun status bits.
  324. * \hideinitializer
  325. */
  326. #define EADC_CLR_SAMPLE_MODULE_OV_FLAG(eadc, u32ModuleMask) ((eadc)->OVSTS = (u32ModuleMask))
  327. /**
  328. * @brief Check all sample module A/D result data register overrun flags.
  329. * @param[in] eadc The pointer of the specified EADC module.
  330. * @retval 0 None of sample module data register overrun flag is set to 1.
  331. * @retval 1 Any one of sample module data register overrun flag is set to 1.
  332. * @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.
  333. * \hideinitializer
  334. */
  335. #define EADC_IS_DATA_OV(eadc) (((eadc)->STATUS2 & EADC_STATUS2_AOV_Msk) >> EADC_STATUS2_AOV_Pos)
  336. /**
  337. * @brief Check all sample module A/D result data register valid flags.
  338. * @param[in] eadc The pointer of the specified EADC module.
  339. * @retval 0 None of sample module data register valid flag is set to 1.
  340. * @retval 1 Any one of sample module data register valid flag is set to 1.
  341. * @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.
  342. * \hideinitializer
  343. */
  344. #define EADC_IS_DATA_VALID(eadc) (((eadc)->STATUS2 & EADC_STATUS2_AVALID_Msk) >> EADC_STATUS2_AVALID_Pos)
  345. /**
  346. * @brief Check all A/D sample module start of conversion overrun flags.
  347. * @param[in] eadc The pointer of the specified EADC module.
  348. * @retval 0 None of sample module event overrun flag is set to 1.
  349. * @retval 1 Any one of sample module event overrun flag is set to 1.
  350. * @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.
  351. * \hideinitializer
  352. */
  353. #define EADC_IS_SAMPLE_MODULE_OV(eadc) (((eadc)->STATUS2 & EADC_STATUS2_STOVF_Msk) >> EADC_STATUS2_STOVF_Pos)
  354. /**
  355. * @brief Check all A/D interrupt flag overrun bits.
  356. * @param[in] eadc The pointer of the specified EADC module.
  357. * @retval 0 None of ADINT interrupt flag is overwritten to 1.
  358. * @retval 1 Any one of ADINT interrupt flag is overwritten to 1.
  359. * @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.
  360. * \hideinitializer
  361. */
  362. #define EADC_IS_INT_FLAG_OV(eadc) (((eadc)->STATUS2 & EADC_STATUS2_ADOVIF_Msk) >> EADC_STATUS2_ADOVIF_Pos)
  363. /**
  364. * @brief Get the busy state of EADC.
  365. * @param[in] eadc The pointer of the specified EADC module.
  366. * @retval 0 Idle state.
  367. * @retval 1 Busy state.
  368. * @details This macro is used to read BUSY bit (EADC_STATUS2[23]) to get busy state.
  369. * \hideinitializer
  370. */
  371. #define EADC_IS_BUSY(eadc) (((eadc)->STATUS2 & EADC_STATUS2_BUSY_Msk) >> EADC_STATUS2_BUSY_Pos)
  372. /**
  373. * @brief Configure the comparator 0 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_CMP0(EADC, 5, ADC_ADCMPR_CMPCOND_GREATER_OR_EQUAL, 0x800, 10, EADC_CMP_CMPWEN_DISABLE, EADC_CMP_ADCMPIE_ENABLE);
  383. * Means EADC will assert comparator 0 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_CMP0(eadc,\
  388. u32ModuleNum,\
  389. u32Condition,\
  390. u16CMPData,\
  391. u32MatchCount) ((eadc)->CMP[0] = (((eadc)->CMP[0] & ~(EADC_CMP_CMPSPL_Msk|EADC_CMP_CMPCOND_Msk|EADC_CMP_CMPDAT_Msk|EADC_CMP_CMPMCNT_Msk))|\
  392. (((u32ModuleNum) << EADC_CMP_CMPSPL_Pos)|\
  393. (u32Condition) |\
  394. ((u16CMPData) << EADC_CMP_CMPDAT_Pos)| \
  395. (((u32MatchCount) - 1) << EADC_CMP_CMPMCNT_Pos)|\
  396. EADC_CMP_ADCMPEN_Msk)))
  397. /**
  398. * @brief Configure the comparator 1 and enable it.
  399. * @param[in] eadc The pointer of the specified EADC module.
  400. * @param[in] u32ModuleNum specifies the compare sample module, valid value are from 0 to 18.
  401. * @param[in] u32Condition specifies the compare condition. Valid values are:
  402. * - \ref EADC_CMP_CMPCOND_LESS_THAN :The compare condition is "less than the compare value"
  403. * - \ref EADC_CMP_CMPCOND_GREATER_OR_EQUAL :The compare condition is "greater than or equal to the compare value
  404. * @param[in] u16CMPData specifies the compare value, valid range are between 0~0xFFF.
  405. * @param[in] u32MatchCount specifies the match count setting, valid range are between 0~0xF.
  406. * @return None
  407. * @details For example, ADC_ENABLE_CMP1(EADC, 5, ADC_ADCMPR_CMPCOND_GREATER_OR_EQUAL, 0x800, 10, EADC_CMP_ADCMPIE_ENABLE);
  408. * Means EADC will assert comparator 1 flag if sample module 5 conversion result is greater or
  409. * equal to 0x800 for 10 times continuously, and a compare interrupt request is generated.
  410. * \hideinitializer
  411. */
  412. #define EADC_ENABLE_CMP1(eadc,\
  413. u32ModuleNum,\
  414. u32Condition,\
  415. u16CMPData,\
  416. u32MatchCount) ((eadc)->CMP[1] = (((eadc)->CMP[1] & ~(EADC_CMP_CMPSPL_Msk|EADC_CMP_CMPCOND_Msk|EADC_CMP_CMPDAT_Msk|EADC_CMP_CMPMCNT_Msk))|\
  417. (((u32ModuleNum) << EADC_CMP_CMPSPL_Pos)|\
  418. (u32Condition) |\
  419. ((u16CMPData) << EADC_CMP_CMPDAT_Pos)| \
  420. (((u32MatchCount) - 1) << EADC_CMP_CMPMCNT_Pos)|\
  421. EADC_CMP_ADCMPEN_Msk)))
  422. /**
  423. * @brief Configure the comparator 2 and enable it.
  424. * @param[in] eadc The pointer of the specified EADC module.
  425. * @param[in] u32ModuleNum specifies the compare sample module, valid value are from 0 to 18.
  426. * @param[in] u32Condition specifies the compare condition. Valid values are:
  427. * - \ref EADC_CMP_CMPCOND_LESS_THAN :The compare condition is "less than the compare value"
  428. * - \ref EADC_CMP_CMPCOND_GREATER_OR_EQUAL :The compare condition is "greater than or equal to the compare value
  429. * @param[in] u16CMPData specifies the compare value, valid range are between 0~0xFFF.
  430. * @param[in] u32MatchCount specifies the match count setting, valid range are between 0~0xF.
  431. * @return None
  432. * @details For example, ADC_ENABLE_CMP2(EADC, 5, ADC_ADCMPR_CMPCOND_GREATER_OR_EQUAL, 0x800, 10, EADC_CMP_CMPWEN_DISABLE, EADC_CMP_ADCMPIE_ENABLE);
  433. * Means EADC will assert comparator 2 flag if sample module 5 conversion result is greater or
  434. * equal to 0x800 for 10 times continuously, and a compare interrupt request is generated.
  435. * \hideinitializer
  436. */
  437. #define EADC_ENABLE_CMP2(eadc,\
  438. u32ModuleNum,\
  439. u32Condition,\
  440. u16CMPData,\
  441. u32MatchCount) ((eadc)->CMP[2] = (((eadc)->CMP[2] & ~(EADC_CMP_CMPSPL_Msk|EADC_CMP_CMPCOND_Msk|EADC_CMP_CMPDAT_Msk|EADC_CMP_CMPMCNT_Msk))|\
  442. (((u32ModuleNum) << EADC_CMP_CMPSPL_Pos)|\
  443. (u32Condition) |\
  444. ((u16CMPData) << EADC_CMP_CMPDAT_Pos)| \
  445. (((u32MatchCount) - 1) << EADC_CMP_CMPMCNT_Pos)|\
  446. EADC_CMP_ADCMPEN_Msk)))
  447. /**
  448. * @brief Configure the comparator 3 and enable it.
  449. * @param[in] eadc The pointer of the specified EADC module.
  450. * @param[in] u32ModuleNum specifies the compare sample module, valid value are from 0 to 18.
  451. * @param[in] u32Condition specifies the compare condition. Valid values are:
  452. * - \ref EADC_CMP_CMPCOND_LESS_THAN :The compare condition is "less than the compare value"
  453. * - \ref EADC_CMP_CMPCOND_GREATER_OR_EQUAL :The compare condition is "greater than or equal to the compare value
  454. * @param[in] u16CMPData specifies the compare value, valid range are between 0~0xFFF.
  455. * @param[in] u32MatchCount specifies the match count setting, valid range are between 1~0xF.
  456. * @return None
  457. * @details For example, ADC_ENABLE_CMP3(EADC, 5, ADC_ADCMPR_CMPCOND_GREATER_OR_EQUAL, 0x800, 10, EADC_CMP_ADCMPIE_ENABLE);
  458. * Means EADC will assert comparator 3 flag if sample module 5 conversion result is greater or
  459. * equal to 0x800 for 10 times continuously, and a compare interrupt request is generated.
  460. * \hideinitializer
  461. */
  462. #define EADC_ENABLE_CMP3(eadc,\
  463. u32ModuleNum,\
  464. u32Condition,\
  465. u16CMPData,\
  466. u32MatchCount) ((eadc)->CMP[3] = (((eadc)->CMP[3] & ~(EADC_CMP_CMPSPL_Msk|EADC_CMP_CMPCOND_Msk|EADC_CMP_CMPDAT_Msk|EADC_CMP_CMPMCNT_Msk))|\
  467. (((u32ModuleNum) << EADC_CMP_CMPSPL_Pos)|\
  468. (u32Condition) |\
  469. ((u16CMPData) << EADC_CMP_CMPDAT_Pos)| \
  470. (((u32MatchCount) - 1) << EADC_CMP_CMPMCNT_Pos)|\
  471. EADC_CMP_ADCMPEN_Msk)))
  472. /**
  473. * @brief Enable the compare window mode.
  474. * @param[in] eadc The pointer of the specified EADC module.
  475. * @param[in] u32CMP Specifies the compare register, valid value are 0 and 2.
  476. * @return None
  477. * @details ADCMPF0 (EADC_STATUS2[4]) will be set when both EADC_CMP0 and EADC_CMP1 compared condition matched.
  478. * \hideinitializer
  479. */
  480. #define EADC_ENABLE_CMP_WINDOW_MODE(eadc, u32CMP) ((eadc)->CMP[(u32CMP)] |= EADC_CMP_CMPWEN_Msk)
  481. /**
  482. * @brief Disable the compare window mode.
  483. * @param[in] eadc The pointer of the specified EADC module.
  484. * @param[in] u32CMP Specifies the compare register, valid value are 0 and 2.
  485. * @return None
  486. * @details ADCMPF2 (EADC_STATUS2[6]) will be set when both EADC_CMP2 and EADC_CMP3 compared condition matched.
  487. * \hideinitializer
  488. */
  489. #define EADC_DISABLE_CMP_WINDOW_MODE(eadc, u32CMP) ((eadc)->CMP[(u32CMP)] &= ~EADC_CMP_CMPWEN_Msk)
  490. /**
  491. * @brief Enable the compare interrupt.
  492. * @param[in] eadc The pointer of the specified EADC module.
  493. * @param[in] u32CMP Specifies the compare register, valid value are from 0 to 3.
  494. * @return None
  495. * @details If the compare function is enabled and the compare condition matches the setting of CMPCOND (EADC_CMPn[2], n=0~3)
  496. * and CMPMCNT (EADC_CMPn[11:8], n=0~3), ADCMPFn (EADC_STATUS2[7:4], n=0~3) will be asserted, in the meanwhile,
  497. * if ADCMPIE is set to 1, a compare interrupt request is generated.
  498. * \hideinitializer
  499. */
  500. #define EADC_ENABLE_CMP_INT(eadc, u32CMP) ((eadc)->CMP[(u32CMP)] |= EADC_CMP_ADCMPIE_Msk)
  501. /**
  502. * @brief Disable the compare interrupt.
  503. * @param[in] eadc The pointer of the specified EADC module.
  504. * @param[in] u32CMP Specifies the compare register, valid value are from 0 to 3.
  505. * @return None
  506. * @details This macro is used to disable the compare interrupt.
  507. * \hideinitializer
  508. */
  509. #define EADC_DISABLE_CMP_INT(eadc, u32CMP) ((eadc)->CMP[(u32CMP)] &= ~EADC_CMP_ADCMPIE_Msk)
  510. /**
  511. * @brief Disable comparator 0.
  512. * @param[in] eadc The pointer of the specified EADC module.
  513. * @return None
  514. * @details This macro is used to disable comparator 0.
  515. * \hideinitializer
  516. */
  517. #define EADC_DISABLE_CMP0(eadc) ((eadc)->CMP[0] = 0)
  518. /**
  519. * @brief Disable comparator 1.
  520. * @param[in] eadc The pointer of the specified EADC module.
  521. * @return None
  522. * @details This macro is used to disable comparator 1.
  523. * \hideinitializer
  524. */
  525. #define EADC_DISABLE_CMP1(eadc) ((eadc)->CMP[1] = 0)
  526. /**
  527. * @brief Disable comparator 2.
  528. * @param[in] eadc The pointer of the specified EADC module.
  529. * @return None
  530. * @details This macro is used to disable comparator 2.
  531. * \hideinitializer
  532. */
  533. #define EADC_DISABLE_CMP2(eadc) ((eadc)->CMP[2] = 0)
  534. /**
  535. * @brief Disable comparator 3.
  536. * @param[in] eadc The pointer of the specified EADC module.
  537. * @return None
  538. * @details This macro is used to disable comparator 3.
  539. * \hideinitializer
  540. */
  541. #define EADC_DISABLE_CMP3(eadc) ((eadc)->CMP[3] = 0)
  542. /*---------------------------------------------------------------------------------------------------------*/
  543. /* Define EADC functions prototype */
  544. /*---------------------------------------------------------------------------------------------------------*/
  545. void EADC_Open(EADC_T *eadc, uint32_t u32InputMode);
  546. void EADC_Close(EADC_T *eadc);
  547. void EADC_ConfigSampleModule(EADC_T *eadc, uint32_t u32ModuleNum, uint32_t u32TriggerSrc, uint32_t u32Channel);
  548. void EADC_SetTriggerDelayTime(EADC_T *eadc, uint32_t u32ModuleNum, uint32_t u32TriggerDelayTime, uint32_t u32DelayClockDivider);
  549. void EADC_SetExtendSampleTime(EADC_T *eadc, uint32_t u32ModuleNum, uint32_t u32ExtendSampleTime);
  550. /*@}*/ /* end of group EADC_EXPORTED_FUNCTIONS */
  551. /*@}*/ /* end of group EADC_Driver */
  552. /*@}*/ /* end of group Standard_Driver */
  553. #ifdef __cplusplus
  554. }
  555. #endif
  556. #endif /* __NU_EADC_H__ */
  557. /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/