-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path0071-RP2040-Implement-reset-reasons.patch
67 lines (64 loc) · 1.66 KB
/
0071-RP2040-Implement-reset-reasons.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
From 15a24c5fad616ff180b243bbb25bcad1b091ebc7 Mon Sep 17 00:00:00 2001
From: giulcioffi <g.cioffi@arduino.cc>
Date: Mon, 15 Mar 2021 17:52:09 +0100
Subject: [PATCH 71/87] RP2040: Implement reset reasons
---
.../TARGET_RP2040/reset_reason.c | 33 +++++++++++++++++++
targets/targets.json | 3 +-
2 files changed, 35 insertions(+), 1 deletion(-)
create mode 100644 targets/TARGET_RASPBERRYPI/TARGET_RP2040/reset_reason.c
diff --git a/targets/TARGET_RASPBERRYPI/TARGET_RP2040/reset_reason.c b/targets/TARGET_RASPBERRYPI/TARGET_RP2040/reset_reason.c
new file mode 100644
index 0000000000..7e511078c5
--- /dev/null
+++ b/targets/TARGET_RASPBERRYPI/TARGET_RP2040/reset_reason.c
@@ -0,0 +1,33 @@
+#include "reset_reason_api.h"
+#include "hardware/watchdog.h"
+
+#ifdef DEVICE_RESET_REASON
+
+#include "structs/resets.h"
+
+reset_reason_t hal_reset_reason_get(void)
+{
+ if (watchdog_caused_reboot()) {
+ return RESET_REASON_WATCHDOG;
+ } else {
+ return RESET_REASON_PIN_RESET;
+ }
+
+ return RESET_REASON_UNKNOWN;
+}
+
+
+uint32_t hal_reset_reason_get_raw(void)
+{
+ return resets_hw->reset;
+}
+
+
+void hal_reset_reason_clear(void)
+{
+ for (int i = 1; i < 25; i++) {
+ hw_clear_bits(&resets_hw->reset, i);
+ }
+}
+
+#endif // DEVICE_RESET_REASON
diff --git a/targets/targets.json b/targets/targets.json
index 64ade7825c..3cc7853680 100644
--- a/targets/targets.json
+++ b/targets/targets.json
@@ -8390,7 +8390,8 @@
"SPI",
"USTICKER",
"WATCHDOG",
- "USBDEVICE"
+ "USBDEVICE",
+ "RESET_REASON"
]
},
"NANO_RP2040_CONNECT": {
--
2.30.2