mbed-os
Fork of mbed-os by
targets/TARGET_NORDIC/TARGET_NRF5/common_rtc.h@0:f269e3021894, 2016-10-23 (annotated)
- Committer:
- elessair
- Date:
- Sun Oct 23 15:10:02 2016 +0000
- Revision:
- 0:f269e3021894
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | /* mbed Microcontroller Library |
elessair | 0:f269e3021894 | 2 | * Copyright (c) 2015 ARM Limited |
elessair | 0:f269e3021894 | 3 | * |
elessair | 0:f269e3021894 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
elessair | 0:f269e3021894 | 5 | * you may not use this file except in compliance with the License. |
elessair | 0:f269e3021894 | 6 | * You may obtain a copy of the License at |
elessair | 0:f269e3021894 | 7 | * |
elessair | 0:f269e3021894 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
elessair | 0:f269e3021894 | 9 | * |
elessair | 0:f269e3021894 | 10 | * Unless required by applicable law or agreed to in writing, software |
elessair | 0:f269e3021894 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
elessair | 0:f269e3021894 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
elessair | 0:f269e3021894 | 13 | * See the License for the specific language governing permissions and |
elessair | 0:f269e3021894 | 14 | * limitations under the License. |
elessair | 0:f269e3021894 | 15 | */ |
elessair | 0:f269e3021894 | 16 | |
elessair | 0:f269e3021894 | 17 | #ifndef COMMON_RTC_H |
elessair | 0:f269e3021894 | 18 | #define COMMON_RTC_H |
elessair | 0:f269e3021894 | 19 | |
elessair | 0:f269e3021894 | 20 | #include "nrf_rtc.h" |
elessair | 0:f269e3021894 | 21 | |
elessair | 0:f269e3021894 | 22 | #define RTC_COUNTER_BITS 24u |
elessair | 0:f269e3021894 | 23 | |
elessair | 0:f269e3021894 | 24 | // Instance 0 is reserved for SoftDevice. |
elessair | 0:f269e3021894 | 25 | // Instance 1 is used as a common one for us_ticker, lp_ticker and (in case |
elessair | 0:f269e3021894 | 26 | // of NRF51) as an alternative tick source for RTOS. |
elessair | 0:f269e3021894 | 27 | // ["us_ticker.c" uses hard coded addresses of the 'NRF_RTC1->EVENT_COMPARE[1]' |
elessair | 0:f269e3021894 | 28 | // register in inline assembly implementations of COMMON_RTC_IRQ_HANDLER, |
elessair | 0:f269e3021894 | 29 | // please remember to update those in case of doing changes here] |
elessair | 0:f269e3021894 | 30 | #define COMMON_RTC_INSTANCE NRF_RTC1 |
elessair | 0:f269e3021894 | 31 | #define COMMON_RTC_IRQ_HANDLER RTC1_IRQHandler |
elessair | 0:f269e3021894 | 32 | #define US_TICKER_CC_CHANNEL 0 |
elessair | 0:f269e3021894 | 33 | #define OS_TICK_CC_CHANNEL 1 |
elessair | 0:f269e3021894 | 34 | #define LP_TICKER_CC_CHANNEL 2 |
elessair | 0:f269e3021894 | 35 | |
elessair | 0:f269e3021894 | 36 | #define COMMON_RTC_EVENT_COMPARE(channel) \ |
elessair | 0:f269e3021894 | 37 | CONCAT_2(NRF_RTC_EVENT_COMPARE_, channel) |
elessair | 0:f269e3021894 | 38 | #define COMMON_RTC_INT_COMPARE_MASK(channel) \ |
elessair | 0:f269e3021894 | 39 | CONCAT_3(NRF_RTC_INT_COMPARE, channel, _MASK) |
elessair | 0:f269e3021894 | 40 | |
elessair | 0:f269e3021894 | 41 | #define US_TICKER_EVENT COMMON_RTC_EVENT_COMPARE(US_TICKER_CC_CHANNEL) |
elessair | 0:f269e3021894 | 42 | #define US_TICKER_INT_MASK COMMON_RTC_INT_COMPARE_MASK(US_TICKER_CC_CHANNEL) |
elessair | 0:f269e3021894 | 43 | #define OS_TICK_EVENT COMMON_RTC_EVENT_COMPARE(OS_TICK_CC_CHANNEL) |
elessair | 0:f269e3021894 | 44 | #define OS_TICK_INT_MASK COMMON_RTC_INT_COMPARE_MASK(OS_TICK_CC_CHANNEL) |
elessair | 0:f269e3021894 | 45 | #define LP_TICKER_EVENT COMMON_RTC_EVENT_COMPARE(LP_TICKER_CC_CHANNEL) |
elessair | 0:f269e3021894 | 46 | #define LP_TICKER_INT_MASK COMMON_RTC_INT_COMPARE_MASK(LP_TICKER_CC_CHANNEL) |
elessair | 0:f269e3021894 | 47 | |
elessair | 0:f269e3021894 | 48 | extern bool m_common_rtc_enabled; |
elessair | 0:f269e3021894 | 49 | extern uint32_t volatile m_common_rtc_overflows; |
elessair | 0:f269e3021894 | 50 | |
elessair | 0:f269e3021894 | 51 | void common_rtc_init(void); |
elessair | 0:f269e3021894 | 52 | uint32_t common_rtc_32bit_ticks_get(void); |
elessair | 0:f269e3021894 | 53 | uint64_t common_rtc_64bit_us_get(void); |
elessair | 0:f269e3021894 | 54 | void common_rtc_set_interrupt(uint32_t us_timestamp, uint32_t cc_channel, |
elessair | 0:f269e3021894 | 55 | uint32_t int_mask); |
elessair | 0:f269e3021894 | 56 | |
elessair | 0:f269e3021894 | 57 | #endif // COMMON_RTC_H |