| M480 BSP V3.05.001 The Board Support Package for M480 Series

opa.h
Go to the documentation of this file.
1 /**************************************************************************/
9 #ifndef __OPA_H__
10 #define __OPA_H__
11
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16
17
29 #define OPA_CALIBRATION_CLK_1K (0UL)
30 #define OPA_CALIBRATION_RV_1_2_AVDD (0UL)
31 #define OPA_CALIBRATION_RV_H_L_VCM (1UL)
33 /* end of group OPA_EXPORTED_CONSTANTS */
34
39 /*---------------------------------------------------------------------------------------------------------*/
40 /* Define OPA functions prototype */
41 /*---------------------------------------------------------------------------------------------------------*/
42 __STATIC_INLINE int32_t OPA_Calibration(OPA_T *opa, uint32_t u32OpaNum, uint32_t u32ClockSel, uint32_t u32LevelSel);
43
53 #define OPA_POWER_ON(opa, u32OpaNum) ((opa)->CTL |= (1UL<<(OPA_CTL_OPEN0_Pos+(u32OpaNum))))
54
63 #define OPA_POWER_DOWN(opa, u32OpaNum) ((opa)->CTL &= ~(1UL<<(OPA_CTL_OPEN0_Pos+(u32OpaNum))))
64
73 #define OPA_ENABLE_SCH_TRIGGER(opa, u32OpaNum) ((opa)->CTL |= (1UL<<(OPA_CTL_OPDOEN0_Pos+(u32OpaNum))))
74
83 #define OPA_DISABLE_SCH_TRIGGER(opa, u32OpaNum) ((opa)->CTL &= ~(1UL<<(OPA_CTL_OPDOEN0_Pos+(u32OpaNum))))
84
93 #define OPA_ENABLE_INT(opa, u32OpaNum) ((opa)->CTL |= (1UL<<(OPA_CTL_OPDOIEN0_Pos+(u32OpaNum))))
94
103 #define OPA_DISABLE_INT(opa, u32OpaNum) ((opa)->CTL &= ~(1UL<<(OPA_CTL_OPDOIEN0_Pos+(u32OpaNum))))
104
113 #define OPA_GET_DIGITAL_OUTPUT(opa, u32OpaNum) (((opa)->STATUS & (OPA_STATUS_OPDO0_Msk<<(u32OpaNum)))?1UL:0UL)
114
124 #define OPA_GET_INT_FLAG(opa, u32OpaNum) (((opa)->STATUS & (OPA_STATUS_OPDOIF0_Msk<<(u32OpaNum)))?1UL:0UL)
125
134 #define OPA_CLR_INT_FLAG(opa, u32OpaNum) ((opa)->STATUS = (OPA_STATUS_OPDOIF0_Msk<<(u32OpaNum)))
135
136
151 __STATIC_INLINE int32_t OPA_Calibration(OPA_T *opa,
152 uint32_t u32OpaNum,
153 uint32_t u32ClockSel,
154 uint32_t u32RefVol)
155 {
156 uint32_t u32CALResult;
157 int32_t i32Ret = 0L;
158
159 (opa)->CALCTL = (((opa)->CALCTL) & ~(OPA_CALCTL_CALCLK0_Msk << (u32OpaNum << 1)));
160 (opa)->CALCTL = (((opa)->CALCTL) & ~(OPA_CALCTL_CALRVS0_Msk << (u32OpaNum))) | (((u32RefVol) << OPA_CALCTL_CALRVS0_Pos) << (u32OpaNum));
161 (opa)->CALCTL |= (OPA_CALCTL_CALTRG0_Msk << (u32OpaNum));
162 while((opa)->CALCTL & (OPA_CALCTL_CALTRG0_Msk << (u32OpaNum))) {}
163
164 u32CALResult = ((opa)->CALST >> ((u32OpaNum)*4U)) & (OPA_CALST_CALNS0_Msk|OPA_CALST_CALPS0_Msk);
165 if (u32CALResult == 0U)
166 {
167 i32Ret = 0L;
168 }
169 else if (u32CALResult == OPA_CALST_CALNS0_Msk)
170 {
171 i32Ret = -2L;
172 }
173 else if (u32CALResult == OPA_CALST_CALPS0_Msk)
174 {
175 i32Ret = -1L;
176 }
177 else if (u32CALResult == (OPA_CALST_CALNS0_Msk|OPA_CALST_CALPS0_Msk))
178 {
179 i32Ret = -3L;
180 }
181
182 return i32Ret;
183 }
184
191 #define OPA_Reset() \
192 do { \
193 SYS->IPRST2 |= SYS_IPRST2_OPARST_Msk; \
194 SYS->IPRST2 &= ~SYS_IPRST2_OPARST_Msk; \
195 } while(0)
196 /* end of group OPA_EXPORTED_FUNCTIONS */
198 /* end of group OPA_Driver */
200 /* end of group Standard_Driver */
202
203 #ifdef __cplusplus
204 }
205 #endif
206
207 #endif /* __OPA_H__ */
208
209 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
OPA_T
Definition: opa_reg.h:26
OPA_Calibration
__STATIC_INLINE int32_t OPA_Calibration(OPA_T *opa, uint32_t u32OpaNum, uint32_t u32ClockSel, uint32_t u32LevelSel)
This function is used to configure and start OPA calibration.
Definition: opa.h:151
OPA_CALCTL_CALRVS0_Pos
#define OPA_CALCTL_CALRVS0_Pos
Definition: opa_reg.h:382
OPA_CALCTL_CALRVS0_Msk
#define OPA_CALCTL_CALRVS0_Msk
Definition: opa_reg.h:383
OPA_CALST_CALNS0_Msk
#define OPA_CALST_CALNS0_Msk
Definition: opa_reg.h:395
OPA_CALST_CALPS0_Msk
#define OPA_CALST_CALPS0_Msk
Definition: opa_reg.h:398
OPA_CALCTL_CALTRG0_Msk
#define OPA_CALCTL_CALTRG0_Msk
Definition: opa_reg.h:365
OPA_CALCTL_CALCLK0_Msk
#define OPA_CALCTL_CALCLK0_Msk
Definition: opa_reg.h:374