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.

Committer:
mbed_official
Date:
Fri Sep 25 14:15:10 2015 +0100
Revision:
627:4fa1328d9c60
Parent:
548:1abac31e188e
Synchronized with git revision fe238a91ab7a4d1d72c4cab9da04967c619d54ad

Full URL: https://github.com/mbedmicro/mbed/commit/fe238a91ab7a4d1d72c4cab9da04967c619d54ad/

Silicon Labs - Add support for low-power async Serial

Who changed what in which revision?

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