xtensa/esp32_wdt_lowerhalf.c: Use device specific locks.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
This commit is contained in:
parent
19a096cdfe
commit
04bd27400a
@ -33,9 +33,12 @@
|
|||||||
|
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/timers/watchdog.h>
|
#include <nuttx/timers/watchdog.h>
|
||||||
|
#include <nuttx/spinlock.h>
|
||||||
|
|
||||||
#include "xtensa.h"
|
#include "xtensa.h"
|
||||||
|
|
||||||
#include "hardware/esp32_soc.h"
|
#include "hardware/esp32_soc.h"
|
||||||
|
|
||||||
#include "esp32_wdt.h"
|
#include "esp32_wdt.h"
|
||||||
#include "esp32_wdt_lowerhalf.h"
|
#include "esp32_wdt_lowerhalf.h"
|
||||||
|
|
||||||
@ -80,6 +83,7 @@ struct esp32_wdt_lowerhalf_s
|
|||||||
bool started; /* True: Timer has been started */
|
bool started; /* True: Timer has been started */
|
||||||
xcpt_t handler; /* User Handler */
|
xcpt_t handler; /* User Handler */
|
||||||
void *upper; /* Pointer to watchdog_upperhalf_s */
|
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 */
|
/* 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);
|
ESP32_WDT_SETISR(priv->wdt, esp32_wdt_handler, priv);
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&priv->lock, flags);
|
||||||
|
|
||||||
ESP32_WDT_ENABLEINT(priv->wdt);
|
ESP32_WDT_ENABLEINT(priv->wdt);
|
||||||
}
|
}
|
||||||
flags = enter_critical_section();
|
|
||||||
|
flags = spin_lock_irqsave(&priv->lock);
|
||||||
priv->lastreset = clock_systime_ticks();
|
priv->lastreset = clock_systime_ticks();
|
||||||
ESP32_WDT_START(priv->wdt);
|
ESP32_WDT_START(priv->wdt);
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&priv->lock, flags);
|
||||||
|
|
||||||
/* Lock it again */
|
/* Lock it again */
|
||||||
|
|
||||||
@ -267,9 +273,10 @@ static int esp32_wdt_stop(struct watchdog_lowerhalf_s *lower)
|
|||||||
if (priv->handler != NULL)
|
if (priv->handler != NULL)
|
||||||
{
|
{
|
||||||
ESP32_WDT_DISABLEINT(priv->wdt);
|
ESP32_WDT_DISABLEINT(priv->wdt);
|
||||||
flags = enter_critical_section();
|
|
||||||
|
flags = spin_lock_irqsave(&priv->lock);
|
||||||
ESP32_WDT_SETISR(priv->wdt, NULL, NULL);
|
ESP32_WDT_SETISR(priv->wdt, NULL, NULL);
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&priv->lock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lock it again */
|
/* 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 */
|
/* Feed the dog and updates the lastreset variable */
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = spin_lock_irqsave(&priv->lock);
|
||||||
priv->lastreset = clock_systime_ticks();
|
priv->lastreset = clock_systime_ticks();
|
||||||
ESP32_WDT_FEED(priv->wdt);
|
ESP32_WDT_FEED(priv->wdt);
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&priv->lock, flags);
|
||||||
|
|
||||||
/* Lock */
|
/* Lock */
|
||||||
|
|
||||||
@ -514,7 +521,7 @@ static xcpt_t esp32_wdt_capture(struct watchdog_lowerhalf_s *lower,
|
|||||||
|
|
||||||
ESP32_WDT_UNLOCK(priv->wdt);
|
ESP32_WDT_UNLOCK(priv->wdt);
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = spin_lock_irqsave(&priv->lock);
|
||||||
|
|
||||||
/* Save the new user handler */
|
/* 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);
|
ESP32_WDT_LOCK(priv->wdt);
|
||||||
return oldhandler;
|
return oldhandler;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user