mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
targets/hal/TARGET_Freescale/TARGET_K20D50M/sleep.c@255:20b371a9491b, 2014-07-11 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Jul 11 10:00:08 2014 +0100
- Revision:
- 255:20b371a9491b
- Parent:
- targets/hal/TARGET_Freescale/TARGET_K20D5M/sleep.c@161:09d8213f0000
Synchronized with git revision bbf5cbc71510e72033aaacbd76c3f127b70f08b6
Full URL: https://github.com/mbedmicro/mbed/commit/bbf5cbc71510e72033aaacbd76c3f127b70f08b6/
[K20D50M] K20D5M -> K20D50M
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 161:09d8213f0000 | 1 | /* mbed Microcontroller Library |
mbed_official | 161:09d8213f0000 | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbed_official | 161:09d8213f0000 | 3 | * |
mbed_official | 161:09d8213f0000 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 161:09d8213f0000 | 5 | * you may not use this file except in compliance with the License. |
mbed_official | 161:09d8213f0000 | 6 | * You may obtain a copy of the License at |
mbed_official | 161:09d8213f0000 | 7 | * |
mbed_official | 161:09d8213f0000 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 161:09d8213f0000 | 9 | * |
mbed_official | 161:09d8213f0000 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 161:09d8213f0000 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 161:09d8213f0000 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 161:09d8213f0000 | 13 | * See the License for the specific language governing permissions and |
mbed_official | 161:09d8213f0000 | 14 | * limitations under the License. |
mbed_official | 161:09d8213f0000 | 15 | */ |
mbed_official | 161:09d8213f0000 | 16 | #include "sleep_api.h" |
mbed_official | 161:09d8213f0000 | 17 | #include "cmsis.h" |
mbed_official | 161:09d8213f0000 | 18 | |
mbed_official | 161:09d8213f0000 | 19 | //Normal wait mode |
mbed_official | 161:09d8213f0000 | 20 | void sleep(void) |
mbed_official | 161:09d8213f0000 | 21 | { |
mbed_official | 161:09d8213f0000 | 22 | SMC->PMPROT = SMC_PMPROT_AVLLS_MASK | SMC_PMPROT_ALLS_MASK | SMC_PMPROT_AVLP_MASK; |
mbed_official | 161:09d8213f0000 | 23 | |
mbed_official | 161:09d8213f0000 | 24 | //Normal sleep mode for ARM core: |
mbed_official | 161:09d8213f0000 | 25 | SCB->SCR = 0; |
mbed_official | 161:09d8213f0000 | 26 | __WFI(); |
mbed_official | 161:09d8213f0000 | 27 | } |
mbed_official | 161:09d8213f0000 | 28 | |
mbed_official | 161:09d8213f0000 | 29 | //Very low-power stop mode |
mbed_official | 161:09d8213f0000 | 30 | void deepsleep(void) |
mbed_official | 161:09d8213f0000 | 31 | { |
mbed_official | 161:09d8213f0000 | 32 | //Check if PLL/FLL is enabled: |
mbed_official | 161:09d8213f0000 | 33 | uint32_t PLL_FLL_en = (MCG->C1 & MCG_C1_CLKS_MASK) == MCG_C1_CLKS(0); |
mbed_official | 161:09d8213f0000 | 34 | |
mbed_official | 161:09d8213f0000 | 35 | SMC->PMPROT = SMC_PMPROT_AVLLS_MASK | SMC_PMPROT_ALLS_MASK | SMC_PMPROT_AVLP_MASK; |
mbed_official | 161:09d8213f0000 | 36 | SMC->PMCTRL = SMC_PMCTRL_STOPM(2); |
mbed_official | 161:09d8213f0000 | 37 | |
mbed_official | 161:09d8213f0000 | 38 | //Deep sleep for ARM core: |
mbed_official | 161:09d8213f0000 | 39 | SCB->SCR = 1<<SCB_SCR_SLEEPDEEP_Pos; |
mbed_official | 161:09d8213f0000 | 40 | |
mbed_official | 161:09d8213f0000 | 41 | __WFI(); |
mbed_official | 161:09d8213f0000 | 42 | |
mbed_official | 161:09d8213f0000 | 43 | //Switch back to PLL as clock source if needed |
mbed_official | 161:09d8213f0000 | 44 | //The interrupt that woke up the device will run at reduced speed |
mbed_official | 161:09d8213f0000 | 45 | if (PLL_FLL_en) { |
mbed_official | 161:09d8213f0000 | 46 | if (MCG->C6 & (1<<MCG_C6_PLLS_SHIFT) != 0) /* If PLL */ |
mbed_official | 161:09d8213f0000 | 47 | while((MCG->S & MCG_S_LOCK0_MASK) == 0x00U); /* Wait until locked */ |
mbed_official | 161:09d8213f0000 | 48 | MCG->C1 &= ~MCG_C1_CLKS_MASK; |
mbed_official | 161:09d8213f0000 | 49 | } |
mbed_official | 161:09d8213f0000 | 50 | |
mbed_official | 161:09d8213f0000 | 51 | } |