20
20
#include "PeripheralNames.h"
21
21
#include "nrf_delay.h"
22
22
#include "mbed_toolchain.h"
23
+ #include "mbed_critical.h"
23
24
24
25
/*
25
26
* Note: The micro-second timer API on the nRF51 platform is implemented using
52
53
#define RTC_UNITS_TO_MICROSECONDS (RTC_UNITS ) (((RTC_UNITS) * (uint64_t)1000000) / RTC_CLOCK_FREQ)
53
54
#define MICROSECONDS_TO_RTC_UNITS (MICROS ) ((((uint64_t)(MICROS) * RTC_CLOCK_FREQ) + 999999) / 1000000)
54
55
56
+ #define US_TICKER_SW_IRQ_MASK 0x1
57
+
55
58
static bool us_ticker_inited = false;
56
59
static volatile uint32_t overflowCount ; /**< The number of times the 24-bit RTC counter has overflowed. */
57
60
static volatile bool us_ticker_callbackPending = false;
@@ -62,6 +65,9 @@ static bool os_tick_started = false; /**< flag indicating i
62
65
*/
63
66
static uint32_t previous_tick_cc_value = 0 ;
64
67
68
+ // us ticker fire interrupt flag for IRQ handler
69
+ volatile uint8_t m_common_sw_irq_flag = 0 ;
70
+
65
71
/*
66
72
RTX provide the following definitions which are used by the tick code:
67
73
* os_trv: The number (minus 1) of clock cycle between two tick.
@@ -181,6 +187,11 @@ static inline uint32_t rtc1_getCounter(void)
181
187
*/
182
188
void us_ticker_handler (void )
183
189
{
190
+ if (m_common_sw_irq_flag & US_TICKER_SW_IRQ_MASK ) {
191
+ m_common_sw_irq_flag &= ~US_TICKER_SW_IRQ_MASK ;
192
+ us_ticker_irq_handler ();
193
+ }
194
+
184
195
if (NRF_RTC1 -> EVENTS_OVRFLW ) {
185
196
overflowCount ++ ;
186
197
NRF_RTC1 -> EVENTS_OVRFLW = 0 ;
@@ -287,7 +298,10 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
287
298
288
299
void us_ticker_fire_interrupt (void )
289
300
{
301
+ core_util_critical_section_enter ();
302
+ m_common_sw_irq_flag |= US_TICKER_SW_IRQ_MASK ;
290
303
NVIC_SetPendingIRQ (RTC1_IRQn );
304
+ core_util_critical_section_exit ();
291
305
}
292
306
293
307
void us_ticker_disable_interrupt (void )
0 commit comments