mbed library sources
Dependents: FRDM-KL46Z_LCD_Test FRDM-KL46Z_LCD_Test FRDM-KL46Z_Plantilla FRDM-KL46Z_Plantilla ... more
targets/hal/TARGET_NXP/TARGET_LPC11UXX/sleep.c@0:6bc4ac881c8e, 2016-07-28 (annotated)
- Committer:
- ebrus
- Date:
- Thu Jul 28 15:56:34 2016 +0000
- Revision:
- 0:6bc4ac881c8e
1;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ebrus | 0:6bc4ac881c8e | 1 | /* mbed Microcontroller Library |
ebrus | 0:6bc4ac881c8e | 2 | * Copyright (c) 2006-2013 ARM Limited |
ebrus | 0:6bc4ac881c8e | 3 | * |
ebrus | 0:6bc4ac881c8e | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ebrus | 0:6bc4ac881c8e | 5 | * you may not use this file except in compliance with the License. |
ebrus | 0:6bc4ac881c8e | 6 | * You may obtain a copy of the License at |
ebrus | 0:6bc4ac881c8e | 7 | * |
ebrus | 0:6bc4ac881c8e | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
ebrus | 0:6bc4ac881c8e | 9 | * |
ebrus | 0:6bc4ac881c8e | 10 | * Unless required by applicable law or agreed to in writing, software |
ebrus | 0:6bc4ac881c8e | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
ebrus | 0:6bc4ac881c8e | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ebrus | 0:6bc4ac881c8e | 13 | * See the License for the specific language governing permissions and |
ebrus | 0:6bc4ac881c8e | 14 | * limitations under the License. |
ebrus | 0:6bc4ac881c8e | 15 | */ |
ebrus | 0:6bc4ac881c8e | 16 | #include "sleep_api.h" |
ebrus | 0:6bc4ac881c8e | 17 | #include "cmsis.h" |
ebrus | 0:6bc4ac881c8e | 18 | #include "mbed_interface.h" |
ebrus | 0:6bc4ac881c8e | 19 | |
ebrus | 0:6bc4ac881c8e | 20 | void sleep(void) { |
ebrus | 0:6bc4ac881c8e | 21 | // ensure debug is disconnected |
ebrus | 0:6bc4ac881c8e | 22 | #if DEVICE_SEMIHOST |
ebrus | 0:6bc4ac881c8e | 23 | mbed_interface_disconnect(); |
ebrus | 0:6bc4ac881c8e | 24 | #endif |
ebrus | 0:6bc4ac881c8e | 25 | |
ebrus | 0:6bc4ac881c8e | 26 | // PCON[PD] set to sleep |
ebrus | 0:6bc4ac881c8e | 27 | LPC_PMU->PCON = 0x0; |
ebrus | 0:6bc4ac881c8e | 28 | |
ebrus | 0:6bc4ac881c8e | 29 | // SRC[SLEEPDEEP] set to 0 = sleep |
ebrus | 0:6bc4ac881c8e | 30 | SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; |
ebrus | 0:6bc4ac881c8e | 31 | |
ebrus | 0:6bc4ac881c8e | 32 | // wait for interrupt |
ebrus | 0:6bc4ac881c8e | 33 | __WFI(); |
ebrus | 0:6bc4ac881c8e | 34 | } |
ebrus | 0:6bc4ac881c8e | 35 | |
ebrus | 0:6bc4ac881c8e | 36 | /* |
ebrus | 0:6bc4ac881c8e | 37 | * The mbed lpc1768 does not support the deepsleep mode |
ebrus | 0:6bc4ac881c8e | 38 | * as a debugger is connected to it (the mbed interface). |
ebrus | 0:6bc4ac881c8e | 39 | * |
ebrus | 0:6bc4ac881c8e | 40 | * As mentionned in an application note from NXP: |
ebrus | 0:6bc4ac881c8e | 41 | * |
ebrus | 0:6bc4ac881c8e | 42 | * http://www.po-star.com/public/uploads/20120319123122_141.pdf |
ebrus | 0:6bc4ac881c8e | 43 | * |
ebrus | 0:6bc4ac881c8e | 44 | * {{{ |
ebrus | 0:6bc4ac881c8e | 45 | * The user should be aware of certain limitations during debugging. |
ebrus | 0:6bc4ac881c8e | 46 | * The most important is that, due to limitations of the Cortex-M3 |
ebrus | 0:6bc4ac881c8e | 47 | * integration, the LPC17xx cannot wake up in the usual manner from |
ebrus | 0:6bc4ac881c8e | 48 | * Deep Sleep and Power-down modes. It is recommended not to use these |
ebrus | 0:6bc4ac881c8e | 49 | * modes during debug. Once an application is downloaded via JTAG/SWD |
ebrus | 0:6bc4ac881c8e | 50 | * interface, the USB to SWD/JTAG debug adapter (Keil ULINK2 for example) |
ebrus | 0:6bc4ac881c8e | 51 | * should be removed from the target board, and thereafter, power cycle |
ebrus | 0:6bc4ac881c8e | 52 | * the LPC17xx to allow wake-up from deep sleep and power-down modes |
ebrus | 0:6bc4ac881c8e | 53 | * }}} |
ebrus | 0:6bc4ac881c8e | 54 | * |
ebrus | 0:6bc4ac881c8e | 55 | * As the interface firmware does not reset the target when a |
ebrus | 0:6bc4ac881c8e | 56 | * mbed_interface_disconnect() semihosting call is made, the |
ebrus | 0:6bc4ac881c8e | 57 | * core cannot wake-up from deepsleep. |
ebrus | 0:6bc4ac881c8e | 58 | * |
ebrus | 0:6bc4ac881c8e | 59 | * We treat a deepsleep() as a normal sleep(). |
ebrus | 0:6bc4ac881c8e | 60 | */ |
ebrus | 0:6bc4ac881c8e | 61 | |
ebrus | 0:6bc4ac881c8e | 62 | void deepsleep(void) { |
ebrus | 0:6bc4ac881c8e | 63 | // ensure debug is disconnected |
ebrus | 0:6bc4ac881c8e | 64 | #if DEVICE_SEMIHOST |
ebrus | 0:6bc4ac881c8e | 65 | mbed_interface_disconnect(); |
ebrus | 0:6bc4ac881c8e | 66 | #endif |
ebrus | 0:6bc4ac881c8e | 67 | |
ebrus | 0:6bc4ac881c8e | 68 | // PCON[PD] set to deepsleep |
ebrus | 0:6bc4ac881c8e | 69 | LPC_PMU->PCON = 0x1; |
ebrus | 0:6bc4ac881c8e | 70 | |
ebrus | 0:6bc4ac881c8e | 71 | // SRC[SLEEPDEEP] set to 1 = deep sleep |
ebrus | 0:6bc4ac881c8e | 72 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; |
ebrus | 0:6bc4ac881c8e | 73 | |
ebrus | 0:6bc4ac881c8e | 74 | // Power up everything after powerdown |
ebrus | 0:6bc4ac881c8e | 75 | LPC_SYSCON->PDAWAKECFG &= 0xFFFFF800; |
ebrus | 0:6bc4ac881c8e | 76 | |
ebrus | 0:6bc4ac881c8e | 77 | // wait for interrupt |
ebrus | 0:6bc4ac881c8e | 78 | __WFI(); |
ebrus | 0:6bc4ac881c8e | 79 | } |