libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
pwr_common_v1.c
Go to the documentation of this file.
1/** @addtogroup pwr_file PWR peripheral API
2@ingroup peripheral_apis
3
4@author @htmlonly © @endhtmlonly 2012
5Ken Sarkies <ksarkies@internode.on.net>
6
7*/
8/*
9 * This file is part of the libopencm3 project.
10 *
11 * Copyright (C) 2012 Ken Sarkies <ksarkies@internode.on.net>
12 *
13 * This library is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU Lesser General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public License
24 * along with this library. If not, see <http://www.gnu.org/licenses/>.
25 */
26
27/**@{*/
28
30
31/*---------------------------------------------------------------------------*/
32/** @brief Disable Backup Domain Write Protection.
33
34This allows backup domain registers to be changed. These registers are write
35protected after a reset.
36*/
37
39{
41}
42
43/*---------------------------------------------------------------------------*/
44/** @brief Re-enable Backup Domain Write Protection.
45
46This protects backup domain registers from inadvertent change.
47*/
48
50{
51 PWR_CR &= ~PWR_CR_DBP;
52}
53
54/*---------------------------------------------------------------------------*/
55/** @brief Enable Power Voltage Detector.
56
57This provides voltage level threshold detection. The result of detection is
58provided in the power voltage detector output flag (see @ref pwr_voltage_high)
59or by setting the EXTI16 interrupt (see datasheet for configuration details).
60
61@param[in] pvd_level uint32_t. Taken from @ref pwr_pls.
62*/
63
64void pwr_enable_power_voltage_detect(uint32_t pvd_level)
65{
66 PWR_CR &= ~PWR_CR_PLS_MASK;
67 PWR_CR |= (PWR_CR_PVDE | pvd_level);
68}
69
70/*---------------------------------------------------------------------------*/
71/** @brief Disable Power Voltage Detector.
72
73*/
74
76{
77 PWR_CR &= ~PWR_CR_PVDE;
78}
79
80/*---------------------------------------------------------------------------*/
81/** @brief Clear the Standby Flag.
82
83This is set when the processor returns from a standby mode.
84*/
85
87{
89}
90
91/*---------------------------------------------------------------------------*/
92/** @brief Clear the Wakeup Flag.
93
94This is set when the processor receives a wakeup signal.
95*/
96
98{
100}
101
102/*---------------------------------------------------------------------------*/
103/** @brief Set Standby Mode in Deep Sleep.
104
105*/
106
108{
110}
111
112/*---------------------------------------------------------------------------*/
113/** @brief Set Stop Mode in Deep Sleep.
114
115*/
116
118{
119 PWR_CR &= ~PWR_CR_PDDS;
120}
121
122/*---------------------------------------------------------------------------*/
123/** @brief Voltage Regulator On in Stop Mode.
124
125*/
126
128{
129 PWR_CR &= ~PWR_CR_LPDS;
130}
131
132/*---------------------------------------------------------------------------*/
133/** @brief Voltage Regulator Low Power in Stop Mode.
134
135*/
136
138{
140}
141
142/*---------------------------------------------------------------------------*/
143/** @brief Enable Wakeup Pin.
144
145The wakeup pin is used for waking the processor from standby mode.
146*/
147
149{
151}
152
153/*---------------------------------------------------------------------------*/
154/** @brief Release Wakeup Pin.
155
156The wakeup pin is used for general purpose I/O.
157*/
158
160{
161 PWR_CSR &= ~PWR_CSR_EWUP;
162}
163
164/*---------------------------------------------------------------------------*/
165/** @brief Get Voltage Detector Output.
166
167The voltage detector threshold must be set when the power voltage detector is
168enabled, see @ref pwr_enable_power_voltage_detect.
169
170@returns boolean: TRUE if the power voltage is above the preset voltage
171threshold.
172*/
173
175{
176 return !(PWR_CSR & PWR_CSR_PVDO);
177}
178
179/*---------------------------------------------------------------------------*/
180/** @brief Get Standby Flag.
181
182The standby flag is set when the processor returns from a standby state. It is
183cleared by software (see @ref pwr_clear_standby_flag).
184
185@returns boolean: TRUE if the processor was in standby state.
186*/
187
189{
190 return PWR_CSR & PWR_CSR_SBF;
191}
192
193/*---------------------------------------------------------------------------*/
194/** @brief Get Wakeup Flag.
195
196The wakeup flag is set when a wakeup event has been received. It is
197cleared by software (see @ref pwr_clear_wakeup_flag).
198
199@returns boolean: TRUE if a wakeup event was received.
200*/
201
203{
204 return PWR_CSR & PWR_CSR_WUF;
205}
206/**@}*/
#define PWR_CR_PVDE
PVDE: Power voltage detector enable.
Definition: pwr_common_v1.h:71
#define PWR_CR
Power control register (PWR_CR)
Definition: pwr_common_v1.h:41
#define PWR_CSR_PVDO
PVDO: PVD output.
Definition: pwr_common_v1.h:95
#define PWR_CR_CWUF
CWUF: Clear wakeup flag.
Definition: pwr_common_v1.h:77
#define PWR_CR_LPDS
LPDS: Low-power deepsleep.
Definition: pwr_common_v1.h:83
#define PWR_CSR_EWUP
EWUP: Enable WKUP pin.
Definition: pwr_common_v1.h:90
#define PWR_CR_PDDS
PDDS: Power down deepsleep.
Definition: pwr_common_v1.h:80
#define PWR_CSR_WUF
WUF: Wakeup flag.
#define PWR_CR_CSBF
CSBF: Clear standby flag.
Definition: pwr_common_v1.h:74
#define PWR_CSR_SBF
SBF: Standby flag.
Definition: pwr_common_v1.h:98
#define PWR_CR_DBP
DBP: Disable backup domain write protection.
Definition: pwr_common_v1.h:51
#define PWR_CSR
Power control/status register (PWR_CSR)
Definition: pwr_common_v1.h:44
void pwr_set_standby_mode(void)
Set Standby Mode in Deep Sleep.
void pwr_enable_backup_domain_write_protect(void)
Re-enable Backup Domain Write Protection.
Definition: pwr_common_v1.c:49
void pwr_disable_power_voltage_detect(void)
Disable Power Voltage Detector.
Definition: pwr_common_v1.c:75
void pwr_voltage_regulator_on_in_stop(void)
Voltage Regulator On in Stop Mode.
void pwr_disable_backup_domain_write_protect(void)
Disable Backup Domain Write Protection.
Definition: pwr_common_v1.c:38
void pwr_clear_wakeup_flag(void)
Clear the Wakeup Flag.
Definition: pwr_common_v1.c:97
bool pwr_get_standby_flag(void)
Get Standby Flag.
void pwr_disable_wakeup_pin(void)
Release Wakeup Pin.
void pwr_voltage_regulator_low_power_in_stop(void)
Voltage Regulator Low Power in Stop Mode.
bool pwr_get_wakeup_flag(void)
Get Wakeup Flag.
void pwr_clear_standby_flag(void)
Clear the Standby Flag.
Definition: pwr_common_v1.c:86
bool pwr_voltage_high(void)
Get Voltage Detector Output.
void pwr_enable_power_voltage_detect(uint32_t pvd_level)
Enable Power Voltage Detector.
Definition: pwr_common_v1.c:64
void pwr_enable_wakeup_pin(void)
Enable Wakeup Pin.
void pwr_set_stop_mode(void)
Set Stop Mode in Deep Sleep.