Skip to content

Commit a40a192

Browse files
giulcioffifacchinm
authored andcommitted
RP2040: Implement watchdog
1 parent d3ac8e2 commit a40a192

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "watchdog_api.h"
2+
#include "hardware/watchdog.h"
3+
#include "structs/watchdog.h"
4+
5+
#if DEVICE_WATCHDOG
6+
7+
watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
8+
{
9+
// The pico watchdogs accept a maximum value of 0x7fffff
10+
if ( config->timeout_ms < 0x1 && config->timeout_ms > 0x7FFFFF ) {
11+
return WATCHDOG_STATUS_INVALID_ARGUMENT;
12+
}
13+
14+
watchdog_enable(config->timeout_ms, true);
15+
16+
return WATCHDOG_STATUS_OK;
17+
}
18+
19+
void hal_watchdog_kick(void)
20+
{
21+
watchdog_update();
22+
}
23+
24+
watchdog_status_t hal_watchdog_stop(void)
25+
{
26+
hw_clear_bits(&watchdog_hw->ctrl, WATCHDOG_CTRL_ENABLE_BITS);
27+
return WATCHDOG_STATUS_OK;
28+
}
29+
30+
uint32_t hal_watchdog_get_reload_value(void)
31+
{
32+
return (watchdog_hw->load / 2000U);
33+
}
34+
35+
watchdog_features_t hal_watchdog_get_platform_features(void)
36+
{
37+
watchdog_features_t features;
38+
39+
features.max_timeout = 0x7FFFFF;
40+
features.update_config = true;
41+
features.disable_watchdog = true;
42+
return features;
43+
44+
}
45+
46+
#endif // DEVICE_WATCHDOG

targets/targets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7976,6 +7976,7 @@
79767976
"SERIAL_FC",
79777977
"SPI",
79787978
"USTICKER",
7979+
"WATCHDOG",
79797980
"USBDEVICE"
79807981
]
79817982
},

0 commit comments

Comments
 (0)