|
| 1 | +/* mbed Microcontroller Library |
| 2 | + * Copyright (c) 2006-2013 ARM Limited |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +#include "sleep_api.h" |
| 17 | +#include "cmsis.h" |
| 18 | + |
| 19 | +static void SYSCLKConfig_STOP(void) |
| 20 | +{ |
| 21 | + ErrorStatus HSEStartUpStatus; |
| 22 | + |
| 23 | + RCC_HSEConfig(RCC_HSE_ON); // Enable HSE |
| 24 | + |
| 25 | + HSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait till HSE is ready |
| 26 | + |
| 27 | + if (HSEStartUpStatus == SUCCESS) { |
| 28 | + RCC_PLLCmd(ENABLE); // Enable PLL |
| 29 | + while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {} // Wait till PLL is ready |
| 30 | + RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // Select PLL as system clock source |
| 31 | + while(RCC_GetSYSCLKSource() != 0x08) {} // Wait till PLL is used as system clock source |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +void sleep(void) |
| 36 | +{ |
| 37 | + SCB->SCR = 0; // Normal sleep mode for ARM core |
| 38 | + __WFI(); |
| 39 | +} |
| 40 | + |
| 41 | +void deepsleep(void) |
| 42 | +{ |
| 43 | + // Enable PWR clock |
| 44 | + RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); |
| 45 | + |
| 46 | + // Request to enter STOP mode with regulator in low power mode |
| 47 | + PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); |
| 48 | + |
| 49 | + // At this stage the system has resumed from STOP mode. |
| 50 | + // Re-configure the system clock: enable HSE, PLL and select |
| 51 | + // PLL as system clock source (because HSE and PLL are disabled in STOP mode). |
| 52 | + SYSCLKConfig_STOP(); |
| 53 | +} |
0 commit comments