17
17
18
18
#include "common_rtc.h"
19
19
#include "toolchain.h"
20
- #include "nrf_delay .h"
20
+ #include "nrf_drv_common .h"
21
21
22
22
23
23
#define MAX_RTC_COUNTER_VAL ((1uL << RTC_COUNTER_BITS) - 1)
@@ -44,7 +44,7 @@ MBED_WEAK void OS_Tick_Handler() { }
44
44
45
45
#if defined (__CC_ARM ) /* ARMCC Compiler */
46
46
47
- __asm void RTC1_IRQHandler (void )
47
+ __asm void COMMON_RTC_IRQ_HANDLER (void )
48
48
{
49
49
IMPORT OS_Tick_Handler
50
50
IMPORT common_rtc_irq_handler
@@ -59,7 +59,7 @@ __asm void RTC1_IRQHandler(void)
59
59
* would never been dequeued.
60
60
*
61
61
* \code
62
- * void RTC1_IRQHandler (void) {
62
+ * void COMMON_RTC_IRQ_HANDLER (void) {
63
63
if(NRF_RTC1->EVENTS_COMPARE[1]) {
64
64
// never return...
65
65
OS_Tick_Handler();
@@ -83,7 +83,7 @@ US_TICKER_HANDLER
83
83
84
84
#elif defined (__GNUC__ ) /* GNU Compiler */
85
85
86
- __attribute__((naked )) void RTC1_IRQHandler (void )
86
+ __attribute__((naked )) void COMMON_RTC_IRQ_HANDLER (void )
87
87
{
88
88
/**
89
89
* Chanel 1 of RTC1 is used by RTX as a systick.
@@ -95,7 +95,7 @@ __attribute__((naked)) void RTC1_IRQHandler(void)
95
95
* would never been dequeued.
96
96
*
97
97
* \code
98
- * void RTC1_IRQHandler (void) {
98
+ * void COMMON_RTC_IRQ_HANDLER (void) {
99
99
if(NRF_RTC1->EVENTS_COMPARE[1]) {
100
100
// never return...
101
101
OS_Tick_Handler();
@@ -122,7 +122,7 @@ __attribute__((naked)) void RTC1_IRQHandler(void)
122
122
#else
123
123
124
124
#error Compiler not supported.
125
- #error Provide a definition of RTC1_IRQHandler .
125
+ #error Provide a definition of COMMON_RTC_IRQ_HANDLER .
126
126
127
127
/*
128
128
* Chanel 1 of RTC1 is used by RTX as a systick.
@@ -134,7 +134,7 @@ __attribute__((naked)) void RTC1_IRQHandler(void)
134
134
* will never been dequeued. After a certain time a stack overflow will happen.
135
135
*
136
136
* \code
137
- * void RTC1_IRQHandler (void) {
137
+ * void COMMON_RTC_IRQ_HANDLER (void) {
138
138
if(NRF_RTC1->EVENTS_COMPARE[1]) {
139
139
// never return...
140
140
OS_Tick_Handler();
@@ -188,8 +188,8 @@ static uint32_t get_next_tick_cc_delta() {
188
188
}
189
189
190
190
static inline void clear_tick_interrupt () {
191
- NRF_RTC1 -> EVENTS_COMPARE [ 1 ] = 0 ;
192
- NRF_RTC1 -> EVTENCLR = ( 1 << 17 );
191
+ nrf_rtc_event_clear ( COMMON_RTC_INSTANCE , OS_TICK_EVENT ) ;
192
+ nrf_rtc_event_disable ( COMMON_RTC_INSTANCE , OS_TICK_INT_MASK );
193
193
}
194
194
195
195
/**
@@ -224,7 +224,7 @@ static inline bool is_in_wrapped_range(uint32_t begin, uint32_t end, uint32_t va
224
224
* Register the next tick.
225
225
*/
226
226
static void register_next_tick () {
227
- previous_tick_cc_value = NRF_RTC1 -> CC [ 1 ] ;
227
+ previous_tick_cc_value = nrf_rtc_cc_get ( COMMON_RTC_INSTANCE , OS_TICK_CC_CHANNEL ) ;
228
228
uint32_t delta = get_next_tick_cc_delta ();
229
229
uint32_t new_compare_value = (previous_tick_cc_value + delta ) & MAX_RTC_COUNTER_VAL ;
230
230
@@ -236,16 +236,16 @@ static void register_next_tick() {
236
236
// This code is very short 20-38 cycles in the worst case, it shouldn't
237
237
// disturb softdevice.
238
238
__disable_irq ();
239
- uint32_t current_counter = NRF_RTC1 -> COUNTER ;
239
+ uint32_t current_counter = nrf_rtc_counter_get ( COMMON_RTC_INSTANCE ) ;
240
240
241
241
// If an overflow occur, set the next tick in COUNTER + delta clock cycles
242
242
if (is_in_wrapped_range (previous_tick_cc_value , new_compare_value , current_counter ) == false) {
243
243
new_compare_value = current_counter + delta ;
244
244
}
245
- NRF_RTC1 -> CC [ 1 ] = new_compare_value ;
246
-
247
- // set the interrupt of CC channel 1 and reenable IRQs
248
- NRF_RTC1 -> INTENSET = RTC_INTENSET_COMPARE1_Msk ;
245
+ nrf_rtc_cc_set ( COMMON_RTC_INSTANCE , OS_TICK_CC_CHANNEL , new_compare_value ) ;
246
+ // Enable generation of the compare event for the value set above (this
247
+ // event will trigger the interrupt).
248
+ nrf_rtc_event_enable ( COMMON_RTC_INSTANCE , OS_TICK_INT_MASK ) ;
249
249
__enable_irq ();
250
250
}
251
251
@@ -259,11 +259,10 @@ int os_tick_init (void)
259
259
{
260
260
common_rtc_init ();
261
261
262
- NRF_RTC1 -> CC [1 ] = 0 ;
263
- clear_tick_interrupt ();
262
+ nrf_rtc_cc_set (COMMON_RTC_INSTANCE , OS_TICK_CC_CHANNEL , 0 );
264
263
register_next_tick ();
265
264
266
- return RTC1_IRQn ;
265
+ return nrf_drv_get_IRQn ( COMMON_RTC_INSTANCE ) ;
267
266
}
268
267
269
268
/**
@@ -283,8 +282,8 @@ void os_tick_irqack(void)
283
282
* @return 1 if the timer has overflowed and 0 otherwise.
284
283
*/
285
284
uint32_t os_tick_ovf (void ) {
286
- uint32_t current_counter = NRF_RTC1 -> COUNTER ;
287
- uint32_t next_tick_cc_value = NRF_RTC1 -> CC [ 1 ] ;
285
+ uint32_t current_counter = nrf_rtc_counter_get ( COMMON_RTC_INSTANCE ) ;
286
+ uint32_t next_tick_cc_value = nrf_rtc_cc_get ( COMMON_RTC_INSTANCE , OS_TICK_CC_CHANNEL ) ;
288
287
289
288
return is_in_wrapped_range (previous_tick_cc_value , next_tick_cc_value , current_counter ) ? 0 : 1 ;
290
289
}
@@ -299,8 +298,8 @@ uint32_t os_tick_ovf(void) {
299
298
* @return the value of the alternative hardware timer.
300
299
*/
301
300
uint32_t os_tick_val (void ) {
302
- uint32_t current_counter = NRF_RTC1 -> COUNTER ;
303
- uint32_t next_tick_cc_value = NRF_RTC1 -> CC [ 1 ] ;
301
+ uint32_t current_counter = nrf_rtc_counter_get ( COMMON_RTC_INSTANCE ) ;
302
+ uint32_t next_tick_cc_value = nrf_rtc_cc_get ( COMMON_RTC_INSTANCE , OS_TICK_CC_CHANNEL ) ;
304
303
305
304
// do not use os_tick_ovf because its counter value can be different
306
305
if (is_in_wrapped_range (previous_tick_cc_value , next_tick_cc_value , current_counter )) {
0 commit comments