rumpk/core/watchdog.nim

35 lines
1.0 KiB
Nim

# Watchdog Fiber - Logic Core Immune System
const MAX_PAUSE_TICKS = 1_000_000'u64
# Import timer from HAL (Exposed via abi.zig)
proc cpu_ticks(): uint64 {.importc: "rumpk_timer_now_ns", cdecl.}
proc watchdog_loop() {.cdecl.} =
## Fiber 0: The Immune System
# Note: Uses globals from kernel.nim via 'include'
kprintln("[Watchdog] Immune System Online.")
while true:
# Check if network is stuck in PAUSE state
if net_paused:
let now = cpu_ticks()
# If paused and time exceeds threshold
# Note: pause_start needs to be set when pausing!
if (pause_start > 0) and (now > pause_start) and (now - pause_start >
MAX_PAUSE_TICKS):
# HEAL
kprint("[IMMUNE] Network paused too long. Forcing RESUME.\n")
net_paused = false
pause_start = 0
# Send CMD_NET_START to the Control Loop
var cmd = CmdPacket(kind: uint32(ion.CmdType.CMD_NET_START), arg: 0)
chan_cmd.send(cmd)
# Cooperative Multitasking: Must yield!
fiber_yield()
# asm "wfi"