43
43
#include "lp_ticker_api.h"
44
44
#include "mbed_critical.h"
45
45
46
+ #if defined(NRF52_ERRATA_20 )
46
47
#if defined(SOFTDEVICE_PRESENT )
47
48
#include "nrf_sdh.h"
48
49
#define NRF_HAL_US_TICKER_SD_IS_ENABLED () nrf_sdh_is_enabled()
49
50
#else
50
51
#define NRF_HAL_US_TICKER_SD_IS_ENABLED () 0
51
52
#endif
53
+ #endif
52
54
53
55
//------------------------------------------------------------------------------
54
56
// Common stuff used also by lp_ticker and rtc_api (see "common_rtc.h").
58
60
bool m_common_rtc_enabled = false;
59
61
uint32_t volatile m_common_rtc_overflows = 0 ;
60
62
63
+ // lp/us ticker fire interrupt flag for IRQ handler
64
+ volatile uint8_t m_common_sw_irq_flag = 0 ;
65
+
61
66
__STATIC_INLINE void rtc_ovf_event_check (void )
62
67
{
63
68
if (nrf_rtc_event_pending (COMMON_RTC_INSTANCE , NRF_RTC_EVENT_OVERFLOW )) {
@@ -77,11 +82,15 @@ void COMMON_RTC_IRQ_HANDLER(void)
77
82
78
83
rtc_ovf_event_check ();
79
84
80
- if (nrf_rtc_event_pending (COMMON_RTC_INSTANCE , US_TICKER_EVENT )) {
85
+ if (( m_common_sw_irq_flag & US_TICKER_SW_IRQ_MASK ) || nrf_rtc_event_pending (COMMON_RTC_INSTANCE , US_TICKER_EVENT )) {
81
86
us_ticker_irq_handler ();
82
87
}
83
88
84
89
#if DEVICE_LOWPOWERTIMER
90
+ if (m_common_sw_irq_flag & LP_TICKER_SW_IRQ_MASK ) {
91
+ m_common_sw_irq_flag &= ~LP_TICKER_SW_IRQ_MASK ;
92
+ lp_ticker_irq_handler ();
93
+ }
85
94
if (nrf_rtc_event_pending (COMMON_RTC_INSTANCE , LP_TICKER_EVENT )) {
86
95
87
96
lp_ticker_irq_handler ();
@@ -117,7 +126,7 @@ void common_rtc_init(void)
117
126
errata_20 ();
118
127
119
128
NVIC_SetVector (RTC1_IRQn , (uint32_t )RTC1_IRQHandler );
120
-
129
+
121
130
// RTC is driven by the low frequency (32.768 kHz) clock, a proper request
122
131
// must be made to have it running.
123
132
// Currently this clock is started in 'SystemInit' (see "system_nrf51.c"
@@ -276,10 +285,10 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
276
285
277
286
void us_ticker_fire_interrupt (void )
278
287
{
279
- uint32_t closest_safe_compare = common_rtc_32bit_ticks_get () + 2 ;
280
-
281
- nrf_rtc_cc_set ( COMMON_RTC_INSTANCE , US_TICKER_CC_CHANNEL , RTC_WRAP ( closest_safe_compare ) );
282
- nrf_rtc_event_enable ( COMMON_RTC_INSTANCE , US_TICKER_INT_MASK );
288
+ core_util_critical_section_enter () ;
289
+ m_common_sw_irq_flag |= US_TICKER_SW_IRQ_MASK ;
290
+ NVIC_SetPendingIRQ ( RTC1_IRQn );
291
+ core_util_critical_section_exit ( );
283
292
}
284
293
285
294
void us_ticker_disable_interrupt (void )
@@ -289,6 +298,7 @@ void us_ticker_disable_interrupt(void)
289
298
290
299
void us_ticker_clear_interrupt (void )
291
300
{
301
+ m_common_sw_irq_flag &= ~US_TICKER_SW_IRQ_MASK ;
292
302
nrf_rtc_event_clear (COMMON_RTC_INSTANCE , US_TICKER_EVENT );
293
303
}
294
304
0 commit comments