2 **************************************************************************
3 * @file at32f435_437_pwc.c
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
34 * @brief PWC driver modules
38 #ifdef PWC_MODULE_ENABLED
40 /** @defgroup PWC_private_functions
45 * @brief deinitialize the pwc peripheral registers to their default reset values.
51 crm_periph_reset(CRM_PWC_PERIPH_RESET
, TRUE
);
52 crm_periph_reset(CRM_PWC_PERIPH_RESET
, FALSE
);
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.
61 void pwc_battery_powered_domain_access(confirm_state new_state
)
63 PWC
->ctrl_bit
.bpwen
= new_state
;
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
79 void pwc_pvm_level_select(pwc_pvm_voltage_type pvm_voltage
)
81 PWC
->ctrl_bit
.pvmsel
= pvm_voltage
;
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.
90 void pwc_power_voltage_monitor_enable(confirm_state new_state
)
92 PWC
->ctrl_bit
.pvmen
= new_state
;
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:
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>
107 void pwc_wakeup_pin_enable(uint32_t pin_num
, confirm_state new_state
)
109 if(new_state
== TRUE
)
111 PWC
->ctrlsts
|= pin_num
;
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:
125 * - note:"PWC_PVM_OUTPUT_FLAG" cannot be choose!this bit is readonly bit,it means the voltage monitoring output state
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:
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
)
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
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
)
176 else if(pwc_sleep_enter
== PWC_SLEEP_ENTER_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
190 void pwc_deep_sleep_mode_enter(pwc_deep_sleep_enter_type pwc_deep_sleep_enter
)
193 if(pwc_deep_sleep_enter
== PWC_DEEP_SLEEP_ENTER_WFE
)
199 else if(pwc_deep_sleep_enter
== PWC_DEEP_SLEEP_ENTER_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:
211 * - PWC_REGULATOR_LOW_POWER
214 void pwc_voltage_regulate_set(pwc_regulator_type pwc_regulator
)
216 PWC
->ctrl_bit
.vrsel
= pwc_regulator
;
220 * @brief enter pwc standby mode
224 void pwc_standby_mode_enter(void)
226 PWC
->ctrl_bit
.clswef
= TRUE
;
227 PWC
->ctrl_bit
.lpsel
= TRUE
;
229 #if defined (__CC_ARM)