diff --git a/Cargo.lock b/Cargo.lock index 8695ff3d0..2f79f22e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1131,6 +1131,17 @@ dependencies = [ "syn", ] +[[package]] +name = "xous-names" +version = "0.1.0" +dependencies = [ + "heapless", + "log", + "log-server", + "utralib", + "xous", +] + [[package]] name = "xtask" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 4dd45fd9a..8b9e74132 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ members = [ "services/log-server", "services/ticktimer-server", "services/com", + "services/xous-names", "svd2utra", "xtask", ] @@ -16,6 +17,7 @@ default-members = [ "services/log-server", "services/graphics-server", "services/ticktimer-server", + "services/xous-names", "services/com", ] diff --git a/services/ticktimer-server/src/main.rs b/services/ticktimer-server/src/main.rs index 54302e4f9..e5b5015f9 100644 --- a/services/ticktimer-server/src/main.rs +++ b/services/ticktimer-server/src/main.rs @@ -45,6 +45,7 @@ mod implementation { pub struct XousTickTimer { csr: utralib::CSR, + wdt: utralib::CSR, current_response: Option, response_start: u64, connection: xous::CID, @@ -77,14 +78,24 @@ mod implementation { xous::MemoryFlags::R | xous::MemoryFlags::W, ) .expect("couldn't map Tick Timer CSR range"); + let wdt = xous::syscall::map_memory( + xous::MemoryAddress::new(utra::wdt::HW_WDT_BASE), + None, + 4096, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ) + .expect("couldn't map Watchdog timer CSR range"); let mut xtt = XousTickTimer { csr: CSR::new(csr.as_mut_ptr() as *mut u32), + wdt: CSR::new(wdt.as_mut_ptr() as *mut u32), current_response: None, response_start: 0, connection, }; + xtt.wdt.wfo(utra::wdt::WATCHDOG_ENABLE, 1); + xous::claim_interrupt( utra::ticktimer::TICKTIMER_IRQ, handle_irq, @@ -142,6 +153,24 @@ mod implementation { .wo(utra::ticktimer::MSLEEP_TARGET0, irq_target as _); self.csr.wfo(utra::ticktimer::EV_ENABLE_ALARM, 1); // Enable the interrupt } + + pub fn reset_wdt(&mut self) { + // disarm the WDT + + // why do we write the registers three times? because: + // - the WDT is triggered on a "ring oscillator" that's entirely internal to the SoC + // (so you can't defeat the WDT by just pausing the external clock sourc) + // - the ring oscillator has a tolerance band of 65MHz +/- 50% + // - the CPU runs at 100MHz with a tight tolerance + // - presenting the data three times ensures the WDT will pick it up, + // even at the slowest end of tolerance + self.wdt.wfo(utra::wdt::WATCHDOG_RESET_CODE, 0x600d); + self.wdt.wfo(utra::wdt::WATCHDOG_RESET_CODE, 0x600d); + self.wdt.wfo(utra::wdt::WATCHDOG_RESET_CODE, 0x600d); + self.wdt.wfo(utra::wdt::WATCHDOG_RESET_CODE, 0xc0de); + self.wdt.wfo(utra::wdt::WATCHDOG_RESET_CODE, 0xc0de); + self.wdt.wfo(utra::wdt::WATCHDOG_RESET_CODE, 0xc0de); + } } } @@ -235,6 +264,10 @@ mod implementation { .send(SleepComms::StartSleep(sender, milliseconds as _)) .unwrap(); } + + pub fn reset_wdt() { + // dummy function, does nothing + } } } @@ -281,6 +314,8 @@ fn xmain() -> ! { let mut ticktimer = XousTickTimer::new(ticktimer_client); loop { + ticktimer.reset_wdt(); + //info!("TickTimer: waiting for message"); let envelope = xous::receive_message(ticktimer_server).unwrap(); //info!("TickTimer: Message: {:?}", envelope); diff --git a/xtask/src/main.rs b/xtask/src/main.rs index a623661a5..9f0fccc9a 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -76,7 +76,7 @@ fn build_hw_image(debug: bool, svd: Option) -> Result<(), DynError> { let kernel = build_kernel(debug)?; let mut init = vec![]; - for pkg in &["shell", "graphics-server", "ticktimer-server", "log-server", "com"] { + for pkg in &["shell", "graphics-server", "ticktimer-server", "log-server", "com"] { // "xous-names" init.push(build(pkg, debug, Some(TARGET), None)?); } let loader = build("loader", debug, Some(TARGET), Some("loader".into()))?; @@ -145,7 +145,7 @@ fn renode_image(debug: bool) -> Result<(), DynError> { std::env::set_var("XOUS_SVD_FILE", path.canonicalize().unwrap()); let kernel = build_kernel(debug)?; let mut init = vec![]; - for pkg in &["shell", "log-server", "graphics-server", "ticktimer-server", "com"] { + for pkg in &["shell", "log-server", "graphics-server", "ticktimer-server", "com", "xous-names"] { init.push(build(pkg, debug, Some(TARGET), None)?); } build("loader", debug, Some(TARGET), Some("loader".into()))?; @@ -162,7 +162,7 @@ fn renode_image(debug: bool) -> Result<(), DynError> { fn run(debug: bool) -> Result<(), DynError> { let stream = if debug { "debug" } else { "release" }; - let init = ["shell", "log-server", "graphics-server", "ticktimer-server", "com"]; + let init = ["shell", "log-server", "graphics-server", "ticktimer-server", "com", "xous-names"]; // let mut init_paths = vec![]; for pkg in &init {