Skip to content

Commit 857a188

Browse files
Felipe Nevescfriedt
authored andcommitted
drivers: watchdog: esp32: enabled esp32c3
support for the unified esp32 wdt driver. Signed-off-by: Felipe Neves <[email protected]>
1 parent 28d2ee6 commit 857a188

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

boards/riscv/esp32c3_devkitm/esp32c3_devkitm.dts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@
6969
status = "okay";
7070
};
7171

72+
&wdt0 {
73+
status = "okay";
74+
};
75+
7276
&flash0 {
7377
status = "okay";
7478
partitions {

drivers/watchdog/Kconfig.esp32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ DT_COMPAT_ESP32_WDT := espressif,esp32-watchdog
77

88
config WDT_ESP32
99
bool "ESP32 Watchdog (WDT) Driver"
10-
depends on SOC_ESP32 || SOC_ESP32S2
10+
depends on SOC_ESP32 || SOC_ESP32S2 || SOC_ESP32C3
1111
default $(dt_compat_enabled,$(DT_COMPAT_ESP32_WDT))
1212
help
1313
Enable WDT driver for ESP32.

drivers/watchdog/wdt_esp32.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@
1212

1313
#include <string.h>
1414
#include <drivers/watchdog.h>
15+
#ifndef CONFIG_SOC_ESP32C3
1516
#include <drivers/interrupt_controller/intc_esp32.h>
17+
#else
18+
#include <drivers/interrupt_controller/intc_esp32c3.h>
19+
#endif
1620
#include <device.h>
1721

22+
#ifdef CONFIG_SOC_ESP32C3
23+
#define ISR_HANDLER isr_handler_t
24+
#else
25+
#define ISR_HANDLER intr_handler_t
26+
#endif
27+
1828
/* FIXME: This struct shall be removed from here, when esp32 timer driver got
1929
* implemented.
2030
* That's why the type name starts with `timer` not `wdt`
@@ -150,15 +160,23 @@ static int wdt_esp32_set_config(const struct device *dev, uint8_t options)
150160
v |= TIMG_WDT_STG_SEL_OFF << TIMG_WDT_STG1_S;
151161

152162
/* Disable interrupts for this mode. */
163+
#ifndef CONFIG_SOC_ESP32C3
153164
v &= ~(TIMG_WDT_LEVEL_INT_EN | TIMG_WDT_EDGE_INT_EN);
165+
#else
166+
v &= ~(TIMG_WDT_INT_ENA);
167+
#endif
154168
} else if (data->mode == WDT_MODE_INTERRUPT_RESET) {
155169
/* Interrupt first, and warm reset if not reloaded */
156170
v |= TIMG_WDT_STG_SEL_INT << TIMG_WDT_STG0_S;
157171
v |= TIMG_WDT_STG_SEL_RESET_SYSTEM << TIMG_WDT_STG1_S;
158172

159173
/* Use level-triggered interrupts. */
174+
#ifndef CONFIG_SOC_ESP32C3
160175
v |= TIMG_WDT_LEVEL_INT_EN;
161176
v &= ~TIMG_WDT_EDGE_INT_EN;
177+
#else
178+
v |= TIMG_WDT_INT_ENA;
179+
#endif
162180
} else {
163181
return -EINVAL;
164182
}
@@ -206,10 +224,15 @@ static int wdt_esp32_init(const struct device *dev)
206224
wdt_esp32_disable(dev);
207225
#endif
208226

209-
/* This is a level 4 interrupt, which is handled by _Level4Vector,
227+
/* For xtensa esp32 chips, this is a level 4 interrupt,
228+
* which is handled by _Level4Vector,
210229
* located in xtensa_vectors.S.
211230
*/
212-
data->irq_line = esp_intr_alloc(config->irq_source, 0, wdt_esp32_isr, (void *)dev, NULL);
231+
data->irq_line = esp_intr_alloc(config->irq_source,
232+
0,
233+
(ISR_HANDLER)wdt_esp32_isr,
234+
(void *)dev,
235+
NULL);
213236

214237
wdt_esp32_enable(dev);
215238

dts/riscv/espressif/esp32c3.dtsi

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,25 @@
153153
status = "disabled";
154154
use-iomux;
155155
};
156+
157+
wdt0: watchdog@6001f048 {
158+
compatible = "espressif,esp32-watchdog";
159+
reg = <0x6001f048 0x20>;
160+
interrupts = <TG0_WDT_LEVEL_INTR_SOURCE>;
161+
interrupt-parent = <&intc>;
162+
label = "WDT_0";
163+
status = "disabled";
164+
};
165+
166+
wdt1: watchdog@60020048 {
167+
compatible = "espressif,esp32-watchdog";
168+
reg = <0x60020048 0x20>;
169+
interrupts = <TG1_WDT_LEVEL_INTR_SOURCE>;
170+
interrupt-parent = <&intc>;
171+
label = "WDT_1";
172+
status = "disabled";
173+
};
174+
156175
};
157176

158177
};

0 commit comments

Comments
 (0)