mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
screamer
Date:
Tue Aug 02 14:07:36 2016 +0000
Revision:
144:423e1876dc07
Parent:
18:da299f395b9e
Added targets.json file for the supported targets in the release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 18:da299f395b9e 1 /**
mbed_official 18:da299f395b9e 2 * \file
mbed_official 18:da299f395b9e 3 *
mbed_official 18:da299f395b9e 4 * \brief SAM L21 Power functionality
mbed_official 18:da299f395b9e 5 *
mbed_official 18:da299f395b9e 6 * Copyright (C) 2014-2015 Atmel Corporation. All rights reserved.
mbed_official 18:da299f395b9e 7 *
mbed_official 18:da299f395b9e 8 * \asf_license_start
mbed_official 18:da299f395b9e 9 *
mbed_official 18:da299f395b9e 10 * \page License
mbed_official 18:da299f395b9e 11 *
mbed_official 18:da299f395b9e 12 * Redistribution and use in source and binary forms, with or without
mbed_official 18:da299f395b9e 13 * modification, are permitted provided that the following conditions are met:
mbed_official 18:da299f395b9e 14 *
mbed_official 18:da299f395b9e 15 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 18:da299f395b9e 16 * this list of conditions and the following disclaimer.
mbed_official 18:da299f395b9e 17 *
mbed_official 18:da299f395b9e 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 18:da299f395b9e 19 * this list of conditions and the following disclaimer in the documentation
mbed_official 18:da299f395b9e 20 * and/or other materials provided with the distribution.
mbed_official 18:da299f395b9e 21 *
mbed_official 18:da299f395b9e 22 * 3. The name of Atmel may not be used to endorse or promote products derived
mbed_official 18:da299f395b9e 23 * from this software without specific prior written permission.
mbed_official 18:da299f395b9e 24 *
mbed_official 18:da299f395b9e 25 * 4. This software may only be redistributed and used in connection with an
mbed_official 18:da299f395b9e 26 * Atmel microcontroller product.
mbed_official 18:da299f395b9e 27 *
mbed_official 18:da299f395b9e 28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
mbed_official 18:da299f395b9e 29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed_official 18:da299f395b9e 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
mbed_official 18:da299f395b9e 31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
mbed_official 18:da299f395b9e 32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 18:da299f395b9e 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
mbed_official 18:da299f395b9e 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
mbed_official 18:da299f395b9e 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
mbed_official 18:da299f395b9e 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 18:da299f395b9e 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 18:da299f395b9e 38 * POSSIBILITY OF SUCH DAMAGE.
mbed_official 18:da299f395b9e 39 *
mbed_official 18:da299f395b9e 40 * \asf_license_stop
mbed_official 18:da299f395b9e 41 *
mbed_official 18:da299f395b9e 42 */
mbed_official 18:da299f395b9e 43 /*
mbed_official 18:da299f395b9e 44 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
mbed_official 18:da299f395b9e 45 */
mbed_official 18:da299f395b9e 46 #ifndef POWER_H_INCLUDED
mbed_official 18:da299f395b9e 47 #define POWER_H_INCLUDED
mbed_official 18:da299f395b9e 48
mbed_official 18:da299f395b9e 49 #include <compiler.h>
mbed_official 18:da299f395b9e 50 #include <clock.h>
mbed_official 18:da299f395b9e 51
mbed_official 18:da299f395b9e 52 #ifdef __cplusplus
mbed_official 18:da299f395b9e 53 extern "C" {
mbed_official 18:da299f395b9e 54 #endif
mbed_official 18:da299f395b9e 55
mbed_official 18:da299f395b9e 56 /**
mbed_official 18:da299f395b9e 57 * \addtogroup asfdoc_sam0_system_group
mbed_official 18:da299f395b9e 58 * @{
mbed_official 18:da299f395b9e 59 */
mbed_official 18:da299f395b9e 60
mbed_official 18:da299f395b9e 61 /**
mbed_official 18:da299f395b9e 62 * \brief Device sleep modes.
mbed_official 18:da299f395b9e 63 *
mbed_official 18:da299f395b9e 64 * List of available sleep modes in the device. A table of clocks available in
mbed_official 18:da299f395b9e 65 * different sleep modes can be found in \ref asfdoc_sam0_system_module_overview_sleep_mode.
mbed_official 18:da299f395b9e 66 */
mbed_official 18:da299f395b9e 67 enum system_sleepmode {
mbed_official 18:da299f395b9e 68 /** IDLE sleep mode */
mbed_official 18:da299f395b9e 69 SYSTEM_SLEEPMODE_IDLE = PM_SLEEPCFG_SLEEPMODE(0x2),
mbed_official 18:da299f395b9e 70 /** STANDBY sleep mode */
mbed_official 18:da299f395b9e 71 SYSTEM_SLEEPMODE_STANDBY = PM_SLEEPCFG_SLEEPMODE_STANDBY,
mbed_official 18:da299f395b9e 72 /** BACKUP sleep mode */
mbed_official 18:da299f395b9e 73 SYSTEM_SLEEPMODE_BACKUP = PM_SLEEPCFG_SLEEPMODE_BACKUP,
mbed_official 18:da299f395b9e 74 /** OFF sleep mode */
mbed_official 18:da299f395b9e 75 SYSTEM_SLEEPMODE_OFF = PM_SLEEPCFG_SLEEPMODE_OFF,
mbed_official 18:da299f395b9e 76 };
mbed_official 18:da299f395b9e 77
mbed_official 18:da299f395b9e 78 /**
mbed_official 18:da299f395b9e 79 * \brief Performance level.
mbed_official 18:da299f395b9e 80 *
mbed_official 18:da299f395b9e 81 * List of performance levels. Performance level technique consists of
mbed_official 18:da299f395b9e 82 * adjusting the regulator output voltage to reduce power consumption.
mbed_official 18:da299f395b9e 83 */
mbed_official 18:da299f395b9e 84 enum system_performance_level {
mbed_official 18:da299f395b9e 85 /** Performance level 0 */
mbed_official 18:da299f395b9e 86 SYSTEM_PERFORMANCE_LEVEL_0 = PM_PLCFG_PLSEL_PL0,
mbed_official 18:da299f395b9e 87 /** Performance level 2 */
mbed_official 18:da299f395b9e 88 SYSTEM_PERFORMANCE_LEVEL_2 = PM_PLCFG_PLSEL_PL2,
mbed_official 18:da299f395b9e 89 };
mbed_official 18:da299f395b9e 90
mbed_official 18:da299f395b9e 91 /**
mbed_official 18:da299f395b9e 92 * \brief RAM Back-biasing mode.
mbed_official 18:da299f395b9e 93 *
mbed_official 18:da299f395b9e 94 * List of RAM back bias modes. By default, in standby sleep mode,
mbed_official 18:da299f395b9e 95 * RAM is in low power mode (back biased) if its power domain is in
mbed_official 18:da299f395b9e 96 * retention state. This behavior can be changed by configuring the Back Bias
mbed_official 18:da299f395b9e 97 * bit groups in STDBYCFG(STDBYCFG.BBIASxx).
mbed_official 18:da299f395b9e 98 */
mbed_official 18:da299f395b9e 99 enum system_ram_back_bias_mode {
mbed_official 18:da299f395b9e 100 /** Retention Back biasing mode */
mbed_official 18:da299f395b9e 101 SYSTEM_RAM_BACK_BIAS_RETENTION = 0,
mbed_official 18:da299f395b9e 102 /** Standby Back Biasing mode */
mbed_official 18:da299f395b9e 103 SYSTEM_RAM_BACK_BIAS_STANDBY,
mbed_official 18:da299f395b9e 104 /** Standby OFF mode */
mbed_official 18:da299f395b9e 105 SYSTEM_RAM_BACK_BIAS_STANDBY_OFF,
mbed_official 18:da299f395b9e 106 /** Always OFF mode */
mbed_official 18:da299f395b9e 107 SYSTEM_RAM_BACK_BIAS_OFF,
mbed_official 18:da299f395b9e 108 };
mbed_official 18:da299f395b9e 109
mbed_official 18:da299f395b9e 110 /**
mbed_official 18:da299f395b9e 111 * \brief Linked power domain.
mbed_official 18:da299f395b9e 112 *
mbed_official 18:da299f395b9e 113 * List of linked power domains. Power domains can be linked to each other.
mbed_official 18:da299f395b9e 114 * It allows a power domain (PDn) to be kept in active state if the inferior
mbed_official 18:da299f395b9e 115 * power domain (PDn-1) is in active state too.
mbed_official 18:da299f395b9e 116 */
mbed_official 18:da299f395b9e 117 enum system_linked_power_domain {
mbed_official 18:da299f395b9e 118 /** Power domains PD0/PD1/PD2 are not linked */
mbed_official 18:da299f395b9e 119 SYSTEM_LINKED_POWER_DOMAIN_DEFAULT = PM_STDBYCFG_LINKPD_DEFAULT_Val,
mbed_official 18:da299f395b9e 120 /** Power domains PD0 and PD1 are linked */
mbed_official 18:da299f395b9e 121 SYSTEM_LINKED_POWER_DOMAIN_PD01 = PM_STDBYCFG_LINKPD_PD01_Val,
mbed_official 18:da299f395b9e 122 /** Power domains PD1 and PD2 are linked */
mbed_official 18:da299f395b9e 123 SYSTEM_LINKED_POWER_DOMAIN_PD12 = PM_STDBYCFG_LINKPD_PD12_Val,
mbed_official 18:da299f395b9e 124 /** All Power domains are linked */
mbed_official 18:da299f395b9e 125 SYSTEM_LINKED_POWER_DOMAIN_PD012 = PM_STDBYCFG_LINKPD_PD012_Val,
mbed_official 18:da299f395b9e 126 };
mbed_official 18:da299f395b9e 127
mbed_official 18:da299f395b9e 128 /**
mbed_official 18:da299f395b9e 129 * \brief Power domain.
mbed_official 18:da299f395b9e 130 *
mbed_official 18:da299f395b9e 131 * List of power domains. Power domain gating technique consists of turning
mbed_official 18:da299f395b9e 132 * on or off power domain voltage to save power while keeping other domains
mbed_official 18:da299f395b9e 133 * powered up.
mbed_official 18:da299f395b9e 134 */
mbed_official 18:da299f395b9e 135 enum system_power_domain {
mbed_official 18:da299f395b9e 136 /** All power domains switching are handled by hardware */
mbed_official 18:da299f395b9e 137 SYSTEM_POWER_DOMAIN_DEFAULT = PM_STDBYCFG_PDCFG_DEFAULT_Val,
mbed_official 18:da299f395b9e 138 /** Power domain 0 (PD0) is forced ACTIVE */
mbed_official 18:da299f395b9e 139 SYSTEM_POWER_DOMAIN_PD0 = PM_STDBYCFG_PDCFG_PD0_Val,
mbed_official 18:da299f395b9e 140 /** Power domain 0 and 1 (PD0 and PD1) are forced ACTIVE */
mbed_official 18:da299f395b9e 141 SYSTEM_POWER_DOMAIN_PD01 = PM_STDBYCFG_PDCFG_PD01_Val,
mbed_official 18:da299f395b9e 142 /** All power domains are forced ACTIVE */
mbed_official 18:da299f395b9e 143 SYSTEM_POWER_DOMAIN_PD012 = PM_STDBYCFG_PDCFG_PD012_Val,
mbed_official 18:da299f395b9e 144 };
mbed_official 18:da299f395b9e 145
mbed_official 18:da299f395b9e 146 /**
mbed_official 18:da299f395b9e 147 * \brief Voltage regulator.
mbed_official 18:da299f395b9e 148 *
mbed_official 18:da299f395b9e 149 * Voltage regulators selection. In active mode, the voltage regulator
mbed_official 18:da299f395b9e 150 * can be chosen on the fly between a LDO or a Buck converter.
mbed_official 18:da299f395b9e 151 */
mbed_official 18:da299f395b9e 152 enum system_voltage_regulator_sel {
mbed_official 18:da299f395b9e 153 /** The voltage regulator in active mode is a LDO voltage regulator */
mbed_official 18:da299f395b9e 154 SYSTEM_VOLTAGE_REGULATOR_LDO = SUPC_VREG_SEL_LDO_Val,
mbed_official 18:da299f395b9e 155 /** The voltage regulator in active mode is a buck converter */
mbed_official 18:da299f395b9e 156 SYSTEM_VOLTAGE_REGULATOR_BUCK = SUPC_VREG_SEL_BUCK_Val,
mbed_official 18:da299f395b9e 157 };
mbed_official 18:da299f395b9e 158
mbed_official 18:da299f395b9e 159 /**
mbed_official 18:da299f395b9e 160 * \brief Low power efficiency.
mbed_official 18:da299f395b9e 161 *
mbed_official 18:da299f395b9e 162 * Low power mode efficiency.
mbed_official 18:da299f395b9e 163 */
mbed_official 18:da299f395b9e 164 enum system_voltage_regulator_low_power_efficiency {
mbed_official 18:da299f395b9e 165 /** The voltage regulator in Low power mode has the default efficiency and
mbed_official 18:da299f395b9e 166 support the whole VDD range (1.62V to 3.6V) */
mbed_official 18:da299f395b9e 167 SYSTEM_VOLTAGE_REGULATOR_LOW_POWER_EFFICIENCY_DEFAULT,
mbed_official 18:da299f395b9e 168 /** The voltage regulator in Low power mode has the highest efficiency and
mbed_official 18:da299f395b9e 169 support the limited VDD range (2.5V to 3.6V) */
mbed_official 18:da299f395b9e 170 SYSTEM_VOLTAGE_REGULATOR_LOW_POWER_EFFICIENCY_HIGHTEST,
mbed_official 18:da299f395b9e 171 };
mbed_official 18:da299f395b9e 172
mbed_official 18:da299f395b9e 173 /**
mbed_official 18:da299f395b9e 174 * \brief Voltage reference value.
mbed_official 18:da299f395b9e 175 *
mbed_official 18:da299f395b9e 176 * Voltage references selection.
mbed_official 18:da299f395b9e 177 */
mbed_official 18:da299f395b9e 178 enum system_voltage_references_sel {
mbed_official 18:da299f395b9e 179 /** 1.0V voltage reference typical value */
mbed_official 18:da299f395b9e 180 SYSTEM_VOLTAGE_REFERENCE_1V0 = SUPC_VREF_SEL_1V0_Val,
mbed_official 18:da299f395b9e 181 /** 1.1V voltage reference typical value */
mbed_official 18:da299f395b9e 182 SYSTEM_VOLTAGE_REFERENCE_1V1 = SUPC_VREF_SEL_1V1_Val,
mbed_official 18:da299f395b9e 183 /** 1.2V voltage reference typical value */
mbed_official 18:da299f395b9e 184 SYSTEM_VOLTAGE_REFERENCE_1V2 = SUPC_VREF_SEL_1V2_Val,
mbed_official 18:da299f395b9e 185 /** 1.25V voltage reference typical value */
mbed_official 18:da299f395b9e 186 SYSTEM_VOLTAGE_REFERENCE_1V25 = SUPC_VREF_SEL_1V25_Val,
mbed_official 18:da299f395b9e 187 /** 2.0V voltage reference typical value */
mbed_official 18:da299f395b9e 188 SYSTEM_VOLTAGE_REFERENCE_2V0 = SUPC_VREF_SEL_2V0_Val,
mbed_official 18:da299f395b9e 189 /** 2.2V voltage reference typical value */
mbed_official 18:da299f395b9e 190 SYSTEM_VOLTAGE_REFERENCE_2V2 = SUPC_VREF_SEL_2V2_Val,
mbed_official 18:da299f395b9e 191 /** 2.4V voltage reference typical value */
mbed_official 18:da299f395b9e 192 SYSTEM_VOLTAGE_REFERENCE_2V4 = SUPC_VREF_SEL_2V4_Val,
mbed_official 18:da299f395b9e 193 /** 2.5V voltage reference typical value */
mbed_official 18:da299f395b9e 194 SYSTEM_VOLTAGE_REFERENCE_2V5 = SUPC_VREF_SEL_2V5_Val,
mbed_official 18:da299f395b9e 195 };
mbed_official 18:da299f395b9e 196
mbed_official 18:da299f395b9e 197 /**
mbed_official 18:da299f395b9e 198 * \brief Battery power switch configuration enum.
mbed_official 18:da299f395b9e 199 *
mbed_official 18:da299f395b9e 200 * Enum for Battery power switch modes.
mbed_official 18:da299f395b9e 201 */
mbed_official 18:da299f395b9e 202 enum system_battery_power_switch {
mbed_official 18:da299f395b9e 203 /** The backup domain is always supplied by main power */
mbed_official 18:da299f395b9e 204 SYSTEM_BATTERY_POWER_SWITCH_NONE = SUPC_BBPS_CONF_NONE_Val,
mbed_official 18:da299f395b9e 205 /** The power switch is handled by the automatic power switch */
mbed_official 18:da299f395b9e 206 SYSTEM_BATTERY_POWER_SWITCH_AUTOMATIC = SUPC_BBPS_CONF_APWS_Val,
mbed_official 18:da299f395b9e 207 /** The backup domain is always supplied by battery backup power */
mbed_official 18:da299f395b9e 208 SYSTEM_BATTERY_POWER_SWITCH_FORCED = SUPC_BBPS_CONF_FORCED_Val,
mbed_official 18:da299f395b9e 209 /** The power switch is handled by the BOD33 */
mbed_official 18:da299f395b9e 210 SYSTEM_BATTERY_POWER_SWITCH_BOD33 = SUPC_BBPS_CONF_BOD33_Val,
mbed_official 18:da299f395b9e 211 };
mbed_official 18:da299f395b9e 212
mbed_official 18:da299f395b9e 213 /**
mbed_official 18:da299f395b9e 214 * \brief Voltage reference.
mbed_official 18:da299f395b9e 215 *
mbed_official 18:da299f395b9e 216 * List of available voltage references (VREF) that may be used within the
mbed_official 18:da299f395b9e 217 * device.
mbed_official 18:da299f395b9e 218 */
mbed_official 18:da299f395b9e 219 enum system_voltage_reference {
mbed_official 18:da299f395b9e 220 /** Temperature sensor voltage reference */
mbed_official 18:da299f395b9e 221 SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE,
mbed_official 18:da299f395b9e 222 /** Voltage reference output */
mbed_official 18:da299f395b9e 223 SYSTEM_VOLTAGE_REFERENCE_OUTPUT,
mbed_official 18:da299f395b9e 224 };
mbed_official 18:da299f395b9e 225
mbed_official 18:da299f395b9e 226 /**
mbed_official 18:da299f395b9e 227 * \brief Backup IO enum.
mbed_official 18:da299f395b9e 228 *
mbed_official 18:da299f395b9e 229 * List of Backup input and output pins.
mbed_official 18:da299f395b9e 230 * If enabled (\ref system_backup_pin_output_enable), the pins can be driven
mbed_official 18:da299f395b9e 231 * by the SUPC.
mbed_official 18:da299f395b9e 232 */
mbed_official 18:da299f395b9e 233 enum system_backup_pin {
mbed_official 18:da299f395b9e 234 /** Power Supply OK status pin */
mbed_official 18:da299f395b9e 235 SYSTEM_BACKUP_PIN_PSOK = (0x1 << 0),
mbed_official 18:da299f395b9e 236 /** Backup output pin 0 */
mbed_official 18:da299f395b9e 237 SYSTEM_BACKUP_PIN_OUT_0 = (0x1 << 1),
mbed_official 18:da299f395b9e 238 /** Backup output pin 1 */
mbed_official 18:da299f395b9e 239 SYSTEM_BACKUP_PIN_OUT_1 = (0x1 << 2)
mbed_official 18:da299f395b9e 240 };
mbed_official 18:da299f395b9e 241
mbed_official 18:da299f395b9e 242 /**
mbed_official 18:da299f395b9e 243 * \brief Standby configuration.
mbed_official 18:da299f395b9e 244 *
mbed_official 18:da299f395b9e 245 * Configuration structure for standby mode.
mbed_official 18:da299f395b9e 246 */
mbed_official 18:da299f395b9e 247 struct system_standby_config {
mbed_official 18:da299f395b9e 248 /** Power domain */
mbed_official 18:da299f395b9e 249 enum system_power_domain power_domain;
mbed_official 18:da299f395b9e 250 /** Enable dynamic power gating for power domain 0 */
mbed_official 18:da299f395b9e 251 bool enable_dpgpd0;
mbed_official 18:da299f395b9e 252 /** Enable dynamic power gating for power domain 1 */
mbed_official 18:da299f395b9e 253 bool enable_dpgpd1;
mbed_official 18:da299f395b9e 254 /** Automatic VREG switching disable */
mbed_official 18:da299f395b9e 255 bool disable_avregsd;
mbed_official 18:da299f395b9e 256 /** Linked power domain */
mbed_official 18:da299f395b9e 257 enum system_linked_power_domain linked_power_domain;
mbed_official 18:da299f395b9e 258 /** Back bias for HMCRAMCHS */
mbed_official 18:da299f395b9e 259 enum system_ram_back_bias_mode hmcramchs_back_bias;
mbed_official 18:da299f395b9e 260 /** Back bias for HMCRAMCLP */
mbed_official 18:da299f395b9e 261 enum system_ram_back_bias_mode hmcramclp_back_bias;
mbed_official 18:da299f395b9e 262 };
mbed_official 18:da299f395b9e 263
mbed_official 18:da299f395b9e 264 /**
mbed_official 18:da299f395b9e 265 * \brief Voltage Regulator System (VREG) Control configuration.
mbed_official 18:da299f395b9e 266 *
mbed_official 18:da299f395b9e 267 * Configuration structure for VREG.
mbed_official 18:da299f395b9e 268 */
mbed_official 18:da299f395b9e 269 struct system_voltage_regulator_config {
mbed_official 18:da299f395b9e 270 /** Voltage scaling period */
mbed_official 18:da299f395b9e 271 uint8_t voltage_scale_period;
mbed_official 18:da299f395b9e 272 /** Voltage scaling voltage step */
mbed_official 18:da299f395b9e 273 uint8_t voltage_scale_step;
mbed_official 18:da299f395b9e 274 /** Run in standby in standby sleep mode */
mbed_official 18:da299f395b9e 275 bool run_in_standby;
mbed_official 18:da299f395b9e 276 /** Voltage Regulator Selection */
mbed_official 18:da299f395b9e 277 enum system_voltage_regulator_sel regulator_sel;
mbed_official 18:da299f395b9e 278 /** Low power efficiency */
mbed_official 18:da299f395b9e 279 enum system_voltage_regulator_low_power_efficiency low_power_efficiency;
mbed_official 18:da299f395b9e 280 };
mbed_official 18:da299f395b9e 281
mbed_official 18:da299f395b9e 282 /**
mbed_official 18:da299f395b9e 283 * \brief Voltage References System (VREF) Control configuration.
mbed_official 18:da299f395b9e 284 *
mbed_official 18:da299f395b9e 285 * Configuration structure for VREF.
mbed_official 18:da299f395b9e 286 */
mbed_official 18:da299f395b9e 287 struct system_voltage_references_config {
mbed_official 18:da299f395b9e 288 /** Voltage References Selection */
mbed_official 18:da299f395b9e 289 enum system_voltage_references_sel sel;
mbed_official 18:da299f395b9e 290 /** On Demand Control */
mbed_official 18:da299f395b9e 291 bool on_demand;
mbed_official 18:da299f395b9e 292 /** Run in standby */
mbed_official 18:da299f395b9e 293 bool run_in_standby;
mbed_official 18:da299f395b9e 294 };
mbed_official 18:da299f395b9e 295
mbed_official 18:da299f395b9e 296 /**
mbed_official 18:da299f395b9e 297 * \brief Battery Backup Power Switch (BBPS) Control configuration.
mbed_official 18:da299f395b9e 298 *
mbed_official 18:da299f395b9e 299 * Configuration structure for Battery Backup Power Switch (BBPS).
mbed_official 18:da299f395b9e 300 */
mbed_official 18:da299f395b9e 301 struct system_battery_backup_power_switch_config {
mbed_official 18:da299f395b9e 302 /** Enable device wake up when BBPS switches from
mbed_official 18:da299f395b9e 303 battery backup power to main power */
mbed_official 18:da299f395b9e 304 bool wake_enabled;
mbed_official 18:da299f395b9e 305 /** Battery backup power switch configuration */
mbed_official 18:da299f395b9e 306 enum system_battery_power_switch battery_power_switch;
mbed_official 18:da299f395b9e 307 };
mbed_official 18:da299f395b9e 308
mbed_official 18:da299f395b9e 309 /**
mbed_official 18:da299f395b9e 310 * \name Voltage Regulator
mbed_official 18:da299f395b9e 311 * @{
mbed_official 18:da299f395b9e 312 */
mbed_official 18:da299f395b9e 313
mbed_official 18:da299f395b9e 314 /**
mbed_official 18:da299f395b9e 315 * \brief Retrieve the default configuration for voltage regulator.
mbed_official 18:da299f395b9e 316 *
mbed_official 18:da299f395b9e 317 * Fills a configuration structure with the default configuration:
mbed_official 18:da299f395b9e 318 * - Voltage scaling period is 1μs
mbed_official 18:da299f395b9e 319 * - Voltage scaling voltage step is 2*min_step
mbed_official 18:da299f395b9e 320 * - The voltage regulator is in low power mode in Standby sleep mode
mbed_official 18:da299f395b9e 321 * - The voltage regulator in active mode is an LDO voltage regulator
mbed_official 18:da299f395b9e 322 * - The voltage regulator in Low power mode has the default efficiency
mbed_official 18:da299f395b9e 323 *
mbed_official 18:da299f395b9e 324 * \param[out] config Configuration structure to fill with default values
mbed_official 18:da299f395b9e 325 */
mbed_official 18:da299f395b9e 326 static inline void system_voltage_regulator_get_config_defaults(
mbed_official 18:da299f395b9e 327 struct system_voltage_regulator_config *const config)
mbed_official 18:da299f395b9e 328 {
mbed_official 18:da299f395b9e 329 Assert(config);
mbed_official 18:da299f395b9e 330 config->voltage_scale_period = 0;
mbed_official 18:da299f395b9e 331 config->voltage_scale_step = 0;
mbed_official 18:da299f395b9e 332 config->run_in_standby = false;
mbed_official 18:da299f395b9e 333 config->regulator_sel = SYSTEM_VOLTAGE_REGULATOR_LDO;
mbed_official 18:da299f395b9e 334 config->low_power_efficiency = SYSTEM_VOLTAGE_REGULATOR_LOW_POWER_EFFICIENCY_DEFAULT;
mbed_official 18:da299f395b9e 335 }
mbed_official 18:da299f395b9e 336
mbed_official 18:da299f395b9e 337 /**
mbed_official 18:da299f395b9e 338 * \brief Configure voltage regulator.
mbed_official 18:da299f395b9e 339 *
mbed_official 18:da299f395b9e 340 * Configures voltage regulator with the given configuration.
mbed_official 18:da299f395b9e 341 *
mbed_official 18:da299f395b9e 342 * \param[in] config Voltage regulator configuration structure containing
mbed_official 18:da299f395b9e 343 * the new config
mbed_official 18:da299f395b9e 344 */
mbed_official 18:da299f395b9e 345 static inline void system_voltage_regulator_set_config(
mbed_official 18:da299f395b9e 346 struct system_voltage_regulator_config *const config)
mbed_official 18:da299f395b9e 347 {
mbed_official 18:da299f395b9e 348 Assert(config);
mbed_official 18:da299f395b9e 349 SUPC->VREG.bit.VSPER = config->voltage_scale_period;
mbed_official 18:da299f395b9e 350 SUPC->VREG.bit.VSVSTEP = config->voltage_scale_step;
mbed_official 18:da299f395b9e 351 SUPC->VREG.bit.RUNSTDBY = config->run_in_standby;
mbed_official 18:da299f395b9e 352 SUPC->VREG.bit.SEL = config->regulator_sel;
mbed_official 18:da299f395b9e 353 SUPC->VREG.bit.LPEFF = config->low_power_efficiency;
mbed_official 18:da299f395b9e 354 while(!(SUPC->STATUS.reg & SUPC_STATUS_VREGRDY)) {
mbed_official 18:da299f395b9e 355 ;
mbed_official 18:da299f395b9e 356 }
mbed_official 18:da299f395b9e 357 }
mbed_official 18:da299f395b9e 358
mbed_official 18:da299f395b9e 359 /**
mbed_official 18:da299f395b9e 360 * \brief Enable the selected voltage regulator.
mbed_official 18:da299f395b9e 361 *
mbed_official 18:da299f395b9e 362 * Enables the selected voltage regulator source.
mbed_official 18:da299f395b9e 363 */
mbed_official 18:da299f395b9e 364 static inline void system_voltage_regulator_enable(void)
mbed_official 18:da299f395b9e 365 {
mbed_official 18:da299f395b9e 366 SUPC->VREG.reg |= SUPC_VREG_ENABLE;
mbed_official 18:da299f395b9e 367 }
mbed_official 18:da299f395b9e 368
mbed_official 18:da299f395b9e 369 /**
mbed_official 18:da299f395b9e 370 * \brief Disable the selected voltage regulator.
mbed_official 18:da299f395b9e 371 *
mbed_official 18:da299f395b9e 372 * Disables the selected voltage regulator.
mbed_official 18:da299f395b9e 373 */
mbed_official 18:da299f395b9e 374 static inline void system_voltage_regulator_disable(void)
mbed_official 18:da299f395b9e 375 {
mbed_official 18:da299f395b9e 376 SUPC->VREG.reg &= ~SUPC_VREG_ENABLE;
mbed_official 18:da299f395b9e 377 }
mbed_official 18:da299f395b9e 378
mbed_official 18:da299f395b9e 379 /**
mbed_official 18:da299f395b9e 380 * @}
mbed_official 18:da299f395b9e 381 */
mbed_official 18:da299f395b9e 382
mbed_official 18:da299f395b9e 383 /**
mbed_official 18:da299f395b9e 384 * \name Voltage References
mbed_official 18:da299f395b9e 385 * @{
mbed_official 18:da299f395b9e 386 */
mbed_official 18:da299f395b9e 387
mbed_official 18:da299f395b9e 388 /**
mbed_official 18:da299f395b9e 389 * \brief Retrieve the default configuration for voltage reference.
mbed_official 18:da299f395b9e 390 *
mbed_official 18:da299f395b9e 391 * Fill a configuration structure with the default configuration:
mbed_official 18:da299f395b9e 392 * - 1.0V voltage reference typical value
mbed_official 18:da299f395b9e 393 * - On demand control disabled
mbed_official 18:da299f395b9e 394 * - The voltage reference and the temperature sensor are halted during standby sleep mode
mbed_official 18:da299f395b9e 395 *
mbed_official 18:da299f395b9e 396 * \param[out] config Configuration structure to fill with default values
mbed_official 18:da299f395b9e 397 */
mbed_official 18:da299f395b9e 398 static inline void system_voltage_reference_get_config_defaults(
mbed_official 18:da299f395b9e 399 struct system_voltage_references_config *const config)
mbed_official 18:da299f395b9e 400 {
mbed_official 18:da299f395b9e 401 Assert(config);
mbed_official 18:da299f395b9e 402 config->sel = SYSTEM_VOLTAGE_REFERENCE_1V0;
mbed_official 18:da299f395b9e 403 config->on_demand = false;
mbed_official 18:da299f395b9e 404 config->run_in_standby = false;
mbed_official 18:da299f395b9e 405 }
mbed_official 18:da299f395b9e 406
mbed_official 18:da299f395b9e 407 /**
mbed_official 18:da299f395b9e 408 * \brief Configure voltage reference.
mbed_official 18:da299f395b9e 409 *
mbed_official 18:da299f395b9e 410 * Configures voltage reference with the given configuration.
mbed_official 18:da299f395b9e 411 *
mbed_official 18:da299f395b9e 412 * \param[in] config Voltage reference configuration structure containing
mbed_official 18:da299f395b9e 413 * the new config
mbed_official 18:da299f395b9e 414 */
mbed_official 18:da299f395b9e 415 static inline void system_voltage_reference_set_config(
mbed_official 18:da299f395b9e 416 struct system_voltage_references_config *const config)
mbed_official 18:da299f395b9e 417 {
mbed_official 18:da299f395b9e 418 Assert(config);
mbed_official 18:da299f395b9e 419 SUPC->VREF.bit.SEL = config->sel;
mbed_official 18:da299f395b9e 420 SUPC->VREF.bit.ONDEMAND = config->on_demand;
mbed_official 18:da299f395b9e 421 SUPC->VREF.bit.RUNSTDBY = config->run_in_standby;
mbed_official 18:da299f395b9e 422 }
mbed_official 18:da299f395b9e 423
mbed_official 18:da299f395b9e 424 /**
mbed_official 18:da299f395b9e 425 * \brief Enable the selected voltage reference.
mbed_official 18:da299f395b9e 426 *
mbed_official 18:da299f395b9e 427 * Enables the selected voltage reference source, making the voltage reference
mbed_official 18:da299f395b9e 428 * available on a pin as well as an input source to the analog peripherals.
mbed_official 18:da299f395b9e 429 *
mbed_official 18:da299f395b9e 430 * \param[in] vref Voltage reference to enable
mbed_official 18:da299f395b9e 431 */
mbed_official 18:da299f395b9e 432 static inline void system_voltage_reference_enable(
mbed_official 18:da299f395b9e 433 const enum system_voltage_reference vref)
mbed_official 18:da299f395b9e 434 {
mbed_official 18:da299f395b9e 435 switch (vref) {
mbed_official 18:da299f395b9e 436 case SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE:
mbed_official 18:da299f395b9e 437 SUPC->VREF.reg |= SUPC_VREF_TSEN;
mbed_official 18:da299f395b9e 438 break;
mbed_official 18:da299f395b9e 439 case SYSTEM_VOLTAGE_REFERENCE_OUTPUT:
mbed_official 18:da299f395b9e 440 SUPC->VREF.reg |= SUPC_VREF_VREFOE;
mbed_official 18:da299f395b9e 441 break;
mbed_official 18:da299f395b9e 442 default:
mbed_official 18:da299f395b9e 443 Assert(false);
mbed_official 18:da299f395b9e 444 return;
mbed_official 18:da299f395b9e 445 }
mbed_official 18:da299f395b9e 446 }
mbed_official 18:da299f395b9e 447
mbed_official 18:da299f395b9e 448 /**
mbed_official 18:da299f395b9e 449 * \brief Disable the selected voltage reference.
mbed_official 18:da299f395b9e 450 *
mbed_official 18:da299f395b9e 451 * Disables the selected voltage reference source.
mbed_official 18:da299f395b9e 452 *
mbed_official 18:da299f395b9e 453 * \param[in] vref Voltage reference to disable
mbed_official 18:da299f395b9e 454 */
mbed_official 18:da299f395b9e 455 static inline void system_voltage_reference_disable(
mbed_official 18:da299f395b9e 456 const enum system_voltage_reference vref)
mbed_official 18:da299f395b9e 457 {
mbed_official 18:da299f395b9e 458 switch (vref) {
mbed_official 18:da299f395b9e 459 case SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE:
mbed_official 18:da299f395b9e 460 SUPC->VREF.reg &= ~SUPC_VREF_TSEN;
mbed_official 18:da299f395b9e 461 break;
mbed_official 18:da299f395b9e 462 case SYSTEM_VOLTAGE_REFERENCE_OUTPUT:
mbed_official 18:da299f395b9e 463 SUPC->VREF.reg &= ~SUPC_VREF_VREFOE;
mbed_official 18:da299f395b9e 464 break;
mbed_official 18:da299f395b9e 465 default:
mbed_official 18:da299f395b9e 466 Assert(false);
mbed_official 18:da299f395b9e 467 return;
mbed_official 18:da299f395b9e 468 }
mbed_official 18:da299f395b9e 469 }
mbed_official 18:da299f395b9e 470
mbed_official 18:da299f395b9e 471 /**
mbed_official 18:da299f395b9e 472 * @}
mbed_official 18:da299f395b9e 473 */
mbed_official 18:da299f395b9e 474
mbed_official 18:da299f395b9e 475 /**
mbed_official 18:da299f395b9e 476 * \name Battery Backup Power Switch
mbed_official 18:da299f395b9e 477 * @{
mbed_official 18:da299f395b9e 478 */
mbed_official 18:da299f395b9e 479
mbed_official 18:da299f395b9e 480 /**
mbed_official 18:da299f395b9e 481 * \brief Retrieve the default configuration for battery backup power switch control.
mbed_official 18:da299f395b9e 482 *
mbed_official 18:da299f395b9e 483 * Fills a configuration structure with the default configuration:
mbed_official 18:da299f395b9e 484 * - The main Power Supply OK status is not available on the PSOK pin
mbed_official 18:da299f395b9e 485 * - The device is not woken up when switched from battery backup power to main power
mbed_official 18:da299f395b9e 486 * - The backup domain is always supplied by main power
mbed_official 18:da299f395b9e 487 *
mbed_official 18:da299f395b9e 488 * \param[out] config Configuration structure to fill with default values
mbed_official 18:da299f395b9e 489 */
mbed_official 18:da299f395b9e 490 static inline void system_battery_backup_power_switch_get_config_defaults(
mbed_official 18:da299f395b9e 491 struct system_battery_backup_power_switch_config *const config)
mbed_official 18:da299f395b9e 492 {
mbed_official 18:da299f395b9e 493 Assert(config);
mbed_official 18:da299f395b9e 494 config->wake_enabled = false;
mbed_official 18:da299f395b9e 495 config->battery_power_switch = SYSTEM_BATTERY_POWER_SWITCH_NONE;
mbed_official 18:da299f395b9e 496 }
mbed_official 18:da299f395b9e 497
mbed_official 18:da299f395b9e 498 /**
mbed_official 18:da299f395b9e 499 * \brief Configure battery backup power switch.
mbed_official 18:da299f395b9e 500 *
mbed_official 18:da299f395b9e 501 * Configures battery backup power switch with the given configuration.
mbed_official 18:da299f395b9e 502 *
mbed_official 18:da299f395b9e 503 * \param[in] config Battery backup power switch configuration structure containing
mbed_official 18:da299f395b9e 504 * the new config
mbed_official 18:da299f395b9e 505 */
mbed_official 18:da299f395b9e 506 static inline void system_battery_backup_power_switch_set_config(
mbed_official 18:da299f395b9e 507 struct system_battery_backup_power_switch_config *const config)
mbed_official 18:da299f395b9e 508 {
mbed_official 18:da299f395b9e 509 Assert(config);
mbed_official 18:da299f395b9e 510 uint32_t new_config = SUPC->BBPS.reg & SUPC_BBPS_PSOKEN;
mbed_official 18:da299f395b9e 511
mbed_official 18:da299f395b9e 512 if(config->wake_enabled) {
mbed_official 18:da299f395b9e 513 new_config |= SUPC_BBPS_WAKEEN;
mbed_official 18:da299f395b9e 514 }
mbed_official 18:da299f395b9e 515
mbed_official 18:da299f395b9e 516 new_config |= SUPC_BBPS_CONF(config->battery_power_switch);
mbed_official 18:da299f395b9e 517
mbed_official 18:da299f395b9e 518 SUPC->BBPS.reg = new_config;
mbed_official 18:da299f395b9e 519
mbed_official 18:da299f395b9e 520 if (config->battery_power_switch == SYSTEM_BATTERY_POWER_SWITCH_AUTOMATIC) {
mbed_official 18:da299f395b9e 521 while (!(SUPC->STATUS.reg & SUPC_STATUS_APWSRDY)) {
mbed_official 18:da299f395b9e 522 ;
mbed_official 18:da299f395b9e 523 }
mbed_official 18:da299f395b9e 524 }
mbed_official 18:da299f395b9e 525 }
mbed_official 18:da299f395b9e 526
mbed_official 18:da299f395b9e 527 /**
mbed_official 18:da299f395b9e 528 * @}
mbed_official 18:da299f395b9e 529 */
mbed_official 18:da299f395b9e 530
mbed_official 18:da299f395b9e 531 /**
mbed_official 18:da299f395b9e 532 * \name Output Pins in Backup Mode
mbed_official 18:da299f395b9e 533 * @{
mbed_official 18:da299f395b9e 534 */
mbed_official 18:da299f395b9e 535
mbed_official 18:da299f395b9e 536 /**
mbed_official 18:da299f395b9e 537 * \brief Enable the backup pin output.
mbed_official 18:da299f395b9e 538 *
mbed_official 18:da299f395b9e 539 * The output is enabled and driven by the SUPC.
mbed_official 18:da299f395b9e 540 *
mbed_official 18:da299f395b9e 541 * \param[in] pin Backup pin index
mbed_official 18:da299f395b9e 542 */
mbed_official 18:da299f395b9e 543 static inline void system_backup_pin_output_enable(
mbed_official 18:da299f395b9e 544 enum system_backup_pin pin)
mbed_official 18:da299f395b9e 545 {
mbed_official 18:da299f395b9e 546 if (pin == SYSTEM_BACKUP_PIN_PSOK) {
mbed_official 18:da299f395b9e 547 SUPC->BBPS.reg |= SUPC_BBPS_PSOKEN;
mbed_official 18:da299f395b9e 548 } else {
mbed_official 18:da299f395b9e 549 SUPC->BKOUT.reg |= SUPC_BKOUT_EN(pin >> 1);
mbed_official 18:da299f395b9e 550 }
mbed_official 18:da299f395b9e 551 }
mbed_official 18:da299f395b9e 552
mbed_official 18:da299f395b9e 553 /**
mbed_official 18:da299f395b9e 554 * \brief Disable the backup pin output.
mbed_official 18:da299f395b9e 555 *
mbed_official 18:da299f395b9e 556 * The output is not enabled.
mbed_official 18:da299f395b9e 557 *
mbed_official 18:da299f395b9e 558 * \param[in] pin Backup pin index
mbed_official 18:da299f395b9e 559 */
mbed_official 18:da299f395b9e 560 static inline void system_backup_pin_output_disable(
mbed_official 18:da299f395b9e 561 enum system_backup_pin pin)
mbed_official 18:da299f395b9e 562 {
mbed_official 18:da299f395b9e 563 if (pin == SYSTEM_BACKUP_PIN_PSOK) {
mbed_official 18:da299f395b9e 564 SUPC->BBPS.reg &= ~SUPC_BBPS_PSOKEN;
mbed_official 18:da299f395b9e 565 } else {
mbed_official 18:da299f395b9e 566 SUPC->BKOUT.reg &= ~SUPC_BKOUT_EN(pin >> 1);
mbed_official 18:da299f395b9e 567 }
mbed_official 18:da299f395b9e 568 }
mbed_official 18:da299f395b9e 569
mbed_official 18:da299f395b9e 570 /**
mbed_official 18:da299f395b9e 571 * \brief Check if backup pin output is enabled.
mbed_official 18:da299f395b9e 572 *
mbed_official 18:da299f395b9e 573 * \param[in] pin Backup pin index
mbed_official 18:da299f395b9e 574 *
mbed_official 18:da299f395b9e 575 * \return The enabled status.
mbed_official 18:da299f395b9e 576 * \retval true The output is enabled
mbed_official 18:da299f395b9e 577 * \retval false The output is not enabled
mbed_official 18:da299f395b9e 578 */
mbed_official 18:da299f395b9e 579 static inline bool system_backup_pin_output_is_enabled(
mbed_official 18:da299f395b9e 580 enum system_backup_pin pin)
mbed_official 18:da299f395b9e 581 {
mbed_official 18:da299f395b9e 582 bool enabled = false;
mbed_official 18:da299f395b9e 583
mbed_official 18:da299f395b9e 584 if (pin == SYSTEM_BACKUP_PIN_PSOK) {
mbed_official 18:da299f395b9e 585 if (SUPC->BBPS.reg & SUPC_BBPS_PSOKEN) {
mbed_official 18:da299f395b9e 586 enabled = true;
mbed_official 18:da299f395b9e 587 }
mbed_official 18:da299f395b9e 588 } else {
mbed_official 18:da299f395b9e 589 if (SUPC->BKOUT.reg & SUPC_BKOUT_EN(pin >> 1)) {
mbed_official 18:da299f395b9e 590 enabled = true;
mbed_official 18:da299f395b9e 591 }
mbed_official 18:da299f395b9e 592 }
mbed_official 18:da299f395b9e 593 return enabled;
mbed_official 18:da299f395b9e 594 }
mbed_official 18:da299f395b9e 595
mbed_official 18:da299f395b9e 596 /**
mbed_official 18:da299f395b9e 597 * \brief Enable the backup pin toggle on RTC event.
mbed_official 18:da299f395b9e 598 *
mbed_official 18:da299f395b9e 599 * Toggle output on RTC event is enabled.
mbed_official 18:da299f395b9e 600 *
mbed_official 18:da299f395b9e 601 * \param[in] pin Backup pin index
mbed_official 18:da299f395b9e 602 */
mbed_official 18:da299f395b9e 603 static inline void system_backup_pin_output_enable_rtc_toggle(
mbed_official 18:da299f395b9e 604 enum system_backup_pin pin)
mbed_official 18:da299f395b9e 605 {
mbed_official 18:da299f395b9e 606 Assert(pin != SYSTEM_BACKUP_PIN_PSOK);
mbed_official 18:da299f395b9e 607
mbed_official 18:da299f395b9e 608 SUPC->BKOUT.reg |= SUPC_BKOUT_RTCTGL(pin >> 1);
mbed_official 18:da299f395b9e 609 }
mbed_official 18:da299f395b9e 610
mbed_official 18:da299f395b9e 611 /**
mbed_official 18:da299f395b9e 612 * \brief Disable the backup pin toggle on RTC event.
mbed_official 18:da299f395b9e 613 *
mbed_official 18:da299f395b9e 614 * Toggle output on RTC event is disabled.
mbed_official 18:da299f395b9e 615 *
mbed_official 18:da299f395b9e 616 * \param[in] pin Backup pin index
mbed_official 18:da299f395b9e 617 */
mbed_official 18:da299f395b9e 618 static inline void system_backup_pin_output_disable_rtc_toggle(
mbed_official 18:da299f395b9e 619 enum system_backup_pin pin)
mbed_official 18:da299f395b9e 620 {
mbed_official 18:da299f395b9e 621 Assert(pin != SYSTEM_BACKUP_PIN_PSOK);
mbed_official 18:da299f395b9e 622
mbed_official 18:da299f395b9e 623 SUPC->BKOUT.reg &= ~SUPC_BKOUT_RTCTGL(pin >> 1);
mbed_official 18:da299f395b9e 624 }
mbed_official 18:da299f395b9e 625
mbed_official 18:da299f395b9e 626 /**
mbed_official 18:da299f395b9e 627 * \brief Set the backup pin.
mbed_official 18:da299f395b9e 628 *
mbed_official 18:da299f395b9e 629 * Set the corresponding output pin.
mbed_official 18:da299f395b9e 630 *
mbed_official 18:da299f395b9e 631 * \param[in] pin Backup pin index
mbed_official 18:da299f395b9e 632 */
mbed_official 18:da299f395b9e 633 static inline void system_backup_pin_output_set(
mbed_official 18:da299f395b9e 634 enum system_backup_pin pin)
mbed_official 18:da299f395b9e 635 {
mbed_official 18:da299f395b9e 636 Assert(pin != SYSTEM_BACKUP_PIN_PSOK);
mbed_official 18:da299f395b9e 637
mbed_official 18:da299f395b9e 638 SUPC->BKOUT.reg |= SUPC_BKOUT_SET(pin >> 1);
mbed_official 18:da299f395b9e 639 }
mbed_official 18:da299f395b9e 640
mbed_official 18:da299f395b9e 641 /**
mbed_official 18:da299f395b9e 642 * \brief Clear the backup pin.
mbed_official 18:da299f395b9e 643 *
mbed_official 18:da299f395b9e 644 * Clear the corresponding output.
mbed_official 18:da299f395b9e 645 *
mbed_official 18:da299f395b9e 646 * \param[in] pin Backup pin index
mbed_official 18:da299f395b9e 647 */
mbed_official 18:da299f395b9e 648 static inline void system_backup_pin_output_clear(
mbed_official 18:da299f395b9e 649 enum system_backup_pin pin)
mbed_official 18:da299f395b9e 650 {
mbed_official 18:da299f395b9e 651 Assert(pin != SYSTEM_BACKUP_PIN_PSOK);
mbed_official 18:da299f395b9e 652
mbed_official 18:da299f395b9e 653 SUPC->BKOUT.reg |= SUPC_BKOUT_CLR(pin >> 1);
mbed_official 18:da299f395b9e 654 }
mbed_official 18:da299f395b9e 655
mbed_official 18:da299f395b9e 656 /**
mbed_official 18:da299f395b9e 657 * \brief Get the backup I/O input values.
mbed_official 18:da299f395b9e 658 *
mbed_official 18:da299f395b9e 659 * Get the backup I/O data input values. If the corresponding pin is enabled,
mbed_official 18:da299f395b9e 660 * the I/O input value is given on the pin.
mbed_official 18:da299f395b9e 661 *
mbed_official 18:da299f395b9e 662 * \param[in] pin Backup pin index
mbed_official 18:da299f395b9e 663 *
mbed_official 18:da299f395b9e 664 * \return The backup I/O input level value.
mbed_official 18:da299f395b9e 665 */
mbed_official 18:da299f395b9e 666 static inline bool system_backup_pin_output_get(enum system_backup_pin pin)
mbed_official 18:da299f395b9e 667 {
mbed_official 18:da299f395b9e 668 Assert(pin != SYSTEM_BACKUP_PIN_PSOK);
mbed_official 18:da299f395b9e 669
mbed_official 18:da299f395b9e 670 return (SUPC->BKIN.reg & SUPC_BKIN_BKIN(pin >> 1));
mbed_official 18:da299f395b9e 671 }
mbed_official 18:da299f395b9e 672
mbed_official 18:da299f395b9e 673 /**
mbed_official 18:da299f395b9e 674 * @}
mbed_official 18:da299f395b9e 675 */
mbed_official 18:da299f395b9e 676
mbed_official 18:da299f395b9e 677 /**
mbed_official 18:da299f395b9e 678 * \name Device Sleep Control
mbed_official 18:da299f395b9e 679 * @{
mbed_official 18:da299f395b9e 680 */
mbed_official 18:da299f395b9e 681
mbed_official 18:da299f395b9e 682 /**
mbed_official 18:da299f395b9e 683 * \brief Set the sleep mode of the device.
mbed_official 18:da299f395b9e 684 *
mbed_official 18:da299f395b9e 685 * Sets the sleep mode of the device; the configured sleep mode will be entered
mbed_official 18:da299f395b9e 686 * upon the next call of the \ref system_sleep() function.
mbed_official 18:da299f395b9e 687 *
mbed_official 18:da299f395b9e 688 * For an overview of which systems are disabled in sleep for the different
mbed_official 18:da299f395b9e 689 * sleep modes, see \ref asfdoc_sam0_system_module_overview_sleep_mode.
mbed_official 18:da299f395b9e 690 *
mbed_official 18:da299f395b9e 691 * \param[in] sleep_mode Sleep mode to configure for the next sleep operation
mbed_official 18:da299f395b9e 692 */
mbed_official 18:da299f395b9e 693 static inline void system_set_sleepmode(
mbed_official 18:da299f395b9e 694 const enum system_sleepmode sleep_mode)
mbed_official 18:da299f395b9e 695 {
mbed_official 18:da299f395b9e 696 PM->SLEEPCFG.reg = sleep_mode;
mbed_official 18:da299f395b9e 697 while(PM->SLEEPCFG.reg != sleep_mode) ;
mbed_official 18:da299f395b9e 698 }
mbed_official 18:da299f395b9e 699
mbed_official 18:da299f395b9e 700 /**
mbed_official 18:da299f395b9e 701 * \brief Put the system to sleep waiting for interrupt.
mbed_official 18:da299f395b9e 702 *
mbed_official 18:da299f395b9e 703 * Executes a device DSB (Data Synchronization Barrier) instruction to ensure
mbed_official 18:da299f395b9e 704 * all ongoing memory accesses have completed. Further, a WFI (Wait For Interrupt)
mbed_official 18:da299f395b9e 705 * instruction is executed to place the device into the sleep mode specified by
mbed_official 18:da299f395b9e 706 * \ref system_set_sleepmode.
mbed_official 18:da299f395b9e 707 */
mbed_official 18:da299f395b9e 708 static inline void system_sleep(void)
mbed_official 18:da299f395b9e 709 {
mbed_official 18:da299f395b9e 710 __DSB();
mbed_official 18:da299f395b9e 711 __WFI();
mbed_official 18:da299f395b9e 712 }
mbed_official 18:da299f395b9e 713
mbed_official 18:da299f395b9e 714 /**
mbed_official 18:da299f395b9e 715 * @}
mbed_official 18:da299f395b9e 716 */
mbed_official 18:da299f395b9e 717
mbed_official 18:da299f395b9e 718 /**
mbed_official 18:da299f395b9e 719 * \name Performance Level Control
mbed_official 18:da299f395b9e 720 * @{
mbed_official 18:da299f395b9e 721 */
mbed_official 18:da299f395b9e 722
mbed_official 18:da299f395b9e 723 /**
mbed_official 18:da299f395b9e 724 * \brief Switch performance level.
mbed_official 18:da299f395b9e 725 *
mbed_official 18:da299f395b9e 726 * The bus frequency must be reduced prior to scaling down the performance level,
mbed_official 18:da299f395b9e 727 * in order to not exceed the maximum frequency allowed for the performance level.
mbed_official 18:da299f395b9e 728 *
mbed_official 18:da299f395b9e 729 * When scaling up the performance level (for example from PL0 to PL2), the bus
mbed_official 18:da299f395b9e 730 * frequency can be increased first when the performance level transition is
mbed_official 18:da299f395b9e 731 * completed. Check the performance level status before increasing the frequency.
mbed_official 18:da299f395b9e 732 *
mbed_official 18:da299f395b9e 733 * \param[in] performance_level Performance level to switch
mbed_official 18:da299f395b9e 734 *
mbed_official 18:da299f395b9e 735 * \retval STATUS_ERR_INVALID_ARG Invalid parameter
mbed_official 18:da299f395b9e 736 * \retval STATUS_OK Successfully
mbed_official 18:da299f395b9e 737 */
mbed_official 18:da299f395b9e 738 static inline enum status_code system_switch_performance_level(
mbed_official 18:da299f395b9e 739 const enum system_performance_level performance_level)
mbed_official 18:da299f395b9e 740 {
mbed_official 18:da299f395b9e 741
mbed_official 18:da299f395b9e 742 if (performance_level == (enum system_performance_level)PM->PLCFG.reg) {
mbed_official 18:da299f395b9e 743 return STATUS_OK;
mbed_official 18:da299f395b9e 744 }
mbed_official 18:da299f395b9e 745
mbed_official 18:da299f395b9e 746 /* Clear performance level status */
mbed_official 18:da299f395b9e 747 PM->INTFLAG.reg = PM_INTFLAG_PLRDY;
mbed_official 18:da299f395b9e 748
mbed_official 18:da299f395b9e 749 /* Switch performance level */
mbed_official 18:da299f395b9e 750 PM->PLCFG.reg = performance_level;
mbed_official 18:da299f395b9e 751
mbed_official 18:da299f395b9e 752 /* Waiting performance level ready */
mbed_official 18:da299f395b9e 753 while (!PM->INTFLAG.reg) {
mbed_official 18:da299f395b9e 754 ;
mbed_official 18:da299f395b9e 755 }
mbed_official 18:da299f395b9e 756 return STATUS_OK;
mbed_official 18:da299f395b9e 757 }
mbed_official 18:da299f395b9e 758
mbed_official 18:da299f395b9e 759 /**
mbed_official 18:da299f395b9e 760 * \brief Get performance level.
mbed_official 18:da299f395b9e 761 *
mbed_official 18:da299f395b9e 762 * Get performance level.
mbed_official 18:da299f395b9e 763 *
mbed_official 18:da299f395b9e 764 * \return Current performance level.
mbed_official 18:da299f395b9e 765 */
mbed_official 18:da299f395b9e 766 static inline enum system_performance_level system_get_performance_level(void)
mbed_official 18:da299f395b9e 767 {
mbed_official 18:da299f395b9e 768 return (enum system_performance_level)PM->PLCFG.reg;
mbed_official 18:da299f395b9e 769 }
mbed_official 18:da299f395b9e 770
mbed_official 18:da299f395b9e 771 /**
mbed_official 18:da299f395b9e 772 * \brief Get performance level status.
mbed_official 18:da299f395b9e 773 *
mbed_official 18:da299f395b9e 774 * Get performance level status.
mbed_official 18:da299f395b9e 775 * \return Performance level status: Written to one when the performance level is ready.
mbed_official 18:da299f395b9e 776 */
mbed_official 18:da299f395b9e 777 static inline uint8_t system_get_performance_level_status(void)
mbed_official 18:da299f395b9e 778 {
mbed_official 18:da299f395b9e 779 return PM->INTFLAG.reg;
mbed_official 18:da299f395b9e 780 }
mbed_official 18:da299f395b9e 781
mbed_official 18:da299f395b9e 782 /**
mbed_official 18:da299f395b9e 783 * \brief Clear performance level status.
mbed_official 18:da299f395b9e 784 *
mbed_official 18:da299f395b9e 785 * Clear performance level status.
mbed_official 18:da299f395b9e 786 */
mbed_official 18:da299f395b9e 787 static inline void system_clear_performance_level_status(void)
mbed_official 18:da299f395b9e 788 {
mbed_official 18:da299f395b9e 789 PM->INTFLAG.reg = PM_INTFLAG_PLRDY;
mbed_official 18:da299f395b9e 790 }
mbed_official 18:da299f395b9e 791
mbed_official 18:da299f395b9e 792 /**
mbed_official 18:da299f395b9e 793 * @}
mbed_official 18:da299f395b9e 794 */
mbed_official 18:da299f395b9e 795
mbed_official 18:da299f395b9e 796 /**
mbed_official 18:da299f395b9e 797 * \name Standby Configuration
mbed_official 18:da299f395b9e 798 * @{
mbed_official 18:da299f395b9e 799 */
mbed_official 18:da299f395b9e 800
mbed_official 18:da299f395b9e 801 /**
mbed_official 18:da299f395b9e 802 * \brief Retrieve the default configuration for standby.
mbed_official 18:da299f395b9e 803 *
mbed_official 18:da299f395b9e 804 * Fills a configuration structure with the default configuration for standby:
mbed_official 18:da299f395b9e 805 * - Retention back biasing mode for HMCRAMCLP
mbed_official 18:da299f395b9e 806 * - Retention back biasing mode for HMCRAMCHS
mbed_official 18:da299f395b9e 807 * - Power domains PD0/PD1/PD2 are not linked
mbed_official 18:da299f395b9e 808 * - Automatic VREG switching is used
mbed_official 18:da299f395b9e 809 * - Dynamic power gating for power domain 1 is disabled
mbed_official 18:da299f395b9e 810 * - Dynamic power gating for power domain 0 is disabled
mbed_official 18:da299f395b9e 811 * - All power domains switching are handled by hardware
mbed_official 18:da299f395b9e 812 *
mbed_official 18:da299f395b9e 813 * \param[out] config Configuration structure to fill with default values
mbed_official 18:da299f395b9e 814 */
mbed_official 18:da299f395b9e 815 static inline void system_standby_get_config_defaults(
mbed_official 18:da299f395b9e 816 struct system_standby_config *const config)
mbed_official 18:da299f395b9e 817 {
mbed_official 18:da299f395b9e 818 Assert(config);
mbed_official 18:da299f395b9e 819 config->power_domain = SYSTEM_POWER_DOMAIN_DEFAULT;
mbed_official 18:da299f395b9e 820 config->enable_dpgpd0 = false;
mbed_official 18:da299f395b9e 821 config->enable_dpgpd1 = false;
mbed_official 18:da299f395b9e 822 config->disable_avregsd = false;
mbed_official 18:da299f395b9e 823 config->linked_power_domain = SYSTEM_LINKED_POWER_DOMAIN_DEFAULT;
mbed_official 18:da299f395b9e 824 config->hmcramchs_back_bias = SYSTEM_RAM_BACK_BIAS_RETENTION;
mbed_official 18:da299f395b9e 825 config->hmcramclp_back_bias = SYSTEM_RAM_BACK_BIAS_RETENTION;
mbed_official 18:da299f395b9e 826 }
mbed_official 18:da299f395b9e 827
mbed_official 18:da299f395b9e 828 /**
mbed_official 18:da299f395b9e 829 * \brief Configure standby mode.
mbed_official 18:da299f395b9e 830 *
mbed_official 18:da299f395b9e 831 * Configures standby with the given configuration.
mbed_official 18:da299f395b9e 832 *
mbed_official 18:da299f395b9e 833 * \param[in] config Standby configuration structure containing
mbed_official 18:da299f395b9e 834 * the new config
mbed_official 18:da299f395b9e 835 */
mbed_official 18:da299f395b9e 836 static inline void system_standby_set_config(
mbed_official 18:da299f395b9e 837 struct system_standby_config *const config)
mbed_official 18:da299f395b9e 838 {
mbed_official 18:da299f395b9e 839 Assert(config);
mbed_official 18:da299f395b9e 840 PM->STDBYCFG.reg = PM_STDBYCFG_PDCFG(config->power_domain)
mbed_official 18:da299f395b9e 841 | (config->enable_dpgpd0 << PM_STDBYCFG_DPGPD0_Pos)
mbed_official 18:da299f395b9e 842 | (config->enable_dpgpd1 << PM_STDBYCFG_DPGPD1_Pos)
mbed_official 18:da299f395b9e 843 | (config->disable_avregsd << PM_STDBYCFG_AVREGSD_Pos)
mbed_official 18:da299f395b9e 844 | PM_STDBYCFG_LINKPD(config->linked_power_domain)
mbed_official 18:da299f395b9e 845 | PM_STDBYCFG_BBIASHS(config->hmcramchs_back_bias)
mbed_official 18:da299f395b9e 846 | PM_STDBYCFG_BBIASLP(config->hmcramclp_back_bias);
mbed_official 18:da299f395b9e 847 }
mbed_official 18:da299f395b9e 848
mbed_official 18:da299f395b9e 849 /**
mbed_official 18:da299f395b9e 850 * @}
mbed_official 18:da299f395b9e 851 */
mbed_official 18:da299f395b9e 852
mbed_official 18:da299f395b9e 853 /**
mbed_official 18:da299f395b9e 854 * \name I/O Retention
mbed_official 18:da299f395b9e 855 * @{
mbed_official 18:da299f395b9e 856 */
mbed_official 18:da299f395b9e 857
mbed_official 18:da299f395b9e 858 /**
mbed_official 18:da299f395b9e 859 * \brief Enable I/O retention.
mbed_official 18:da299f395b9e 860 *
mbed_official 18:da299f395b9e 861 * Enable I/O retention. After waking up from Backup mode, I/O lines are held
mbed_official 18:da299f395b9e 862 * until the bit is written to 0.
mbed_official 18:da299f395b9e 863 */
mbed_official 18:da299f395b9e 864 static inline void system_io_retension_enable(void)
mbed_official 18:da299f395b9e 865 {
mbed_official 18:da299f395b9e 866 PM->CTRLA.reg = PM_CTRLA_IORET;
mbed_official 18:da299f395b9e 867 }
mbed_official 18:da299f395b9e 868
mbed_official 18:da299f395b9e 869 /**
mbed_official 18:da299f395b9e 870 * \brief Disable I/O retention.
mbed_official 18:da299f395b9e 871 *
mbed_official 18:da299f395b9e 872 * Disable IO retention. After waking up from Backup mode, I/O lines are not held.
mbed_official 18:da299f395b9e 873 */
mbed_official 18:da299f395b9e 874 static inline void system_io_retension_disable(void)
mbed_official 18:da299f395b9e 875 {
mbed_official 18:da299f395b9e 876 PM->CTRLA.reg = PM_CTRLA_MASK & (~PM_CTRLA_IORET);
mbed_official 18:da299f395b9e 877 }
mbed_official 18:da299f395b9e 878
mbed_official 18:da299f395b9e 879 /**
mbed_official 18:da299f395b9e 880 * @}
mbed_official 18:da299f395b9e 881 */
mbed_official 18:da299f395b9e 882
mbed_official 18:da299f395b9e 883 /** @} */
mbed_official 18:da299f395b9e 884
mbed_official 18:da299f395b9e 885 #ifdef __cplusplus
mbed_official 18:da299f395b9e 886 }
mbed_official 18:da299f395b9e 887 #endif
mbed_official 18:da299f395b9e 888
mbed_official 18:da299f395b9e 889 #endif /* POWER_H_INCLUDED */