add WDT support to xous-core

This commit is contained in:
bunnie 2020-12-13 01:54:25 +08:00
parent 95719852b3
commit e1c4b702a9
4 changed files with 51 additions and 3 deletions

11
Cargo.lock generated
View file

@ -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"

View file

@ -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",
]

View file

@ -45,6 +45,7 @@ mod implementation {
pub struct XousTickTimer {
csr: utralib::CSR<u32>,
wdt: utralib::CSR<u32>,
current_response: Option<SleepResponse>,
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);

View file

@ -76,7 +76,7 @@ fn build_hw_image(debug: bool, svd: Option<String>) -> 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 {