Thierry Pébayle / mbed-STM32F030K6

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Tue Apr 28 11:45:12 2015 +0100
Revision:
525:c320967f86b9
Child:
526:7c4bdfe6a168
Synchronized with git revision 299385b8331142b9dc524da7a986536f60b14553

Full URL: https://github.com/mbedmicro/mbed/commit/299385b8331142b9dc524da7a986536f60b14553/

Add in Silicon Labs targets with asynchronous API support

Who changed what in which revision?

UserRevisionLine numberNew 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 525:c320967f86b9 21 #include "cmsis.h"
mbed_official 525:c320967f86b9 22 #include "em_emu.h"
mbed_official 525:c320967f86b9 23 #include "em_int.h"
mbed_official 525:c320967f86b9 24
mbed_official 525:c320967f86b9 25 uint32_t sleep_block_counter[NUM_SLEEP_MODES] = {0};
mbed_official 525:c320967f86b9 26
mbed_official 525:c320967f86b9 27 /**
mbed_official 525:c320967f86b9 28 * Sleep mode.
mbed_official 525:c320967f86b9 29 * Enter Energy Mode 1, which turns off the clock to the CPU.
mbed_official 525:c320967f86b9 30 *
mbed_official 525:c320967f86b9 31 * In EM1, the CPU is sleeping and the power consumption is only 50 μA/MHz.
mbed_official 525:c320967f86b9 32 * All peripherals, including DMA, PRS and memory system, are still available.
mbed_official 525:c320967f86b9 33 */
mbed_official 525:c320967f86b9 34 void sleep(void)
mbed_official 525:c320967f86b9 35 {
mbed_official 525:c320967f86b9 36 if (sleep_block_counter[0] > 0) {
mbed_official 525:c320967f86b9 37 // Blocked everything below EM0, so just return
mbed_official 525:c320967f86b9 38 return;
mbed_official 525:c320967f86b9 39 } else if (sleep_block_counter[1] > 0) {
mbed_official 525:c320967f86b9 40 // Blocked everything below EM1, enter EM1
mbed_official 525:c320967f86b9 41 EMU_EnterEM1();
mbed_official 525:c320967f86b9 42 } else if (sleep_block_counter[2] > 0) {
mbed_official 525:c320967f86b9 43 // Blocked everything below EM2, enter EM2
mbed_official 525:c320967f86b9 44 EMU_EnterEM2(true);
mbed_official 525:c320967f86b9 45 } else if (sleep_block_counter[3] > 0) {
mbed_official 525:c320967f86b9 46 // Blocked everything below EM3, enter EM3
mbed_official 525:c320967f86b9 47 EMU_EnterEM3(true);
mbed_official 525:c320967f86b9 48 }
mbed_official 525:c320967f86b9 49 return;
mbed_official 525:c320967f86b9 50 }
mbed_official 525:c320967f86b9 51
mbed_official 525:c320967f86b9 52 /**
mbed_official 525:c320967f86b9 53 * Deep Sleep mode.
mbed_official 525:c320967f86b9 54 * Enter Energy Mode 2, turning off all high-frequency clocks.
mbed_official 525:c320967f86b9 55 *
mbed_official 525:c320967f86b9 56 * In EM2 the high frequency oscillator is turned off, but with the 32.768 kHz
mbed_official 525:c320967f86b9 57 * oscillator running, selected low energy peripherals (LCD, RTC, LETIMER,
mbed_official 525:c320967f86b9 58 * PCNT, LEUART, I2C, LESENSE, OPAMP, USB, WDOG and ACMP) are still
mbed_official 525:c320967f86b9 59 * available. This gives a high degree of autonomous operation with a current
mbed_official 525:c320967f86b9 60 * consumption as low as 1.1 μA with RTC enabled. Power-on Reset, Brown-out
mbed_official 525:c320967f86b9 61 * Detection and full RAM and CPU retention is also included.
mbed_official 525:c320967f86b9 62 */
mbed_official 525:c320967f86b9 63 void deepsleep(void)
mbed_official 525:c320967f86b9 64 {
mbed_official 525:c320967f86b9 65 EMU_EnterEM2(true);
mbed_official 525:c320967f86b9 66 }
mbed_official 525:c320967f86b9 67
mbed_official 525:c320967f86b9 68 /** Block the microcontroller from sleeping below a certain mode
mbed_official 525:c320967f86b9 69 *
mbed_official 525:c320967f86b9 70 * This will block sleep() from entering an energy mode below the one given.
mbed_official 525:c320967f86b9 71 * -- To be called by peripheral HAL's --
mbed_official 525:c320967f86b9 72 *
mbed_official 525:c320967f86b9 73 * After the peripheral is finished with the operation, it should call unblock with the same state
mbed_official 525:c320967f86b9 74 *
mbed_official 525:c320967f86b9 75 */
mbed_official 525:c320967f86b9 76 void blockSleepMode(sleepstate_enum minimumMode)
mbed_official 525:c320967f86b9 77 {
mbed_official 525:c320967f86b9 78 INT_Disable();
mbed_official 525:c320967f86b9 79 sleep_block_counter[minimumMode]++;
mbed_official 525:c320967f86b9 80 INT_Enable();
mbed_official 525:c320967f86b9 81 }
mbed_official 525:c320967f86b9 82
mbed_official 525:c320967f86b9 83 /** Unblock the microcontroller from sleeping below a certain mode
mbed_official 525:c320967f86b9 84 *
mbed_official 525:c320967f86b9 85 * This will unblock sleep() from entering an energy mode below the one given.
mbed_official 525:c320967f86b9 86 * -- To be called by peripheral HAL's --
mbed_official 525:c320967f86b9 87 *
mbed_official 525:c320967f86b9 88 * This should be called after all transactions on a peripheral are done.
mbed_official 525:c320967f86b9 89 */
mbed_official 525:c320967f86b9 90 void unblockSleepMode(sleepstate_enum minimumMode)
mbed_official 525:c320967f86b9 91 {
mbed_official 525:c320967f86b9 92 INT_Disable();
mbed_official 525:c320967f86b9 93 if(sleep_block_counter[minimumMode] > 0)
mbed_official 525:c320967f86b9 94 {
mbed_official 525:c320967f86b9 95 sleep_block_counter[minimumMode]--;
mbed_official 525:c320967f86b9 96 }
mbed_official 525:c320967f86b9 97 INT_Enable();
mbed_official 525:c320967f86b9 98 }
mbed_official 525:c320967f86b9 99
mbed_official 525:c320967f86b9 100 #endif