xtensa/esp32_wdt_lowerhalf.c: Use device specific locks.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
This commit is contained in:
Abdelatif Guettouche 2021-09-27 14:04:53 +02:00 committed by Xiang Xiao
parent 19a096cdfe
commit 04bd27400a

View File

@ -33,9 +33,12 @@
#include <nuttx/arch.h>
#include <nuttx/timers/watchdog.h>
#include <nuttx/spinlock.h>
#include "xtensa.h"
#include "hardware/esp32_soc.h"
#include "esp32_wdt.h"
#include "esp32_wdt_lowerhalf.h"
@ -72,14 +75,15 @@
struct esp32_wdt_lowerhalf_s
{
const struct watchdog_ops_s *ops; /* Lower half operations */
struct esp32_wdt_dev_s *wdt; /* esp32 watchdog driver */
uint32_t timeout; /* The current timeout */
enum wdt_peripherals peripheral; /* Indicates if it is from RTC or Timer Module */
uint32_t lastreset; /* The last reset time */
bool started; /* True: Timer has been started */
xcpt_t handler; /* User Handler */
void *upper; /* Pointer to watchdog_upperhalf_s */
const struct watchdog_ops_s *ops; /* Lower half operations */
struct esp32_wdt_dev_s *wdt; /* esp32 watchdog driver */
uint32_t timeout; /* The current timeout */
enum wdt_peripherals peripheral; /* Indicates if it is from RTC or Timer Module */
uint32_t lastreset; /* The last reset time */
bool started; /* True: Timer has been started */
xcpt_t handler; /* User Handler */
void *upper; /* Pointer to watchdog_upperhalf_s */
spinlock_t lock; /* Device specific lock */
};
/****************************************************************************
@ -217,15 +221,17 @@ static int esp32_wdt_start(struct watchdog_lowerhalf_s *lower)
/* Set the lower half handler and enable interrupt */
flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
ESP32_WDT_SETISR(priv->wdt, esp32_wdt_handler, priv);
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
ESP32_WDT_ENABLEINT(priv->wdt);
}
flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
priv->lastreset = clock_systime_ticks();
ESP32_WDT_START(priv->wdt);
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
/* Lock it again */
@ -267,9 +273,10 @@ static int esp32_wdt_stop(struct watchdog_lowerhalf_s *lower)
if (priv->handler != NULL)
{
ESP32_WDT_DISABLEINT(priv->wdt);
flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
ESP32_WDT_SETISR(priv->wdt, NULL, NULL);
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
}
/* Lock it again */
@ -310,10 +317,10 @@ static int esp32_wdt_keepalive(struct watchdog_lowerhalf_s *lower)
/* Feed the dog and updates the lastreset variable */
flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
priv->lastreset = clock_systime_ticks();
ESP32_WDT_FEED(priv->wdt);
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
/* Lock */
@ -514,7 +521,7 @@ static xcpt_t esp32_wdt_capture(struct watchdog_lowerhalf_s *lower,
ESP32_WDT_UNLOCK(priv->wdt);
flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
/* Save the new user handler */
@ -569,7 +576,7 @@ static xcpt_t esp32_wdt_capture(struct watchdog_lowerhalf_s *lower,
}
}
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
ESP32_WDT_LOCK(priv->wdt);
return oldhandler;
}