aboutsummaryrefslogtreecommitdiffstats
path: root/src/rp2040
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2022-12-14 19:21:25 -0500
committerKevin O'Connor <kevin@koconnor.net>2022-12-14 19:21:25 -0500
commitfe0fc2961688588b0a4d6ad7783df961903bc736 (patch)
tree4cde699dfd9d1395bb9e3529bf6c065eaadb8497 /src/rp2040
parent9b342c65c8a038ff980645452ab84556376bedc7 (diff)
downloadkutter-fe0fc2961688588b0a4d6ad7783df961903bc736.tar.gz
kutter-fe0fc2961688588b0a4d6ad7783df961903bc736.tar.xz
kutter-fe0fc2961688588b0a4d6ad7783df961903bc736.zip
rp2040: Move watchdog code to new watchdog.c file
Move the watchdog code to its own file so that it is easier to disable it for development builds. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/rp2040')
-rw-r--r--src/rp2040/Makefile5
-rw-r--r--src/rp2040/main.c25
-rw-r--r--src/rp2040/watchdog.c29
3 files changed, 32 insertions, 27 deletions
diff --git a/src/rp2040/Makefile b/src/rp2040/Makefile
index 47954c9a..32d731f2 100644
--- a/src/rp2040/Makefile
+++ b/src/rp2040/Makefile
@@ -9,9 +9,10 @@ CFLAGS += -mcpu=cortex-m0plus -mthumb -Ilib/cmsis-core
CFLAGS += -Ilib/rp2040 -Ilib/rp2040/cmsis_include -Ilib/fast-hash -Ilib/can2040
# Add source files
-src-y += rp2040/main.c rp2040/gpio.c rp2040/adc.c generic/crc16_ccitt.c
+src-y += rp2040/main.c rp2040/watchdog.c rp2040/gpio.c
+src-y += rp2040/adc.c rp2040/timer.c rp2040/bootrom.c
src-y += generic/armcm_boot.c generic/armcm_irq.c generic/armcm_reset.c
-src-y += generic/timer_irq.c rp2040/timer.c rp2040/bootrom.c
+src-y += generic/timer_irq.c generic/crc16_ccitt.c
src-$(CONFIG_USBSERIAL) += rp2040/usbserial.c generic/usb_cdc.c
src-$(CONFIG_USBSERIAL) += rp2040/chipid.c
src-$(CONFIG_SERIAL) += rp2040/serial.c generic/serial_irq.c
diff --git a/src/rp2040/main.c b/src/rp2040/main.c
index c14e2759..0b144d0b 100644
--- a/src/rp2040/main.c
+++ b/src/rp2040/main.c
@@ -9,7 +9,6 @@
#include "generic/armcm_reset.h" // try_request_canboot
#include "hardware/structs/clocks.h" // clock_hw_t
#include "hardware/structs/pll.h" // pll_hw_t
-#include "hardware/structs/psm.h" // psm_hw
#include "hardware/structs/resets.h" // sio_hw
#include "hardware/structs/watchdog.h" // watchdog_hw
#include "hardware/structs/xosc.h" // xosc_hw
@@ -18,30 +17,6 @@
/****************************************************************
- * watchdog handler
- ****************************************************************/
-
-void
-watchdog_reset(void)
-{
- watchdog_hw->load = 0x800000; // ~350ms
-}
-DECL_TASK(watchdog_reset);
-
-void
-watchdog_init(void)
-{
- psm_hw->wdsel = PSM_WDSEL_BITS & ~(PSM_WDSEL_ROSC_BITS|PSM_WDSEL_XOSC_BITS);
- watchdog_reset();
- watchdog_hw->ctrl = (WATCHDOG_CTRL_PAUSE_DBG0_BITS
- | WATCHDOG_CTRL_PAUSE_DBG1_BITS
- | WATCHDOG_CTRL_PAUSE_JTAG_BITS
- | WATCHDOG_CTRL_ENABLE_BITS);
-}
-DECL_INIT(watchdog_init);
-
-
-/****************************************************************
* Bootloader
****************************************************************/
diff --git a/src/rp2040/watchdog.c b/src/rp2040/watchdog.c
new file mode 100644
index 00000000..dda7aa55
--- /dev/null
+++ b/src/rp2040/watchdog.c
@@ -0,0 +1,29 @@
+// Watchdog code on rp2040
+//
+// Copyright (C) 2021-2022 Kevin O'Connor <kevin@koconnor.net>
+//
+// This file may be distributed under the terms of the GNU GPLv3 license.
+
+#include <stdint.h> // uint32_t
+#include "hardware/structs/psm.h" // psm_hw
+#include "hardware/structs/watchdog.h" // watchdog_hw
+#include "sched.h" // DECL_TASK
+
+void
+watchdog_reset(void)
+{
+ watchdog_hw->load = 0x800000; // ~350ms
+}
+DECL_TASK(watchdog_reset);
+
+void
+watchdog_init(void)
+{
+ psm_hw->wdsel = PSM_WDSEL_BITS & ~(PSM_WDSEL_ROSC_BITS|PSM_WDSEL_XOSC_BITS);
+ watchdog_reset();
+ watchdog_hw->ctrl = (WATCHDOG_CTRL_PAUSE_DBG0_BITS
+ | WATCHDOG_CTRL_PAUSE_DBG1_BITS
+ | WATCHDOG_CTRL_PAUSE_JTAG_BITS
+ | WATCHDOG_CTRL_ENABLE_BITS);
+}
+DECL_INIT(watchdog_init);