mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-22 09:23:16 +00:00
emulation: connect EC
Connect the EC to the SoC. This allows for emulating both the EC and SoC in tandem. Messages flow via a 16-bit bus. When data is not available, `0xdddd` is returned. There is a HOLD line that goes from the EC to the SoC. This is tied to the inverse of presence of data in the EC FIFO -- when it's empty, HOLD is `1`, and when there is data it's `0`. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
fbbb2120ab
commit
49e1eb19c0
12 changed files with 553 additions and 516 deletions
|
|
@ -19,17 +19,29 @@ i2c: I2C.BetrustedEcI2C @ sysbus 0xE0004800
|
||||||
ticktimer: Timers.TickTimer @ sysbus 0xe0005000
|
ticktimer: Timers.TickTimer @ sysbus 0xe0005000
|
||||||
-> cpu @ 1003
|
-> cpu @ 1003
|
||||||
|
|
||||||
|
com: SPI.BetrustedEcCom @ sysbus 0xe0005800
|
||||||
|
memAddr: 0xD0000000
|
||||||
|
memSize: 0x1000
|
||||||
|
|
||||||
sram: Memory.MappedMemory @ {
|
sram: Memory.MappedMemory @ {
|
||||||
sysbus 0x10000000;
|
sysbus 0x10000000;
|
||||||
sysbus 0x90000000 // shadow
|
sysbus 0x90000000 // shadow
|
||||||
}
|
}
|
||||||
size: 0x00020000
|
size: 0x00020000
|
||||||
|
|
||||||
|
power: Miscellaneous.EcPower @ sysbus 0xE0002800
|
||||||
|
|
||||||
|
rom: Memory.MappedMemory @ {
|
||||||
|
sysbus 0x00000000;
|
||||||
|
sysbus 0x80000000 // shadow
|
||||||
|
}
|
||||||
|
size: 0x00002000
|
||||||
|
|
||||||
flash_mem: Memory.MappedMemory @ {
|
flash_mem: Memory.MappedMemory @ {
|
||||||
sysbus 0x20000000;
|
sysbus 0x20000000;
|
||||||
sysbus 0xA0000000 // shadow
|
sysbus 0xA0000000 // shadow
|
||||||
}
|
}
|
||||||
size: 0x8000000
|
size: 0x00100000
|
||||||
|
|
||||||
lm3509: Mocks.LM3509 @ i2c 0x36
|
lm3509: Mocks.LM3509 @ i2c 0x36
|
||||||
tusb320lai: Mocks.TUSB320LAI @ i2c 0x47
|
tusb320lai: Mocks.TUSB320LAI @ i2c 0x47
|
||||||
|
|
|
||||||
BIN
emulation/ec/bt-ec.bin
Normal file
BIN
emulation/ec/bt-ec.bin
Normal file
Binary file not shown.
Binary file not shown.
BIN
emulation/ec/loader.bin
Normal file
BIN
emulation/ec/loader.bin
Normal file
Binary file not shown.
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<device schemaVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" >
|
<device schemaVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" >
|
||||||
<vendor>litex</vendor>
|
<vendor>litex</vendor>
|
||||||
<name>SOC</name>
|
<name>EC</name>
|
||||||
<description>Betrusted EC</description>
|
<description>Betrusted EC</description>
|
||||||
<addressUnitBits>8</addressUnitBits>
|
<addressUnitBits>8</addressUnitBits>
|
||||||
<width>32</width>
|
<width>32</width>
|
||||||
|
|
@ -261,10 +261,10 @@ Notably, a watchdog reset will disable the watchdog.]]></description>
|
||||||
<register>
|
<register>
|
||||||
<name>GITREV</name>
|
<name>GITREV</name>
|
||||||
<description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev
|
<description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev
|
||||||
``03ba1c49``, so this value is 62528585, which should be enough to check out the
|
``b565873d``, so this value is 3043329853, which should be enough to check out
|
||||||
exact git version used to build this firmware.]]></description>
|
the exact git version used to build this firmware.]]></description>
|
||||||
<addressOffset>0x0000</addressOffset>
|
<addressOffset>0x0000</addressOffset>
|
||||||
<resetValue>0x3ba1c49</resetValue>
|
<resetValue>0xb565873d</resetValue>
|
||||||
<size>32</size>
|
<size>32</size>
|
||||||
<fields>
|
<fields>
|
||||||
<field>
|
<field>
|
||||||
|
|
@ -324,18 +324,10 @@ modifications.]]></description>
|
||||||
<description><![CDATA[Writing `1` to this powers on the SoC]]></description>
|
<description><![CDATA[Writing `1` to this powers on the SoC]]></description>
|
||||||
</field>
|
</field>
|
||||||
<field>
|
<field>
|
||||||
<name>discharge</name>
|
<name>kbddrive</name>
|
||||||
<msb>2</msb>
|
<msb>2</msb>
|
||||||
<bitRange>[2:2]</bitRange>
|
<bitRange>[2:2]</bitRange>
|
||||||
<lsb>2</lsb>
|
<lsb>2</lsb>
|
||||||
<description><![CDATA[Writing `1` to this connects a low-value resistor across FPGA domain supplies to
|
|
||||||
force a full discharge]]></description>
|
|
||||||
</field>
|
|
||||||
<field>
|
|
||||||
<name>kbddrive</name>
|
|
||||||
<msb>3</msb>
|
|
||||||
<bitRange>[3:3]</bitRange>
|
|
||||||
<lsb>3</lsb>
|
|
||||||
<description><![CDATA[Writing `1` to this drives the scan column to 1. Do this prior to reading to
|
<description><![CDATA[Writing `1` to this drives the scan column to 1. Do this prior to reading to
|
||||||
mitigate noise]]></description>
|
mitigate noise]]></description>
|
||||||
</field>
|
</field>
|
||||||
|
|
|
||||||
505
emulation/peripherals/Com.cs
Normal file
505
emulation/peripherals/Com.cs
Normal file
|
|
@ -0,0 +1,505 @@
|
||||||
|
//
|
||||||
|
// Copyright (c) 2010-2021 Antmicro
|
||||||
|
//
|
||||||
|
// This file is licensed under the MIT License.
|
||||||
|
// Full license text is available in 'licenses/MIT.txt'.
|
||||||
|
//
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Antmicro.Renode.Core;
|
||||||
|
using Antmicro.Renode.Core.Structure;
|
||||||
|
using Antmicro.Renode.Exceptions;
|
||||||
|
using Antmicro.Renode.Logging;
|
||||||
|
using Antmicro.Renode.Time;
|
||||||
|
using Antmicro.Renode.Utilities;
|
||||||
|
using Antmicro.Renode.Peripherals.Bus;
|
||||||
|
using Antmicro.Renode.Core.Structure.Registers;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
|
namespace Antmicro.Renode.Peripherals.SPI
|
||||||
|
{
|
||||||
|
public interface IComPeripheral : IPeripheral, IInterestingType
|
||||||
|
{
|
||||||
|
ushort Transmit(ushort data);
|
||||||
|
void FinishTransmission();
|
||||||
|
}
|
||||||
|
public interface IComController : IPeripheral, IInterestingType, IGPIOReceiver
|
||||||
|
{
|
||||||
|
ushort Transmit(ushort data);
|
||||||
|
void FinishTransmission();
|
||||||
|
}
|
||||||
|
public static class ComConnectorExtensions
|
||||||
|
{
|
||||||
|
public static void CreateComConnector(this Emulation emulation, string name)
|
||||||
|
{
|
||||||
|
emulation.ExternalsManager.AddExternal(new BetrustedComConnector(), name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This class is responsible for synchronizing communication between the EC and SoC.
|
||||||
|
// Note that the "Controller" is the SoC side and the "Peripheral" is the EC side.
|
||||||
|
public class BetrustedComConnector : IExternal, IComController, IConnectable<IComPeripheral>, IConnectable<NullRegistrationPointPeripheralContainer<IComController>>, IGPIOReceiver
|
||||||
|
{
|
||||||
|
public BetrustedComConnector()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AttachTo(NullRegistrationPointPeripheralContainer<IComController> controller)
|
||||||
|
{
|
||||||
|
lock (locker)
|
||||||
|
{
|
||||||
|
if (controller == this.controller)
|
||||||
|
{
|
||||||
|
throw new RecoverableException("Cannot attach to the provided peripheral as it is already registered in this connector.");
|
||||||
|
}
|
||||||
|
else if (this.controller != null)
|
||||||
|
{
|
||||||
|
this.Log(LogLevel.Warning, "Overwriting controller connection.");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.controller?.Unregister(this);
|
||||||
|
this.controller = controller;
|
||||||
|
this.controller.Register(this, NullRegistrationPoint.Instance);
|
||||||
|
foreach (var gpio in controller.GetGPIOs())
|
||||||
|
{
|
||||||
|
if (gpio.Item1 == "HOLD")
|
||||||
|
{
|
||||||
|
this.holdGpio = gpio.Item2;
|
||||||
|
}
|
||||||
|
if (gpio.Item1 == "INTERRUPT")
|
||||||
|
{
|
||||||
|
this.interruptGpio = gpio.Item2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AttachTo(IComPeripheral peripheral)
|
||||||
|
{
|
||||||
|
lock (locker)
|
||||||
|
{
|
||||||
|
if (peripheral == this.peripheral)
|
||||||
|
{
|
||||||
|
throw new RecoverableException("Cannot attach to the provided peripheral as it is already registered in this connector.");
|
||||||
|
}
|
||||||
|
else if (this.peripheral != null)
|
||||||
|
{
|
||||||
|
this.Log(LogLevel.Warning, "Overwriting peripheral connection.");
|
||||||
|
}
|
||||||
|
this.peripheral = peripheral;
|
||||||
|
foreach (var gpio in peripheral.GetGPIOs())
|
||||||
|
{
|
||||||
|
if (gpio.Item1 == "Hold")
|
||||||
|
{
|
||||||
|
gpio.Item2.Connect(this, 0);
|
||||||
|
}
|
||||||
|
else if (gpio.Item1 == "Interrupt")
|
||||||
|
{
|
||||||
|
gpio.Item2.Connect(this, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DetachFrom(NullRegistrationPointPeripheralContainer<IComController> controller)
|
||||||
|
{
|
||||||
|
lock (locker)
|
||||||
|
{
|
||||||
|
if (controller == this.controller)
|
||||||
|
{
|
||||||
|
this.controller.Unregister(this);
|
||||||
|
this.controller = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new RecoverableException("Cannot detach from the provided controller as it is not registered in this connector.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DetachFrom(IComPeripheral peripheral)
|
||||||
|
{
|
||||||
|
lock (locker)
|
||||||
|
{
|
||||||
|
if (peripheral == this.peripheral)
|
||||||
|
{
|
||||||
|
foreach (var gpio in peripheral.GetGPIOs())
|
||||||
|
{
|
||||||
|
if (gpio.Item1 == "Hold")
|
||||||
|
{
|
||||||
|
gpio.Item2.Disconnect();
|
||||||
|
}
|
||||||
|
else if (gpio.Item1 == "Interrupt")
|
||||||
|
{
|
||||||
|
gpio.Item2.Disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
peripheral = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new RecoverableException("Cannot detach from the provided peripheral as it is not registered in this connector.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnGPIO(int number, bool value)
|
||||||
|
{
|
||||||
|
if (number == 0)
|
||||||
|
{
|
||||||
|
// "Hold" pin
|
||||||
|
if (holdGpio != null)
|
||||||
|
{
|
||||||
|
// controller.GetMachine().HandleTimeDomainEvent(holdGpio.Set, value, new TimeStamp(default(TimeInterval), EmulationManager.ExternalWorld));
|
||||||
|
controller.GetMachine().HandleTimeDomainEvent(holdGpio.Set, value, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (number == 1)
|
||||||
|
{
|
||||||
|
// "Interrupt" pin
|
||||||
|
if (interruptGpio != null)
|
||||||
|
{
|
||||||
|
// controller.GetMachine().HandleTimeDomainEvent(holdGpio.Set, value, new TimeStamp(default(TimeInterval), EmulationManager.ExternalWorld));
|
||||||
|
controller.GetMachine().HandleTimeDomainEvent(holdGpio.Set, value, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ushort Transmit(ushort data)
|
||||||
|
{
|
||||||
|
lock (locker)
|
||||||
|
{
|
||||||
|
if (peripheral == null)
|
||||||
|
{
|
||||||
|
this.Log(LogLevel.Warning, "Controller sent data (0x{0:X}), but peripheral is not connected.", data);
|
||||||
|
return 0xDDDD;
|
||||||
|
}
|
||||||
|
// We don't use a separate time domain here because the peripheral's output is buffered and we
|
||||||
|
// want it to operate at the same speed as the host. If we used a separate time domain then there would
|
||||||
|
// be gaps in the buffer, whereas the real hardware will have no gaps.
|
||||||
|
return peripheral.Transmit(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void FinishTransmission()
|
||||||
|
{
|
||||||
|
lock (locker)
|
||||||
|
{
|
||||||
|
peripheral.GetMachine().HandleTimeDomainEvent<object>(_ => peripheral.FinishTransmission(), null, TimeDomainsManager.Instance.VirtualTimeStamp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private NullRegistrationPointPeripheralContainer<IComController> controller;
|
||||||
|
private IComPeripheral peripheral;
|
||||||
|
private IGPIO holdGpio;
|
||||||
|
private IGPIO interruptGpio;
|
||||||
|
private readonly object locker = new object();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BetrustedEcRam : IDoubleWordPeripheral, IKnownSize
|
||||||
|
{
|
||||||
|
public BetrustedEcRam(Machine machine, BetrustedEcCom spi, long size)
|
||||||
|
{
|
||||||
|
this.machine = machine;
|
||||||
|
this.spi = spi;
|
||||||
|
this.size = size;
|
||||||
|
// Hardware defaults to 1280 entries
|
||||||
|
readFifo = new ConcurrentQueue<uint>();
|
||||||
|
writeFifo = new ConcurrentQueue<uint>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Machine machine;
|
||||||
|
private BetrustedEcCom spi;
|
||||||
|
private long size;
|
||||||
|
private ConcurrentQueue<uint> readFifo;
|
||||||
|
private ConcurrentQueue<uint> writeFifo;
|
||||||
|
public long Size { get { return size; } }
|
||||||
|
|
||||||
|
public bool WriteNextWord(uint value)
|
||||||
|
{
|
||||||
|
readFifo.Enqueue(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ReadFifoHasData()
|
||||||
|
{
|
||||||
|
return !readFifo.IsEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ReadFifoCount()
|
||||||
|
{
|
||||||
|
return readFifo.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GetNextWord(out uint value)
|
||||||
|
{
|
||||||
|
bool have_data = writeFifo.TryDequeue(out value);
|
||||||
|
return have_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int WriteFifoCount()
|
||||||
|
{
|
||||||
|
return writeFifo.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool WriteFifoHasData()
|
||||||
|
{
|
||||||
|
return !writeFifo.IsEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteDoubleWord(long address, uint value)
|
||||||
|
{
|
||||||
|
if (address == 0)
|
||||||
|
{
|
||||||
|
// machine.Log(LogLevel.Error, "EC queueing word: {0:X4}", value);
|
||||||
|
writeFifo.Enqueue(value);
|
||||||
|
spi.Hold.Set(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
machine.Log(LogLevel.Error, "Write to unsupported address: {}", address);
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint ReadDoubleWord(long address)
|
||||||
|
{
|
||||||
|
uint ret = 0;
|
||||||
|
if ((address == 0) && readFifo.TryDequeue(out ret))
|
||||||
|
{
|
||||||
|
// machine.Log(LogLevel.Error, "EC received word: {0:X4}", ret);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// machine.Log(LogLevel.Error, "Read double word, but have no data");
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
readFifo = new ConcurrentQueue<uint>();
|
||||||
|
writeFifo = new ConcurrentQueue<uint>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BetrustedEcCom : IComPeripheral, IDoubleWordPeripheral, IKnownSize, IProvidesRegisterCollection<DoubleWordRegisterCollection>, IGPIOSender
|
||||||
|
{
|
||||||
|
|
||||||
|
public BetrustedEcCom(Machine machine, uint memAddr, uint memSize)
|
||||||
|
{
|
||||||
|
Hold = new GPIO();
|
||||||
|
Interrupt = new GPIO();
|
||||||
|
EcRam = new BetrustedEcRam(machine, this, memSize);
|
||||||
|
machine.SystemBus.Register(EcRam, new BusRangeRegistration(memAddr, memSize));
|
||||||
|
|
||||||
|
RegistersCollection = new DoubleWordRegisterCollection(this);
|
||||||
|
Registers.ComControl.Define32(this)
|
||||||
|
.WithFlag(0, FieldMode.Write, name: "CLRERR")
|
||||||
|
.WithFlag(1, FieldMode.Write, writeCallback: (_, val) => Interrupt.Set(val), name: "HOST_INT")
|
||||||
|
.WithFlag(2, FieldMode.Write, writeCallback: (_, val) =>
|
||||||
|
{
|
||||||
|
if (!val)
|
||||||
|
return;
|
||||||
|
machine.Log(LogLevel.Debug, "Resetting FIFO due to RESET bit being set");
|
||||||
|
Reset();
|
||||||
|
}, name: "RESET")
|
||||||
|
;
|
||||||
|
|
||||||
|
Registers.ComStatus.Define32(this)
|
||||||
|
.WithFlag(0, FieldMode.Read, valueProviderCallback: (_) => false, name: "TIP")
|
||||||
|
.WithFlag(1, FieldMode.Read, valueProviderCallback: (_) => EcRam.ReadFifoHasData(), name: "RX_AVAIL")
|
||||||
|
.WithFlag(2, FieldMode.Read, valueProviderCallback: (_) => EcRam.ReadFifoCount() >= 1280, name: "RX_OVER")
|
||||||
|
.WithFlag(3, FieldMode.Read, valueProviderCallback: (_) => EcRam.ReadFifoCount() == 0, name: "RX_UNDER")
|
||||||
|
.WithValueField(4, 12, FieldMode.Read, valueProviderCallback: (_) => (uint)EcRam.ReadFifoCount(), name: "RX_LEVEL")
|
||||||
|
.WithFlag(16, FieldMode.Read, valueProviderCallback: (_) => EcRam.WriteFifoHasData(), name: "TX_AVAIL")
|
||||||
|
.WithFlag(17, FieldMode.Read, valueProviderCallback: (_) => EcRam.WriteFifoCount() == 0, name: "TX_EMPTY")
|
||||||
|
.WithValueField(18, 12, FieldMode.Read, valueProviderCallback: (_) => (uint)EcRam.WriteFifoCount(), name: "TX_LEVEL")
|
||||||
|
.WithFlag(30, FieldMode.Read, valueProviderCallback: (_) => EcRam.WriteFifoCount() >= 1280, name: "TX_OVER")
|
||||||
|
.WithFlag(31, FieldMode.Read, valueProviderCallback: (_) => false, name: "TX_UNDER")
|
||||||
|
;
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteDoubleWord(long address, uint value)
|
||||||
|
{
|
||||||
|
RegistersCollection.Write(address, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint ReadDoubleWord(long offset)
|
||||||
|
{
|
||||||
|
return RegistersCollection.Read(offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ushort Transmit(ushort value)
|
||||||
|
{
|
||||||
|
uint TxValue;
|
||||||
|
if (!EcRam.GetNextWord(out TxValue))
|
||||||
|
{
|
||||||
|
TxValue = 0xDDDD;
|
||||||
|
}
|
||||||
|
this.Log(LogLevel.Debug, "EC received:{0:X4} sent:{1:X4}", value, TxValue);
|
||||||
|
Hold.Set(!EcRam.WriteFifoHasData());
|
||||||
|
EcRam.WriteNextWord((ushort)value);
|
||||||
|
// this.Log(LogLevel.Info, "EcRam.ReadFifo now contains {0} items, EcRam.WriteFifo contains {1} items", EcRam.ReadFifoCount(), EcRam.WriteFifoCount());
|
||||||
|
return (ushort)(TxValue & 0xffff);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void FinishTransmission()
|
||||||
|
{
|
||||||
|
// this.Log(LogLevel.Info, "EC finished transmission");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
EcRam.Reset();
|
||||||
|
Hold.Set(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long Size { get { return 0x100; } }
|
||||||
|
private uint TxValue;
|
||||||
|
private BetrustedEcRam EcRam;
|
||||||
|
public GPIO Hold { get; }
|
||||||
|
public GPIO Interrupt { get; }
|
||||||
|
public DoubleWordRegisterCollection RegistersCollection { get; private set; }
|
||||||
|
|
||||||
|
private enum Registers
|
||||||
|
{
|
||||||
|
ComControl = 0x00,
|
||||||
|
|
||||||
|
ComStatus = 0x04,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BetrustedSocCom : NullRegistrationPointPeripheralContainer<IComController>, IDoubleWordPeripheral, IProvidesRegisterCollection<DoubleWordRegisterCollection>, IKnownSize
|
||||||
|
{
|
||||||
|
public BetrustedSocCom(Machine machine) : base(machine)
|
||||||
|
{
|
||||||
|
IRQ = new GPIO();
|
||||||
|
HOLD = new GPIO();
|
||||||
|
RegistersCollection = new DoubleWordRegisterCollection(this);
|
||||||
|
|
||||||
|
Registers.ComTx.Define32(this)
|
||||||
|
.WithValueField(0, 16, FieldMode.Write, writeCallback: (_, val) =>
|
||||||
|
{
|
||||||
|
// Skip transaction if HOLD is set
|
||||||
|
// if (AutoHold.Value && (HOLD && HOLD.IsSet)
|
||||||
|
// {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
Rx.Value = (uint)RegisteredPeripheral.Transmit((ushort)val);
|
||||||
|
RegisteredPeripheral.FinishTransmission();
|
||||||
|
machine.Log(LogLevel.Debug, "SoC sent {0:X4} received {1:X4}", val, Rx.Value);
|
||||||
|
if (IntEna.Value)
|
||||||
|
{
|
||||||
|
SpiIntStatus.Value = true;
|
||||||
|
UpdateInterrupts();
|
||||||
|
SpiIntStatus.Value = false;
|
||||||
|
}
|
||||||
|
}, name: "TX")
|
||||||
|
;
|
||||||
|
|
||||||
|
Registers.ComRx.Define32(this)
|
||||||
|
.WithValueField(0, 16, out Rx, FieldMode.Read, name: "RX")
|
||||||
|
;
|
||||||
|
|
||||||
|
Registers.ComControl.Define32(this)
|
||||||
|
.WithFlag(0, out IntEna, FieldMode.Read | FieldMode.Write, name: "IntEna")
|
||||||
|
.WithFlag(1, out AutoHold, FieldMode.Read | FieldMode.Write, name: "AutoHold")
|
||||||
|
;
|
||||||
|
Registers.ComStatus.Define32(this)
|
||||||
|
.WithFlag(0, out Tip, FieldMode.Read, name: "Tip")
|
||||||
|
.WithFlag(1, FieldMode.Read, valueProviderCallback: (_) => HOLD.IsSet, name: "Hold")
|
||||||
|
;
|
||||||
|
|
||||||
|
Registers.ComEvStatus.Define32(this)
|
||||||
|
.WithFlag(0, out SpiIntStatus, FieldMode.Read, name: "SpiInt")
|
||||||
|
.WithFlag(1, FieldMode.Read, valueProviderCallback: (_) => HOLD.IsSet, name: "SpiHold")
|
||||||
|
;
|
||||||
|
|
||||||
|
Registers.ComEvPending.Define32(this)
|
||||||
|
.WithFlag(0, out SpiIntPending, FieldMode.Read | FieldMode.WriteOneToClear, name: "SpiInt", changeCallback: (_, __) => UpdateInterrupts())
|
||||||
|
.WithFlag(1, out SpiHoldPending, FieldMode.Read | FieldMode.WriteOneToClear, name: "SpiHold", changeCallback: (_, __) => UpdateInterrupts())
|
||||||
|
;
|
||||||
|
|
||||||
|
Registers.ComEvEnable.Define32(this)
|
||||||
|
.WithFlag(0, out SpiIntEnable, name: "SpiInt", changeCallback: (_, __) => UpdateInterrupts())
|
||||||
|
.WithFlag(1, out SpiHoldEnable, name: "SpiHold", changeCallback: (_, __) => UpdateInterrupts())
|
||||||
|
;
|
||||||
|
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateInterrupts()
|
||||||
|
{
|
||||||
|
// if (RegisteredPeripheral.Interrupt())
|
||||||
|
// {
|
||||||
|
// SpiIntPending.Value = true;
|
||||||
|
// }
|
||||||
|
if (HOLD.IsSet)
|
||||||
|
{
|
||||||
|
SpiHoldPending.Value = true;
|
||||||
|
}
|
||||||
|
IRQ.Set((SpiIntPending.Value && SpiIntEnable.Value)
|
||||||
|
|| (SpiHoldPending.Value && SpiHoldEnable.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteDoubleWord(long address, uint value)
|
||||||
|
{
|
||||||
|
RegistersCollection.Write(address, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint ReadDoubleWord(long offset)
|
||||||
|
{
|
||||||
|
return RegistersCollection.Read(offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Reset()
|
||||||
|
{
|
||||||
|
// IntEna.Value = false;
|
||||||
|
// AutoHold.Value = false;
|
||||||
|
// Tip.Value = false;
|
||||||
|
// Rx.Value = 0;
|
||||||
|
|
||||||
|
SpiIntStatus.Value = false;
|
||||||
|
SpiIntPending.Value = false;
|
||||||
|
SpiHoldPending.Value = false;
|
||||||
|
SpiIntEnable.Value = false;
|
||||||
|
SpiHoldEnable.Value = false;
|
||||||
|
|
||||||
|
Tip.Value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public long Size { get { return 0x100; } }
|
||||||
|
|
||||||
|
public GPIO IRQ { get; private set; }
|
||||||
|
public GPIO HOLD { get; private set; }
|
||||||
|
|
||||||
|
private IFlagRegisterField IntEna;
|
||||||
|
private IFlagRegisterField AutoHold;
|
||||||
|
private IFlagRegisterField Tip;
|
||||||
|
private IValueRegisterField Rx;
|
||||||
|
|
||||||
|
// Interrupts
|
||||||
|
private IFlagRegisterField SpiIntStatus;
|
||||||
|
private IFlagRegisterField SpiIntPending;
|
||||||
|
private IFlagRegisterField SpiHoldPending;
|
||||||
|
private IFlagRegisterField SpiIntEnable;
|
||||||
|
private IFlagRegisterField SpiHoldEnable;
|
||||||
|
|
||||||
|
public DoubleWordRegisterCollection RegistersCollection { get; private set; }
|
||||||
|
|
||||||
|
private enum Registers
|
||||||
|
{
|
||||||
|
ComTx = 0x00,
|
||||||
|
|
||||||
|
ComRx = 0x04,
|
||||||
|
ComControl = 0x08,
|
||||||
|
ComStatus = 0x0c,
|
||||||
|
ComEvStatus = 0x10,
|
||||||
|
ComEvPending = 0x14,
|
||||||
|
ComEvEnable = 0x18,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,137 +0,0 @@
|
||||||
//
|
|
||||||
// Copyright (c) 2010-2021 Antmicro
|
|
||||||
//
|
|
||||||
// This file is licensed under the MIT License.
|
|
||||||
// Full license text is available in 'licenses/MIT.txt'.
|
|
||||||
//
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Antmicro.Renode.Core;
|
|
||||||
using Antmicro.Renode.Core.Structure;
|
|
||||||
using Antmicro.Renode.Exceptions;
|
|
||||||
using Antmicro.Renode.Logging;
|
|
||||||
using Antmicro.Renode.Time;
|
|
||||||
using Antmicro.Renode.Utilities;
|
|
||||||
|
|
||||||
namespace Antmicro.Renode.Peripherals.EC
|
|
||||||
{
|
|
||||||
public interface IECPeripheral : IPeripheral, IEmulationElement, IInterestingType, IAnalyzable
|
|
||||||
{
|
|
||||||
void FinishTransmission();
|
|
||||||
ushort Transmit(ushort data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ECConnectorExtensions
|
|
||||||
{
|
|
||||||
public static void CreateECConnector(this Emulation emulation, string name)
|
|
||||||
{
|
|
||||||
emulation.ExternalsManager.AddExternal(new ECConnector(), name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ECConnector : IExternal, IECPeripheral, IConnectable<IECPeripheral>, IConnectable<NullRegistrationPointPeripheralContainer<IECPeripheral>>
|
|
||||||
{
|
|
||||||
public void Reset()
|
|
||||||
{
|
|
||||||
peripheralOutput.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AttachTo(NullRegistrationPointPeripheralContainer<IECPeripheral> controller)
|
|
||||||
{
|
|
||||||
lock(locker)
|
|
||||||
{
|
|
||||||
if(controller == this.controller)
|
|
||||||
{
|
|
||||||
throw new RecoverableException("Cannot attach to the provided peripheral as it is already registered in this connector.");
|
|
||||||
}
|
|
||||||
else if(this.controller != null)
|
|
||||||
{
|
|
||||||
this.Log(LogLevel.Warning, "Overwriting controller connection.");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.controller?.Unregister(this);
|
|
||||||
this.controller = controller;
|
|
||||||
this.controller.Register(this, NullRegistrationPoint.Instance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AttachTo(IECPeripheral peripheral)
|
|
||||||
{
|
|
||||||
lock(locker)
|
|
||||||
{
|
|
||||||
if(peripheral == this.peripheral)
|
|
||||||
{
|
|
||||||
throw new RecoverableException("Cannot attach to the provided peripheral as it is already registered in this connector.");
|
|
||||||
}
|
|
||||||
else if(this.peripheral != null)
|
|
||||||
{
|
|
||||||
this.Log(LogLevel.Warning, "Overwriting peripheral connection.");
|
|
||||||
}
|
|
||||||
this.peripheral = peripheral;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DetachFrom(NullRegistrationPointPeripheralContainer<IECPeripheral> controller)
|
|
||||||
{
|
|
||||||
lock(locker)
|
|
||||||
{
|
|
||||||
if(controller == this.controller)
|
|
||||||
{
|
|
||||||
this.controller.Unregister(this);
|
|
||||||
this.controller = null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new RecoverableException("Cannot detach from the provided controller as it is not registered in this connector.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DetachFrom(IECPeripheral peripheral)
|
|
||||||
{
|
|
||||||
lock(locker)
|
|
||||||
{
|
|
||||||
if(peripheral == this.peripheral)
|
|
||||||
{
|
|
||||||
peripheral = null;
|
|
||||||
peripheralOutput.Clear();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new RecoverableException("Cannot detach from the provided peripheral as it is not registered in this connector.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ushort Transmit(ushort data)
|
|
||||||
{
|
|
||||||
lock(locker)
|
|
||||||
{
|
|
||||||
if(peripheral == null)
|
|
||||||
{
|
|
||||||
this.Log(LogLevel.Warning, "Controller sent data (0x{0:X}), but peripheral is not connected.", data);
|
|
||||||
return 0x0;
|
|
||||||
}
|
|
||||||
peripheral.GetMachine().HandleTimeDomainEvent(InnerTransmit, data, TimeDomainsManager.Instance.VirtualTimeStamp);
|
|
||||||
return peripheralOutput.Count > 0 ? peripheralOutput.Dequeue() : (byte)0x0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void FinishTransmission()
|
|
||||||
{
|
|
||||||
lock(locker)
|
|
||||||
{
|
|
||||||
peripheral.GetMachine().HandleTimeDomainEvent<object>(_ => peripheral.FinishTransmission(), null, TimeDomainsManager.Instance.VirtualTimeStamp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InnerTransmit(ushort data)
|
|
||||||
{
|
|
||||||
peripheralOutput.Enqueue(peripheral.Transmit(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
private NullRegistrationPointPeripheralContainer<IECPeripheral> controller;
|
|
||||||
private IECPeripheral peripheral;
|
|
||||||
private readonly Queue<ushort> peripheralOutput = new Queue<ushort>();
|
|
||||||
private readonly object locker = new object();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,198 +0,0 @@
|
||||||
//
|
|
||||||
// Copyright (c) 2010-2021 Antmicro
|
|
||||||
//
|
|
||||||
// This file is licensed under the MIT License.
|
|
||||||
// Full license text is available in 'licenses/MIT.txt'.
|
|
||||||
//
|
|
||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using Antmicro.Renode.Core;
|
|
||||||
using Antmicro.Renode.Logging;
|
|
||||||
using Antmicro.Renode.Peripherals.Bus;
|
|
||||||
using Antmicro.Renode.Core.Structure.Registers;
|
|
||||||
using System.Collections.Concurrent;
|
|
||||||
|
|
||||||
namespace Antmicro.Renode.Peripherals.SPI
|
|
||||||
{
|
|
||||||
public class BetrustedEcRam : IDoubleWordPeripheral, IKnownSize
|
|
||||||
{
|
|
||||||
public BetrustedEcRam(Machine machine, BetrustedEcSpi spi, long size)
|
|
||||||
{
|
|
||||||
this.machine = machine;
|
|
||||||
this.spi = spi;
|
|
||||||
this.size = size;
|
|
||||||
// Hardware defaults to 1280 entries
|
|
||||||
readFifo = new ConcurrentQueue<uint>();
|
|
||||||
writeFifo = new ConcurrentQueue<uint>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Machine machine;
|
|
||||||
private BetrustedEcSpi spi;
|
|
||||||
private long size;
|
|
||||||
private ConcurrentQueue<uint> readFifo;
|
|
||||||
private ConcurrentQueue<uint> writeFifo;
|
|
||||||
public long Size { get { return size; } }
|
|
||||||
|
|
||||||
public bool WriteNextWord(uint value)
|
|
||||||
{
|
|
||||||
readFifo.Enqueue(value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public bool ReadFifoHasData()
|
|
||||||
{
|
|
||||||
return !readFifo.IsEmpty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int ReadFifoCount()
|
|
||||||
{
|
|
||||||
return readFifo.Count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool GetNextWord(out uint value)
|
|
||||||
{
|
|
||||||
return writeFifo.TryDequeue(out value);
|
|
||||||
}
|
|
||||||
public int WriteFifoCount()
|
|
||||||
{
|
|
||||||
return writeFifo.Count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool WriteFifoHasData()
|
|
||||||
{
|
|
||||||
return !writeFifo.IsEmpty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WriteDoubleWord(long address, uint value)
|
|
||||||
{
|
|
||||||
if (address == 0)
|
|
||||||
{
|
|
||||||
machine.Log(LogLevel.Error, "EC sending word: {0:X4}", value);
|
|
||||||
writeFifo.Enqueue(value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
machine.Log(LogLevel.Error, "Write to unsupported address: {}", address);
|
|
||||||
}
|
|
||||||
|
|
||||||
public uint ReadDoubleWord(long address)
|
|
||||||
{
|
|
||||||
uint ret = 0;
|
|
||||||
if ((address == 0) && readFifo.TryDequeue(out ret))
|
|
||||||
{
|
|
||||||
machine.Log(LogLevel.Error, "EC received word: {0:X4}", ret);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
machine.Log(LogLevel.Error, "Read double word, but have no data");
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Reset()
|
|
||||||
{
|
|
||||||
readFifo = new ConcurrentQueue<uint>();
|
|
||||||
writeFifo = new ConcurrentQueue<uint>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class BetrustedEcSpi : ISPIPeripheral, IDoubleWordPeripheral, IKnownSize, IProvidesRegisterCollection<DoubleWordRegisterCollection>, IGPIOSender
|
|
||||||
{
|
|
||||||
|
|
||||||
public BetrustedEcSpi(Machine machine, uint memAddr, uint memSize)
|
|
||||||
{
|
|
||||||
HOLD = new GPIO();
|
|
||||||
EcRam = new BetrustedEcRam(machine, this, memSize);
|
|
||||||
machine.SystemBus.Register(EcRam, new BusRangeRegistration(memAddr, memSize));
|
|
||||||
|
|
||||||
RegistersCollection = new DoubleWordRegisterCollection(this);
|
|
||||||
Registers.ComControl.Define32(this)
|
|
||||||
.WithFlag(0, FieldMode.Write, name: "CLRERR")
|
|
||||||
.WithFlag(1, FieldMode.Read | FieldMode.Write, name: "HOST_INT")
|
|
||||||
.WithFlag(2, FieldMode.Write, writeCallback: (_, val) =>
|
|
||||||
{
|
|
||||||
if (!val)
|
|
||||||
return;
|
|
||||||
machine.Log(LogLevel.Error, "Resetting FIFO due to RESET bit being set");
|
|
||||||
Reset();
|
|
||||||
}, name: "RESET")
|
|
||||||
;
|
|
||||||
|
|
||||||
Registers.ComStatus.Define32(this)
|
|
||||||
.WithFlag(0, FieldMode.Read, valueProviderCallback: (_) => false, name: "TIP")
|
|
||||||
.WithFlag(1, FieldMode.Read, valueProviderCallback: (_) => EcRam.ReadFifoHasData(), name: "RX_AVAIL")
|
|
||||||
.WithFlag(2, FieldMode.Read, valueProviderCallback: (_) => EcRam.ReadFifoCount() >= 1280, name: "RX_OVER")
|
|
||||||
.WithFlag(3, FieldMode.Read, valueProviderCallback: (_) => EcRam.ReadFifoCount() == 0, name: "RX_UNDER")
|
|
||||||
.WithValueField(4, 12, FieldMode.Read, valueProviderCallback: (_) => (uint)EcRam.ReadFifoCount(), name: "RX_LEVEL")
|
|
||||||
.WithFlag(16, FieldMode.Read, valueProviderCallback: (_) => EcRam.WriteFifoCount() < 1280, name: "TX_AVAIL")
|
|
||||||
.WithFlag(17, FieldMode.Read, valueProviderCallback: (_) => EcRam.WriteFifoCount() == 0, name: "TX_EMPTY")
|
|
||||||
.WithValueField(18, 12, FieldMode.Read, valueProviderCallback: (_) => (uint)EcRam.WriteFifoCount(), name: "TX_LEVEL")
|
|
||||||
.WithFlag(30, FieldMode.Read, valueProviderCallback: (_) => EcRam.WriteFifoCount() >= 1280, name: "TX_OVER")
|
|
||||||
.WithFlag(31, FieldMode.Read, valueProviderCallback: (_) => !EcRam.WriteFifoHasData(), name: "TX_UNDER")
|
|
||||||
;
|
|
||||||
Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WriteDoubleWord(long address, uint value)
|
|
||||||
{
|
|
||||||
RegistersCollection.Write(address, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public uint ReadDoubleWord(long offset)
|
|
||||||
{
|
|
||||||
return RegistersCollection.Read(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte Transmit(byte value)
|
|
||||||
{
|
|
||||||
if (IsFirstByte)
|
|
||||||
{
|
|
||||||
if (!EcRam.GetNextWord(out TxValue))
|
|
||||||
{
|
|
||||||
TxValue = 0xdddd;
|
|
||||||
}
|
|
||||||
FirstRxByte = (uint)value;
|
|
||||||
IsFirstByte = false;
|
|
||||||
return (byte)(TxValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
uint secondRxByte = (uint)value;
|
|
||||||
this.Log(LogLevel.Info, "EC received:{0:X2}{1:X2} sent:{2:X2}{3:X2}", secondRxByte, FirstRxByte, (TxValue >> 8), (TxValue & 0xff));
|
|
||||||
IsFirstByte = true;
|
|
||||||
uint receivedWord = FirstRxByte | (secondRxByte << 8);
|
|
||||||
EcRam.WriteNextWord(receivedWord);
|
|
||||||
this.Log(LogLevel.Info, "EcRam.ReadFifo now contains {0} items", EcRam.ReadFifoCount());
|
|
||||||
return (byte)(TxValue >> 8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void FinishTransmission()
|
|
||||||
{
|
|
||||||
this.Log(LogLevel.Info, "EC finished transmission");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Reset()
|
|
||||||
{
|
|
||||||
IsFirstByte = true;
|
|
||||||
FirstRxByte = 0;
|
|
||||||
HOLD.Set(false);
|
|
||||||
EcRam.Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long Size { get { return 0x100; } }
|
|
||||||
private bool IsFirstByte;
|
|
||||||
private uint FirstRxByte;
|
|
||||||
private uint TxValue;
|
|
||||||
private BetrustedEcRam EcRam;
|
|
||||||
public GPIO HOLD { get; }
|
|
||||||
public DoubleWordRegisterCollection RegistersCollection { get; private set; }
|
|
||||||
|
|
||||||
private enum Registers
|
|
||||||
{
|
|
||||||
ComControl = 0x00,
|
|
||||||
|
|
||||||
ComStatus = 0x04,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,148 +0,0 @@
|
||||||
//
|
|
||||||
// Copyright (c) 2010-2021 Antmicro
|
|
||||||
//
|
|
||||||
// This file is licensed under the MIT License.
|
|
||||||
// Full license text is available in 'licenses/MIT.txt'.
|
|
||||||
//
|
|
||||||
using Antmicro.Renode.Core;
|
|
||||||
using Antmicro.Renode.Core.Structure;
|
|
||||||
using Antmicro.Renode.Core.Structure.Registers;
|
|
||||||
using Antmicro.Renode.Logging;
|
|
||||||
using Antmicro.Renode.Time;
|
|
||||||
using Antmicro.Renode.Peripherals.Bus;
|
|
||||||
using Antmicro.Renode.Peripherals.Timers;
|
|
||||||
|
|
||||||
namespace Antmicro.Renode.Peripherals.SPI
|
|
||||||
{
|
|
||||||
public class BetrustedSocSpi : NullRegistrationPointPeripheralContainer<ISPIPeripheral>, IDoubleWordPeripheral, IProvidesRegisterCollection<DoubleWordRegisterCollection>, IKnownSize
|
|
||||||
{
|
|
||||||
public BetrustedSocSpi(Machine machine) : base(machine)
|
|
||||||
{
|
|
||||||
IRQ = new GPIO();
|
|
||||||
// HOLD = new GPIO();
|
|
||||||
RegistersCollection = new DoubleWordRegisterCollection(this);
|
|
||||||
|
|
||||||
Registers.ComTx.Define32(this)
|
|
||||||
.WithValueField(0, 16, FieldMode.Write, writeCallback: (_, val) =>
|
|
||||||
{
|
|
||||||
// Skip transaction if HOLD is set
|
|
||||||
// if (AutoHold.Value && (HOLD && HOLD.IsSet)
|
|
||||||
// {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
Rx.Value = (uint)RegisteredPeripheral.Transmit((byte)val);
|
|
||||||
Rx.Value |= ((uint)RegisteredPeripheral.Transmit((byte)(val >> 8))) << 8;
|
|
||||||
if (IntEna.Value)
|
|
||||||
{
|
|
||||||
SpiIntStatus.Value = true;
|
|
||||||
UpdateInterrupts();
|
|
||||||
SpiIntStatus.Value = false;
|
|
||||||
}
|
|
||||||
}, name: "TX")
|
|
||||||
;
|
|
||||||
|
|
||||||
Registers.ComRx.Define32(this)
|
|
||||||
.WithValueField(0, 16, out Rx, FieldMode.Read, name: "RX")
|
|
||||||
;
|
|
||||||
|
|
||||||
Registers.ComControl.Define32(this)
|
|
||||||
.WithFlag(0, out IntEna, FieldMode.Read | FieldMode.Write, name: "IntEna")
|
|
||||||
.WithFlag(1, out AutoHold, FieldMode.Read | FieldMode.Write, name: "AutoHold")
|
|
||||||
;
|
|
||||||
Registers.ComStatus.Define32(this)
|
|
||||||
.WithFlag(0, out Tip, FieldMode.Read, name: "IntEna")
|
|
||||||
.WithFlag(1, out Hold, FieldMode.Read, name: "AutoHold")
|
|
||||||
;
|
|
||||||
|
|
||||||
Registers.ComEvStatus.Define32(this)
|
|
||||||
.WithFlag(0, out SpiIntStatus, FieldMode.Read, name: "SpiInt")
|
|
||||||
.WithFlag(1, out SpiHoldStatus, FieldMode.Read, name: "SpiHold")
|
|
||||||
;
|
|
||||||
|
|
||||||
Registers.ComEvPending.Define32(this)
|
|
||||||
.WithFlag(0, out SpiIntPending, FieldMode.Read | FieldMode.WriteOneToClear, name: "SpiInt", changeCallback: (_, __) => UpdateInterrupts())
|
|
||||||
.WithFlag(1, out SpiHoldPending, FieldMode.Read | FieldMode.WriteOneToClear, name: "SpiHold", changeCallback: (_, __) => UpdateInterrupts())
|
|
||||||
;
|
|
||||||
|
|
||||||
Registers.ComEvEnable.Define32(this)
|
|
||||||
.WithFlag(0, out SpiIntEnable, name: "SpiInt", changeCallback: (_, __) => UpdateInterrupts())
|
|
||||||
.WithFlag(1, out SpiHoldEnable, name: "SpiHold", changeCallback: (_, __) => UpdateInterrupts())
|
|
||||||
;
|
|
||||||
|
|
||||||
Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateInterrupts()
|
|
||||||
{
|
|
||||||
if (SpiIntStatus.Value)
|
|
||||||
{
|
|
||||||
SpiIntPending.Value = true;
|
|
||||||
}
|
|
||||||
if (SpiHoldStatus.Value)
|
|
||||||
{
|
|
||||||
SpiHoldPending.Value = true;
|
|
||||||
}
|
|
||||||
IRQ.Set((SpiIntPending.Value && SpiIntEnable.Value)
|
|
||||||
|| (SpiHoldPending.Value && SpiHoldEnable.Value));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WriteDoubleWord(long address, uint value)
|
|
||||||
{
|
|
||||||
RegistersCollection.Write(address, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public uint ReadDoubleWord(long offset)
|
|
||||||
{
|
|
||||||
return RegistersCollection.Read(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Reset()
|
|
||||||
{
|
|
||||||
// IntEna.Value = false;
|
|
||||||
// AutoHold.Value = false;
|
|
||||||
// Tip.Value = false;
|
|
||||||
// Rx.Value = 0;
|
|
||||||
|
|
||||||
SpiIntStatus.Value = false;
|
|
||||||
SpiHoldStatus.Value = false;
|
|
||||||
SpiIntPending.Value = false;
|
|
||||||
SpiHoldPending.Value = false;
|
|
||||||
SpiIntEnable.Value = false;
|
|
||||||
SpiHoldEnable.Value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public long Size { get { return 0x100; } }
|
|
||||||
|
|
||||||
public GPIO IRQ { get; private set; }
|
|
||||||
// public GPIO HOLD;
|
|
||||||
|
|
||||||
private IFlagRegisterField IntEna;
|
|
||||||
private IFlagRegisterField AutoHold;
|
|
||||||
private IFlagRegisterField Tip;
|
|
||||||
private IFlagRegisterField Hold;
|
|
||||||
private IValueRegisterField Rx;
|
|
||||||
|
|
||||||
// Interrupts
|
|
||||||
private IFlagRegisterField SpiIntStatus;
|
|
||||||
private IFlagRegisterField SpiHoldStatus;
|
|
||||||
private IFlagRegisterField SpiIntPending;
|
|
||||||
private IFlagRegisterField SpiHoldPending;
|
|
||||||
private IFlagRegisterField SpiIntEnable;
|
|
||||||
private IFlagRegisterField SpiHoldEnable;
|
|
||||||
|
|
||||||
public DoubleWordRegisterCollection RegistersCollection { get; private set; }
|
|
||||||
|
|
||||||
private enum Registers
|
|
||||||
{
|
|
||||||
ComTx = 0x00,
|
|
||||||
|
|
||||||
ComRx = 0x04,
|
|
||||||
ComControl = 0x08,
|
|
||||||
ComStatus = 0x0c,
|
|
||||||
ComEvStatus = 0x10,
|
|
||||||
ComEvPending = 0x14,
|
|
||||||
ComEvEnable = 0x18,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -9,20 +9,20 @@ cpu: CPU.VexRiscv @ sysbus
|
||||||
|
|
||||||
timer0: Timers.LiteX_Timer_32 @ sysbus 0xf0001000
|
timer0: Timers.LiteX_Timer_32 @ sysbus 0xf0001000
|
||||||
frequency: 100000000
|
frequency: 100000000
|
||||||
-> cpu @ 1000
|
IRQ -> cpu @ 1000
|
||||||
|
|
||||||
// Unrecognized peripheral: crg @ 0xf0002000
|
// Unrecognized peripheral: crg @ 0xf0002000
|
||||||
|
|
||||||
// Unrecognized peripheral: gpio @ 0xf0003000
|
// Unrecognized peripheral: gpio @ 0xf0003000
|
||||||
|
|
||||||
uart: UART.LiteX_UART @ sysbus 0xf0005000
|
uart: UART.LiteX_UART @ sysbus 0xf0005000
|
||||||
-> cpu @ 1002
|
IRQ -> cpu @ 1002
|
||||||
|
|
||||||
console: UART.LiteX_UART @ sysbus 0xf0007000
|
console: UART.LiteX_UART @ sysbus 0xf0007000
|
||||||
-> cpu @ 1003
|
IRQ -> cpu @ 1003
|
||||||
|
|
||||||
app_uart: UART.LiteX_UART @ sysbus 0xf0009000
|
app_uart: UART.LiteX_UART @ sysbus 0xf0009000
|
||||||
-> cpu @ 1004
|
IRQ -> cpu @ 1004
|
||||||
|
|
||||||
// Unrecognized peripheral: info @ 0xf000a000
|
// Unrecognized peripheral: info @ 0xf000a000
|
||||||
|
|
||||||
|
|
@ -32,11 +32,11 @@ memlcd: Video.BetrustedLCD @ sysbus 0xf000c000
|
||||||
memAddr: 0xb0000000
|
memAddr: 0xb0000000
|
||||||
memSize: 0x5c20
|
memSize: 0x5c20
|
||||||
|
|
||||||
com: SPI.BetrustedSocSpi @ sysbus 0xf000d000
|
com: SPI.BetrustedSocCom @ sysbus 0xf000d000
|
||||||
IRQ -> cpu @ 1005
|
IRQ -> cpu @ 1005
|
||||||
|
|
||||||
i2c: I2C.BetrustedSocI2C @ sysbus 0xf000e000
|
i2c: I2C.BetrustedSocI2C @ sysbus 0xf000e000
|
||||||
-> cpu @ 1006
|
IRQ -> cpu @ 1006
|
||||||
|
|
||||||
// Unrecognized peripheral: btevents @ 0xf000f000
|
// Unrecognized peripheral: btevents @ 0xf000f000
|
||||||
|
|
||||||
|
|
@ -45,19 +45,19 @@ i2c: I2C.BetrustedSocI2C @ sysbus 0xf000e000
|
||||||
// Unrecognized peripheral: messible2 @ 0xf0011000
|
// Unrecognized peripheral: messible2 @ 0xf0011000
|
||||||
|
|
||||||
ticktimer: Timers.TickTimer @ sysbus 0xf0012000
|
ticktimer: Timers.TickTimer @ sysbus 0xf0012000
|
||||||
-> cpu @ 1008
|
IRQ -> cpu @ 1008
|
||||||
|
|
||||||
// Unrecognized peripheral: susres @ 0xf0013000
|
// Unrecognized peripheral: susres @ 0xf0013000
|
||||||
|
|
||||||
// Unrecognized peripheral: power @ 0xf0014000
|
// Unrecognized peripheral: power @ 0xf0014000
|
||||||
|
|
||||||
spinor_soft_int: Miscellaneous.SpinorSoftInt @ sysbus 0xf0015000
|
spinor_soft_int: Miscellaneous.SpinorSoftInt @ sysbus 0xf0015000
|
||||||
-> cpu @ 1011
|
IRQ -> cpu @ 1011
|
||||||
|
|
||||||
// Unrecognized peripheral: spinor @ 0xf0016000
|
// Unrecognized peripheral: spinor @ 0xf0016000
|
||||||
|
|
||||||
keyboard: Input.BetrustedKbd @ sysbus 0xf0017000
|
keyboard: Input.BetrustedKbd @ sysbus 0xf0017000
|
||||||
-> cpu @ 1013
|
IRQ -> cpu @ 1013
|
||||||
|
|
||||||
// Unrecognized peripheral: keyinject @ 0xf0018000
|
// Unrecognized peripheral: keyinject @ 0xf0018000
|
||||||
|
|
||||||
|
|
@ -68,22 +68,22 @@ keyrom: Miscellaneous.Keyrom @ sysbus 0xf001a000
|
||||||
// Unrecognized peripheral: audio @ 0xf001b000
|
// Unrecognized peripheral: audio @ 0xf001b000
|
||||||
|
|
||||||
trng_kernel: Miscellaneous.BetrustedRNGKernel @ sysbus 0xf001c000
|
trng_kernel: Miscellaneous.BetrustedRNGKernel @ sysbus 0xf001c000
|
||||||
-> cpu @ 1015
|
IRQ -> cpu @ 1015
|
||||||
|
|
||||||
trng_server: Miscellaneous.BetrustedRNGServer @ sysbus 0xf001d000
|
trng_server: Miscellaneous.BetrustedRNGServer @ sysbus 0xf001d000
|
||||||
-> cpu @ 1016
|
IRQ -> cpu @ 1016
|
||||||
|
|
||||||
// Unrecognized peripheral: trng @ 0xf001e000
|
// Unrecognized peripheral: trng @ 0xf001e000
|
||||||
|
|
||||||
sha512: Miscellaneous.Sha512 @ sysbus 0xf001f000
|
sha512: Miscellaneous.Sha512 @ sysbus 0xf001f000
|
||||||
memAddr: 0xe0002000
|
memAddr: 0xe0002000
|
||||||
memSize: 0x4
|
memSize: 0x4
|
||||||
-> cpu @ 1017
|
IRQ -> cpu @ 1017
|
||||||
|
|
||||||
engine: Miscellaneous.Engine @ sysbus 0xf0020000
|
engine: Miscellaneous.Engine @ sysbus 0xf0020000
|
||||||
memAddr: 0xe0020000
|
memAddr: 0xe0020000
|
||||||
memSize: 0x20000
|
memSize: 0x20000
|
||||||
-> cpu @ 1018
|
IRQ -> cpu @ 1018
|
||||||
|
|
||||||
// Unrecognized peripheral: jtag @ 0xf0021000
|
// Unrecognized peripheral: jtag @ 0xf0021000
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ i @peripherals/BetrustedSocI2C.cs
|
||||||
i @peripherals/BetrustedWatchdog.cs
|
i @peripherals/BetrustedWatchdog.cs
|
||||||
i @peripherals/BQ24157.cs
|
i @peripherals/BQ24157.cs
|
||||||
i @peripherals/BQ27421.cs
|
i @peripherals/BQ27421.cs
|
||||||
|
i @peripherals/Com.cs
|
||||||
|
i @peripherals/ec_power.cs
|
||||||
i @peripherals/engine.cs
|
i @peripherals/engine.cs
|
||||||
i @peripherals/keyboard.cs
|
i @peripherals/keyboard.cs
|
||||||
i @peripherals/keyrom.cs
|
i @peripherals/keyrom.cs
|
||||||
|
|
@ -29,6 +31,9 @@ i @peripherals/trng_server.cs
|
||||||
i @peripherals/TUSB320LAI.cs
|
i @peripherals/TUSB320LAI.cs
|
||||||
i @peripherals/wfi.cs
|
i @peripherals/wfi.cs
|
||||||
|
|
||||||
|
# Create the COM SPI bus
|
||||||
|
emulation CreateComConnector "com"
|
||||||
|
|
||||||
############### Define the Betrusted SoC ###############
|
############### Define the Betrusted SoC ###############
|
||||||
mach create "SoC"
|
mach create "SoC"
|
||||||
machine LoadPlatformDescription @soc/betrusted-soc.repl
|
machine LoadPlatformDescription @soc/betrusted-soc.repl
|
||||||
|
|
@ -61,6 +66,9 @@ sysbus Tag <0xB0000000, 0xB0006000> "Framebuffer"
|
||||||
# Load the SPI flash into RAM
|
# Load the SPI flash into RAM
|
||||||
sysbus LoadBinary @precursors/soc_csr.bin 0x20000000
|
sysbus LoadBinary @precursors/soc_csr.bin 0x20000000
|
||||||
|
|
||||||
|
# Connect the SoC to the SPI bus
|
||||||
|
connector Connect sysbus.com com
|
||||||
|
|
||||||
# The macro `reset` gets called implicitly when running `machine Reset`
|
# The macro `reset` gets called implicitly when running `machine Reset`
|
||||||
macro reset
|
macro reset
|
||||||
"""
|
"""
|
||||||
|
|
@ -87,16 +95,18 @@ machine LoadPlatformDescription @ec/betrusted-ec.repl
|
||||||
# logLevel -1 i2c
|
# logLevel -1 i2c
|
||||||
# logLevel -1 i2c.bq27421
|
# logLevel -1 i2c.bq27421
|
||||||
|
|
||||||
machine StartGdbServer 2222 true
|
machine StartGdbServer 3334 true
|
||||||
showAnalyzer uart
|
showAnalyzer uart
|
||||||
|
|
||||||
# Silence the COM bus, which is currently unimplemented
|
# Connect the EC to the SPI bus
|
||||||
sysbus SilenceRange <0xE0005800, 0xE0005FFF>
|
connector Connect sysbus.com com
|
||||||
|
|
||||||
macro reset
|
macro reset
|
||||||
"""
|
"""
|
||||||
sysbus LoadBinary @ec/kernel.bin 0x10000000
|
sysbus LoadBinary @ec/bt-ec.bin 0x20000000
|
||||||
cpu PC 0x10000000
|
sysbus LoadBinary @ec/loader.bin 0x00000000
|
||||||
|
cpu PC 0
|
||||||
|
cpu SP 0x1001FFFC
|
||||||
"""
|
"""
|
||||||
runMacro $reset
|
runMacro $reset
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -589,7 +589,7 @@ fn print_peripherals<U: Write>(
|
||||||
|
|
||||||
// Add the interrupt, if one exists.
|
// Add the interrupt, if one exists.
|
||||||
if let Some(irq) = peripheral.interrupt.get(0) {
|
if let Some(irq) = peripheral.interrupt.get(0) {
|
||||||
writeln!(out, " -> cpu @ {}", 1000 + irq.value)?;
|
writeln!(out, " IRQ -> cpu @ {}", 1000 + irq.value)?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
writeln!(out, "// Unrecognized peripheral: {} @ 0x{:08x}", lc_name, peripheral.base)?;
|
writeln!(out, "// Unrecognized peripheral: {} @ 0x{:08x}", lc_name, peripheral.base)?;
|
||||||
|
|
@ -633,6 +633,7 @@ pub fn generate<T: Read, U: Write>(src: T, dest: &mut U) -> Result<(), ParseErro
|
||||||
cs_peripherals.insert("app_uart", "UART.LiteX_UART");
|
cs_peripherals.insert("app_uart", "UART.LiteX_UART");
|
||||||
cs_peripherals.insert("console", "UART.LiteX_UART");
|
cs_peripherals.insert("console", "UART.LiteX_UART");
|
||||||
cs_peripherals.insert("engine", "Miscellaneous.Engine");
|
cs_peripherals.insert("engine", "Miscellaneous.Engine");
|
||||||
|
cs_peripherals.insert("com", "SPI.BetrustedSocCom");
|
||||||
cs_peripherals.insert("i2c", "I2C.BetrustedSocI2C");
|
cs_peripherals.insert("i2c", "I2C.BetrustedSocI2C");
|
||||||
cs_peripherals.insert("keyboard", "Input.BetrustedKbd");
|
cs_peripherals.insert("keyboard", "Input.BetrustedKbd");
|
||||||
cs_peripherals.insert("keyrom", "Miscellaneous.Keyrom");
|
cs_peripherals.insert("keyrom", "Miscellaneous.Keyrom");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue