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