mbed os with nrf51 internal bandgap enabled to read battery level

Dependents:   BLE_file_test BLE_Blink ExternalEncoder

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

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