mbed library sources modify the rtc/i2c
Dependents: SSD1306_smart_watch
Fork of mbed-src by
targets/hal/TARGET_STM/TARGET_STM32F0/sleep.c@577:545d200432a1, 2015-06-29 (annotated)
- Committer:
- eunkyoungkim
- Date:
- Mon Jun 29 05:49:52 2015 +0000
- Revision:
- 577:545d200432a1
- Parent:
- 469:fc4922e0c183
modify the i2c.c/i2c.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 469:fc4922e0c183 | 1 | /* mbed Microcontroller Library |
mbed_official | 469:fc4922e0c183 | 2 | ******************************************************************************* |
mbed_official | 469:fc4922e0c183 | 3 | * Copyright (c) 2014, STMicroelectronics |
mbed_official | 469:fc4922e0c183 | 4 | * All rights reserved. |
mbed_official | 469:fc4922e0c183 | 5 | * |
mbed_official | 469:fc4922e0c183 | 6 | * Redistribution and use in source and binary forms, with or without |
mbed_official | 469:fc4922e0c183 | 7 | * modification, are permitted provided that the following conditions are met: |
mbed_official | 469:fc4922e0c183 | 8 | * |
mbed_official | 469:fc4922e0c183 | 9 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 469:fc4922e0c183 | 10 | * this list of conditions and the following disclaimer. |
mbed_official | 469:fc4922e0c183 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 469:fc4922e0c183 | 12 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 469:fc4922e0c183 | 13 | * and/or other materials provided with the distribution. |
mbed_official | 469:fc4922e0c183 | 14 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 469:fc4922e0c183 | 15 | * may be used to endorse or promote products derived from this software |
mbed_official | 469:fc4922e0c183 | 16 | * without specific prior written permission. |
mbed_official | 469:fc4922e0c183 | 17 | * |
mbed_official | 469:fc4922e0c183 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 469:fc4922e0c183 | 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 469:fc4922e0c183 | 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 469:fc4922e0c183 | 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 469:fc4922e0c183 | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 469:fc4922e0c183 | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 469:fc4922e0c183 | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 469:fc4922e0c183 | 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 469:fc4922e0c183 | 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 469:fc4922e0c183 | 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 469:fc4922e0c183 | 28 | ******************************************************************************* |
mbed_official | 469:fc4922e0c183 | 29 | */ |
mbed_official | 469:fc4922e0c183 | 30 | #include "sleep_api.h" |
mbed_official | 469:fc4922e0c183 | 31 | |
mbed_official | 469:fc4922e0c183 | 32 | #if DEVICE_SLEEP |
mbed_official | 469:fc4922e0c183 | 33 | |
mbed_official | 469:fc4922e0c183 | 34 | #include "cmsis.h" |
mbed_official | 469:fc4922e0c183 | 35 | |
mbed_official | 469:fc4922e0c183 | 36 | #if defined(TARGET_STM32F070RB) |
mbed_official | 469:fc4922e0c183 | 37 | void sleep(void) |
mbed_official | 469:fc4922e0c183 | 38 | { |
mbed_official | 469:fc4922e0c183 | 39 | TIM_HandleTypeDef TimMasterHandle; |
mbed_official | 469:fc4922e0c183 | 40 | |
mbed_official | 469:fc4922e0c183 | 41 | TimMasterHandle.Instance = TIM1; |
mbed_official | 469:fc4922e0c183 | 42 | |
mbed_official | 469:fc4922e0c183 | 43 | // Disable HAL tick and us_ticker update interrupts |
mbed_official | 469:fc4922e0c183 | 44 | __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); |
mbed_official | 469:fc4922e0c183 | 45 | |
mbed_official | 469:fc4922e0c183 | 46 | // Request to enter SLEEP mode |
mbed_official | 469:fc4922e0c183 | 47 | HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); |
mbed_official | 469:fc4922e0c183 | 48 | |
mbed_official | 469:fc4922e0c183 | 49 | // Enable HAL tick and us_ticker update interrupts |
mbed_official | 469:fc4922e0c183 | 50 | __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); |
mbed_official | 469:fc4922e0c183 | 51 | } |
mbed_official | 469:fc4922e0c183 | 52 | |
mbed_official | 469:fc4922e0c183 | 53 | #elif defined(TARGET_STM32F030R8) || defined (TARGET_STM32F051R8) |
mbed_official | 469:fc4922e0c183 | 54 | void sleep(void) |
mbed_official | 469:fc4922e0c183 | 55 | { |
mbed_official | 469:fc4922e0c183 | 56 | // Stop HAL systick |
mbed_official | 469:fc4922e0c183 | 57 | HAL_SuspendTick(); |
mbed_official | 469:fc4922e0c183 | 58 | // Request to enter SLEEP mode |
mbed_official | 469:fc4922e0c183 | 59 | HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); |
mbed_official | 469:fc4922e0c183 | 60 | // Restart HAL systick |
mbed_official | 469:fc4922e0c183 | 61 | HAL_ResumeTick(); |
mbed_official | 469:fc4922e0c183 | 62 | } |
mbed_official | 469:fc4922e0c183 | 63 | |
mbed_official | 469:fc4922e0c183 | 64 | #else |
mbed_official | 469:fc4922e0c183 | 65 | static TIM_HandleTypeDef TimMasterHandle; |
mbed_official | 469:fc4922e0c183 | 66 | |
mbed_official | 469:fc4922e0c183 | 67 | void sleep(void) |
mbed_official | 469:fc4922e0c183 | 68 | { |
mbed_official | 469:fc4922e0c183 | 69 | TimMasterHandle.Instance = TIM2; |
mbed_official | 469:fc4922e0c183 | 70 | |
mbed_official | 469:fc4922e0c183 | 71 | // Disable HAL tick interrupt |
mbed_official | 469:fc4922e0c183 | 72 | __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); |
mbed_official | 469:fc4922e0c183 | 73 | |
mbed_official | 469:fc4922e0c183 | 74 | // Request to enter SLEEP mode |
mbed_official | 469:fc4922e0c183 | 75 | HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); |
mbed_official | 469:fc4922e0c183 | 76 | |
mbed_official | 469:fc4922e0c183 | 77 | // Enable HAL tick interrupt |
mbed_official | 469:fc4922e0c183 | 78 | __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); |
mbed_official | 469:fc4922e0c183 | 79 | } |
mbed_official | 469:fc4922e0c183 | 80 | #endif |
mbed_official | 469:fc4922e0c183 | 81 | |
mbed_official | 469:fc4922e0c183 | 82 | #if defined(TARGET_STM32F030R8) || defined (TARGET_STM32F051R8) |
mbed_official | 469:fc4922e0c183 | 83 | void deepsleep(void) |
mbed_official | 469:fc4922e0c183 | 84 | { |
mbed_official | 469:fc4922e0c183 | 85 | // Request to enter STOP mode with regulator in low power mode |
mbed_official | 469:fc4922e0c183 | 86 | HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); |
mbed_official | 469:fc4922e0c183 | 87 | |
mbed_official | 469:fc4922e0c183 | 88 | HAL_InitTick(TICK_INT_PRIORITY); |
mbed_official | 469:fc4922e0c183 | 89 | |
mbed_official | 469:fc4922e0c183 | 90 | // After wake-up from STOP reconfigure the PLL |
mbed_official | 469:fc4922e0c183 | 91 | SetSysClock(); |
mbed_official | 469:fc4922e0c183 | 92 | |
mbed_official | 469:fc4922e0c183 | 93 | HAL_InitTick(TICK_INT_PRIORITY); |
mbed_official | 469:fc4922e0c183 | 94 | } |
mbed_official | 469:fc4922e0c183 | 95 | |
mbed_official | 469:fc4922e0c183 | 96 | #else |
mbed_official | 469:fc4922e0c183 | 97 | void deepsleep(void) |
mbed_official | 469:fc4922e0c183 | 98 | { |
mbed_official | 469:fc4922e0c183 | 99 | // Request to enter STOP mode with regulator in low power mode |
mbed_official | 469:fc4922e0c183 | 100 | HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); |
mbed_official | 469:fc4922e0c183 | 101 | |
mbed_official | 469:fc4922e0c183 | 102 | // After wake-up from STOP reconfigure the PLL |
mbed_official | 469:fc4922e0c183 | 103 | SetSysClock(); |
mbed_official | 469:fc4922e0c183 | 104 | } |
mbed_official | 469:fc4922e0c183 | 105 | #endif |
mbed_official | 469:fc4922e0c183 | 106 | |
mbed_official | 469:fc4922e0c183 | 107 | #endif |