diff --git a/arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c b/arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c index 3c911fe4b5..e807939908 100644 --- a/arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c +++ b/arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "esp32_oneshot.h" @@ -60,6 +61,7 @@ struct esp32_oneshot_lowerhalf_s oneshot_callback_t callback; /* Upper half Interrupt callback */ void *arg; /* Argument passed to handler */ uint16_t resolution; + spinlock_t lock; /* Device specific lock */ }; /**************************************************************************** @@ -208,12 +210,12 @@ static int esp32_lh_start(struct oneshot_lowerhalf_s *lower, /* Save the callback information and start the timer */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); priv->callback = callback; priv->arg = arg; ret = esp32_oneshot_start(&priv->oneshot, esp32_oneshot_lh_handler, priv, ts); - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); if (ret < 0) { @@ -259,11 +261,11 @@ static int esp32_lh_cancel(struct oneshot_lowerhalf_s *lower, /* Cancel the timer */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); ret = esp32_oneshot_cancel(&priv->oneshot, ts); priv->callback = NULL; priv->arg = NULL; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); if (ret < 0) {