diff --git a/emulation/peripherals/spinor_soft_int.cs b/emulation/peripherals/spinor_soft_int.cs new file mode 100644 index 000000000..b56f54562 --- /dev/null +++ b/emulation/peripherals/spinor_soft_int.cs @@ -0,0 +1,94 @@ +// +// Copyright (c) 2010-2018 Antmicro +// Copyright (c) 2011-2015 Realtime Embedded +// +// This file is licensed under the MIT License. +// Full license text is available in 'licenses/MIT.txt'. +// +using System; +using System.Threading; +using System.Text; +using System.Linq; +using System.Globalization; +using System.Numerics; +using Antmicro.Renode.Core; +using Antmicro.Renode.Core.Structure.Registers; +using Antmicro.Renode.Logging; +using Antmicro.Renode.Peripherals.Bus; + +namespace Antmicro.Renode.Peripherals.Miscellaneous +{ + + public class SpinorSoftInt : IDoubleWordPeripheral, IProvidesRegisterCollection, IKnownSize + { + public SpinorSoftInt(Machine machine) + { + this.RegistersCollection = new DoubleWordRegisterCollection(this); + this.IRQ = new GPIO(); + DefineRegisters(); + Reset(); + } + + private void DefineRegisters() + { + Registers.EV_STATUS.Define32(this) + .WithFlag(0, FieldMode.Read, name: "SOFTINT", valueProviderCallback: _ => softintStatus) + ; + + Registers.EV_PENDING.Define32(this) + .WithFlag(0, out this.softintPending, FieldMode.Read | FieldMode.WriteOneToClear, name: "SOFTINT", changeCallback: (_, __) => UpdateInterrupts()) + ; + + Registers.EV_ENABLE.Define32(this) + .WithFlag(0, out this.softintEnabled, name: "SOFTINT", changeCallback: (_, __) => UpdateInterrupts()) + ; + + Registers.SOFTINT.Define32(this) + .WithFlag(0, writeCallback: (_, val) => { if (val) { this.softintStatus = true; UpdateInterrupts(); this.softintStatus = false; } }) + ; + } + + private void UpdateInterrupts() + { + if (this.softintStatus) + { + this.softintPending.Value = true; + } + IRQ.Set(this.softintPending.Value && this.softintEnabled.Value); + } + + public void WriteDoubleWord(long address, uint value) + { + RegistersCollection.Write(address, value); + } + + public uint ReadDoubleWord(long offset) + { + return RegistersCollection.Read(offset); + } + + public long Size { get { return 4096; } } + public DoubleWordRegisterCollection RegistersCollection { get; private set; } + + public void Reset() + { + this.softintStatus = false; + this.softintPending.Value = false; + this.softintEnabled.Value = false; + } + + public GPIO IRQ { get; private set; } + + private IFlagRegisterField softintEnabled; + private IFlagRegisterField softintPending; + private bool softintStatus; + + private enum Registers + { + EV_STATUS = 0x00, + EV_PENDING = 0x04, + EV_ENABLE = 0x08, + SOFTINT = 0x0c + } + } +} diff --git a/emulation/peripherals/wfi.cs b/emulation/peripherals/wfi.cs new file mode 100644 index 000000000..fc49c92e7 --- /dev/null +++ b/emulation/peripherals/wfi.cs @@ -0,0 +1,69 @@ +// +// Copyright (c) 2010-2018 Antmicro +// Copyright (c) 2011-2015 Realtime Embedded +// +// This file is licensed under the MIT License. +// Full license text is available in 'licenses/MIT.txt'. +// +using System; +using System.Threading; +using System.Text; +using System.Linq; +using System.Globalization; +using System.Numerics; +using Antmicro.Renode.Core; +using Antmicro.Renode.Core.Structure.Registers; +using Antmicro.Renode.Logging; +using Antmicro.Renode.Peripherals.Bus; +using Antmicro.Renode.Utilities.Binding; + +namespace Antmicro.Renode.Peripherals.Miscellaneous +{ + + public class BetrustedWfi : IDoubleWordPeripheral, IProvidesRegisterCollection, IKnownSize + { + [Import] + private Action TlibEnterWfi; + + public BetrustedWfi(Machine machine) + { + this.RegistersCollection = new DoubleWordRegisterCollection(this); + DefineRegisters(); + Reset(); + } + + private void DefineRegisters() + { + Registers.WFI.Define32(this) + .WithFlag(0, writeCallback: (_, val) => { if (val) { /*TlibEnterWfi(); */ } }) + ; + + Registers.IGNORE_LOCKED.Define32(this) + .WithFlag(0, name: "IGNORE_LOCKED", changeCallback: (_, __) => { }) + ; + } + + public void WriteDoubleWord(long address, uint value) + { + RegistersCollection.Write(address, value); + } + + public uint ReadDoubleWord(long offset) + { + return RegistersCollection.Read(offset); + } + + public long Size { get { return 4096; } } + public DoubleWordRegisterCollection RegistersCollection { get; private set; } + + public void Reset() + { + } + + private enum Registers + { + WFI = 0x00, + IGNORE_LOCKED = 0x04 + } + } +} diff --git a/emulation/xous-release.resc b/emulation/xous-release.resc index 6d372ba28..344f0596f 100644 --- a/emulation/xous-release.resc +++ b/emulation/xous-release.resc @@ -16,9 +16,11 @@ i @peripherals/keyrom.cs i @peripherals/LiteX_Timer_32.cs i @peripherals/memlcd.cs i @peripherals/sha512.cs +i @peripherals/spinor_soft_int.cs i @peripherals/ticktimer.cs i @peripherals/trng_kernel.cs i @peripherals/trng_server.cs +i @peripherals/wfi.cs ############### Define the Betrusted SoC ############### mach create "SoC" diff --git a/svd2repl/src/generate.rs b/svd2repl/src/generate.rs index 4146b186a..305ed89e3 100644 --- a/svd2repl/src/generate.rs +++ b/svd2repl/src/generate.rs @@ -638,11 +638,13 @@ pub fn generate(src: T, dest: &mut U) -> Result<(), ParseErro cs_peripherals.insert("keyrom", "Miscellaneous.Keyrom"); cs_peripherals.insert("memlcd", "Video.BetrustedLCD"); cs_peripherals.insert("sha512", "Miscellaneous.Sha512"); + cs_peripherals.insert("spinor_soft_int", "Miscellaneous.SpinorSoftInt"); cs_peripherals.insert("timer0", "Timers.LiteX_Timer_32"); cs_peripherals.insert("trng_kernel", "Miscellaneous.BetrustedRNGKernel"); cs_peripherals.insert("trng_server", "Miscellaneous.BetrustedRNGServer"); cs_peripherals.insert("ticktimer", "Timers.TickTimer"); cs_peripherals.insert("uart", "UART.LiteX_UART"); + cs_peripherals.insert("wfi", "Miscellaneous.BetrustedWfi"); print_header(dest).or(Err(ParseError::WriteError))?; print_peripherals(