1 /*****************************************************************************
2  * Copyright (c) 2019, Nations Technologies Inc.
3  *
4  * All rights reserved.
5  * ****************************************************************************
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * - Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the disclaimer below.
12  *
13  * Nations' name may not be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
19  * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
22  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  * ****************************************************************************/
27 
28 /**
29  * @file n32wb452_pwr.h
30  * @author Nations
31  * @version v1.0.0
32  *
33  * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
34  */
35 #ifndef __N32WB452_PWR_H__
36 #define __N32WB452_PWR_H__
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #include "n32wb452.h"
43 
44 /** @addtogroup N32WB452_StdPeriph_Driver
45  * @{
46  */
47 
48 /** @addtogroup PWR
49  * @{
50  */
51 
52 /** @addtogroup PWR_Exported_Types
53  * @{
54  */
55 
56 /**
57  * @}
58  */
59 
60 /** @addtogroup PWR_Exported_Constants
61  * @{
62  */
63 
64 /** @addtogroup PVD_detection_level
65  * @{
66  */
67 
68 #define PWR_PVDRANGRE_2V2 ((uint32_t)0x00000000)
69 #define PWR_PVDRANGRE_2V3 ((uint32_t)0x00000020)
70 #define PWR_PVDRANGRE_2V4 ((uint32_t)0x00000040)
71 #define PWR_PVDRANGRE_2V5 ((uint32_t)0x00000060)
72 #define PWR_PVDRANGRE_2V6 ((uint32_t)0x00000080)
73 #define PWR_PVDRANGRE_2V7 ((uint32_t)0x000000A0)
74 #define PWR_PVDRANGRE_2V8 ((uint32_t)0x000000C0)
75 #define PWR_PVDRANGRE_2V9 ((uint32_t)0x000000E0)
76 
77 #define PWR_PVDRANGE_1V78 ((uint32_t)0x00000200)
78 #define PWR_PVDRANGE_1V88 ((uint32_t)0x00000220)
79 #define PWR_PVDRANGE_1V98 ((uint32_t)0x00000240)
80 #define PWR_PVDRANGE_2V08 ((uint32_t)0x00000260)
81 #define PWR_PVDRANGE_3V06 ((uint32_t)0x00000280)
82 #define PWR_PVDRANGE_3V24 ((uint32_t)0x000002A0)
83 #define PWR_PVDRANGE_3V42 ((uint32_t)0x000002C0)
84 #define PWR_PVDRANGE_3V60 ((uint32_t)0x000002E0)
85 #define IS_PWR_PVD_LEVEL(LEVEL)                                                                                        \
86     (((LEVEL) == PWR_PVDRANGRE_2V2) || ((LEVEL) == PWR_PVDRANGRE_2V3) || ((LEVEL) == PWR_PVDRANGRE_2V4)                \
87      || ((LEVEL) == PWR_PVDRANGRE_2V5) || ((LEVEL) == PWR_PVDRANGRE_2V6) || ((LEVEL) == PWR_PVDRANGRE_2V7)             \
88      || ((LEVEL) == PWR_PVDRANGRE_2V8) || ((LEVEL) == PWR_PVDRANGRE_2V9) || ((LEVEL) == PWR_PVDRANGE_1V78)             \
89      || ((LEVEL) == PWR_PVDRANGE_1V88) || ((LEVEL) == PWR_PVDRANGE_1V98) || ((LEVEL) == PWR_PVDRANGE_2V08)             \
90      || ((LEVEL) == PWR_PVDRANGE_3V06) || ((LEVEL) == PWR_PVDRANGE_3V24) || ((LEVEL) == PWR_PVDRANGE_3V42)             \
91      || ((LEVEL) == PWR_PVDRANGE_3V60))
92 
93 /**
94  * @}
95  */
96 
97 /** @addtogroup Regulator_state_is_STOP_mode
98  * @{
99  */
100 
101 #define PWR_REGULATOR_ON            ((uint32_t)0x00000000)
102 #define PWR_REGULATOR_LOWPOWER      ((uint32_t)0x00000001)
103 #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_REGULATOR_ON) || ((REGULATOR) == PWR_REGULATOR_LOWPOWER))
104 /**
105  * @}
106  */
107 
108 /** @addtogroup STOP_mode_entry
109  * @{
110  */
111 
112 #define PWR_STOPENTRY_WFI        ((uint8_t)0x01)
113 #define PWR_STOPENTRY_WFE        ((uint8_t)0x02)
114 #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE))
115 
116 /**
117  * @}
118  */
119 
120 /** @addtogroup PWR_Flag
121  * @{
122  */
123 
124 #define PWR_WU_FLAG    ((uint32_t)0x00000001)
125 #define PWR_SB_FLAG    ((uint32_t)0x00000002)
126 #define PWR_PVDO_FLAG  ((uint32_t)0x00000004)
127 #define PWR_VBATF_FLAG ((uint32_t)0x00000008)
128 #define IS_PWR_GET_FLAG(FLAG)                                                                                          \
129     (((FLAG) == PWR_WU_FLAG) || ((FLAG) == PWR_SB_FLAG) || ((FLAG) == PWR_PVDO_FLAG) || ((FLAG) == PWR_VBATF_FLAG))
130 
131 #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_WU_FLAG) || ((FLAG) == PWR_SB_FLAG) || ((FLAG) == PWR_VBATF_FLAG))
132 /**
133  * @}
134  */
135 
136 /**
137  * @}
138  */
139 
140 /** @addtogroup PWR_Exported_Macros
141  * @{
142  */
143 
144 /**
145  * @}
146  */
147 
148 /** @addtogroup PWR_Exported_Functions
149  * @{
150  */
151 
152 void PWR_DeInit(void);
153 void PWR_BackupAccessEnable(FunctionalState Cmd);
154 void PWR_PvdEnable(FunctionalState Cmd);
155 void PWR_PvdRangeConfig(uint32_t PWR_PVDLevel);
156 void PWR_WakeUpPinEnable(FunctionalState Cmd);
157 void PWR_EnterStopState(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);
158 void PWR_EnterSLEEPMode(uint8_t SLEEPONEXIT, uint8_t PWR_STOPEntry);
159 void PWR_EnterSTOP2Mode(uint8_t PWR_STOPEntry);
160 void PWR_EnterStandbyState(void);
161 FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG);
162 void PWR_ClearFlag(uint32_t PWR_FLAG);
163 
164 #ifdef __cplusplus
165 }
166 #endif
167 
168 #endif /* __N32WB452_PWR_H__ */
169        /**
170         * @}
171         */
172 
173 /**
174  * @}
175  */
176 
177 /**
178  * @}
179  */
180