mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

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