Skip to content

Commit f4fda91

Browse files
JordanYateskartben
authored andcommitted
watchdog: cmsdk_apb: don't reconfigure after start
Do not allow attempting to install new channels after the watchdog has been started. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 1f02f39 commit f4fda91

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/watchdog/wdt_cmsdk_apb.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const struct device *wdog_r;
6969
static unsigned int reload_cycles = CMSDK_APB_WDOG_RELOAD;
7070
static uint8_t assigned_channels;
7171
static uint8_t flags;
72+
static bool enabled;
7273

7374
static void (*user_cb)(const struct device *dev, int channel_id);
7475

@@ -88,13 +89,19 @@ static int wdog_cmsdk_apb_setup(const struct device *dev, uint8_t options)
8889
ARG_UNUSED(dev);
8990
ARG_UNUSED(options);
9091

92+
/* Check if watchdog is already running */
93+
if (enabled) {
94+
return -EBUSY;
95+
}
96+
9197
/* Reset pending interrupts before starting */
9298
wdog->intclr = CMSDK_APB_WDOG_INTCLR;
9399
wdog->load = reload_cycles;
94100

95101
/* Start the watchdog counter with INTEN bit */
96102
wdog->ctrl = (CMSDK_APB_WDOG_CTRL_RESEN | CMSDK_APB_WDOG_CTRL_INTEN);
97103

104+
enabled = true;
98105
return 0;
99106
}
100107

@@ -107,6 +114,7 @@ static int wdog_cmsdk_apb_disable(const struct device *dev)
107114
/* Stop the watchdog counter with INTEN bit */
108115
wdog->ctrl = ~(CMSDK_APB_WDOG_CTRL_RESEN | CMSDK_APB_WDOG_CTRL_INTEN);
109116

117+
enabled = false;
110118
assigned_channels = 0;
111119

112120
return 0;
@@ -123,6 +131,9 @@ static int wdog_cmsdk_apb_install_timeout(const struct device *dev,
123131
if (config->window.max == 0) {
124132
return -EINVAL;
125133
}
134+
if (enabled == true) {
135+
return -EBUSY;
136+
}
126137
if (assigned_channels == 1) {
127138
return -ENOMEM;
128139
}

0 commit comments

Comments
 (0)