helpfor studient

Dependents:   STM32_F103-C8T6basecanblink_led

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Thu Apr 19 17:12:19 2018 +0100
Revision:
185:08ed48f1de7f
mbed-dev library. Release version 161

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 185:08ed48f1de7f 1 /* mbed Microcontroller Library
AnnaBridge 185:08ed48f1de7f 2 * (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2017 All rights reserved
AnnaBridge 185:08ed48f1de7f 3 *
AnnaBridge 185:08ed48f1de7f 4 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 185:08ed48f1de7f 5 * you may not use this file except in compliance with the License.
AnnaBridge 185:08ed48f1de7f 6 * You may obtain a copy of the License at
AnnaBridge 185:08ed48f1de7f 7 *
AnnaBridge 185:08ed48f1de7f 8 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 185:08ed48f1de7f 9 *
AnnaBridge 185:08ed48f1de7f 10 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 185:08ed48f1de7f 11 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 185:08ed48f1de7f 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 185:08ed48f1de7f 13 * See the License for the specific language governing permissions and
AnnaBridge 185:08ed48f1de7f 14 * limitations under the License.
AnnaBridge 185:08ed48f1de7f 15 */
AnnaBridge 185:08ed48f1de7f 16 #include "sleep_api.h"
AnnaBridge 185:08ed48f1de7f 17
AnnaBridge 185:08ed48f1de7f 18 // Number of warm-up cycle = warm-up time to set / input frequency cycle (s)
AnnaBridge 185:08ed48f1de7f 19 // Number of 3*10^-6 (s) / (1/12 (MHz)) = 60000 = 0xea60
AnnaBridge 185:08ed48f1de7f 20 #define CG_WUODR_INT ((uint16_t)0xea60)
AnnaBridge 185:08ed48f1de7f 21
AnnaBridge 185:08ed48f1de7f 22 static void external_losc_enable(void);
AnnaBridge 185:08ed48f1de7f 23
AnnaBridge 185:08ed48f1de7f 24 void hal_sleep(void)
AnnaBridge 185:08ed48f1de7f 25 {
AnnaBridge 185:08ed48f1de7f 26 // Set low power consumption mode IDLE
AnnaBridge 185:08ed48f1de7f 27 CG_SetSTBYMode(CG_STBY_MODE_IDLE);
AnnaBridge 185:08ed48f1de7f 28 // Enter idle mode
AnnaBridge 185:08ed48f1de7f 29 __WFI();
AnnaBridge 185:08ed48f1de7f 30 }
AnnaBridge 185:08ed48f1de7f 31
AnnaBridge 185:08ed48f1de7f 32 void hal_deepsleep(void)
AnnaBridge 185:08ed48f1de7f 33 {
AnnaBridge 185:08ed48f1de7f 34 // Set low power consumption mode STOP1
AnnaBridge 185:08ed48f1de7f 35 CG_SetSTBYMode(CG_STBY_MODE_STOP1);
AnnaBridge 185:08ed48f1de7f 36 // Setup warm up time
AnnaBridge 185:08ed48f1de7f 37 CG_SetWarmUpTime(CG_WARM_UP_SRC_OSC_EXT_HIGH, CG_WUODR_INT);
AnnaBridge 185:08ed48f1de7f 38 // Enter stop1 mode
AnnaBridge 185:08ed48f1de7f 39 __WFI();
AnnaBridge 185:08ed48f1de7f 40 // Switch over from IHOSC to EHOSC
AnnaBridge 185:08ed48f1de7f 41 external_losc_enable();
AnnaBridge 185:08ed48f1de7f 42 }
AnnaBridge 185:08ed48f1de7f 43
AnnaBridge 185:08ed48f1de7f 44 static void external_losc_enable(void)
AnnaBridge 185:08ed48f1de7f 45 {
AnnaBridge 185:08ed48f1de7f 46 // Enable high-speed oscillator
AnnaBridge 185:08ed48f1de7f 47 CG_SetFosc(CG_FOSC_OSC_EXT, ENABLE);
AnnaBridge 185:08ed48f1de7f 48 // Select internal(fIHOSC) as warm-up clock
AnnaBridge 185:08ed48f1de7f 49 CG_SetWarmUpTime(CG_WARM_UP_SRC_OSC_INT_HIGH, CG_WUODR_INT);
AnnaBridge 185:08ed48f1de7f 50 // Start warm-up
AnnaBridge 185:08ed48f1de7f 51 CG_StartWarmUp();
AnnaBridge 185:08ed48f1de7f 52 // Wait until EHOSC become stable
AnnaBridge 185:08ed48f1de7f 53 while (CG_GetWarmUpState() != DONE) {
AnnaBridge 185:08ed48f1de7f 54 // Do nothing
AnnaBridge 185:08ed48f1de7f 55 }
AnnaBridge 185:08ed48f1de7f 56
AnnaBridge 185:08ed48f1de7f 57 // Set fosc source
AnnaBridge 185:08ed48f1de7f 58 CG_SetFoscSrc(CG_FOSC_OSC_EXT);
AnnaBridge 185:08ed48f1de7f 59 // Wait for <OSCSEL> to become "1"
AnnaBridge 185:08ed48f1de7f 60 while (CG_GetFoscSrc() != CG_FOSC_OSC_EXT) {
AnnaBridge 185:08ed48f1de7f 61 // Do nothing
AnnaBridge 185:08ed48f1de7f 62 }
AnnaBridge 185:08ed48f1de7f 63
AnnaBridge 185:08ed48f1de7f 64 // Stop IHOSC
AnnaBridge 185:08ed48f1de7f 65 CG_SetFosc(CG_FOSC_OSC_INT, DISABLE);
AnnaBridge 185:08ed48f1de7f 66 }