This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 19a096cdfe58cdcb6aaac8c0a012f6cb8fe189a5 Author: Abdelatif Guettouche <[email protected]> AuthorDate: Mon Sep 27 14:02:32 2021 +0200 arch/xtensa/esp32_tim_lowerhalf.c: Use device specific locks. Signed-off-by: Abdelatif Guettouche <[email protected]> --- arch/xtensa/src/esp32/esp32_tim_lowerhalf.c | 38 +++++++++++++++++------------ 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/arch/xtensa/src/esp32/esp32_tim_lowerhalf.c b/arch/xtensa/src/esp32/esp32_tim_lowerhalf.c index 30e9c2c..0506b33 100644 --- a/arch/xtensa/src/esp32/esp32_tim_lowerhalf.c +++ b/arch/xtensa/src/esp32/esp32_tim_lowerhalf.c @@ -23,21 +23,24 @@ ****************************************************************************/ #include <nuttx/config.h> -#include <nuttx/arch.h> -#include <nuttx/timers/timer.h> -#include <sys/types.h> + #include <stdbool.h> #include <string.h> #include <assert.h> #include <errno.h> #include <debug.h> +#include <sys/types.h> + +#include <nuttx/arch.h> +#include <nuttx/timers/timer.h> +#include <nuttx/spinlock.h> #include "xtensa.h" #include "hardware/esp32_soc.h" -#include "esp32_tim.h" #include "esp32_clockconfig.h" +#include "esp32_tim.h" /**************************************************************************** * Pre-processor Definitions @@ -53,12 +56,13 @@ struct esp32_timer_lowerhalf_s { - const struct timer_ops_s *ops; /* Lower half operations */ - struct esp32_tim_dev_s *tim; /* esp32 timer driver */ - tccb_t callback; /* Current user interrupt callback */ - void *arg; /* Argument passed to upper half callback */ - bool started; /* True: Timer has been started */ - void *upper; /* Pointer to watchdog_upperhalf_s */ + const struct timer_ops_s *ops; /* Lower half operations */ + struct esp32_tim_dev_s *tim; /* esp32 timer driver */ + tccb_t callback; /* Current user interrupt callback */ + void *arg; /* Argument passed to upper half callback */ + bool started; /* True: Timer has been started */ + void *upper; /* Pointer to watchdog_upperhalf_s */ + spinlock_t lock; /* Device specific lock */ }; /**************************************************************************** @@ -247,9 +251,9 @@ static int esp32_timer_start(struct timer_lowerhalf_s *lower) if (priv->callback != NULL) { - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); ret = ESP32_TIM_SETISR(priv->tim, esp32_timer_handler, priv); - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); if (ret != OK) { goto errout; @@ -300,9 +304,11 @@ static int esp32_timer_stop(struct timer_lowerhalf_s *lower) } ESP32_TIM_DISABLEINT(priv->tim); - flags = enter_critical_section(); + + flags = spin_lock_irqsave(&priv->lock); ret = ESP32_TIM_SETISR(priv->tim, NULL, NULL); - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); + ESP32_TIM_STOP(priv->tim); priv->started = false; @@ -467,7 +473,7 @@ static void esp32_timer_setcallback(struct timer_lowerhalf_s *lower, priv->callback = callback; priv->arg = arg; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); /* There is a user callback and the timer has already been started */ @@ -482,7 +488,7 @@ static void esp32_timer_setcallback(struct timer_lowerhalf_s *lower, ret = ESP32_TIM_SETISR(priv->tim, NULL, NULL); } - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); assert(ret == OK); }
