mbed library sources. Supersedes mbed-src. Add PORTG support for STM32L476JG (SensorTile kit)
Fork of mbed-dev by
targets/TARGET_Silicon_Labs/TARGET_EFM32/sleep.c@149:156823d33999, 2016-10-28 (annotated)
- Committer:
- <>
- Date:
- Fri Oct 28 11:17:30 2016 +0100
- Revision:
- 149:156823d33999
- Parent:
- targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/sleep.c@144:ef7eb2e8f9f7
- Child:
- 150:02e0a0aed4ec
This updates the lib to the mbed lib v128
NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.
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 "cmsis.h" |
<> | 144:ef7eb2e8f9f7 | 30 | #include "em_emu.h" |
<> | 144:ef7eb2e8f9f7 | 31 | #include "critical.h" |
<> | 144:ef7eb2e8f9f7 | 32 | |
<> | 144:ef7eb2e8f9f7 | 33 | uint32_t sleep_block_counter[NUM_SLEEP_MODES] = {0}; |
<> | 144:ef7eb2e8f9f7 | 34 | |
<> | 144:ef7eb2e8f9f7 | 35 | /** |
<> | 144:ef7eb2e8f9f7 | 36 | * Sleep mode. |
<> | 144:ef7eb2e8f9f7 | 37 | * Enter the lowest possible sleep mode that is not blocked by ongoing activity. |
<> | 144:ef7eb2e8f9f7 | 38 | */ |
<> | 144:ef7eb2e8f9f7 | 39 | void sleep(void) |
<> | 144:ef7eb2e8f9f7 | 40 | { |
<> | 144:ef7eb2e8f9f7 | 41 | if (sleep_block_counter[0] > 0) { |
<> | 144:ef7eb2e8f9f7 | 42 | /* Blocked everything below EM0, so just return */ |
<> | 144:ef7eb2e8f9f7 | 43 | return; |
<> | 144:ef7eb2e8f9f7 | 44 | } else if (sleep_block_counter[1] > 0) { |
<> | 144:ef7eb2e8f9f7 | 45 | /* Blocked everything below EM1, enter EM1 */ |
<> | 144:ef7eb2e8f9f7 | 46 | EMU_EnterEM1(); |
<> | 144:ef7eb2e8f9f7 | 47 | } else if (sleep_block_counter[2] > 0) { |
<> | 144:ef7eb2e8f9f7 | 48 | /* Blocked everything below EM2, enter EM2 */ |
<> | 144:ef7eb2e8f9f7 | 49 | EMU_EnterEM2(true); |
<> | 144:ef7eb2e8f9f7 | 50 | } else { |
<> | 144:ef7eb2e8f9f7 | 51 | /* Blocked everything below EM3, enter EM3 */ |
<> | 144:ef7eb2e8f9f7 | 52 | EMU_EnterEM3(true); |
<> | 144:ef7eb2e8f9f7 | 53 | } /* Never enter EM4, as mbed has no way of configuring EM4 wakeup */ |
<> | 144:ef7eb2e8f9f7 | 54 | return; |
<> | 144:ef7eb2e8f9f7 | 55 | } |
<> | 144:ef7eb2e8f9f7 | 56 | |
<> | 144:ef7eb2e8f9f7 | 57 | /** |
<> | 144:ef7eb2e8f9f7 | 58 | * Deep Sleep mode. |
<> | 144:ef7eb2e8f9f7 | 59 | * Enter Energy Mode 2, turning off all high-frequency clocks. |
<> | 144:ef7eb2e8f9f7 | 60 | * |
<> | 144:ef7eb2e8f9f7 | 61 | * In EM2 the high frequency oscillator is turned off, but with the 32.768 kHz |
<> | 144:ef7eb2e8f9f7 | 62 | * oscillator running, selected low energy peripherals (LCD, RTC, LETIMER, |
<> | 144:ef7eb2e8f9f7 | 63 | * PCNT, LEUART, I2C, LESENSE, OPAMP, USB, WDOG and ACMP) are still |
<> | 144:ef7eb2e8f9f7 | 64 | * available. This gives a high degree of autonomous operation with a current |
<> | 144:ef7eb2e8f9f7 | 65 | * consumption as low as 1.1 μA with RTC enabled. Power-on Reset, Brown-out |
<> | 144:ef7eb2e8f9f7 | 66 | * Detection and full RAM and CPU retention is also included. |
<> | 144:ef7eb2e8f9f7 | 67 | */ |
<> | 144:ef7eb2e8f9f7 | 68 | void deepsleep(void) |
<> | 144:ef7eb2e8f9f7 | 69 | { |
<> | 144:ef7eb2e8f9f7 | 70 | EMU_EnterEM2(true); |
<> | 144:ef7eb2e8f9f7 | 71 | } |
<> | 144:ef7eb2e8f9f7 | 72 | |
<> | 144:ef7eb2e8f9f7 | 73 | /** Block the microcontroller from sleeping below a certain mode |
<> | 144:ef7eb2e8f9f7 | 74 | * |
<> | 144:ef7eb2e8f9f7 | 75 | * This will block sleep() from entering an energy mode below the one given. |
<> | 144:ef7eb2e8f9f7 | 76 | * -- To be called by peripheral HAL's -- |
<> | 144:ef7eb2e8f9f7 | 77 | * |
<> | 144:ef7eb2e8f9f7 | 78 | * After the peripheral is finished with the operation, it should call unblock with the same state |
<> | 144:ef7eb2e8f9f7 | 79 | * |
<> | 144:ef7eb2e8f9f7 | 80 | */ |
<> | 144:ef7eb2e8f9f7 | 81 | void blockSleepMode(sleepstate_enum minimumMode) |
<> | 144:ef7eb2e8f9f7 | 82 | { |
<> | 144:ef7eb2e8f9f7 | 83 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 84 | sleep_block_counter[minimumMode]++; |
<> | 144:ef7eb2e8f9f7 | 85 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 86 | } |
<> | 144:ef7eb2e8f9f7 | 87 | |
<> | 144:ef7eb2e8f9f7 | 88 | /** Unblock the microcontroller from sleeping below a certain mode |
<> | 144:ef7eb2e8f9f7 | 89 | * |
<> | 144:ef7eb2e8f9f7 | 90 | * This will unblock sleep() from entering an energy mode below the one given. |
<> | 144:ef7eb2e8f9f7 | 91 | * -- To be called by peripheral HAL's -- |
<> | 144:ef7eb2e8f9f7 | 92 | * |
<> | 144:ef7eb2e8f9f7 | 93 | * This should be called after all transactions on a peripheral are done. |
<> | 144:ef7eb2e8f9f7 | 94 | */ |
<> | 144:ef7eb2e8f9f7 | 95 | void unblockSleepMode(sleepstate_enum minimumMode) |
<> | 144:ef7eb2e8f9f7 | 96 | { |
<> | 144:ef7eb2e8f9f7 | 97 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 98 | if(sleep_block_counter[minimumMode] > 0) { |
<> | 144:ef7eb2e8f9f7 | 99 | sleep_block_counter[minimumMode]--; |
<> | 144:ef7eb2e8f9f7 | 100 | } |
<> | 144:ef7eb2e8f9f7 | 101 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 102 | } |
<> | 144:ef7eb2e8f9f7 | 103 | |
<> | 144:ef7eb2e8f9f7 | 104 | #endif |