mbed library sources. Supersedes mbed-src. Fixed broken STM32F1xx RTC on rtc_api.c
Dependents: Nucleo_F103RB_RTC_battery_bkup_pwr_off_okay
Fork of mbed-dev by
targets/TARGET_Silicon_Labs/TARGET_EFM32/sleep.c@150:02e0a0aed4ec, 2016-11-08 (annotated)
- Committer:
- <>
- Date:
- Tue Nov 08 17:45:16 2016 +0000
- Revision:
- 150:02e0a0aed4ec
- Parent:
- 149:156823d33999
- Child:
- 160:d5399cc887bb
This updates the lib to the mbed lib v129
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 144:ef7eb2e8f9f7 | 1 | /***************************************************************************//** |
<> | 144:ef7eb2e8f9f7 | 2 | * @file sleep.c |
<> | 144:ef7eb2e8f9f7 | 3 | ******************************************************************************* |
<> | 144:ef7eb2e8f9f7 | 4 | * @section License |
<> | 144:ef7eb2e8f9f7 | 5 | * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b> |
<> | 144:ef7eb2e8f9f7 | 6 | ******************************************************************************* |
<> | 144:ef7eb2e8f9f7 | 7 | * |
<> | 144:ef7eb2e8f9f7 | 8 | * SPDX-License-Identifier: Apache-2.0 |
<> | 144:ef7eb2e8f9f7 | 9 | * |
<> | 144:ef7eb2e8f9f7 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
<> | 144:ef7eb2e8f9f7 | 11 | * not use this file except in compliance with the License. |
<> | 144:ef7eb2e8f9f7 | 12 | * You may obtain a copy of the License at |
<> | 144:ef7eb2e8f9f7 | 13 | * |
<> | 144:ef7eb2e8f9f7 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 144:ef7eb2e8f9f7 | 15 | * |
<> | 144:ef7eb2e8f9f7 | 16 | * Unless required by applicable law or agreed to in writing, software |
<> | 144:ef7eb2e8f9f7 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
<> | 144:ef7eb2e8f9f7 | 18 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 144:ef7eb2e8f9f7 | 19 | * See the License for the specific language governing permissions and |
<> | 144:ef7eb2e8f9f7 | 20 | * limitations under the License. |
<> | 144:ef7eb2e8f9f7 | 21 | * |
<> | 144:ef7eb2e8f9f7 | 22 | ******************************************************************************/ |
<> | 144:ef7eb2e8f9f7 | 23 | |
<> | 144:ef7eb2e8f9f7 | 24 | #include "device.h" |
<> | 144:ef7eb2e8f9f7 | 25 | #if DEVICE_SLEEP |
<> | 144:ef7eb2e8f9f7 | 26 | |
<> | 144:ef7eb2e8f9f7 | 27 | #include "sleep_api.h" |
<> | 144:ef7eb2e8f9f7 | 28 | #include "sleepmodes.h" |
<> | 144:ef7eb2e8f9f7 | 29 | #include "em_emu.h" |
<> | 144:ef7eb2e8f9f7 | 30 | #include "critical.h" |
<> | 144:ef7eb2e8f9f7 | 31 | |
<> | 144:ef7eb2e8f9f7 | 32 | uint32_t sleep_block_counter[NUM_SLEEP_MODES] = {0}; |
<> | 144:ef7eb2e8f9f7 | 33 | |
<> | 144:ef7eb2e8f9f7 | 34 | /** |
<> | 144:ef7eb2e8f9f7 | 35 | * Sleep mode. |
<> | 144:ef7eb2e8f9f7 | 36 | * Enter the lowest possible sleep mode that is not blocked by ongoing activity. |
<> | 144:ef7eb2e8f9f7 | 37 | */ |
<> | 144:ef7eb2e8f9f7 | 38 | void sleep(void) |
<> | 144:ef7eb2e8f9f7 | 39 | { |
<> | 144:ef7eb2e8f9f7 | 40 | if (sleep_block_counter[0] > 0) { |
<> | 144:ef7eb2e8f9f7 | 41 | /* Blocked everything below EM0, so just return */ |
<> | 144:ef7eb2e8f9f7 | 42 | return; |
<> | 144:ef7eb2e8f9f7 | 43 | } else if (sleep_block_counter[1] > 0) { |
<> | 144:ef7eb2e8f9f7 | 44 | /* Blocked everything below EM1, enter EM1 */ |
<> | 144:ef7eb2e8f9f7 | 45 | EMU_EnterEM1(); |
<> | 144:ef7eb2e8f9f7 | 46 | } else if (sleep_block_counter[2] > 0) { |
<> | 144:ef7eb2e8f9f7 | 47 | /* Blocked everything below EM2, enter EM2 */ |
<> | 144:ef7eb2e8f9f7 | 48 | EMU_EnterEM2(true); |
<> | 144:ef7eb2e8f9f7 | 49 | } else { |
<> | 144:ef7eb2e8f9f7 | 50 | /* Blocked everything below EM3, enter EM3 */ |
<> | 144:ef7eb2e8f9f7 | 51 | EMU_EnterEM3(true); |
<> | 144:ef7eb2e8f9f7 | 52 | } /* Never enter EM4, as mbed has no way of configuring EM4 wakeup */ |
<> | 144:ef7eb2e8f9f7 | 53 | return; |
<> | 144:ef7eb2e8f9f7 | 54 | } |
<> | 144:ef7eb2e8f9f7 | 55 | |
<> | 144:ef7eb2e8f9f7 | 56 | /** |
<> | 144:ef7eb2e8f9f7 | 57 | * Deep Sleep mode. |
<> | 144:ef7eb2e8f9f7 | 58 | * Enter Energy Mode 2, turning off all high-frequency clocks. |
<> | 144:ef7eb2e8f9f7 | 59 | * |
<> | 144:ef7eb2e8f9f7 | 60 | * In EM2 the high frequency oscillator is turned off, but with the 32.768 kHz |
<> | 144:ef7eb2e8f9f7 | 61 | * oscillator running, selected low energy peripherals (LCD, RTC, LETIMER, |
<> | 144:ef7eb2e8f9f7 | 62 | * PCNT, LEUART, I2C, LESENSE, OPAMP, USB, WDOG and ACMP) are still |
<> | 144:ef7eb2e8f9f7 | 63 | * available. This gives a high degree of autonomous operation with a current |
<> | 144:ef7eb2e8f9f7 | 64 | * consumption as low as 1.1 μA with RTC enabled. Power-on Reset, Brown-out |
<> | 144:ef7eb2e8f9f7 | 65 | * Detection and full RAM and CPU retention is also included. |
<> | 144:ef7eb2e8f9f7 | 66 | */ |
<> | 144:ef7eb2e8f9f7 | 67 | void deepsleep(void) |
<> | 144:ef7eb2e8f9f7 | 68 | { |
<> | 144:ef7eb2e8f9f7 | 69 | EMU_EnterEM2(true); |
<> | 144:ef7eb2e8f9f7 | 70 | } |
<> | 144:ef7eb2e8f9f7 | 71 | |
<> | 144:ef7eb2e8f9f7 | 72 | /** Block the microcontroller from sleeping below a certain mode |
<> | 144:ef7eb2e8f9f7 | 73 | * |
<> | 144:ef7eb2e8f9f7 | 74 | * This will block sleep() from entering an energy mode below the one given. |
<> | 144:ef7eb2e8f9f7 | 75 | * -- To be called by peripheral HAL's -- |
<> | 144:ef7eb2e8f9f7 | 76 | * |
<> | 144:ef7eb2e8f9f7 | 77 | * After the peripheral is finished with the operation, it should call unblock with the same state |
<> | 144:ef7eb2e8f9f7 | 78 | * |
<> | 144:ef7eb2e8f9f7 | 79 | */ |
<> | 144:ef7eb2e8f9f7 | 80 | void blockSleepMode(sleepstate_enum minimumMode) |
<> | 144:ef7eb2e8f9f7 | 81 | { |
<> | 144:ef7eb2e8f9f7 | 82 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 83 | sleep_block_counter[minimumMode]++; |
<> | 144:ef7eb2e8f9f7 | 84 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 85 | } |
<> | 144:ef7eb2e8f9f7 | 86 | |
<> | 144:ef7eb2e8f9f7 | 87 | /** Unblock the microcontroller from sleeping below a certain mode |
<> | 144:ef7eb2e8f9f7 | 88 | * |
<> | 144:ef7eb2e8f9f7 | 89 | * This will unblock sleep() from entering an energy mode below the one given. |
<> | 144:ef7eb2e8f9f7 | 90 | * -- To be called by peripheral HAL's -- |
<> | 144:ef7eb2e8f9f7 | 91 | * |
<> | 144:ef7eb2e8f9f7 | 92 | * This should be called after all transactions on a peripheral are done. |
<> | 144:ef7eb2e8f9f7 | 93 | */ |
<> | 144:ef7eb2e8f9f7 | 94 | void unblockSleepMode(sleepstate_enum minimumMode) |
<> | 144:ef7eb2e8f9f7 | 95 | { |
<> | 144:ef7eb2e8f9f7 | 96 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 97 | if(sleep_block_counter[minimumMode] > 0) { |
<> | 144:ef7eb2e8f9f7 | 98 | sleep_block_counter[minimumMode]--; |
<> | 144:ef7eb2e8f9f7 | 99 | } |
<> | 144:ef7eb2e8f9f7 | 100 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 101 | } |
<> | 144:ef7eb2e8f9f7 | 102 | |
<> | 144:ef7eb2e8f9f7 | 103 | #endif |