before merging master
[inav.git] / lib / main / AT32F43x / Drivers / AT32F43x_StdPeriph_Driver / src / at32f435_437_pwc.c
blobb952928ff8326bb1429ffb6604eab0f0417167b4
1 /**
2 **************************************************************************
3 * @file at32f435_437_pwc.c
4 * @version v2.1.0
5 * @date 2022-08-16
6 * @brief contains all the functions for the pwc firmware library
7 **************************************************************************
8 * Copyright notice & Disclaimer
10 * The software Board Support Package (BSP) that is made available to
11 * download from Artery official website is the copyrighted work of Artery.
12 * Artery authorizes customers to use, copy, and distribute the BSP
13 * software and its related documentation for the purpose of design and
14 * development in conjunction with Artery microcontrollers. Use of the
15 * software is governed by this copyright notice and the following disclaimer.
17 * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
18 * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
19 * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
20 * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
21 * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
24 **************************************************************************
27 #include "at32f435_437_conf.h"
29 /** @addtogroup AT32F435_437_periph_driver
30 * @{
33 /** @defgroup PWC
34 * @brief PWC driver modules
35 * @{
38 #ifdef PWC_MODULE_ENABLED
40 /** @defgroup PWC_private_functions
41 * @{
44 /**
45 * @brief deinitialize the pwc peripheral registers to their default reset values.
46 * @param none
47 * @retval none
49 void pwc_reset(void)
51 crm_periph_reset(CRM_PWC_PERIPH_RESET, TRUE);
52 crm_periph_reset(CRM_PWC_PERIPH_RESET, FALSE);
55 /**
56 * @brief enable or disable access to the battery powered domain.
57 * @param new_state: new state of battery powered domain access.
58 * this parameter can be: TRUE or FALSE.
59 * @retval none
61 void pwc_battery_powered_domain_access(confirm_state new_state)
63 PWC->ctrl_bit.bpwen= new_state;
66 /**
67 * @brief select the voltage threshold detected by the power voltage detector.
68 * @param pvm_voltage: select pwc pvm voltage
69 * this parameter can be one of the following values:
70 * - PWC_PVM_VOLTAGE_2V3
71 * - PWC_PVM_VOLTAGE_2V4
72 * - PWC_PVM_VOLTAGE_2V5
73 * - PWC_PVM_VOLTAGE_2V6
74 * - PWC_PVM_VOLTAGE_2V7
75 * - PWC_PVM_VOLTAGE_2V8
76 * - PWC_PVM_VOLTAGE_2V9
77 * @retval none
79 void pwc_pvm_level_select(pwc_pvm_voltage_type pvm_voltage)
81 PWC->ctrl_bit.pvmsel= pvm_voltage;
84 /**
85 * @brief enable or disable pwc power voltage monitor (pvm)
86 * @param new_state: new state of pvm.
87 * this parameter can be: TRUE or FALSE.
88 * @retval none
90 void pwc_power_voltage_monitor_enable(confirm_state new_state)
92 PWC->ctrl_bit.pvmen= new_state;
95 /**
96 * @brief enable or disable pwc standby wakeup pin
97 * @param pin_num: choose the wakeup pin.
98 * this parameter can be be any combination of the following values:
99 * - PWC_WAKEUP_PIN_1
100 * - PWC_WAKEUP_PIN_2
101 * @param new_state: new state of the standby wakeup pin.
102 * this parameter can be one of the following values:
103 * - TRUE <wakeup pin is used for wake up cpu from standby mode>
104 * - FALSE <wakeup pin is used for general purpose I/O>
105 * @retval none
107 void pwc_wakeup_pin_enable(uint32_t pin_num, confirm_state new_state)
109 if(new_state == TRUE)
111 PWC->ctrlsts |= pin_num;
113 else
115 PWC->ctrlsts &= ~pin_num;
120 * @brief clear flag of pwc
121 * @param pwc_flag: select the pwc flag.
122 * this parameter can be any combination of the following values:
123 * - PWC_WAKEUP_FLAG
124 * - PWC_STANDBY_FLAG
125 * - note:"PWC_PVM_OUTPUT_FLAG" cannot be choose!this bit is readonly bit,it means the voltage monitoring output state
126 * @retval none
128 void pwc_flag_clear(uint32_t pwc_flag)
130 if(pwc_flag & PWC_STANDBY_FLAG)
131 PWC->ctrl_bit.clsef = TRUE;
132 if(pwc_flag & PWC_WAKEUP_FLAG)
133 PWC->ctrl_bit.clswef = TRUE;
137 * @brief get flag of pwc
138 * @param pwc_flag: select the pwc flag.
139 * this parameter can be one of the following values:
140 * - PWC_WAKEUP_FLAG
141 * - PWC_STANDBY_FLAG
142 * - PWC_PVM_OUTPUT_FLAG
143 * @retval state of select flag(SET or RESET).
145 flag_status pwc_flag_get(uint32_t pwc_flag)
147 flag_status status = RESET;
148 if ((PWC->ctrlsts & pwc_flag) == RESET)
150 status = RESET;
152 else
154 status = SET;
156 return status;
160 * @brief enter pwc sleep mode
161 * @param sleep_mode_enter: choose the instruction to enter sleep mode.
162 * this parameter can be one of the following values:
163 * - PWC_SLEEP_ENTER_WFI
164 * - PWC_SLEEP_ENTER_WFE
165 * @retval none
167 void pwc_sleep_mode_enter(pwc_sleep_enter_type pwc_sleep_enter)
169 SCB->SCR &= (uint32_t)~0x4;
170 if(pwc_sleep_enter == PWC_SLEEP_ENTER_WFE)
172 __SEV();
173 __WFE();
174 __WFE();
176 else if(pwc_sleep_enter == PWC_SLEEP_ENTER_WFI)
178 __WFI();
183 * @brief enter pwc deep-sleep mode
184 * @param pwc_deep_sleep_enter: choose the instruction to enter deep sleep mode.
185 * this parameter can be one of the following values:
186 * - PWC_DEEP_SLEEP_ENTER_WFI
187 * - PWC_DEEP_SLEEP_ENTER_WFE
188 * @retval none
190 void pwc_deep_sleep_mode_enter(pwc_deep_sleep_enter_type pwc_deep_sleep_enter)
192 SCB->SCR |= 0x04;
193 if(pwc_deep_sleep_enter == PWC_DEEP_SLEEP_ENTER_WFE)
195 __SEV();
196 __WFE();
197 __WFE();
199 else if(pwc_deep_sleep_enter == PWC_DEEP_SLEEP_ENTER_WFI)
201 __WFI();
203 SCB->SCR &= (uint32_t)~0x4;
207 * @brief regulate low power consumption in the deep sleep mode
208 * @param pwc_regulator: set the regulator state.
209 * this parameter can be one of the following values:
210 * - PWC_REGULATOR_ON
211 * - PWC_REGULATOR_LOW_POWER
212 * @retval none
214 void pwc_voltage_regulate_set(pwc_regulator_type pwc_regulator)
216 PWC->ctrl_bit.vrsel = pwc_regulator;
220 * @brief enter pwc standby mode
221 * @param none
222 * @retval none
224 void pwc_standby_mode_enter(void)
226 PWC->ctrl_bit.clswef = TRUE;
227 PWC->ctrl_bit.lpsel = TRUE;
228 SCB->SCR |= 0x04;
229 #if defined (__CC_ARM)
230 __force_stores();
231 #endif
232 while(1)
234 __WFI();
239 * @}
242 #endif
245 * @}
249 * @}