@@ -87,12 +87,25 @@ static int wdt_gecko_convert_window(uint32_t window, uint32_t period)
87
87
return idx ;
88
88
}
89
89
90
+ static bool wdt_gecko_is_enabled (WDOG_TypeDef * wdog )
91
+ {
92
+ #if defined(CONFIG_SOC_FAMILY_SILABS_S2 )
93
+ return FIELD_GET (WDOG_EN_EN , wdog -> EN );
94
+ #else
95
+ return FIELD_GET (WDOG_CTRL_EN , wdog -> CTRL );
96
+ #endif
97
+ }
98
+
90
99
static int wdt_gecko_setup (const struct device * dev , uint8_t options )
91
100
{
92
101
const struct wdt_gecko_cfg * config = dev -> config ;
93
102
struct wdt_gecko_data * data = dev -> data ;
94
103
WDOG_TypeDef * wdog = config -> base ;
95
104
105
+ if (wdt_gecko_is_enabled (wdog )) {
106
+ return - EBUSY ;
107
+ }
108
+
96
109
if (!data -> timeout_installed ) {
97
110
LOG_ERR ("No valid timeouts installed" );
98
111
return - EINVAL ;
@@ -134,8 +147,14 @@ static int wdt_gecko_disable(const struct device *dev)
134
147
struct wdt_gecko_data * data = dev -> data ;
135
148
WDOG_TypeDef * wdog = config -> base ;
136
149
137
- WDOGn_Enable ( wdog , false);
150
+ /* Always uninstall timeouts, independent of watchdog enable state */
138
151
data -> timeout_installed = false;
152
+
153
+ if (!wdt_gecko_is_enabled (wdog )) {
154
+ return - EFAULT ;
155
+ }
156
+
157
+ WDOGn_Enable (wdog , false);
139
158
LOG_DBG ("Disabled the watchdog" );
140
159
141
160
return 0 ;
@@ -144,10 +163,16 @@ static int wdt_gecko_disable(const struct device *dev)
144
163
static int wdt_gecko_install_timeout (const struct device * dev ,
145
164
const struct wdt_timeout_cfg * cfg )
146
165
{
166
+ const struct wdt_gecko_cfg * config = dev -> config ;
147
167
struct wdt_gecko_data * data = dev -> data ;
148
- data -> wdog_config = (WDOG_Init_TypeDef )WDOG_INIT_DEFAULT ;
149
168
uint32_t installed_timeout ;
150
169
170
+ data -> wdog_config = (WDOG_Init_TypeDef )WDOG_INIT_DEFAULT ;
171
+
172
+ if (wdt_gecko_is_enabled (config -> base )) {
173
+ return - EBUSY ;
174
+ }
175
+
151
176
if (data -> timeout_installed ) {
152
177
LOG_ERR ("No more timeouts can be installed" );
153
178
return - ENOMEM ;
@@ -189,13 +214,12 @@ static int wdt_gecko_install_timeout(const struct device *dev,
189
214
/* Set mode of watchdog and callback */
190
215
switch (cfg -> flags ) {
191
216
case WDT_FLAG_RESET_SOC :
192
- case WDT_FLAG_RESET_CPU_CORE :
193
217
if (cfg -> callback != NULL ) {
194
218
LOG_ERR ("Reset mode with callback not supported\n" );
195
219
return - ENOTSUP ;
196
220
}
197
221
data -> wdog_config .resetDisable = false;
198
- LOG_DBG ("Configuring reset CPU/ SoC mode\n" );
222
+ LOG_DBG ("Configuring reset SoC mode\n" );
199
223
break ;
200
224
201
225
case WDT_FLAG_RESET_NONE :
@@ -204,6 +228,10 @@ static int wdt_gecko_install_timeout(const struct device *dev,
204
228
LOG_DBG ("Configuring non-reset mode\n" );
205
229
break ;
206
230
231
+ case WDT_FLAG_RESET_CPU_CORE :
232
+ LOG_ERR ("CPU core only reset not supported" );
233
+ return - ENOTSUP ;
234
+
207
235
default :
208
236
LOG_ERR ("Unsupported watchdog config flag" );
209
237
return - EINVAL ;
@@ -224,6 +252,10 @@ static int wdt_gecko_feed(const struct device *dev, int channel_id)
224
252
return - EINVAL ;
225
253
}
226
254
255
+ if (!wdt_gecko_is_enabled (wdog )) {
256
+ return - EINVAL ;
257
+ }
258
+
227
259
WDOGn_Feed (wdog );
228
260
LOG_DBG ("Fed the watchdog" );
229
261
0 commit comments