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