mbed library sources. Supersedes mbed-src.
Fork of mbed-dev by
targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/sleep.c@22:9c52de9bc1d7, 2015-11-17 (annotated)
- Committer:
- mbed_official
- Date:
- Tue Nov 17 10:15:10 2015 +0000
- Revision:
- 22:9c52de9bc1d7
- Parent:
- 0:9b334a45a8ff
- Child:
- 144:ef7eb2e8f9f7
Synchronized with git revision 8c540341dd44e9b99388db7b8389d756a7103dfd
Full URL: https://github.com/mbedmicro/mbed/commit/8c540341dd44e9b99388db7b8389d756a7103dfd/
Bugfixes to EFM32 serial, spi and sleep HAL
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 0:9b334a45a8ff | 1 | /***************************************************************************//** |
bogdanm | 0:9b334a45a8ff | 2 | * @file sleep.c |
bogdanm | 0:9b334a45a8ff | 3 | ******************************************************************************* |
bogdanm | 0:9b334a45a8ff | 4 | * @section License |
bogdanm | 0:9b334a45a8ff | 5 | * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b> |
bogdanm | 0:9b334a45a8ff | 6 | ******************************************************************************* |
bogdanm | 0:9b334a45a8ff | 7 | * |
bogdanm | 0:9b334a45a8ff | 8 | * Permission is granted to anyone to use this software for any purpose, |
bogdanm | 0:9b334a45a8ff | 9 | * including commercial applications, and to alter it and redistribute it |
bogdanm | 0:9b334a45a8ff | 10 | * freely, subject to the following restrictions: |
bogdanm | 0:9b334a45a8ff | 11 | * |
bogdanm | 0:9b334a45a8ff | 12 | * 1. The origin of this software must not be misrepresented; you must not |
bogdanm | 0:9b334a45a8ff | 13 | * claim that you wrote the original software. |
bogdanm | 0:9b334a45a8ff | 14 | * 2. Altered source versions must be plainly marked as such, and must not be |
bogdanm | 0:9b334a45a8ff | 15 | * misrepresented as being the original software. |
bogdanm | 0:9b334a45a8ff | 16 | * 3. This notice may not be removed or altered from any source distribution. |
bogdanm | 0:9b334a45a8ff | 17 | * |
bogdanm | 0:9b334a45a8ff | 18 | * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no |
bogdanm | 0:9b334a45a8ff | 19 | * obligation to support this Software. Silicon Labs is providing the |
bogdanm | 0:9b334a45a8ff | 20 | * Software "AS IS", with no express or implied warranties of any kind, |
bogdanm | 0:9b334a45a8ff | 21 | * including, but not limited to, any implied warranties of merchantability |
bogdanm | 0:9b334a45a8ff | 22 | * or fitness for any particular purpose or warranties against infringement |
bogdanm | 0:9b334a45a8ff | 23 | * of any proprietary rights of a third party. |
bogdanm | 0:9b334a45a8ff | 24 | * |
bogdanm | 0:9b334a45a8ff | 25 | * Silicon Labs will not be liable for any consequential, incidental, or |
bogdanm | 0:9b334a45a8ff | 26 | * special damages, or any other relief, or for any claim by any third party, |
bogdanm | 0:9b334a45a8ff | 27 | * arising from your use of this Software. |
bogdanm | 0:9b334a45a8ff | 28 | * |
bogdanm | 0:9b334a45a8ff | 29 | ******************************************************************************/ |
bogdanm | 0:9b334a45a8ff | 30 | |
bogdanm | 0:9b334a45a8ff | 31 | #include "device.h" |
bogdanm | 0:9b334a45a8ff | 32 | #if DEVICE_SLEEP |
bogdanm | 0:9b334a45a8ff | 33 | |
bogdanm | 0:9b334a45a8ff | 34 | #include "sleep_api.h" |
bogdanm | 0:9b334a45a8ff | 35 | #include "sleepmodes.h" |
bogdanm | 0:9b334a45a8ff | 36 | #include "cmsis.h" |
bogdanm | 0:9b334a45a8ff | 37 | #include "em_emu.h" |
bogdanm | 0:9b334a45a8ff | 38 | #include "em_int.h" |
bogdanm | 0:9b334a45a8ff | 39 | |
bogdanm | 0:9b334a45a8ff | 40 | uint32_t sleep_block_counter[NUM_SLEEP_MODES] = {0}; |
bogdanm | 0:9b334a45a8ff | 41 | |
bogdanm | 0:9b334a45a8ff | 42 | /** |
bogdanm | 0:9b334a45a8ff | 43 | * Sleep mode. |
mbed_official | 22:9c52de9bc1d7 | 44 | * Enter the lowest possible sleep mode that is not blocked by ongoing activity. |
bogdanm | 0:9b334a45a8ff | 45 | */ |
bogdanm | 0:9b334a45a8ff | 46 | void sleep(void) |
bogdanm | 0:9b334a45a8ff | 47 | { |
bogdanm | 0:9b334a45a8ff | 48 | if (sleep_block_counter[0] > 0) { |
bogdanm | 0:9b334a45a8ff | 49 | /* Blocked everything below EM0, so just return */ |
bogdanm | 0:9b334a45a8ff | 50 | return; |
bogdanm | 0:9b334a45a8ff | 51 | } else if (sleep_block_counter[1] > 0) { |
bogdanm | 0:9b334a45a8ff | 52 | /* Blocked everything below EM1, enter EM1 */ |
bogdanm | 0:9b334a45a8ff | 53 | EMU_EnterEM1(); |
bogdanm | 0:9b334a45a8ff | 54 | } else if (sleep_block_counter[2] > 0) { |
bogdanm | 0:9b334a45a8ff | 55 | /* Blocked everything below EM2, enter EM2 */ |
bogdanm | 0:9b334a45a8ff | 56 | EMU_EnterEM2(true); |
mbed_official | 22:9c52de9bc1d7 | 57 | } else { |
bogdanm | 0:9b334a45a8ff | 58 | /* Blocked everything below EM3, enter EM3 */ |
bogdanm | 0:9b334a45a8ff | 59 | EMU_EnterEM3(true); |
mbed_official | 22:9c52de9bc1d7 | 60 | } /* Never enter EM4, as mbed has no way of configuring EM4 wakeup */ |
bogdanm | 0:9b334a45a8ff | 61 | return; |
bogdanm | 0:9b334a45a8ff | 62 | } |
bogdanm | 0:9b334a45a8ff | 63 | |
bogdanm | 0:9b334a45a8ff | 64 | /** |
bogdanm | 0:9b334a45a8ff | 65 | * Deep Sleep mode. |
bogdanm | 0:9b334a45a8ff | 66 | * Enter Energy Mode 2, turning off all high-frequency clocks. |
bogdanm | 0:9b334a45a8ff | 67 | * |
bogdanm | 0:9b334a45a8ff | 68 | * In EM2 the high frequency oscillator is turned off, but with the 32.768 kHz |
bogdanm | 0:9b334a45a8ff | 69 | * oscillator running, selected low energy peripherals (LCD, RTC, LETIMER, |
bogdanm | 0:9b334a45a8ff | 70 | * PCNT, LEUART, I2C, LESENSE, OPAMP, USB, WDOG and ACMP) are still |
bogdanm | 0:9b334a45a8ff | 71 | * available. This gives a high degree of autonomous operation with a current |
bogdanm | 0:9b334a45a8ff | 72 | * consumption as low as 1.1 μA with RTC enabled. Power-on Reset, Brown-out |
bogdanm | 0:9b334a45a8ff | 73 | * Detection and full RAM and CPU retention is also included. |
bogdanm | 0:9b334a45a8ff | 74 | */ |
bogdanm | 0:9b334a45a8ff | 75 | void deepsleep(void) |
bogdanm | 0:9b334a45a8ff | 76 | { |
bogdanm | 0:9b334a45a8ff | 77 | EMU_EnterEM2(true); |
bogdanm | 0:9b334a45a8ff | 78 | } |
bogdanm | 0:9b334a45a8ff | 79 | |
bogdanm | 0:9b334a45a8ff | 80 | /** Block the microcontroller from sleeping below a certain mode |
bogdanm | 0:9b334a45a8ff | 81 | * |
bogdanm | 0:9b334a45a8ff | 82 | * This will block sleep() from entering an energy mode below the one given. |
bogdanm | 0:9b334a45a8ff | 83 | * -- To be called by peripheral HAL's -- |
bogdanm | 0:9b334a45a8ff | 84 | * |
bogdanm | 0:9b334a45a8ff | 85 | * After the peripheral is finished with the operation, it should call unblock with the same state |
bogdanm | 0:9b334a45a8ff | 86 | * |
bogdanm | 0:9b334a45a8ff | 87 | */ |
bogdanm | 0:9b334a45a8ff | 88 | void blockSleepMode(sleepstate_enum minimumMode) |
bogdanm | 0:9b334a45a8ff | 89 | { |
bogdanm | 0:9b334a45a8ff | 90 | INT_Disable(); |
bogdanm | 0:9b334a45a8ff | 91 | sleep_block_counter[minimumMode]++; |
bogdanm | 0:9b334a45a8ff | 92 | INT_Enable(); |
bogdanm | 0:9b334a45a8ff | 93 | } |
bogdanm | 0:9b334a45a8ff | 94 | |
bogdanm | 0:9b334a45a8ff | 95 | /** Unblock the microcontroller from sleeping below a certain mode |
bogdanm | 0:9b334a45a8ff | 96 | * |
bogdanm | 0:9b334a45a8ff | 97 | * This will unblock sleep() from entering an energy mode below the one given. |
bogdanm | 0:9b334a45a8ff | 98 | * -- To be called by peripheral HAL's -- |
bogdanm | 0:9b334a45a8ff | 99 | * |
bogdanm | 0:9b334a45a8ff | 100 | * This should be called after all transactions on a peripheral are done. |
bogdanm | 0:9b334a45a8ff | 101 | */ |
bogdanm | 0:9b334a45a8ff | 102 | void unblockSleepMode(sleepstate_enum minimumMode) |
bogdanm | 0:9b334a45a8ff | 103 | { |
bogdanm | 0:9b334a45a8ff | 104 | INT_Disable(); |
bogdanm | 0:9b334a45a8ff | 105 | if(sleep_block_counter[minimumMode] > 0) { |
bogdanm | 0:9b334a45a8ff | 106 | sleep_block_counter[minimumMode]--; |
bogdanm | 0:9b334a45a8ff | 107 | } |
bogdanm | 0:9b334a45a8ff | 108 | INT_Enable(); |
bogdanm | 0:9b334a45a8ff | 109 | } |
bogdanm | 0:9b334a45a8ff | 110 | |
bogdanm | 0:9b334a45a8ff | 111 | #endif |