mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Fri Jul 17 09:15:10 2015 +0100
Revision:
592:a274ee790e56
Parent:
579:53297373a894
Synchronized with git revision e7144f83a8d75df80c4877936b6ffe552b0be9e6

Full URL: https://github.com/mbedmicro/mbed/commit/e7144f83a8d75df80c4877936b6ffe552b0be9e6/

More API implementation for SAMR21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 579:53297373a894 1 #ifndef POWER_H_INCLUDED
mbed_official 579:53297373a894 2 #define POWER_H_INCLUDED
mbed_official 579:53297373a894 3
mbed_official 579:53297373a894 4 #include <compiler.h>
mbed_official 579:53297373a894 5
mbed_official 579:53297373a894 6 #ifdef __cplusplus
mbed_official 579:53297373a894 7 extern "C" {
mbed_official 579:53297373a894 8 #endif
mbed_official 579:53297373a894 9
mbed_official 579:53297373a894 10 /**
mbed_official 579:53297373a894 11 * \addtogroup asfdoc_sam0_system_group
mbed_official 579:53297373a894 12 * @{
mbed_official 579:53297373a894 13 */
mbed_official 579:53297373a894 14
mbed_official 579:53297373a894 15 /**
mbed_official 579:53297373a894 16 * \brief Voltage references within the device.
mbed_official 579:53297373a894 17 *
mbed_official 579:53297373a894 18 * List of available voltage references (VREF) that may be used within the
mbed_official 579:53297373a894 19 * device.
mbed_official 579:53297373a894 20 */
mbed_official 579:53297373a894 21 enum system_voltage_reference {
mbed_official 579:53297373a894 22 /** Temperature sensor voltage reference. */
mbed_official 579:53297373a894 23 SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE,
mbed_official 579:53297373a894 24 /** Bandgap voltage reference. */
mbed_official 579:53297373a894 25 SYSTEM_VOLTAGE_REFERENCE_BANDGAP,
mbed_official 579:53297373a894 26 };
mbed_official 579:53297373a894 27
mbed_official 579:53297373a894 28 /**
mbed_official 579:53297373a894 29 * \brief Device sleep modes.
mbed_official 579:53297373a894 30 *
mbed_official 579:53297373a894 31 * List of available sleep modes in the device. A table of clocks available in
mbed_official 579:53297373a894 32 * different sleep modes can be found in \ref asfdoc_sam0_system_module_overview_sleep_mode.
mbed_official 579:53297373a894 33 */
mbed_official 579:53297373a894 34 enum system_sleepmode {
mbed_official 579:53297373a894 35 /** IDLE 0 sleep mode. */
mbed_official 579:53297373a894 36 SYSTEM_SLEEPMODE_IDLE_0,
mbed_official 579:53297373a894 37 /** IDLE 1 sleep mode. */
mbed_official 579:53297373a894 38 SYSTEM_SLEEPMODE_IDLE_1,
mbed_official 579:53297373a894 39 /** IDLE 2 sleep mode. */
mbed_official 579:53297373a894 40 SYSTEM_SLEEPMODE_IDLE_2,
mbed_official 579:53297373a894 41 /** Standby sleep mode. */
mbed_official 579:53297373a894 42 SYSTEM_SLEEPMODE_STANDBY,
mbed_official 579:53297373a894 43 };
mbed_official 579:53297373a894 44
mbed_official 579:53297373a894 45
mbed_official 579:53297373a894 46
mbed_official 579:53297373a894 47 /**
mbed_official 579:53297373a894 48 * \name Voltage References
mbed_official 579:53297373a894 49 * @{
mbed_official 579:53297373a894 50 */
mbed_official 579:53297373a894 51
mbed_official 579:53297373a894 52 /**
mbed_official 579:53297373a894 53 * \brief Enable the selected voltage reference
mbed_official 579:53297373a894 54 *
mbed_official 579:53297373a894 55 * Enables the selected voltage reference source, making the voltage reference
mbed_official 579:53297373a894 56 * available on a pin as well as an input source to the analog peripherals.
mbed_official 579:53297373a894 57 *
mbed_official 579:53297373a894 58 * \param[in] vref Voltage reference to enable
mbed_official 579:53297373a894 59 */
mbed_official 579:53297373a894 60 static inline void system_voltage_reference_enable(
mbed_official 579:53297373a894 61 const enum system_voltage_reference vref)
mbed_official 579:53297373a894 62 {
mbed_official 579:53297373a894 63 switch (vref) {
mbed_official 579:53297373a894 64 case SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE:
mbed_official 579:53297373a894 65 SYSCTRL->VREF.reg |= SYSCTRL_VREF_TSEN;
mbed_official 579:53297373a894 66 break;
mbed_official 579:53297373a894 67
mbed_official 579:53297373a894 68 case SYSTEM_VOLTAGE_REFERENCE_BANDGAP:
mbed_official 579:53297373a894 69 SYSCTRL->VREF.reg |= SYSCTRL_VREF_BGOUTEN;
mbed_official 579:53297373a894 70 break;
mbed_official 579:53297373a894 71
mbed_official 579:53297373a894 72 default:
mbed_official 579:53297373a894 73 Assert(false);
mbed_official 579:53297373a894 74 return;
mbed_official 579:53297373a894 75 }
mbed_official 579:53297373a894 76 }
mbed_official 579:53297373a894 77
mbed_official 579:53297373a894 78 /**
mbed_official 579:53297373a894 79 * \brief Disable the selected voltage reference
mbed_official 579:53297373a894 80 *
mbed_official 579:53297373a894 81 * Disables the selected voltage reference source.
mbed_official 579:53297373a894 82 *
mbed_official 579:53297373a894 83 * \param[in] vref Voltage reference to disable
mbed_official 579:53297373a894 84 */
mbed_official 579:53297373a894 85 static inline void system_voltage_reference_disable(
mbed_official 579:53297373a894 86 const enum system_voltage_reference vref)
mbed_official 579:53297373a894 87 {
mbed_official 579:53297373a894 88 switch (vref) {
mbed_official 579:53297373a894 89 case SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE:
mbed_official 579:53297373a894 90 SYSCTRL->VREF.reg &= ~SYSCTRL_VREF_TSEN;
mbed_official 579:53297373a894 91 break;
mbed_official 579:53297373a894 92
mbed_official 579:53297373a894 93 case SYSTEM_VOLTAGE_REFERENCE_BANDGAP:
mbed_official 579:53297373a894 94 SYSCTRL->VREF.reg &= ~SYSCTRL_VREF_BGOUTEN;
mbed_official 579:53297373a894 95 break;
mbed_official 579:53297373a894 96
mbed_official 579:53297373a894 97 default:
mbed_official 579:53297373a894 98 Assert(false);
mbed_official 579:53297373a894 99 return;
mbed_official 579:53297373a894 100 }
mbed_official 579:53297373a894 101 }
mbed_official 579:53297373a894 102
mbed_official 579:53297373a894 103 /**
mbed_official 579:53297373a894 104 * @}
mbed_official 579:53297373a894 105 */
mbed_official 579:53297373a894 106
mbed_official 579:53297373a894 107
mbed_official 579:53297373a894 108 /**
mbed_official 579:53297373a894 109 * \name Device Sleep Control
mbed_official 579:53297373a894 110 * @{
mbed_official 579:53297373a894 111 */
mbed_official 579:53297373a894 112
mbed_official 579:53297373a894 113 /**
mbed_official 579:53297373a894 114 * \brief Set the sleep mode of the device
mbed_official 579:53297373a894 115 *
mbed_official 579:53297373a894 116 * Sets the sleep mode of the device; the configured sleep mode will be entered
mbed_official 579:53297373a894 117 * upon the next call of the \ref system_sleep() function.
mbed_official 579:53297373a894 118 *
mbed_official 579:53297373a894 119 * For an overview of which systems are disabled in sleep for the different
mbed_official 579:53297373a894 120 * sleep modes, see \ref asfdoc_sam0_system_module_overview_sleep_mode.
mbed_official 579:53297373a894 121 *
mbed_official 579:53297373a894 122 * \param[in] sleep_mode Sleep mode to configure for the next sleep operation
mbed_official 579:53297373a894 123 *
mbed_official 579:53297373a894 124 * \retval STATUS_OK Operation completed successfully
mbed_official 579:53297373a894 125 * \retval STATUS_ERR_INVALID_ARG The requested sleep mode was invalid or not
mbed_official 579:53297373a894 126 * available
mbed_official 579:53297373a894 127 */
mbed_official 579:53297373a894 128 static inline enum status_code system_set_sleepmode(
mbed_official 579:53297373a894 129 const enum system_sleepmode sleep_mode)
mbed_official 579:53297373a894 130 {
mbed_official 579:53297373a894 131 #if (SAMD20 || SAMD21)
mbed_official 579:53297373a894 132 /* Errata: Make sure that the Flash does not power all the way down
mbed_official 579:53297373a894 133 * when in sleep mode. */
mbed_official 579:53297373a894 134 NVMCTRL->CTRLB.bit.SLEEPPRM = NVMCTRL_CTRLB_SLEEPPRM_DISABLED_Val;
mbed_official 579:53297373a894 135 #endif
mbed_official 579:53297373a894 136
mbed_official 579:53297373a894 137 switch (sleep_mode) {
mbed_official 579:53297373a894 138 case SYSTEM_SLEEPMODE_IDLE_0:
mbed_official 579:53297373a894 139 case SYSTEM_SLEEPMODE_IDLE_1:
mbed_official 579:53297373a894 140 case SYSTEM_SLEEPMODE_IDLE_2:
mbed_official 579:53297373a894 141 SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
mbed_official 579:53297373a894 142 PM->SLEEP.reg = sleep_mode;
mbed_official 579:53297373a894 143 break;
mbed_official 579:53297373a894 144
mbed_official 579:53297373a894 145 case SYSTEM_SLEEPMODE_STANDBY:
mbed_official 579:53297373a894 146 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
mbed_official 579:53297373a894 147 break;
mbed_official 579:53297373a894 148
mbed_official 579:53297373a894 149 default:
mbed_official 579:53297373a894 150 return STATUS_ERR_INVALID_ARG;
mbed_official 579:53297373a894 151 }
mbed_official 579:53297373a894 152
mbed_official 579:53297373a894 153 return STATUS_OK;
mbed_official 579:53297373a894 154 }
mbed_official 579:53297373a894 155
mbed_official 579:53297373a894 156 /**
mbed_official 579:53297373a894 157 * \brief Put the system to sleep waiting for interrupt
mbed_official 579:53297373a894 158 *
mbed_official 579:53297373a894 159 * Executes a device DSB (Data Synchronization Barrier) instruction to ensure
mbed_official 579:53297373a894 160 * all ongoing memory accesses have completed, then a WFI (Wait For Interrupt)
mbed_official 579:53297373a894 161 * instruction to place the device into the sleep mode specified by
mbed_official 579:53297373a894 162 * \ref system_set_sleepmode until woken by an interrupt.
mbed_official 579:53297373a894 163 */
mbed_official 579:53297373a894 164 static inline void system_sleep(void)
mbed_official 579:53297373a894 165 {
mbed_official 579:53297373a894 166 __DSB();
mbed_official 579:53297373a894 167 __WFI();
mbed_official 579:53297373a894 168 }
mbed_official 579:53297373a894 169
mbed_official 579:53297373a894 170 /**
mbed_official 579:53297373a894 171 * @}
mbed_official 579:53297373a894 172 */
mbed_official 579:53297373a894 173
mbed_official 579:53297373a894 174 /** @} */
mbed_official 579:53297373a894 175 #ifdef __cplusplus
mbed_official 579:53297373a894 176 }
mbed_official 579:53297373a894 177 #endif
mbed_official 579:53297373a894 178
mbed_official 579:53297373a894 179 #endif /* POWER_H_INCLUDED */