34 lines
981 B
Nim
34 lines
981 B
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 IO is stuck in PAUSE state
|
|
if ion_paused:
|
|
let now = cpu_ticks()
|
|
|
|
# If paused and time exceeds threshold
|
|
if (pause_start > 0) and (now > pause_start) and (now - pause_start >
|
|
MAX_PAUSE_TICKS):
|
|
# HEAL
|
|
kprint("[IMMUNE] IO paused too long. Forcing RESUME.\n")
|
|
ion_paused = false
|
|
pause_start = 0
|
|
|
|
# Send CMD_ION_START to the Control Loop
|
|
var cmd = CmdPacket(kind: uint32(ion.CmdType.CMD_ION_START), arg: 0)
|
|
chan_cmd.send(cmd)
|
|
|
|
# Cooperative Multitasking: Must yield!
|
|
fiber_yield()
|
|
# asm "wfi"
|