mbed library sources. Supersedes mbed-src. Fixed broken STM32F1xx RTC on rtc_api.c
Dependents: Nucleo_F103RB_RTC_battery_bkup_pwr_off_okay
Fork of mbed-dev by
targets/TARGET_STM/lp_ticker.c@174:b96e65c34a4d, 2017-10-02 (annotated)
- Committer:
- AnnaBridge
- Date:
- Mon Oct 02 15:33:19 2017 +0100
- Revision:
- 174:b96e65c34a4d
- Parent:
- 154:37f96f9d4de2
This updates the lib to the mbed lib v 152
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 154:37f96f9d4de2 | 1 | /* mbed Microcontroller Library |
<> | 154:37f96f9d4de2 | 2 | ******************************************************************************* |
<> | 154:37f96f9d4de2 | 3 | * Copyright (c) 2016, STMicroelectronics |
<> | 154:37f96f9d4de2 | 4 | * All rights reserved. |
<> | 154:37f96f9d4de2 | 5 | * |
<> | 154:37f96f9d4de2 | 6 | * Redistribution and use in source and binary forms, with or without |
<> | 154:37f96f9d4de2 | 7 | * modification, are permitted provided that the following conditions are met: |
<> | 154:37f96f9d4de2 | 8 | * |
<> | 154:37f96f9d4de2 | 9 | * 1. Redistributions of source code must retain the above copyright notice, |
<> | 154:37f96f9d4de2 | 10 | * this list of conditions and the following disclaimer. |
<> | 154:37f96f9d4de2 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
<> | 154:37f96f9d4de2 | 12 | * this list of conditions and the following disclaimer in the documentation |
<> | 154:37f96f9d4de2 | 13 | * and/or other materials provided with the distribution. |
<> | 154:37f96f9d4de2 | 14 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
<> | 154:37f96f9d4de2 | 15 | * may be used to endorse or promote products derived from this software |
<> | 154:37f96f9d4de2 | 16 | * without specific prior written permission. |
<> | 154:37f96f9d4de2 | 17 | * |
<> | 154:37f96f9d4de2 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
<> | 154:37f96f9d4de2 | 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
<> | 154:37f96f9d4de2 | 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
<> | 154:37f96f9d4de2 | 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
<> | 154:37f96f9d4de2 | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
<> | 154:37f96f9d4de2 | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
<> | 154:37f96f9d4de2 | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
<> | 154:37f96f9d4de2 | 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
<> | 154:37f96f9d4de2 | 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
<> | 154:37f96f9d4de2 | 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
<> | 154:37f96f9d4de2 | 28 | ******************************************************************************* |
<> | 154:37f96f9d4de2 | 29 | */ |
<> | 154:37f96f9d4de2 | 30 | #include "device.h" |
<> | 154:37f96f9d4de2 | 31 | |
<> | 154:37f96f9d4de2 | 32 | #if DEVICE_LOWPOWERTIMER |
<> | 154:37f96f9d4de2 | 33 | |
<> | 154:37f96f9d4de2 | 34 | #include "ticker_api.h" |
<> | 154:37f96f9d4de2 | 35 | #include "lp_ticker_api.h" |
<> | 154:37f96f9d4de2 | 36 | #include "rtc_api.h" |
<> | 154:37f96f9d4de2 | 37 | #include "rtc_api_hal.h" |
<> | 154:37f96f9d4de2 | 38 | |
<> | 154:37f96f9d4de2 | 39 | static uint8_t lp_ticker_inited = 0; |
<> | 154:37f96f9d4de2 | 40 | |
<> | 154:37f96f9d4de2 | 41 | void lp_ticker_init(void) |
<> | 154:37f96f9d4de2 | 42 | { |
<> | 154:37f96f9d4de2 | 43 | if (lp_ticker_inited) return; |
<> | 154:37f96f9d4de2 | 44 | lp_ticker_inited = 1; |
<> | 154:37f96f9d4de2 | 45 | |
<> | 154:37f96f9d4de2 | 46 | rtc_init(); |
<> | 154:37f96f9d4de2 | 47 | rtc_set_irq_handler((uint32_t) lp_ticker_irq_handler); |
<> | 154:37f96f9d4de2 | 48 | } |
<> | 154:37f96f9d4de2 | 49 | |
<> | 154:37f96f9d4de2 | 50 | uint32_t lp_ticker_read(void) |
<> | 154:37f96f9d4de2 | 51 | { |
<> | 154:37f96f9d4de2 | 52 | uint32_t usecs = 0; |
<> | 154:37f96f9d4de2 | 53 | time_t time = 0; |
<> | 154:37f96f9d4de2 | 54 | |
<> | 154:37f96f9d4de2 | 55 | lp_ticker_init(); |
<> | 154:37f96f9d4de2 | 56 | |
<> | 154:37f96f9d4de2 | 57 | do { |
<> | 154:37f96f9d4de2 | 58 | time = rtc_read(); |
<> | 154:37f96f9d4de2 | 59 | usecs = rtc_read_subseconds(); |
<> | 154:37f96f9d4de2 | 60 | } while (time != rtc_read()); |
<> | 154:37f96f9d4de2 | 61 | |
<> | 154:37f96f9d4de2 | 62 | return (time * 1000000) + usecs; |
<> | 154:37f96f9d4de2 | 63 | } |
<> | 154:37f96f9d4de2 | 64 | |
<> | 154:37f96f9d4de2 | 65 | void lp_ticker_set_interrupt(timestamp_t timestamp) |
<> | 154:37f96f9d4de2 | 66 | { |
<> | 154:37f96f9d4de2 | 67 | uint32_t delta; |
<> | 154:37f96f9d4de2 | 68 | |
<> | 154:37f96f9d4de2 | 69 | delta = timestamp - lp_ticker_read(); |
<> | 154:37f96f9d4de2 | 70 | rtc_set_wake_up_timer(delta); |
<> | 154:37f96f9d4de2 | 71 | } |
<> | 154:37f96f9d4de2 | 72 | |
AnnaBridge | 174:b96e65c34a4d | 73 | void lp_ticker_fire_interrupt(void) |
AnnaBridge | 174:b96e65c34a4d | 74 | { |
AnnaBridge | 174:b96e65c34a4d | 75 | NVIC_SetPendingIRQ(RTC_WKUP_IRQn); |
AnnaBridge | 174:b96e65c34a4d | 76 | } |
AnnaBridge | 174:b96e65c34a4d | 77 | |
<> | 154:37f96f9d4de2 | 78 | void lp_ticker_disable_interrupt(void) |
<> | 154:37f96f9d4de2 | 79 | { |
<> | 154:37f96f9d4de2 | 80 | rtc_deactivate_wake_up_timer(); |
<> | 154:37f96f9d4de2 | 81 | } |
<> | 154:37f96f9d4de2 | 82 | |
<> | 154:37f96f9d4de2 | 83 | void lp_ticker_clear_interrupt(void) |
<> | 154:37f96f9d4de2 | 84 | { |
<> | 154:37f96f9d4de2 | 85 | |
<> | 154:37f96f9d4de2 | 86 | } |
<> | 154:37f96f9d4de2 | 87 | |
<> | 154:37f96f9d4de2 | 88 | #endif |