1 /******************************************************************************
2 *
3 * @brief header file for PMC.
4 *
5 *******************************************************************************
6 *
7 * provide APIs for accessing PMC
8 ******************************************************************************/
9 #ifndef PMC_H_
10 #define PMC_H_
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 /******************************************************************************
16 * Includes
17 ******************************************************************************/
18
19 /******************************************************************************
20 * Macros
21 ******************************************************************************/
22 /******************************************************************************
23 * PMC system mode definition
24 *
25 *//*! @addtogroup pmc_sysmode
26 * @{
27 *******************************************************************************/
28 #define PmcModeRun 0 /*!< run mode */
29 #define PmcModeWait 1 /*!< wait mode */
30 #define PmcModeStop4 2 /*!< stop4 mode */
31 #define PmcModeStop3 3 /*!< stop3 mode */
32 /*! @} End of pmc_sysmode */
33
34 /******************************************************************************
35 * PMC LVD and LVW voltage definition
36 *
37 *//*! @addtogroup pmc_voltageselect
38 * @{
39 *******************************************************************************/
40 #define PmcLVDTrip_Low 0 /*!< LVD low trip point */
41 #define PmcLVDTrip_High 1 /*!< LVD high trip point */
42
43 #define PmcLVWTrip_Low 0 /*!< LVW low trip point */
44 #define PmcLVWTrip_Mid1 1 /*!< LVW mid1 trip point */
45 #define PmcLVWTrip_Mid2 2 /*!< LVW mid2 trip point */
46 #define PmcLVWTrip_High 3 /*!< LVW high trip point */
47 /*! @} End of pmc_voltageselect */
48
49
50 /******************************************************************************
51 * Types
52 ******************************************************************************/
53
54 /******************************************************************************
55 * PMC control struct
56 *
57 *//*! @addtogroup pmc_ctrlstruct
58 * @{
59 *******************************************************************************/
60 /*!
61 * @brief PMC Control Structure Type.
62 *
63 */
64
65 typedef union
66 {
67 uint8_t byte; /*!< byte field of union type */
68 struct
69 {
70 uint8_t bBandgapEn :1; /*!< bandgap enable */
71 uint8_t bBandgapDrv :1; /*!< bandgap drive select */
72 uint8_t bLvdEn :1; /*!< LVD enable */
73 uint8_t bLvdStopEn :1; /*!< LVD enable in stop mode */
74 uint8_t bLvdRstEn :1; /*!< reset enable when VLD evvent */
75 uint8_t bLvwIrqEn :1; /*!< LVW int enable */
76 uint8_t bLvwAck :1; /*!< LVW acknowledge */
77 uint8_t bLvwFlag :1; /*!< LVW flag */
78 }bits; /*!< bitfield of union type */
79 }PMC_Ctrl1Type, *PMC_Ctrl1Ptr; /*!< PMC control1 reg structure */
80 /*! @} End of pmc_ctrlstruct */
81
82 /******************************************************************************
83 * PMC control-- voltage select type.
84 *
85 *//*! @addtogroup pmc_voltselectstruct
86 * @{
87 *******************************************************************************/
88 /*!
89 * @brief PMC control-- voltage select type.
90 *
91 */
92 typedef union
93 {
94 uint8_t byte; /*!< byte field of union type */
95 struct
96 {
97 uint8_t :4; /*!< none */
98 uint8_t bLVWV :2; /*!< LVW voltage select */
99 uint8_t bLVDV :1; /*!< LVD voltage select */
100 uint8_t :1; /*!< none */
101 }bits; /*!< bitfield of union type */
102 }PMC_Ctrl2Type, *PMC_Ctrl2Ptr; /*!< PMC control2 reg structure */
103 /*! @} End of pmc_voltselectstruct */
104
105 /******************************************************************************
106 * PMC configrue type.
107 *
108 *//*! @addtogroup pmc_configstruct
109 * @{
110 *******************************************************************************/
111 /*!
112 * @brief PMC configrue type.
113 *
114 */
115
116 typedef struct
117 {
118 PMC_Ctrl1Type sCtrlstatus; /*!< PMC control and status */
119 PMC_Ctrl2Type sDetectVoltSelect; /*!< LVW and LVW voltage select */
120 }PMC_ConfigType, *PMC_ConfigPtr; /*!< PMC configuration structure */
121 /*! @} End of pmc_configstruct */
122
123
124
125 /******************************************************************************
126 * Global variables
127 ******************************************************************************/
128
129 /*!
130 * inline functions
131 */
132 /******************************************************************************
133 * PMC api list.
134 *
135 *//*! @addtogroup pmc_api_list
136 * @{
137 *******************************************************************************/
138 /*****************************************************************************//*!
139 *
140 * @brief enable LVD events during stop mode.
141 *
142 * @param[in] pPMC pointer to the PMC module.
143 *
144 * @return none.
145 *
146 * @ Pass/ Fail criteria: none.
147 *
148 * @see PMC_DisableLVDInStopMode.
149 *
150 *****************************************************************************/
PMC_EnableLVDInStopMode(PMC_Type * pPMC)151 __STATIC_INLINE void PMC_EnableLVDInStopMode(PMC_Type *pPMC)
152 {
153 pPMC->SPMSC1 |= PMC_SPMSC1_LVDSE_MASK;
154 }
155
156 /*****************************************************************************//*!
157 *
158 * @brief disable LVD events during stop mode.
159 *
160 * @param[in] pPMC pointer to the PMC module.
161 *
162 * @return none.
163 *
164 * @ Pass/ Fail criteria: none.
165 *
166 * @see PMC_EnableLVDInStopMode.
167 *
168 *****************************************************************************/
PMC_DisableLVDInStopMode(PMC_Type * pPMC)169 __STATIC_INLINE void PMC_DisableLVDInStopMode(PMC_Type *pPMC)
170 {
171 pPMC->SPMSC1 &= ~PMC_SPMSC1_LVDSE_MASK;
172 }
173
174 /*****************************************************************************//*!
175 *
176 * @brief enable LVD events to generate a hardware reset, note: write once.
177 *
178 * @param[in] pPMC pointer to the PMC module.
179 *
180 * @return none.
181 *
182 * @ Pass/ Fail criteria: none.
183 *
184 * @see PMC_DisableLVDRst.
185 *
186 *****************************************************************************/
PMC_EnableLVDRst(PMC_Type * pPMC)187 __STATIC_INLINE void PMC_EnableLVDRst(PMC_Type *pPMC)
188 {
189 pPMC->SPMSC1 |= PMC_SPMSC1_LVDRE_MASK;
190 }
191
192 /*****************************************************************************//*!
193 *
194 * @brief disable LVD events to generate a hardware reset, note: write once.
195 *
196 * @param[in] pPMC pointer to the PMC module.
197 *
198 * @return none.
199 *
200 * @ Pass/ Fail criteria: none.
201 *
202 * @see PMC_EnableLVDRst.
203 *
204 *****************************************************************************/
PMC_DisableLVDRst(PMC_Type * pPMC)205 __STATIC_INLINE void PMC_DisableLVDRst(PMC_Type *pPMC)
206 {
207 pPMC->SPMSC1 &= ~PMC_SPMSC1_LVDRE_MASK;
208 }
209
210 /*****************************************************************************//*!
211 *
212 * @brief enable low-voltage detect logic, note: write once.
213 *
214 * @param[in] pPMC pointer to the PMC module.
215 *
216 * @return none.
217 *
218 * @ Pass/ Fail criteria: none.
219 *
220 * @see PMC_DisableLVD.
221 *
222 *****************************************************************************/
PMC_EnableLVD(PMC_Type * pPMC)223 __STATIC_INLINE void PMC_EnableLVD(PMC_Type *pPMC)
224 {
225 pPMC->SPMSC1 |= PMC_SPMSC1_LVDE_MASK;
226 }
227
228 /*****************************************************************************//*!
229 *
230 * @brief disable low-voltage detect logic, note: write once
231 *
232 * @param[in] pPMC pointer to the PMC module.
233 *
234 * @return none.
235 *
236 * @ Pass/ Fail criteria: none
237 *
238 * @see PMC_EnableLVD.
239 *
240 *****************************************************************************/
PMC_DisableLVD(PMC_Type * pPMC)241 __STATIC_INLINE void PMC_DisableLVD(PMC_Type *pPMC)
242 {
243 pPMC->SPMSC1 &= ~PMC_SPMSC1_LVDE_MASK;
244 }
245
246 /*****************************************************************************//*!
247 *
248 * @brief set the low-voltage detect trip point voltage, note: write once.
249 *
250 * @param[in] pPMC pointer to the PMC module.
251 * @param[in] Trippoint LVD trip point voltage,0~1.
252 *
253 * @return none.
254 *
255 * @ Pass/ Fail criteria: none.
256 *
257 * @see PMC_SetLVWTripVolt.
258 *
259 *****************************************************************************/
PMC_SetLVDTripVolt(PMC_Type * pPMC,uint8_t Trippoint)260 __STATIC_INLINE void PMC_SetLVDTripVolt(PMC_Type *pPMC, uint8_t Trippoint)
261 {
262 if(Trippoint)
263 pPMC->SPMSC2 |= PMC_SPMSC2_LVDV_MASK;
264 else
265 pPMC->SPMSC2 &= ~PMC_SPMSC2_LVDV_MASK;
266 }
267
268 /*****************************************************************************//*!
269 *
270 * @brief set the low-voltage warning (LVW) trip point voltage.
271 *
272 * @param[in] pPMC pointer to the PMC module.
273 * @param[in] Trippoint LVW trip point voltage,0~3.
274 *
275 * @return none.
276 *
277 * @ Pass/ Fail criteria: none.
278 *
279 * @see PMC_SetLVDTripVolt.
280 *
281 *****************************************************************************/
PMC_SetLVWTripVolt(PMC_Type * pPMC,uint8_t Trippoint)282 __STATIC_INLINE void PMC_SetLVWTripVolt(PMC_Type *pPMC, uint8_t Trippoint)
283 {
284 pPMC->SPMSC2 &= ~PMC_SPMSC2_LVWV_MASK;
285 pPMC->SPMSC2 |= PMC_SPMSC2_LVWV(Trippoint);
286 }
287
288 /*****************************************************************************//*!
289 *
290 * @brief Enable hardware interrupt requests for LVWF.
291 *
292 * @param[in] pPMC pointer to the PMC module.
293 *
294 * @return none.
295 *
296 * @ Pass/ Fail criteria: none.
297 *
298 * @see PMC_DisableLVWInterrupt.
299 *
300 *****************************************************************************/
PMC_EnableLVWInterrupt(PMC_Type * pPMC)301 __STATIC_INLINE void PMC_EnableLVWInterrupt(PMC_Type *pPMC)
302 {
303 pPMC->SPMSC1 |= PMC_SPMSC1_LVWIE_MASK;
304 }
305
306 /*****************************************************************************//*!
307 *
308 * @brief Disable hardware interrupt requests for LVWF.
309 *
310 * @param[in] pPMC pointer to the PMC module.
311 *
312 * @return none.
313 *
314 * @ Pass/ Fail criteria: none.
315 *
316 * @see PMC_EnableLVWInterrupt.
317 *
318 *****************************************************************************/
PMC_DisableLVWInterrupt(PMC_Type * pPMC)319 __STATIC_INLINE void PMC_DisableLVWInterrupt(PMC_Type *pPMC)
320 {
321 pPMC->SPMSC1 &= ~PMC_SPMSC1_LVWIE_MASK;
322 }
323
324 /*****************************************************************************//*!
325 *
326 * @brief get the lvw warning flag.
327 *
328 * @param[in] pPMC pointer to the PMC module.
329 *
330 * @return uint8_t lvw warning flag.
331 *
332 * @ Pass/ Fail criteria: none.
333 *
334 * @see PMC_ClrLVWFlag.
335 *
336 *****************************************************************************/
PMC_GetLVWFlag(PMC_Type * pPMC)337 __STATIC_INLINE uint8_t PMC_GetLVWFlag(PMC_Type *pPMC)
338 {
339 return (pPMC->SPMSC1 & PMC_SPMSC1_LVWF_MASK);
340 }
341
342 /*****************************************************************************//*!
343 *
344 * @brief clear the lvw warning flag.
345 *
346 * @param[in] pPMC pointer to the PMC module.
347 *
348 * @return none.
349 *
350 * @ Pass/ Fail criteria: none.
351 *
352 * @see PMC_GetLVWFlag.
353 *
354 *****************************************************************************/
PMC_ClrLVWFlag(PMC_Type * pPMC)355 __STATIC_INLINE void PMC_ClrLVWFlag(PMC_Type *pPMC)
356 {
357 pPMC->SPMSC1 |= PMC_SPMSC1_LVWACK_MASK;
358 }
359
360 /*! @} End of pmc_api_list */
361
362 /******************************************************************************
363 * Global functions
364 ******************************************************************************/
365
366 void PMC_Init(PMC_Type *pPMC, PMC_ConfigType *pPMC_Config);
367 void PMC_DeInit(PMC_Type *pPMC);
368 void PMC_SetMode(PMC_Type *pPMC,uint8_t u8PmcMode);
369
370 #ifdef __cplusplus
371 }
372 #endif
373 #endif /* PMC_H_ */
374