mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/TARGET_TOSHIBA/TARGET_TMPM3H6/sleep.c@187:0387e8f68319, 2018-09-06 (annotated)
- Committer:
- AnnaBridge
- Date:
- Thu Sep 06 13:40:20 2018 +0100
- Revision:
- 187:0387e8f68319
mbed-dev library. Release version 163
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 187:0387e8f68319 | 1 | /* mbed Microcontroller Library |
AnnaBridge | 187:0387e8f68319 | 2 | * (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2018 All rights reserved |
AnnaBridge | 187:0387e8f68319 | 3 | * |
AnnaBridge | 187:0387e8f68319 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
AnnaBridge | 187:0387e8f68319 | 5 | * you may not use this file except in compliance with the License. |
AnnaBridge | 187:0387e8f68319 | 6 | * You may obtain a copy of the License at |
AnnaBridge | 187:0387e8f68319 | 7 | * |
AnnaBridge | 187:0387e8f68319 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
AnnaBridge | 187:0387e8f68319 | 9 | * |
AnnaBridge | 187:0387e8f68319 | 10 | * Unless required by applicable law or agreed to in writing, software |
AnnaBridge | 187:0387e8f68319 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
AnnaBridge | 187:0387e8f68319 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
AnnaBridge | 187:0387e8f68319 | 13 | * See the License for the specific language governing permissions and |
AnnaBridge | 187:0387e8f68319 | 14 | * limitations under the License. |
AnnaBridge | 187:0387e8f68319 | 15 | */ |
AnnaBridge | 187:0387e8f68319 | 16 | #include "sleep_api.h" |
AnnaBridge | 187:0387e8f68319 | 17 | #include "gpio_include.h" |
AnnaBridge | 187:0387e8f68319 | 18 | |
AnnaBridge | 187:0387e8f68319 | 19 | static void warming_up_time(void); |
AnnaBridge | 187:0387e8f68319 | 20 | |
AnnaBridge | 187:0387e8f68319 | 21 | void hal_sleep(void) |
AnnaBridge | 187:0387e8f68319 | 22 | { |
AnnaBridge | 187:0387e8f68319 | 23 | // Set low power consumption mode IDLE |
AnnaBridge | 187:0387e8f68319 | 24 | TSB_CG->STBYCR = CG_STBY_MODE_IDLE; |
AnnaBridge | 187:0387e8f68319 | 25 | __DSB(); // Enter idle mode |
AnnaBridge | 187:0387e8f68319 | 26 | __WFI(); |
AnnaBridge | 187:0387e8f68319 | 27 | } |
AnnaBridge | 187:0387e8f68319 | 28 | |
AnnaBridge | 187:0387e8f68319 | 29 | void hal_deepsleep(void) |
AnnaBridge | 187:0387e8f68319 | 30 | { |
AnnaBridge | 187:0387e8f68319 | 31 | uint32_t tmp = 0; |
AnnaBridge | 187:0387e8f68319 | 32 | |
AnnaBridge | 187:0387e8f68319 | 33 | TSB_CG_FSYSENB_IPENB31 = ENABLE; |
AnnaBridge | 187:0387e8f68319 | 34 | |
AnnaBridge | 187:0387e8f68319 | 35 | TSB_SIWD0->EN = DISABLE; |
AnnaBridge | 187:0387e8f68319 | 36 | TSB_SIWD0->CR = 0xB1; |
AnnaBridge | 187:0387e8f68319 | 37 | |
AnnaBridge | 187:0387e8f68319 | 38 | while ((TSB_FC->SR0 & 0x01) != 0x01) { |
AnnaBridge | 187:0387e8f68319 | 39 | // Flash wait |
AnnaBridge | 187:0387e8f68319 | 40 | } |
AnnaBridge | 187:0387e8f68319 | 41 | |
AnnaBridge | 187:0387e8f68319 | 42 | while (TSB_CG_WUPHCR_WUEF) { |
AnnaBridge | 187:0387e8f68319 | 43 | // Wait for end of Warming-up for IHOSC1 |
AnnaBridge | 187:0387e8f68319 | 44 | } |
AnnaBridge | 187:0387e8f68319 | 45 | |
AnnaBridge | 187:0387e8f68319 | 46 | TSB_CG_WUPHCR_WUCLK = DISABLE; |
AnnaBridge | 187:0387e8f68319 | 47 | warming_up_time(); |
AnnaBridge | 187:0387e8f68319 | 48 | TSB_CG->STBYCR = CG_STBY_MODE_STOP1; |
AnnaBridge | 187:0387e8f68319 | 49 | TSB_CG_PLL0SEL_PLL0SEL = DISABLE; |
AnnaBridge | 187:0387e8f68319 | 50 | |
AnnaBridge | 187:0387e8f68319 | 51 | while (TSB_CG_PLL0SEL_PLL0ST) { |
AnnaBridge | 187:0387e8f68319 | 52 | // Wait for PLL status of fsys until off state(fosc=0) |
AnnaBridge | 187:0387e8f68319 | 53 | } |
AnnaBridge | 187:0387e8f68319 | 54 | |
AnnaBridge | 187:0387e8f68319 | 55 | TSB_CG_PLL0SEL_PLL0ON = DISABLE; // Stop PLL of fsys |
AnnaBridge | 187:0387e8f68319 | 56 | TSB_CG_OSCCR_IHOSC1EN = ENABLE; |
AnnaBridge | 187:0387e8f68319 | 57 | TSB_CG_OSCCR_OSCSEL = DISABLE; |
AnnaBridge | 187:0387e8f68319 | 58 | |
AnnaBridge | 187:0387e8f68319 | 59 | while (TSB_CG_OSCCR_OSCF) { |
AnnaBridge | 187:0387e8f68319 | 60 | // Wait for fosc status until IHOSC1 = 0 |
AnnaBridge | 187:0387e8f68319 | 61 | } |
AnnaBridge | 187:0387e8f68319 | 62 | |
AnnaBridge | 187:0387e8f68319 | 63 | tmp = TSB_CG->OSCCR; |
AnnaBridge | 187:0387e8f68319 | 64 | tmp &= EXTERNEL_OSC_MASK; |
AnnaBridge | 187:0387e8f68319 | 65 | TSB_CG->OSCCR = tmp; |
AnnaBridge | 187:0387e8f68319 | 66 | TSB_CG_OSCCR_IHOSC2EN = DISABLE; |
AnnaBridge | 187:0387e8f68319 | 67 | |
AnnaBridge | 187:0387e8f68319 | 68 | while (TSB_CG_OSCCR_IHOSC2F) { |
AnnaBridge | 187:0387e8f68319 | 69 | // Wait for status of OFD until off "0" |
AnnaBridge | 187:0387e8f68319 | 70 | } |
AnnaBridge | 187:0387e8f68319 | 71 | |
AnnaBridge | 187:0387e8f68319 | 72 | __DSB(); |
AnnaBridge | 187:0387e8f68319 | 73 | __WFI(); |
AnnaBridge | 187:0387e8f68319 | 74 | } |
AnnaBridge | 187:0387e8f68319 | 75 | |
AnnaBridge | 187:0387e8f68319 | 76 | static void warming_up_time(void) |
AnnaBridge | 187:0387e8f68319 | 77 | { |
AnnaBridge | 187:0387e8f68319 | 78 | uint32_t work = 0; |
AnnaBridge | 187:0387e8f68319 | 79 | uint64_t x = 0; |
AnnaBridge | 187:0387e8f68319 | 80 | |
AnnaBridge | 187:0387e8f68319 | 81 | x = (uint64_t)(IHOSC_CFG_WARM_UP_TIME * IHOSC_CFG_CLOCK); |
AnnaBridge | 187:0387e8f68319 | 82 | x = (uint64_t)(x / (uint64_t)(1000000)); |
AnnaBridge | 187:0387e8f68319 | 83 | |
AnnaBridge | 187:0387e8f68319 | 84 | work = (uint32_t)x; |
AnnaBridge | 187:0387e8f68319 | 85 | work &= (uint32_t)(0xFFFFFFF0); |
AnnaBridge | 187:0387e8f68319 | 86 | work <<= 16; |
AnnaBridge | 187:0387e8f68319 | 87 | work |= (uint32_t)(TSB_CG->WUPHCR & ~CGWUPHCR_WUPT_HIGH_MASK); |
AnnaBridge | 187:0387e8f68319 | 88 | TSB_CG->WUPHCR = work; |
AnnaBridge | 187:0387e8f68319 | 89 | } |