From 3ddbb4213a7a2de853c3c4528bb7c00accce685d Mon Sep 17 00:00:00 2001 From: Tomas Cerskus Date: Thu, 7 Dec 2017 17:32:41 +0000 Subject: [PATCH] [efr32] Allow calling otPlatAlarmMilliGetNow from an interrupt (#2398) Before this commit if otPlatAlarmMilliGetNow were called from an interrupt the timer state could be corrupted. --- examples/platforms/efr32/alarm.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/platforms/efr32/alarm.c b/examples/platforms/efr32/alarm.c index de4440681..b553e1700 100644 --- a/examples/platforms/efr32/alarm.c +++ b/examples/platforms/efr32/alarm.c @@ -42,6 +42,7 @@ #include "utils/code_utils.h" +#include "em_core.h" #include "rail.h" static uint32_t sTimerHi = 0; @@ -57,6 +58,10 @@ void efr32AlarmInit(void) uint32_t otPlatAlarmMilliGetNow(void) { uint32_t timer_lo; + uint32_t timer_ms; + + CORE_DECLARE_IRQ_STATE; + CORE_ENTER_CRITICAL(); timer_lo = RAIL_GetTime(); @@ -67,7 +72,11 @@ uint32_t otPlatAlarmMilliGetNow(void) sTimerLo = timer_lo; - return (((uint64_t)sTimerHi << 32) | sTimerLo) / 1000; + timer_ms = (((uint64_t)sTimerHi << 32) | sTimerLo) / 1000; + + CORE_EXIT_CRITICAL(); + + return timer_ms; } void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt)