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