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.
targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/sleep.c@548:1abac31e188e, 2015-05-22 (annotated)
- Committer:
- mbed_official
- Date:
- Fri May 22 10:45:46 2015 +0100
- Revision:
- 548:1abac31e188e
- Parent:
- 526:7c4bdfe6a168
- Child:
- 627:4fa1328d9c60
Synchronized with git revision 88d158e43b54f97c5e94da305ea9a096889cc81b
Full URL: https://github.com/mbedmicro/mbed/commit/88d158e43b54f97c5e94da305ea9a096889cc81b/
Silicon Labs - Cosmetic: apply mbed coding style to HAL
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 525:c320967f86b9 | 1 | /* mbed Microcontroller Library |
mbed_official | 525:c320967f86b9 | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbed_official | 525:c320967f86b9 | 3 | * |
mbed_official | 525:c320967f86b9 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 525:c320967f86b9 | 5 | * you may not use this file except in compliance with the License. |
mbed_official | 525:c320967f86b9 | 6 | * You may obtain a copy of the License at |
mbed_official | 525:c320967f86b9 | 7 | * |
mbed_official | 525:c320967f86b9 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 525:c320967f86b9 | 9 | * |
mbed_official | 525:c320967f86b9 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 525:c320967f86b9 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 525:c320967f86b9 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 525:c320967f86b9 | 13 | * See the License for the specific language governing permissions and |
mbed_official | 525:c320967f86b9 | 14 | * limitations under the License. |
mbed_official | 525:c320967f86b9 | 15 | */ |
mbed_official | 525:c320967f86b9 | 16 | |
mbed_official | 525:c320967f86b9 | 17 | #include "device.h" |
mbed_official | 525:c320967f86b9 | 18 | #if DEVICE_SLEEP |
mbed_official | 525:c320967f86b9 | 19 | |
mbed_official | 525:c320967f86b9 | 20 | #include "sleep_api.h" |
mbed_official | 526:7c4bdfe6a168 | 21 | #include "sleepmodes.h" |
mbed_official | 525:c320967f86b9 | 22 | #include "cmsis.h" |
mbed_official | 525:c320967f86b9 | 23 | #include "em_emu.h" |
mbed_official | 525:c320967f86b9 | 24 | #include "em_int.h" |
mbed_official | 525:c320967f86b9 | 25 | |
mbed_official | 525:c320967f86b9 | 26 | uint32_t sleep_block_counter[NUM_SLEEP_MODES] = {0}; |
mbed_official | 525:c320967f86b9 | 27 | |
mbed_official | 525:c320967f86b9 | 28 | /** |
mbed_official | 525:c320967f86b9 | 29 | * Sleep mode. |
mbed_official | 525:c320967f86b9 | 30 | * Enter Energy Mode 1, which turns off the clock to the CPU. |
mbed_official | 525:c320967f86b9 | 31 | * |
mbed_official | 525:c320967f86b9 | 32 | * In EM1, the CPU is sleeping and the power consumption is only 50 μA/MHz. |
mbed_official | 525:c320967f86b9 | 33 | * All peripherals, including DMA, PRS and memory system, are still available. |
mbed_official | 525:c320967f86b9 | 34 | */ |
mbed_official | 525:c320967f86b9 | 35 | void sleep(void) |
mbed_official | 525:c320967f86b9 | 36 | { |
mbed_official | 548:1abac31e188e | 37 | if (sleep_block_counter[0] > 0) { |
mbed_official | 548:1abac31e188e | 38 | // Blocked everything below EM0, so just return |
mbed_official | 548:1abac31e188e | 39 | return; |
mbed_official | 548:1abac31e188e | 40 | } else if (sleep_block_counter[1] > 0) { |
mbed_official | 548:1abac31e188e | 41 | // Blocked everything below EM1, enter EM1 |
mbed_official | 548:1abac31e188e | 42 | EMU_EnterEM1(); |
mbed_official | 548:1abac31e188e | 43 | } else if (sleep_block_counter[2] > 0) { |
mbed_official | 548:1abac31e188e | 44 | // Blocked everything below EM2, enter EM2 |
mbed_official | 548:1abac31e188e | 45 | EMU_EnterEM2(true); |
mbed_official | 548:1abac31e188e | 46 | } else if (sleep_block_counter[3] > 0) { |
mbed_official | 548:1abac31e188e | 47 | // Blocked everything below EM3, enter EM3 |
mbed_official | 548:1abac31e188e | 48 | EMU_EnterEM3(true); |
mbed_official | 548:1abac31e188e | 49 | } |
mbed_official | 525:c320967f86b9 | 50 | return; |
mbed_official | 525:c320967f86b9 | 51 | } |
mbed_official | 525:c320967f86b9 | 52 | |
mbed_official | 525:c320967f86b9 | 53 | /** |
mbed_official | 525:c320967f86b9 | 54 | * Deep Sleep mode. |
mbed_official | 525:c320967f86b9 | 55 | * Enter Energy Mode 2, turning off all high-frequency clocks. |
mbed_official | 525:c320967f86b9 | 56 | * |
mbed_official | 525:c320967f86b9 | 57 | * In EM2 the high frequency oscillator is turned off, but with the 32.768 kHz |
mbed_official | 525:c320967f86b9 | 58 | * oscillator running, selected low energy peripherals (LCD, RTC, LETIMER, |
mbed_official | 525:c320967f86b9 | 59 | * PCNT, LEUART, I2C, LESENSE, OPAMP, USB, WDOG and ACMP) are still |
mbed_official | 525:c320967f86b9 | 60 | * available. This gives a high degree of autonomous operation with a current |
mbed_official | 525:c320967f86b9 | 61 | * consumption as low as 1.1 μA with RTC enabled. Power-on Reset, Brown-out |
mbed_official | 525:c320967f86b9 | 62 | * Detection and full RAM and CPU retention is also included. |
mbed_official | 525:c320967f86b9 | 63 | */ |
mbed_official | 525:c320967f86b9 | 64 | void deepsleep(void) |
mbed_official | 525:c320967f86b9 | 65 | { |
mbed_official | 525:c320967f86b9 | 66 | EMU_EnterEM2(true); |
mbed_official | 525:c320967f86b9 | 67 | } |
mbed_official | 525:c320967f86b9 | 68 | |
mbed_official | 525:c320967f86b9 | 69 | /** Block the microcontroller from sleeping below a certain mode |
mbed_official | 525:c320967f86b9 | 70 | * |
mbed_official | 525:c320967f86b9 | 71 | * This will block sleep() from entering an energy mode below the one given. |
mbed_official | 525:c320967f86b9 | 72 | * -- To be called by peripheral HAL's -- |
mbed_official | 525:c320967f86b9 | 73 | * |
mbed_official | 525:c320967f86b9 | 74 | * After the peripheral is finished with the operation, it should call unblock with the same state |
mbed_official | 525:c320967f86b9 | 75 | * |
mbed_official | 525:c320967f86b9 | 76 | */ |
mbed_official | 548:1abac31e188e | 77 | void blockSleepMode(sleepstate_enum minimumMode) |
mbed_official | 525:c320967f86b9 | 78 | { |
mbed_official | 548:1abac31e188e | 79 | INT_Disable(); |
mbed_official | 548:1abac31e188e | 80 | sleep_block_counter[minimumMode]++; |
mbed_official | 548:1abac31e188e | 81 | INT_Enable(); |
mbed_official | 525:c320967f86b9 | 82 | } |
mbed_official | 525:c320967f86b9 | 83 | |
mbed_official | 525:c320967f86b9 | 84 | /** Unblock the microcontroller from sleeping below a certain mode |
mbed_official | 525:c320967f86b9 | 85 | * |
mbed_official | 525:c320967f86b9 | 86 | * This will unblock sleep() from entering an energy mode below the one given. |
mbed_official | 525:c320967f86b9 | 87 | * -- To be called by peripheral HAL's -- |
mbed_official | 525:c320967f86b9 | 88 | * |
mbed_official | 525:c320967f86b9 | 89 | * This should be called after all transactions on a peripheral are done. |
mbed_official | 525:c320967f86b9 | 90 | */ |
mbed_official | 548:1abac31e188e | 91 | void unblockSleepMode(sleepstate_enum minimumMode) |
mbed_official | 525:c320967f86b9 | 92 | { |
mbed_official | 548:1abac31e188e | 93 | INT_Disable(); |
mbed_official | 548:1abac31e188e | 94 | if(sleep_block_counter[minimumMode] > 0) { |
mbed_official | 548:1abac31e188e | 95 | sleep_block_counter[minimumMode]--; |
mbed_official | 548:1abac31e188e | 96 | } |
mbed_official | 548:1abac31e188e | 97 | INT_Enable(); |
mbed_official | 525:c320967f86b9 | 98 | } |
mbed_official | 525:c320967f86b9 | 99 | |
mbed_official | 525:c320967f86b9 | 100 | #endif |