Merge branch 'main' of github.com:betrusted-io/xous-core into main

This commit is contained in:
bunnie 2023-12-24 23:55:51 +08:00
commit 2b521a75f8
2 changed files with 25 additions and 21 deletions

View file

@ -52,10 +52,13 @@ namespace Antmicro.Renode.Peripherals.Timers.Betrusted
private void OnTick() private void OnTick()
{ {
Interlocked.Increment(ref counter); Interlocked.Increment(ref counter);
if (((uint)counter) >= this.reset_target) if ((((uint)counter) >= reset_target) && RebootOnExpiry)
{ {
this.Log(LogLevel.Error, "Watchdog timer expired -- requesting system reset"); this.Log(LogLevel.Error, "Watchdog timer expired -- requesting system reset");
this.machine.RequestReset(); machine.RequestReset();
} else if (((uint)counter) == reset_target)
{
this.Log(LogLevel.Error, "Watchdog timer expired -- not rebooting because RebootOnExpiry is false");
} }
} }
@ -79,7 +82,7 @@ namespace Antmicro.Renode.Peripherals.Timers.Betrusted
// Convert "approximately 65MHz" ticks to milliseconds // Convert "approximately 65MHz" ticks to milliseconds
private uint XilinxClockToMs(ulong xilinx_clocks) private uint XilinxClockToMs(ulong xilinx_clocks)
{ {
uint adjusted = (uint)((xilinx_clocks * 100) / 65000000); uint adjusted = (uint)(xilinx_clocks * 100 / 65000000);
this.Log(LogLevel.Debug, "Watchdog timer set for {0}. Will expire after {1} msec", xilinx_clocks, adjusted * 10); this.Log(LogLevel.Debug, "Watchdog timer set for {0}. Will expire after {1} msec", xilinx_clocks, adjusted * 10);
return adjusted; return adjusted;
} }
@ -96,6 +99,7 @@ namespace Antmicro.Renode.Peripherals.Timers.Betrusted
private uint reset_target; private uint reset_target;
private bool enabled; private bool enabled;
private readonly DoubleWordRegisterCollection registers; private readonly DoubleWordRegisterCollection registers;
public bool RebootOnExpiry = true;
private enum Registers private enum Registers
{ {
Watchdog = 0x0, Watchdog = 0x0,

View file

@ -6,28 +6,28 @@ use riscv::register::{satp, sie, sstatus};
pub mod exception; pub mod exception;
pub mod irq; pub mod irq;
pub mod mem; pub mod mem;
pub mod panic;
pub mod process; pub mod process;
pub mod syscall; pub mod syscall;
pub mod panic;
pub use process::Thread; pub use process::Thread;
#[cfg(any(feature="precursor", feature="renode"))] #[cfg(any(feature = "precursor", feature = "renode"))]
use utralib::generated::*;
#[cfg(any(feature="precursor", feature="renode"))]
use xous_kernel::{MemoryFlags, MemoryType, PID};
#[cfg(any(feature="precursor", feature="renode"))]
use crate::mem::MemoryManager; use crate::mem::MemoryManager;
#[cfg(any(feature="cramium-soc", feature="cramium-fpga"))] #[cfg(any(feature = "precursor", feature = "renode"))]
use utralib::generated::*;
#[cfg(any(feature = "cramium-soc", feature = "cramium-fpga"))]
use xous_kernel::PID; use xous_kernel::PID;
#[cfg(any(feature = "precursor", feature = "renode"))]
use xous_kernel::{MemoryFlags, MemoryType, PID};
#[cfg(any(feature="precursor", feature="renode"))] #[cfg(any(feature = "precursor", feature = "renode"))]
pub const WFI_KERNEL: Wfi = Wfi { pub const WFI_KERNEL: Wfi = Wfi {
// the manually chosen virtual address has to be in the top 4MiB as it is the only page shared among all processes // the manually chosen virtual address has to be in the top 4MiB as it is the only page shared among all processes
base: 0xffcd_0000 as *mut usize, // see https://github.com/betrusted-io/xous-core/blob/master/docs/memory.md base: 0xffcd_0000 as *mut usize, // see https://github.com/betrusted-io/xous-core/blob/master/docs/memory.md
}; };
#[cfg(any(feature="precursor", feature="renode"))] #[cfg(any(feature = "precursor", feature = "renode"))]
pub struct Wfi { pub struct Wfi {
pub base: *mut usize, pub base: *mut usize,
} }
@ -37,7 +37,7 @@ pub fn current_pid() -> PID {
} }
pub fn init() { pub fn init() {
#[cfg(any(feature="precursor", feature="renode"))] #[cfg(any(feature = "precursor", feature = "renode"))]
MemoryManager::with_mut(|memory_manager| { MemoryManager::with_mut(|memory_manager| {
memory_manager memory_manager
.map_range( .map_range(
@ -50,9 +50,9 @@ pub fn init() {
) )
.expect("unable to map WFI") .expect("unable to map WFI")
}); });
#[cfg(any(feature="precursor", feature="renode"))] #[cfg(any(feature = "precursor", feature = "renode"))]
let mut wfi_kernel_csr = CSR::new(WFI_KERNEL.base as *mut u32); let mut wfi_kernel_csr = CSR::new(WFI_KERNEL.base as *mut u32);
#[cfg(any(feature="precursor", feature="renode"))] #[cfg(any(feature = "precursor", feature = "renode"))]
wfi_kernel_csr.wfo(utra::wfi::IGNORE_LOCKED_IGNORE_LOCKED, 1); wfi_kernel_csr.wfo(utra::wfi::IGNORE_LOCKED_IGNORE_LOCKED, 1);
unsafe { unsafe {
@ -64,17 +64,17 @@ pub fn init() {
/// Put the core to sleep until an interrupt hits. Returns `true` /// Put the core to sleep until an interrupt hits. Returns `true`
/// to indicate the kernel should not exit. /// to indicate the kernel should not exit.
pub fn idle() -> bool { pub fn idle() -> bool {
#[cfg(any(feature="precursor", feature="renode"))]
let mut wfi_kernel_csr = CSR::new(WFI_KERNEL.base as *mut u32);
// Issue `wfi`. This will return as soon as an external interrupt // Issue `wfi`. This will return as soon as an external interrupt
// is available. // is available.
#[cfg(any(feature="cramium-fpga", feature="cramium-soc"))] #[cfg(any(feature = "cramium-fpga", feature = "cramium-soc", feature = "renode"))]
// "traditional" path for stopping a clock // "traditional" path for stopping a clock
unsafe { riscv::asm::wfi() }; unsafe {
riscv::asm::wfi()
};
#[cfg(any(feature="precursor", feature="renode"))] #[cfg(any(feature = "precursor"))]
{ {
let mut wfi_kernel_csr = CSR::new(WFI_KERNEL.base as *mut u32);
// this invokes Precusor-SoC specific path to gate clocks: // this invokes Precusor-SoC specific path to gate clocks:
// 1. ignore_locked prevents the chip from going into reset if the PLL goes unlocked // 1. ignore_locked prevents the chip from going into reset if the PLL goes unlocked
wfi_kernel_csr.wfo(utra::wfi::IGNORE_LOCKED_IGNORE_LOCKED, 1); wfi_kernel_csr.wfo(utra::wfi::IGNORE_LOCKED_IGNORE_LOCKED, 1);