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.
Dependents: MAX34417_demo MAXREFDES1265 MAXREFDES1265
Fork of mbed-dev by
targets/hal/TARGET_NXP/TARGET_LPC82X/sleep.c@0:9b334a45a8ff, 2015-10-01 (annotated)
- Committer:
 - bogdanm
 - Date:
 - Thu Oct 01 15:25:22 2015 +0300
 - Revision:
 - 0:9b334a45a8ff
 - Child:
 - 144:ef7eb2e8f9f7
 
Initial commit on mbed-dev
Replaces mbed-src (now inactive)
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| bogdanm | 0:9b334a45a8ff | 1 | /* mbed Microcontroller Library | 
| bogdanm | 0:9b334a45a8ff | 2 | * Copyright (c) 2006-2013 ARM Limited | 
| bogdanm | 0:9b334a45a8ff | 3 | * | 
| bogdanm | 0:9b334a45a8ff | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
| bogdanm | 0:9b334a45a8ff | 5 | * you may not use this file except in compliance with the License. | 
| bogdanm | 0:9b334a45a8ff | 6 | * You may obtain a copy of the License at | 
| bogdanm | 0:9b334a45a8ff | 7 | * | 
| bogdanm | 0:9b334a45a8ff | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | 
| bogdanm | 0:9b334a45a8ff | 9 | * | 
| bogdanm | 0:9b334a45a8ff | 10 | * Unless required by applicable law or agreed to in writing, software | 
| bogdanm | 0:9b334a45a8ff | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
| bogdanm | 0:9b334a45a8ff | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| bogdanm | 0:9b334a45a8ff | 13 | * See the License for the specific language governing permissions and | 
| bogdanm | 0:9b334a45a8ff | 14 | * limitations under the License. | 
| bogdanm | 0:9b334a45a8ff | 15 | */ | 
| bogdanm | 0:9b334a45a8ff | 16 | #include "sleep_api.h" | 
| bogdanm | 0:9b334a45a8ff | 17 | #include "cmsis.h" | 
| bogdanm | 0:9b334a45a8ff | 18 | |
| bogdanm | 0:9b334a45a8ff | 19 | |
| bogdanm | 0:9b334a45a8ff | 20 | //#define DEEPSLEEP | 
| bogdanm | 0:9b334a45a8ff | 21 | #define POWERDOWN | 
| bogdanm | 0:9b334a45a8ff | 22 | |
| bogdanm | 0:9b334a45a8ff | 23 | void sleep(void) | 
| bogdanm | 0:9b334a45a8ff | 24 | { | 
| bogdanm | 0:9b334a45a8ff | 25 | //Normal sleep mode for PCON: | 
| bogdanm | 0:9b334a45a8ff | 26 | LPC_PMU->PCON &= ~0x03; | 
| bogdanm | 0:9b334a45a8ff | 27 | |
| bogdanm | 0:9b334a45a8ff | 28 | //Normal sleep mode for ARM core: | 
| bogdanm | 0:9b334a45a8ff | 29 | SCB->SCR = 0; | 
| bogdanm | 0:9b334a45a8ff | 30 | |
| bogdanm | 0:9b334a45a8ff | 31 | //And go to sleep | 
| bogdanm | 0:9b334a45a8ff | 32 | __WFI(); | 
| bogdanm | 0:9b334a45a8ff | 33 | } | 
| bogdanm | 0:9b334a45a8ff | 34 | |
| bogdanm | 0:9b334a45a8ff | 35 | // Deepsleep/powerdown modes assume the device is configured to use its internal RC oscillator directly | 
| bogdanm | 0:9b334a45a8ff | 36 | |
| bogdanm | 0:9b334a45a8ff | 37 | void deepsleep(void) | 
| bogdanm | 0:9b334a45a8ff | 38 | { | 
| bogdanm | 0:9b334a45a8ff | 39 | //Deep sleep in PCON | 
| bogdanm | 0:9b334a45a8ff | 40 | LPC_PMU->PCON &= ~0x03; | 
| bogdanm | 0:9b334a45a8ff | 41 | |
| bogdanm | 0:9b334a45a8ff | 42 | #if defined(DEEPSLEEP) | 
| bogdanm | 0:9b334a45a8ff | 43 | LPC_PMU->PCON |= 0x01; | 
| bogdanm | 0:9b334a45a8ff | 44 | #elif defined(POWERDOWN) | 
| bogdanm | 0:9b334a45a8ff | 45 | LPC_PMU->PCON |= 0x02; | 
| bogdanm | 0:9b334a45a8ff | 46 | #endif | 
| bogdanm | 0:9b334a45a8ff | 47 | |
| bogdanm | 0:9b334a45a8ff | 48 | //If brownout detection and WDT are enabled, keep them enabled during sleep | 
| bogdanm | 0:9b334a45a8ff | 49 | LPC_SYSCON->PDSLEEPCFG = LPC_SYSCON->PDRUNCFG; | 
| bogdanm | 0:9b334a45a8ff | 50 | |
| bogdanm | 0:9b334a45a8ff | 51 | //After wakeup same stuff as currently enabled: | 
| bogdanm | 0:9b334a45a8ff | 52 | LPC_SYSCON->PDAWAKECFG = LPC_SYSCON->PDRUNCFG; | 
| bogdanm | 0:9b334a45a8ff | 53 | |
| bogdanm | 0:9b334a45a8ff | 54 | //All interrupts may wake up: | 
| bogdanm | 0:9b334a45a8ff | 55 | LPC_SYSCON->STARTERP0 = 0xFF; | 
| bogdanm | 0:9b334a45a8ff | 56 | LPC_SYSCON->STARTERP1 = 0xFFFF; | 
| bogdanm | 0:9b334a45a8ff | 57 | |
| bogdanm | 0:9b334a45a8ff | 58 | //Deep sleep for ARM core: | 
| bogdanm | 0:9b334a45a8ff | 59 | SCB->SCR = 1<<2; | 
| bogdanm | 0:9b334a45a8ff | 60 | |
| bogdanm | 0:9b334a45a8ff | 61 | __WFI(); | 
| bogdanm | 0:9b334a45a8ff | 62 | } | 
