Files
tinygo/src/machine/machine_rp2_watchdog.go
T
Patricio Whittingslow 37f35f8c91 Add RP2350 support (#4459)
machine/rp2350: add support

* add linker scripts for rp2350
* add bootloader
* begin melding rp2040 and rp2350 APIs
* add UART
* add rp2350 boot patching
* Fix RP2350 memory layout (#4626)
* Remove rp2040-style second stage bootloader.
* Add 'minimum viable' IMAGE_DEF embedded block
* Create a pico2 specific target
* Implement rp2350 init, clock, and uart support
* Merge rp2 reset code back together
* Separate chip-specific clock definitions
* Clear pad isolation bit on rp2350
* Init UART in rp2350 runtime
* Correct usb/serial initialization order
* Implement jump-to-bootloader
* test: add pico2 to smoketests

---------

Signed-off-by: deadprogram <ron@hybridgroup.com>
Co-authored-by: Matthew Mets <matt.mets@cibomahto.com>
Co-authored-by: Matt Mets <matt@blinkinlabs.com>
Co-authored-by: deadprogram <ron@hybridgroup.com>
2024-12-18 19:36:30 +01:00

63 lines
1.6 KiB
Go

//go:build rp2040 || rp2350
package machine
import (
"device/rp"
)
// Watchdog provides access to the hardware watchdog available
// in the RP2040.
var Watchdog = &watchdogImpl{}
const (
// WatchdogMaxTimeout in milliseconds (approx 8.3s).
//
// Nominal 1us per watchdog tick, 24-bit counter,
// but due to errata two ticks consumed per 1us.
// See: Errata RP2040-E1
WatchdogMaxTimeout = (rp.WATCHDOG_LOAD_LOAD_Msk / 1000) / 2
)
type watchdogImpl struct {
// The value to reset the counter to on each Update
loadValue uint32
}
// Configure the watchdog.
//
// This method should not be called after the watchdog is started and on
// some platforms attempting to reconfigure after starting the watchdog
// is explicitly forbidden / will not work.
func (wd *watchdogImpl) Configure(config WatchdogConfig) error {
// x2 due to errata RP2040-E1
wd.loadValue = config.TimeoutMillis * 1000 * 2
if wd.loadValue > rp.WATCHDOG_LOAD_LOAD_Msk {
wd.loadValue = rp.WATCHDOG_LOAD_LOAD_Msk
}
rp.WATCHDOG.CTRL.ClearBits(rp.WATCHDOG_CTRL_ENABLE)
// Reset everything apart from ROSC and XOSC
rp.PSM.WDSEL.Set(0x0001ffff &^ (rp.PSM_WDSEL_ROSC | rp.PSM_WDSEL_XOSC))
// Pause watchdog during debug
rp.WATCHDOG.CTRL.SetBits(rp.WATCHDOG_CTRL_PAUSE_DBG0 | rp.WATCHDOG_CTRL_PAUSE_DBG1 | rp.WATCHDOG_CTRL_PAUSE_JTAG)
// Load initial counter
rp.WATCHDOG.LOAD.Set(wd.loadValue)
return nil
}
// Starts the watchdog.
func (wd *watchdogImpl) Start() error {
rp.WATCHDOG.CTRL.SetBits(rp.WATCHDOG_CTRL_ENABLE)
return nil
}
// Update the watchdog, indicating that the app is healthy.
func (wd *watchdogImpl) Update() {
rp.WATCHDOG.LOAD.Set(wd.loadValue)
}