Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed-os/targets/TARGET_STM/lp_ticker.c@0:fb8047b156bb, 2020-01-15 (annotated)
- Committer:
- rahul_dahiya
- Date:
- Wed Jan 15 15:57:15 2020 +0530
- Revision:
- 0:fb8047b156bb
STM32F7 LWIP
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rahul_dahiya |
0:fb8047b156bb | 1 | /* mbed Microcontroller Library |
rahul_dahiya |
0:fb8047b156bb | 2 | ******************************************************************************* |
rahul_dahiya |
0:fb8047b156bb | 3 | * Copyright (c) 2016, STMicroelectronics |
rahul_dahiya |
0:fb8047b156bb | 4 | * All rights reserved. |
rahul_dahiya |
0:fb8047b156bb | 5 | * |
rahul_dahiya |
0:fb8047b156bb | 6 | * Redistribution and use in source and binary forms, with or without |
rahul_dahiya |
0:fb8047b156bb | 7 | * modification, are permitted provided that the following conditions are met: |
rahul_dahiya |
0:fb8047b156bb | 8 | * |
rahul_dahiya |
0:fb8047b156bb | 9 | * 1. Redistributions of source code must retain the above copyright notice, |
rahul_dahiya |
0:fb8047b156bb | 10 | * this list of conditions and the following disclaimer. |
rahul_dahiya |
0:fb8047b156bb | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
rahul_dahiya |
0:fb8047b156bb | 12 | * this list of conditions and the following disclaimer in the documentation |
rahul_dahiya |
0:fb8047b156bb | 13 | * and/or other materials provided with the distribution. |
rahul_dahiya |
0:fb8047b156bb | 14 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
rahul_dahiya |
0:fb8047b156bb | 15 | * may be used to endorse or promote products derived from this software |
rahul_dahiya |
0:fb8047b156bb | 16 | * without specific prior written permission. |
rahul_dahiya |
0:fb8047b156bb | 17 | * |
rahul_dahiya |
0:fb8047b156bb | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
rahul_dahiya |
0:fb8047b156bb | 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
rahul_dahiya |
0:fb8047b156bb | 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
rahul_dahiya |
0:fb8047b156bb | 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
rahul_dahiya |
0:fb8047b156bb | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
rahul_dahiya |
0:fb8047b156bb | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
rahul_dahiya |
0:fb8047b156bb | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
rahul_dahiya |
0:fb8047b156bb | 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
rahul_dahiya |
0:fb8047b156bb | 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
rahul_dahiya |
0:fb8047b156bb | 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
rahul_dahiya |
0:fb8047b156bb | 28 | ******************************************************************************* |
rahul_dahiya |
0:fb8047b156bb | 29 | */ |
rahul_dahiya |
0:fb8047b156bb | 30 | #include "device.h" |
rahul_dahiya |
0:fb8047b156bb | 31 | |
rahul_dahiya |
0:fb8047b156bb | 32 | #if DEVICE_LOWPOWERTIMER |
rahul_dahiya |
0:fb8047b156bb | 33 | |
rahul_dahiya |
0:fb8047b156bb | 34 | #include "ticker_api.h" |
rahul_dahiya |
0:fb8047b156bb | 35 | #include "lp_ticker_api.h" |
rahul_dahiya |
0:fb8047b156bb | 36 | #include "rtc_api.h" |
rahul_dahiya |
0:fb8047b156bb | 37 | #include "rtc_api_hal.h" |
rahul_dahiya |
0:fb8047b156bb | 38 | |
rahul_dahiya |
0:fb8047b156bb | 39 | static uint8_t lp_ticker_inited = 0; |
rahul_dahiya |
0:fb8047b156bb | 40 | |
rahul_dahiya |
0:fb8047b156bb | 41 | void lp_ticker_init(void) |
rahul_dahiya |
0:fb8047b156bb | 42 | { |
rahul_dahiya |
0:fb8047b156bb | 43 | if (lp_ticker_inited) return; |
rahul_dahiya |
0:fb8047b156bb | 44 | lp_ticker_inited = 1; |
rahul_dahiya |
0:fb8047b156bb | 45 | |
rahul_dahiya |
0:fb8047b156bb | 46 | rtc_init(); |
rahul_dahiya |
0:fb8047b156bb | 47 | rtc_set_irq_handler((uint32_t) lp_ticker_irq_handler); |
rahul_dahiya |
0:fb8047b156bb | 48 | } |
rahul_dahiya |
0:fb8047b156bb | 49 | |
rahul_dahiya |
0:fb8047b156bb | 50 | uint32_t lp_ticker_read(void) |
rahul_dahiya |
0:fb8047b156bb | 51 | { |
rahul_dahiya |
0:fb8047b156bb | 52 | uint32_t usecs = 0; |
rahul_dahiya |
0:fb8047b156bb | 53 | time_t time = 0; |
rahul_dahiya |
0:fb8047b156bb | 54 | |
rahul_dahiya |
0:fb8047b156bb | 55 | lp_ticker_init(); |
rahul_dahiya |
0:fb8047b156bb | 56 | |
rahul_dahiya |
0:fb8047b156bb | 57 | do { |
rahul_dahiya |
0:fb8047b156bb | 58 | time = rtc_read(); |
rahul_dahiya |
0:fb8047b156bb | 59 | usecs = rtc_read_subseconds(); |
rahul_dahiya |
0:fb8047b156bb | 60 | } while (time != rtc_read()); |
rahul_dahiya |
0:fb8047b156bb | 61 | |
rahul_dahiya |
0:fb8047b156bb | 62 | return (time * 1000000) + usecs; |
rahul_dahiya |
0:fb8047b156bb | 63 | } |
rahul_dahiya |
0:fb8047b156bb | 64 | |
rahul_dahiya |
0:fb8047b156bb | 65 | void lp_ticker_set_interrupt(timestamp_t timestamp) |
rahul_dahiya |
0:fb8047b156bb | 66 | { |
rahul_dahiya |
0:fb8047b156bb | 67 | uint32_t delta; |
rahul_dahiya |
0:fb8047b156bb | 68 | |
rahul_dahiya |
0:fb8047b156bb | 69 | delta = timestamp - lp_ticker_read(); |
rahul_dahiya |
0:fb8047b156bb | 70 | rtc_set_wake_up_timer(delta); |
rahul_dahiya |
0:fb8047b156bb | 71 | } |
rahul_dahiya |
0:fb8047b156bb | 72 | |
rahul_dahiya |
0:fb8047b156bb | 73 | void lp_ticker_fire_interrupt(void) |
rahul_dahiya |
0:fb8047b156bb | 74 | { |
rahul_dahiya |
0:fb8047b156bb | 75 | NVIC_SetPendingIRQ(RTC_WKUP_IRQn); |
rahul_dahiya |
0:fb8047b156bb | 76 | } |
rahul_dahiya |
0:fb8047b156bb | 77 | |
rahul_dahiya |
0:fb8047b156bb | 78 | void lp_ticker_disable_interrupt(void) |
rahul_dahiya |
0:fb8047b156bb | 79 | { |
rahul_dahiya |
0:fb8047b156bb | 80 | rtc_deactivate_wake_up_timer(); |
rahul_dahiya |
0:fb8047b156bb | 81 | } |
rahul_dahiya |
0:fb8047b156bb | 82 | |
rahul_dahiya |
0:fb8047b156bb | 83 | void lp_ticker_clear_interrupt(void) |
rahul_dahiya |
0:fb8047b156bb | 84 | { |
rahul_dahiya |
0:fb8047b156bb | 85 | |
rahul_dahiya |
0:fb8047b156bb | 86 | } |
rahul_dahiya |
0:fb8047b156bb | 87 | |
rahul_dahiya |
0:fb8047b156bb | 88 | #endif |