Mouse code for the MacroRat
mbed-dev/targets/TARGET_ONSEMI/TARGET_NCS36510/ncs36510_lp_ticker_api.c@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 18:6a4db94011d3
Final code for internal battlebot competition.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /** |
sahilmgandhi | 18:6a4db94011d3 | 2 | ******************************************************************************* |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @file lpticker.c |
sahilmgandhi | 18:6a4db94011d3 | 4 | * @brief Implementation of a Low Power Ticker functionality based on RTC |
sahilmgandhi | 18:6a4db94011d3 | 5 | * @internal |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @author ON Semiconductor |
sahilmgandhi | 18:6a4db94011d3 | 7 | * $Rev: $ |
sahilmgandhi | 18:6a4db94011d3 | 8 | * $Date: $ |
sahilmgandhi | 18:6a4db94011d3 | 9 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 10 | * Copyright 2016 Semiconductor Components Industries LLC (d/b/a ON Semiconductor). |
sahilmgandhi | 18:6a4db94011d3 | 11 | * All rights reserved. This software and/or documentation is licensed by ON Semiconductor |
sahilmgandhi | 18:6a4db94011d3 | 12 | * under limited terms and conditions. The terms and conditions pertaining to the software |
sahilmgandhi | 18:6a4db94011d3 | 13 | * and/or documentation are available at http://www.onsemi.com/site/pdf/ONSEMI_T&C.pdf |
sahilmgandhi | 18:6a4db94011d3 | 14 | * (ON Semiconductor Standard Terms and Conditions of Sale, Section 8 Software) and |
sahilmgandhi | 18:6a4db94011d3 | 15 | * if applicable the software license agreement. Do not use this software and/or |
sahilmgandhi | 18:6a4db94011d3 | 16 | * documentation unless you have carefully read and you agree to the limited terms and |
sahilmgandhi | 18:6a4db94011d3 | 17 | * conditions. By using this software and/or documentation, you agree to the limited |
sahilmgandhi | 18:6a4db94011d3 | 18 | * terms and conditions. |
sahilmgandhi | 18:6a4db94011d3 | 19 | * |
sahilmgandhi | 18:6a4db94011d3 | 20 | * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED |
sahilmgandhi | 18:6a4db94011d3 | 21 | * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF |
sahilmgandhi | 18:6a4db94011d3 | 22 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. |
sahilmgandhi | 18:6a4db94011d3 | 23 | * ON SEMICONDUCTOR SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, |
sahilmgandhi | 18:6a4db94011d3 | 24 | * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
sahilmgandhi | 18:6a4db94011d3 | 25 | * @endinternal |
sahilmgandhi | 18:6a4db94011d3 | 26 | * |
sahilmgandhi | 18:6a4db94011d3 | 27 | * @ingroup lpticker |
sahilmgandhi | 18:6a4db94011d3 | 28 | * |
sahilmgandhi | 18:6a4db94011d3 | 29 | * @details |
sahilmgandhi | 18:6a4db94011d3 | 30 | * This is Low Power ticker derived from RTC |
sahilmgandhi | 18:6a4db94011d3 | 31 | * |
sahilmgandhi | 18:6a4db94011d3 | 32 | */ |
sahilmgandhi | 18:6a4db94011d3 | 33 | |
sahilmgandhi | 18:6a4db94011d3 | 34 | #include "device.h" |
sahilmgandhi | 18:6a4db94011d3 | 35 | #if DEVICE_LOWPOWERTIMER |
sahilmgandhi | 18:6a4db94011d3 | 36 | |
sahilmgandhi | 18:6a4db94011d3 | 37 | #include "cmsis_nvic.h" |
sahilmgandhi | 18:6a4db94011d3 | 38 | #include "lp_ticker_api.h" |
sahilmgandhi | 18:6a4db94011d3 | 39 | #include "rtc.h" |
sahilmgandhi | 18:6a4db94011d3 | 40 | #include "rtc_map.h" |
sahilmgandhi | 18:6a4db94011d3 | 41 | |
sahilmgandhi | 18:6a4db94011d3 | 42 | /* Initialize the RTC for low power ticker */ |
sahilmgandhi | 18:6a4db94011d3 | 43 | void lp_ticker_init() |
sahilmgandhi | 18:6a4db94011d3 | 44 | { |
sahilmgandhi | 18:6a4db94011d3 | 45 | fRtcInit(); |
sahilmgandhi | 18:6a4db94011d3 | 46 | } |
sahilmgandhi | 18:6a4db94011d3 | 47 | |
sahilmgandhi | 18:6a4db94011d3 | 48 | /* Return the current RTC counter value in us */ |
sahilmgandhi | 18:6a4db94011d3 | 49 | uint32_t lp_ticker_read() |
sahilmgandhi | 18:6a4db94011d3 | 50 | { |
sahilmgandhi | 18:6a4db94011d3 | 51 | return (uint32_t)(fRtcRead() & 0xFFFFFFFF); /* TODO Truncating 64 bit value to 32 bit */ |
sahilmgandhi | 18:6a4db94011d3 | 52 | } |
sahilmgandhi | 18:6a4db94011d3 | 53 | |
sahilmgandhi | 18:6a4db94011d3 | 54 | /* Set interrupt for specified time */ |
sahilmgandhi | 18:6a4db94011d3 | 55 | void lp_ticker_set_interrupt(timestamp_t timestamp) |
sahilmgandhi | 18:6a4db94011d3 | 56 | { |
sahilmgandhi | 18:6a4db94011d3 | 57 | /* The RTC Match register needs to be Set to the RTC alarm value */ |
sahilmgandhi | 18:6a4db94011d3 | 58 | fRtcSetInterrupt(timestamp); |
sahilmgandhi | 18:6a4db94011d3 | 59 | } |
sahilmgandhi | 18:6a4db94011d3 | 60 | |
sahilmgandhi | 18:6a4db94011d3 | 61 | /** Disable low power ticker interrupt |
sahilmgandhi | 18:6a4db94011d3 | 62 | * |
sahilmgandhi | 18:6a4db94011d3 | 63 | */ |
sahilmgandhi | 18:6a4db94011d3 | 64 | void lp_ticker_disable_interrupt(void) |
sahilmgandhi | 18:6a4db94011d3 | 65 | { |
sahilmgandhi | 18:6a4db94011d3 | 66 | fRtcDisableInterrupt(); |
sahilmgandhi | 18:6a4db94011d3 | 67 | } |
sahilmgandhi | 18:6a4db94011d3 | 68 | |
sahilmgandhi | 18:6a4db94011d3 | 69 | /** Clear the low power ticker interrupt |
sahilmgandhi | 18:6a4db94011d3 | 70 | * |
sahilmgandhi | 18:6a4db94011d3 | 71 | */ |
sahilmgandhi | 18:6a4db94011d3 | 72 | void lp_ticker_clear_interrupt(void) |
sahilmgandhi | 18:6a4db94011d3 | 73 | { |
sahilmgandhi | 18:6a4db94011d3 | 74 | fRtcClearInterrupt(); |
sahilmgandhi | 18:6a4db94011d3 | 75 | } |
sahilmgandhi | 18:6a4db94011d3 | 76 | |
sahilmgandhi | 18:6a4db94011d3 | 77 | #endif /* DEVICE_LOWPOWERTIMER */ |