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