Skip to content

Commit 6a5335a

Browse files
committed
Merge pull request ARMmbed#112 from Sissors/master
Added sleep to LPC81x
2 parents 036f7be + 585e05c commit 6a5335a

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#define DEVICE_SEMIHOST 0
4545
#define DEVICE_LOCALFILESYSTEM 0
4646

47-
#define DEVICE_SLEEP 0
47+
#define DEVICE_SLEEP 1
4848

4949
#define DEVICE_DEBUG_AWARENESS 0
5050

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2006-2013 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "sleep_api.h"
17+
#include "cmsis.h"
18+
19+
20+
//#define DEEPSLEEP
21+
#define POWERDOWN
22+
23+
void sleep(void) {
24+
//Normal sleep mode for PCON:
25+
LPC_PMU->PCON &= ~0x03;
26+
27+
//Normal sleep mode for ARM core:
28+
SCB->SCR = 0;
29+
30+
//And go to sleep
31+
__WFI();
32+
}
33+
34+
35+
36+
//Deepsleep/powerdown modes assume the device is configured to use its internal RC oscillator directly
37+
38+
#ifdef DEEPSLEEP
39+
void deepsleep(void) {
40+
//Deep sleep in PCON
41+
LPC_PMU->PCON &= ~0x03;
42+
LPC_PMU->PCON |= 0x01;
43+
44+
//If brownout detection and WDT are enabled, keep them enabled during sleep
45+
LPC_SYSCON->PDSLEEPCFG = LPC_SYSCON->PDRUNCFG;
46+
47+
//After wakeup same stuff as currently enabled:
48+
LPC_SYSCON->PDAWAKECFG = LPC_SYSCON->PDRUNCFG;
49+
50+
//All interrupts may wake up:
51+
LPC_SYSCON->STARTERP0 = 0xFF;
52+
LPC_SYSCON->STARTERP1 = 0xFFFF;
53+
54+
//Deep sleep for ARM core:
55+
SCB->SCR = 1<<2;
56+
57+
__WFI();
58+
}
59+
#endif
60+
61+
#ifdef POWERDOWN
62+
void deepsleep(void) {
63+
//Powerdown in PCON
64+
LPC_PMU->PCON &= ~0x03;
65+
LPC_PMU->PCON |= 0x02;
66+
67+
//If brownout detection and WDT are enabled, keep them enabled during sleep
68+
LPC_SYSCON->PDSLEEPCFG = LPC_SYSCON->PDRUNCFG;
69+
70+
//After wakeup same stuff as currently enabled:
71+
LPC_SYSCON->PDAWAKECFG = LPC_SYSCON->PDRUNCFG;
72+
73+
//All interrupts may wake up:
74+
LPC_SYSCON->STARTERP0 = 0xFF;
75+
LPC_SYSCON->STARTERP1 = 0xFFFF;
76+
77+
//Deep sleep for ARM core:
78+
SCB->SCR = 1<<2;
79+
80+
__WFI();
81+
}
82+
#endif

0 commit comments

Comments
 (0)