mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 12:03:41 +00:00
samd51,rp2040,nrf528xx,stm32: implement watchdog
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"machine"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
//sleep for 2 secs for console
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
config := machine.WatchdogConfig{
|
||||
TimeoutMillis: 1000,
|
||||
}
|
||||
|
||||
println("configuring watchdog for max 1 second updates")
|
||||
machine.Watchdog.Configure(config)
|
||||
|
||||
// From this point the watchdog is running and Update must be
|
||||
// called periodically, per the config
|
||||
machine.Watchdog.Start()
|
||||
|
||||
// This loop should complete because watchdog update is called
|
||||
// every 100ms.
|
||||
start := time.Now()
|
||||
println("updating watchdog for 3 seconds")
|
||||
for i := 0; i < 30; i++ {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
machine.Watchdog.Update()
|
||||
fmt.Printf("alive @ %v\n", time.Now().Sub(start))
|
||||
}
|
||||
|
||||
// This loop should cause a watchdog reset after 1s since
|
||||
// there is no update call.
|
||||
start = time.Now()
|
||||
println("entering tight loop")
|
||||
for {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
fmt.Printf("alive @ %v\n", time.Now().Sub(start))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user