mbed library sources. Supersedes mbed-src.
Fork of mbed-dev by
targets/hal/TARGET_Atmel/TARGET_SAM_CortexM0P/drivers/system/reset/TARGET_SAML21/reset.h@18:da299f395b9e, 2015-11-09 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Nov 09 13:30:11 2015 +0000
- Revision:
- 18:da299f395b9e
Synchronized with git revision f605825f66bb2e462ff7dbc5fb4ed2dbe979d1c3
Full URL: https://github.com/mbedmicro/mbed/commit/f605825f66bb2e462ff7dbc5fb4ed2dbe979d1c3/
Added support for SAML21
Who changed what in which revision?
User | Revision | Line number | New 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 Reset 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 RESET_H_INCLUDED |
mbed_official | 18:da299f395b9e | 47 | #define RESET_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 Reset causes of the system. |
mbed_official | 18:da299f395b9e | 63 | * |
mbed_official | 18:da299f395b9e | 64 | * List of possible reset causes of the system. |
mbed_official | 18:da299f395b9e | 65 | */ |
mbed_official | 18:da299f395b9e | 66 | enum system_reset_cause { |
mbed_official | 18:da299f395b9e | 67 | /** The system was last reset by a backup reset */ |
mbed_official | 18:da299f395b9e | 68 | SYSTEM_RESET_CAUSE_BACKUP = RSTC_RCAUSE_BACKUP, |
mbed_official | 18:da299f395b9e | 69 | /** The system was last reset by a software reset */ |
mbed_official | 18:da299f395b9e | 70 | SYSTEM_RESET_CAUSE_SOFTWARE = RSTC_RCAUSE_SYST, |
mbed_official | 18:da299f395b9e | 71 | /** The system was last reset by the watchdog timer */ |
mbed_official | 18:da299f395b9e | 72 | SYSTEM_RESET_CAUSE_WDT = RSTC_RCAUSE_WDT, |
mbed_official | 18:da299f395b9e | 73 | /** The system was last reset because the external reset line was pulled low */ |
mbed_official | 18:da299f395b9e | 74 | SYSTEM_RESET_CAUSE_EXTERNAL_RESET = RSTC_RCAUSE_EXT, |
mbed_official | 18:da299f395b9e | 75 | /** The system was last reset by the BOD33 */ |
mbed_official | 18:da299f395b9e | 76 | SYSTEM_RESET_CAUSE_BOD33 = RSTC_RCAUSE_BOD33, |
mbed_official | 18:da299f395b9e | 77 | /** The system was last reset by the BOD12 */ |
mbed_official | 18:da299f395b9e | 78 | SYSTEM_RESET_CAUSE_BOD12 = RSTC_RCAUSE_BOD12, |
mbed_official | 18:da299f395b9e | 79 | /** The system was last reset by the POR (Power on reset) */ |
mbed_official | 18:da299f395b9e | 80 | SYSTEM_RESET_CAUSE_POR = RSTC_RCAUSE_POR, |
mbed_official | 18:da299f395b9e | 81 | }; |
mbed_official | 18:da299f395b9e | 82 | |
mbed_official | 18:da299f395b9e | 83 | /** |
mbed_official | 18:da299f395b9e | 84 | * \brief Backup exit source after a backup reset occurs. |
mbed_official | 18:da299f395b9e | 85 | * |
mbed_official | 18:da299f395b9e | 86 | * List of possible backup exit source. |
mbed_official | 18:da299f395b9e | 87 | */ |
mbed_official | 18:da299f395b9e | 88 | enum system_reset_backup_exit_source { |
mbed_official | 18:da299f395b9e | 89 | /** The backup exit source was external wakeup */ |
mbed_official | 18:da299f395b9e | 90 | SYSTEM_RESET_BACKKUP_EXIT_EXTWAKE = RSTC_BKUPEXIT_EXTWAKE, |
mbed_official | 18:da299f395b9e | 91 | /** The backup exit source was RTC interrupt */ |
mbed_official | 18:da299f395b9e | 92 | SYSTEM_RESET_BACKKUP_EXIT_RTC = RSTC_BKUPEXIT_RTC, |
mbed_official | 18:da299f395b9e | 93 | /** The backup exit source was battery backup power switch */ |
mbed_official | 18:da299f395b9e | 94 | SYSTEM_RESET_BACKKUP_EXIT_BBPS = RSTC_BKUPEXIT_BBPS, |
mbed_official | 18:da299f395b9e | 95 | }; |
mbed_official | 18:da299f395b9e | 96 | |
mbed_official | 18:da299f395b9e | 97 | /** |
mbed_official | 18:da299f395b9e | 98 | * \brief Wakeup debounce counter value. |
mbed_official | 18:da299f395b9e | 99 | * |
mbed_official | 18:da299f395b9e | 100 | * Wakeup debounce counter value when waking up by external wakeup pin from backup mode. |
mbed_official | 18:da299f395b9e | 101 | */ |
mbed_official | 18:da299f395b9e | 102 | enum system_wakeup_debounce_count { |
mbed_official | 18:da299f395b9e | 103 | /** No debouncing */ |
mbed_official | 18:da299f395b9e | 104 | SYSTEM_WAKEUP_DEBOUNCE_OFF = RSTC_WKDBCONF_WKDBCNT_OFF, |
mbed_official | 18:da299f395b9e | 105 | /** Input pin shall be active for at least two 32KHz clock periods */ |
mbed_official | 18:da299f395b9e | 106 | SYSTEM_WAKEUP_DEBOUNCE_2CK32 = RSTC_WKDBCONF_WKDBCNT_2K32, |
mbed_official | 18:da299f395b9e | 107 | /** Input pin shall be active for at least three 32KHz clock periods */ |
mbed_official | 18:da299f395b9e | 108 | SYSTEM_WAKEUP_DEBOUNCE_3CK32 = RSTC_WKDBCONF_WKDBCNT_3CK32, |
mbed_official | 18:da299f395b9e | 109 | /** Input pin shall be active for at least 32 32KHz clock periods */ |
mbed_official | 18:da299f395b9e | 110 | SYSTEM_WAKEUP_DEBOUNCE_32CK32 = RSTC_WKDBCONF_WKDBCNT_32CK32, |
mbed_official | 18:da299f395b9e | 111 | /** Input pin shall be active for at least 512 32KHz clock periods */ |
mbed_official | 18:da299f395b9e | 112 | SYSTEM_WAKEUP_DEBOUNCE_512CK32 = RSTC_WKDBCONF_WKDBCNT_512CK32, |
mbed_official | 18:da299f395b9e | 113 | /** Input pin shall be active for at least 4096 32KHz clock periods */ |
mbed_official | 18:da299f395b9e | 114 | SYSTEM_WAKEUP_DEBOUNCE_4096CK32 = RSTC_WKDBCONF_WKDBCNT_4096CK32, |
mbed_official | 18:da299f395b9e | 115 | /** Input pin shall be active for at least 32768 32KHz clock periods */ |
mbed_official | 18:da299f395b9e | 116 | SYSTEM_WAKEUP_DEBOUNCE_32768CK32 = RSTC_WKDBCONF_WKDBCNT_32768CK32, |
mbed_official | 18:da299f395b9e | 117 | }; |
mbed_official | 18:da299f395b9e | 118 | |
mbed_official | 18:da299f395b9e | 119 | /** |
mbed_official | 18:da299f395b9e | 120 | * \name Reset Control |
mbed_official | 18:da299f395b9e | 121 | * @{ |
mbed_official | 18:da299f395b9e | 122 | */ |
mbed_official | 18:da299f395b9e | 123 | |
mbed_official | 18:da299f395b9e | 124 | /** |
mbed_official | 18:da299f395b9e | 125 | * \brief Reset the MCU. |
mbed_official | 18:da299f395b9e | 126 | * |
mbed_official | 18:da299f395b9e | 127 | * Resets the MCU and all associated peripherals and registers, except RTC, |
mbed_official | 18:da299f395b9e | 128 | * OSC32KCTRL, RSTC, GCLK (if WRTLOCK is set), and I/O retention state of PM. |
mbed_official | 18:da299f395b9e | 129 | * |
mbed_official | 18:da299f395b9e | 130 | */ |
mbed_official | 18:da299f395b9e | 131 | static inline void system_reset(void) |
mbed_official | 18:da299f395b9e | 132 | { |
mbed_official | 18:da299f395b9e | 133 | NVIC_SystemReset(); |
mbed_official | 18:da299f395b9e | 134 | } |
mbed_official | 18:da299f395b9e | 135 | |
mbed_official | 18:da299f395b9e | 136 | /** |
mbed_official | 18:da299f395b9e | 137 | * \brief Get the reset cause. |
mbed_official | 18:da299f395b9e | 138 | * |
mbed_official | 18:da299f395b9e | 139 | * Retrieves the cause of the last system reset. |
mbed_official | 18:da299f395b9e | 140 | * |
mbed_official | 18:da299f395b9e | 141 | * \return An enum value indicating the cause of the last system reset. |
mbed_official | 18:da299f395b9e | 142 | */ |
mbed_official | 18:da299f395b9e | 143 | static inline enum system_reset_cause system_get_reset_cause(void) |
mbed_official | 18:da299f395b9e | 144 | { |
mbed_official | 18:da299f395b9e | 145 | return (enum system_reset_cause)RSTC->RCAUSE.reg; |
mbed_official | 18:da299f395b9e | 146 | } |
mbed_official | 18:da299f395b9e | 147 | |
mbed_official | 18:da299f395b9e | 148 | /** |
mbed_official | 18:da299f395b9e | 149 | * @} |
mbed_official | 18:da299f395b9e | 150 | */ |
mbed_official | 18:da299f395b9e | 151 | |
mbed_official | 18:da299f395b9e | 152 | /** |
mbed_official | 18:da299f395b9e | 153 | * \name Backup Exit Control |
mbed_official | 18:da299f395b9e | 154 | * @{ |
mbed_official | 18:da299f395b9e | 155 | */ |
mbed_official | 18:da299f395b9e | 156 | |
mbed_official | 18:da299f395b9e | 157 | /** |
mbed_official | 18:da299f395b9e | 158 | * \brief Get the backup exit source. |
mbed_official | 18:da299f395b9e | 159 | * |
mbed_official | 18:da299f395b9e | 160 | * Get the backup exit source when a backup reset occurs. |
mbed_official | 18:da299f395b9e | 161 | * |
mbed_official | 18:da299f395b9e | 162 | * \return An enum value indicating the latest backup exit source. |
mbed_official | 18:da299f395b9e | 163 | */ |
mbed_official | 18:da299f395b9e | 164 | static inline enum system_reset_backup_exit_source system_get_backup_exit_source(void) |
mbed_official | 18:da299f395b9e | 165 | { |
mbed_official | 18:da299f395b9e | 166 | return (enum system_reset_backup_exit_source)RSTC->BKUPEXIT.reg; |
mbed_official | 18:da299f395b9e | 167 | } |
mbed_official | 18:da299f395b9e | 168 | |
mbed_official | 18:da299f395b9e | 169 | /** |
mbed_official | 18:da299f395b9e | 170 | * \brief Set wakeup debounce counter. |
mbed_official | 18:da299f395b9e | 171 | * |
mbed_official | 18:da299f395b9e | 172 | * Set the wakeup debounce counter value with the given count. |
mbed_official | 18:da299f395b9e | 173 | * |
mbed_official | 18:da299f395b9e | 174 | * \param[in] wakeup_debounce_count Wakeup debounce counter value |
mbed_official | 18:da299f395b9e | 175 | */ |
mbed_official | 18:da299f395b9e | 176 | static inline void system_set_pin_wakeup_debounce_counter( |
mbed_official | 18:da299f395b9e | 177 | const enum system_wakeup_debounce_count wakeup_debounce_count) |
mbed_official | 18:da299f395b9e | 178 | { |
mbed_official | 18:da299f395b9e | 179 | RSTC->WKDBCONF.reg = wakeup_debounce_count; |
mbed_official | 18:da299f395b9e | 180 | } |
mbed_official | 18:da299f395b9e | 181 | |
mbed_official | 18:da299f395b9e | 182 | /** |
mbed_official | 18:da299f395b9e | 183 | * \brief Set low polarity of wakeup input pin. |
mbed_official | 18:da299f395b9e | 184 | * |
mbed_official | 18:da299f395b9e | 185 | * Set low polarity with the given wakeup input pin mask. |
mbed_official | 18:da299f395b9e | 186 | * |
mbed_official | 18:da299f395b9e | 187 | * \param[in] pin_mask Input pin mask |
mbed_official | 18:da299f395b9e | 188 | */ |
mbed_official | 18:da299f395b9e | 189 | static inline void system_set_pin_wakeup_polarity_low(const uint16_t pin_mask) |
mbed_official | 18:da299f395b9e | 190 | { |
mbed_official | 18:da299f395b9e | 191 | RSTC->WKPOL.reg &= ~(RSTC_WKPOL_WKPOL(pin_mask)); |
mbed_official | 18:da299f395b9e | 192 | } |
mbed_official | 18:da299f395b9e | 193 | |
mbed_official | 18:da299f395b9e | 194 | /** |
mbed_official | 18:da299f395b9e | 195 | * \brief Set high polarity of wakeup input pin. |
mbed_official | 18:da299f395b9e | 196 | * |
mbed_official | 18:da299f395b9e | 197 | * Set high polarity with the given wakeup input pin mask. |
mbed_official | 18:da299f395b9e | 198 | * |
mbed_official | 18:da299f395b9e | 199 | * \param[in] pin_mask Input pin mask |
mbed_official | 18:da299f395b9e | 200 | */ |
mbed_official | 18:da299f395b9e | 201 | static inline void system_set_pin_wakeup_polarity_high(const uint16_t pin_mask) |
mbed_official | 18:da299f395b9e | 202 | { |
mbed_official | 18:da299f395b9e | 203 | RSTC->WKPOL.reg |= RSTC_WKPOL_WKPOL(pin_mask); |
mbed_official | 18:da299f395b9e | 204 | } |
mbed_official | 18:da299f395b9e | 205 | |
mbed_official | 18:da299f395b9e | 206 | /** |
mbed_official | 18:da299f395b9e | 207 | * \brief Enable wakeup of input pin from the backup mode. |
mbed_official | 18:da299f395b9e | 208 | * |
mbed_official | 18:da299f395b9e | 209 | * Enable pin wakeup from the backup mode with the given pin mask. |
mbed_official | 18:da299f395b9e | 210 | * |
mbed_official | 18:da299f395b9e | 211 | * \param[in] pin Input pin mask |
mbed_official | 18:da299f395b9e | 212 | */ |
mbed_official | 18:da299f395b9e | 213 | static inline void system_enable_pin_wakeup(const uint16_t pin_mask) |
mbed_official | 18:da299f395b9e | 214 | { |
mbed_official | 18:da299f395b9e | 215 | RSTC->WKEN.reg |= RSTC_WKEN_WKEN(pin_mask); |
mbed_official | 18:da299f395b9e | 216 | } |
mbed_official | 18:da299f395b9e | 217 | |
mbed_official | 18:da299f395b9e | 218 | /** |
mbed_official | 18:da299f395b9e | 219 | * \brief Disable wakeup of input pin from the backup mode. |
mbed_official | 18:da299f395b9e | 220 | * |
mbed_official | 18:da299f395b9e | 221 | * Disable pin wakeup from the backup mode with the given pin mask. |
mbed_official | 18:da299f395b9e | 222 | * |
mbed_official | 18:da299f395b9e | 223 | * \param[in] pin Input pin mask |
mbed_official | 18:da299f395b9e | 224 | */ |
mbed_official | 18:da299f395b9e | 225 | static inline void system_disable_pin_wakeup(const uint16_t pin_mask) |
mbed_official | 18:da299f395b9e | 226 | { |
mbed_official | 18:da299f395b9e | 227 | RSTC->WKEN.reg &= ~(RSTC_WKEN_WKEN(pin_mask)); |
mbed_official | 18:da299f395b9e | 228 | } |
mbed_official | 18:da299f395b9e | 229 | |
mbed_official | 18:da299f395b9e | 230 | /** |
mbed_official | 18:da299f395b9e | 231 | * \brief Check whether any of the enabled wake up pins are active and caused the wakeup. |
mbed_official | 18:da299f395b9e | 232 | * |
mbed_official | 18:da299f395b9e | 233 | * Check whether any of the enabled wake up pins are active and caused the wakeup |
mbed_official | 18:da299f395b9e | 234 | * from backup sleep mode when exiting backup mode. |
mbed_official | 18:da299f395b9e | 235 | * |
mbed_official | 18:da299f395b9e | 236 | * \return Pin mask, the corresponding pin is active when its pin mask is 1. |
mbed_official | 18:da299f395b9e | 237 | */ |
mbed_official | 18:da299f395b9e | 238 | static inline uint16_t system_get_pin_wakeup_cause(void) |
mbed_official | 18:da299f395b9e | 239 | { |
mbed_official | 18:da299f395b9e | 240 | return (RSTC_WKCAUSE_MASK & (RSTC->WKCAUSE.reg >> RSTC_WKCAUSE_WKCAUSE_Pos)); |
mbed_official | 18:da299f395b9e | 241 | } |
mbed_official | 18:da299f395b9e | 242 | |
mbed_official | 18:da299f395b9e | 243 | /** |
mbed_official | 18:da299f395b9e | 244 | * @} |
mbed_official | 18:da299f395b9e | 245 | */ |
mbed_official | 18:da299f395b9e | 246 | |
mbed_official | 18:da299f395b9e | 247 | /** @} */ |
mbed_official | 18:da299f395b9e | 248 | |
mbed_official | 18:da299f395b9e | 249 | #ifdef __cplusplus |
mbed_official | 18:da299f395b9e | 250 | } |
mbed_official | 18:da299f395b9e | 251 | #endif |
mbed_official | 18:da299f395b9e | 252 | |
mbed_official | 18:da299f395b9e | 253 | #endif /* RESET_H_INCLUDED */ |