esp32: drivers: interrupt_controller: review WDT interrupt usage
Review WDT interrupt allocation usage. Signed-off-by: Glauber Maroto Ferreira <glauber.ferreira@espressif.com>
This commit is contained in:
parent
b6d61587c2
commit
0cf0830ead
4 changed files with 36 additions and 64 deletions
|
@ -3,25 +3,9 @@
|
|||
# Copyright (C) 2017 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
menuconfig WDT_ESP32
|
||||
config WDT_ESP32
|
||||
bool "ESP32 Watchdog (WDT) Driver"
|
||||
depends on SOC_ESP32
|
||||
default y
|
||||
help
|
||||
Enable WDT driver for ESP32.
|
||||
|
||||
config WDT0_ESP32_IRQ
|
||||
int "IRQ line for watchdog interrupt"
|
||||
depends on WDT_ESP32
|
||||
default 24
|
||||
help
|
||||
Set the IRQ line used by the WDT device. Very few lines can be
|
||||
chosen here, as it must be a level 4 interrupt.
|
||||
|
||||
config WDT1_ESP32_IRQ
|
||||
int "IRQ line for watchdog interrupt"
|
||||
depends on WDT_ESP32
|
||||
default 25
|
||||
help
|
||||
Set the IRQ line used by the WDT device. Very few lines can be
|
||||
chosen here, as it must be a level 4 interrupt.
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
#include <soc/rtc_cntl_reg.h>
|
||||
#include <soc/timer_group_reg.h>
|
||||
|
||||
#include <soc.h>
|
||||
#include <string.h>
|
||||
#include <drivers/watchdog.h>
|
||||
#include <drivers/interrupt_controller/intc_esp32.h>
|
||||
#include <device.h>
|
||||
|
||||
/* FIXME: This struct shall be removed from here, when esp32 timer driver got
|
||||
|
@ -44,17 +44,14 @@ struct wdt_esp32_data {
|
|||
uint32_t timeout;
|
||||
enum wdt_mode mode;
|
||||
wdt_callback_t callback;
|
||||
int irq_line;
|
||||
};
|
||||
|
||||
struct wdt_esp32_config {
|
||||
void (*connect_irq)(void);
|
||||
const struct wdt_esp32_regs_t *base;
|
||||
const struct timer_esp32_irq_regs_t irq_regs;
|
||||
|
||||
const struct {
|
||||
int source;
|
||||
int line;
|
||||
} irq;
|
||||
int irq_source;
|
||||
};
|
||||
|
||||
#define DEV_CFG(dev) \
|
||||
|
@ -106,7 +103,7 @@ static void adjust_timeout(const struct device *dev, uint32_t timeout)
|
|||
DEV_BASE(dev)->config3 = timeout;
|
||||
}
|
||||
|
||||
static void wdt_esp32_isr(const struct device *dev);
|
||||
static void wdt_esp32_isr(void *arg);
|
||||
|
||||
static int wdt_esp32_feed(const struct device *dev, int channel_id)
|
||||
{
|
||||
|
@ -123,10 +120,10 @@ static void set_interrupt_enabled(const struct device *dev, bool setting)
|
|||
|
||||
if (setting) {
|
||||
*DEV_CFG(dev)->irq_regs.timer_int_ena |= TIMG_WDT_INT_ENA;
|
||||
irq_enable(DEV_CFG(dev)->irq.line);
|
||||
irq_enable(DEV_DATA(dev)->irq_line);
|
||||
} else {
|
||||
*DEV_CFG(dev)->irq_regs.timer_int_ena &= ~TIMG_WDT_INT_ENA;
|
||||
irq_disable(DEV_CFG(dev)->irq.line);
|
||||
irq_disable(DEV_DATA(dev)->irq_line);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,6 +199,9 @@ static int wdt_esp32_install_timeout(const struct device *dev,
|
|||
|
||||
static int wdt_esp32_init(const struct device *dev)
|
||||
{
|
||||
const struct wdt_esp32_config *const config = DEV_CFG(dev);
|
||||
struct wdt_esp32_data *data = DEV_DATA(dev);
|
||||
|
||||
#ifdef CONFIG_WDT_DISABLE_AT_BOOT
|
||||
wdt_esp32_disable(dev);
|
||||
#endif
|
||||
|
@ -209,8 +209,7 @@ static int wdt_esp32_init(const struct device *dev)
|
|||
/* This is a level 4 interrupt, which is handled by _Level4Vector,
|
||||
* located in xtensa_vectors.S.
|
||||
*/
|
||||
irq_disable(DEV_CFG(dev)->irq.line);
|
||||
DEV_CFG(dev)->connect_irq();
|
||||
data->irq_line = esp_intr_alloc(config->irq_source, 0, wdt_esp32_isr, (void *)dev, NULL);
|
||||
|
||||
wdt_esp32_enable(dev);
|
||||
|
||||
|
@ -225,17 +224,6 @@ static const struct wdt_driver_api wdt_api = {
|
|||
};
|
||||
|
||||
#define ESP32_WDT_INIT(idx) \
|
||||
static void wdt_esp32_connect_irq_func##idx(void) \
|
||||
{ \
|
||||
esp32_rom_intr_matrix_set(0, ETS_TG##idx##_WDT_LEVEL_INTR_SOURCE, \
|
||||
CONFIG_WDT##idx##_ESP32_IRQ); \
|
||||
IRQ_CONNECT(CONFIG_WDT##idx##_ESP32_IRQ, \
|
||||
4, \
|
||||
wdt_esp32_isr, \
|
||||
DEVICE_DT_INST_GET(idx), \
|
||||
0); \
|
||||
} \
|
||||
\
|
||||
static struct wdt_esp32_data wdt##idx##_data; \
|
||||
static struct wdt_esp32_config wdt_esp32_config##idx = { \
|
||||
.base = (struct wdt_esp32_regs_t *) DT_INST_REG_ADDR(idx), \
|
||||
|
@ -243,11 +231,7 @@ static const struct wdt_driver_api wdt_api = {
|
|||
.timer_int_ena = (uint32_t *)TIMG_INT_ENA_TIMERS_REG(idx), \
|
||||
.timer_int_clr = (uint32_t *)TIMG_INT_CLR_TIMERS_REG(idx), \
|
||||
}, \
|
||||
.irq = { \
|
||||
.source = ETS_TG##idx##_WDT_LEVEL_INTR_SOURCE, \
|
||||
.line = CONFIG_WDT##idx##_ESP32_IRQ, \
|
||||
}, \
|
||||
.connect_irq = wdt_esp32_connect_irq_func##idx \
|
||||
.irq_source = DT_IRQN(DT_NODELABEL(wdt##idx)), \
|
||||
}; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(idx, \
|
||||
|
@ -258,8 +242,9 @@ static const struct wdt_driver_api wdt_api = {
|
|||
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
|
||||
&wdt_api)
|
||||
|
||||
static void wdt_esp32_isr(const struct device *dev)
|
||||
static void wdt_esp32_isr(void *arg)
|
||||
{
|
||||
const struct device *dev = (const struct device *)arg;
|
||||
struct wdt_esp32_data *data = DEV_DATA(dev);
|
||||
|
||||
if (data->callback) {
|
||||
|
|
|
@ -167,7 +167,8 @@
|
|||
wdt0: watchdog@3ff5f048 {
|
||||
compatible = "espressif,esp32-watchdog";
|
||||
reg = <0x3ff5f048 0x20>;
|
||||
/* interrupts = <24>; - FIXME: Enable interrupts when interrupt-controller got supported in device tree */
|
||||
interrupts = <TG0_WDT_LEVEL_INTR_SOURCE>;
|
||||
interrupt-parent = <&intc>;
|
||||
label = "WDT_0";
|
||||
status = "okay";
|
||||
};
|
||||
|
@ -175,7 +176,8 @@
|
|||
wdt1: watchdog@3ff60048 {
|
||||
compatible = "espressif,esp32-watchdog";
|
||||
reg = <0x3ff60048 0x20>;
|
||||
/* interrupts = <25>; - FIXME: Enable interrupts when interrupt-controller got supported in device tree */
|
||||
interrupts = <TG1_WDT_LEVEL_INTR_SOURCE>;
|
||||
interrupt-parent = <&intc>;
|
||||
label = "WDT_1";
|
||||
status = "disabled";
|
||||
};
|
||||
|
|
1
samples/drivers/watchdog/boards/esp32.conf
Normal file
1
samples/drivers/watchdog/boards/esp32.conf
Normal file
|
@ -0,0 +1 @@
|
|||
CONFIG_HEAP_MEM_POOL_SIZE=256
|
Loading…
Add table
Add a link
Reference in a new issue