mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
Merge branch 'main' of github.com:betrusted-io/xous-core into main
This commit is contained in:
commit
d5063d1ff0
3 changed files with 155 additions and 160 deletions
|
|
@ -83,6 +83,9 @@ sysbus SilenceRange <0xf0003000, 0xF0003FFF>
|
||||||
# Silence POWER
|
# Silence POWER
|
||||||
sysbus SilenceRange <0xF0014000 100>
|
sysbus SilenceRange <0xF0014000 100>
|
||||||
|
|
||||||
|
# Attach the flash backing to the filesystem
|
||||||
|
sysbus.spinor.flash BackingFile $ORIGIN/../tools/pddb-images/renode.bin
|
||||||
|
|
||||||
# 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
|
||||||
|
|
||||||
|
|
@ -115,7 +118,7 @@ machine LoadPlatformDescription @ec/betrusted-ec.repl
|
||||||
# logLevel -1 i2c
|
# logLevel -1 i2c
|
||||||
# logLevel -1 i2c.bq27421
|
# logLevel -1 i2c.bq27421
|
||||||
# logLevel -1 wifi
|
# logLevel -1 wifi
|
||||||
logLevel 0 wifi.wf200
|
# logLevel 0 wifi.wf200
|
||||||
# sysbus LogPeripheralAccess wifi true
|
# sysbus LogPeripheralAccess wifi true
|
||||||
|
|
||||||
machine StartGdbServer 3334 true
|
machine StartGdbServer 3334 true
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ namespace Antmicro.Renode.Peripherals.Sound
|
||||||
this.bufferAddress = memAddr;
|
this.bufferAddress = memAddr;
|
||||||
machine.SystemBus.Register(this.audioRam, new BusRangeRegistration(memAddr, memSize));
|
machine.SystemBus.Register(this.audioRam, new BusRangeRegistration(memAddr, memSize));
|
||||||
|
|
||||||
CreateRegisters();
|
DefineRegisters();
|
||||||
IRQ = new GPIO();
|
IRQ = new GPIO();
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
@ -130,7 +130,7 @@ namespace Antmicro.Renode.Peripherals.Sound
|
||||||
IRQ.Set(rxReady || rxError || txReady || txError);
|
IRQ.Set(rxReady || rxError || txReady || txError);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start()
|
private void StartTx()
|
||||||
{
|
{
|
||||||
if(enableTx.Value)
|
if(enableTx.Value)
|
||||||
{
|
{
|
||||||
|
|
@ -143,7 +143,11 @@ namespace Antmicro.Renode.Peripherals.Sound
|
||||||
encoder.SetBufferingBySamplesCount(maxSamplesCount.Value);
|
encoder.SetBufferingBySamplesCount(maxSamplesCount.Value);
|
||||||
encoder.Output = OutputFile;
|
encoder.Output = OutputFile;
|
||||||
}
|
}
|
||||||
|
StartTxThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartRx()
|
||||||
|
{
|
||||||
if(enableRx.Value)
|
if(enableRx.Value)
|
||||||
{
|
{
|
||||||
if(InputFile == "")
|
if(InputFile == "")
|
||||||
|
|
@ -154,60 +158,62 @@ namespace Antmicro.Renode.Peripherals.Sound
|
||||||
decoder = new PCMDecoder(sampleWidth, sampleFrequency, numberOfChannels, false, this);
|
decoder = new PCMDecoder(sampleWidth, sampleFrequency, numberOfChannels, false, this);
|
||||||
decoder.LoadFile(InputFile);
|
decoder.LoadFile(InputFile);
|
||||||
}
|
}
|
||||||
StartRxTxThread();
|
StartRxThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Stop()
|
private void Stop()
|
||||||
{
|
{
|
||||||
encoder?.FlushBuffer();
|
encoder?.FlushBuffer();
|
||||||
StopRxTxThread();
|
StopTxThread();
|
||||||
eventStopped.Value = true;
|
StopRxThread();
|
||||||
|
// eventStopped.Value = true;
|
||||||
UpdateInterrupts();
|
UpdateInterrupts();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartRxTxThread()
|
private void StartTxThread()
|
||||||
{
|
{
|
||||||
if(!enableI2S.Value)
|
txThread = machine.ObtainManagedThread(OutputFrames, (int)(sampleFrequency / (maxSamplesCount.Value * samplesPerDoubleWord)));
|
||||||
{
|
txThread.Start();
|
||||||
this.Log(LogLevel.Error, "Trying to start aquisition, when peripheral is disabled (ENABLE==0). Will not start");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
rxTxThread = machine.ObtainManagedThread(ProcessFrames, (int)(sampleFrequency / (maxSamplesCount.Value * samplesPerDoubleWord)));
|
|
||||||
rxTxThread.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StopRxTxThread()
|
private void StartRxThread()
|
||||||
{
|
{
|
||||||
if(rxTxThread == null)
|
rxThread = machine.ObtainManagedThread(InputFrames, (int)(sampleFrequency / (maxSamplesCount.Value * samplesPerDoubleWord)));
|
||||||
|
rxThread.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StopTxThread()
|
||||||
|
{
|
||||||
|
if(txThread == null)
|
||||||
{
|
{
|
||||||
this.Log(LogLevel.Debug, "Trying to stop sampling when it is not active");
|
this.Log(LogLevel.Debug, "Trying to stop sampling when it is not active");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rxTxThread.Stop();
|
txThread.Stop();
|
||||||
rxTxThread = null;
|
txThread = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessFrames()
|
private void StopRxThread()
|
||||||
{
|
{
|
||||||
if(enableRx.Value)
|
if(rxThread == null)
|
||||||
{
|
{
|
||||||
InputFrames();
|
this.Log(LogLevel.Debug, "Trying to stop sampling when it is not active");
|
||||||
}
|
return;
|
||||||
if(enableTx.Value)
|
|
||||||
{
|
|
||||||
OutputFrames();
|
|
||||||
}
|
}
|
||||||
|
rxThread.Stop();
|
||||||
|
rxThread = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void OutputFrames()
|
private void OutputFrames()
|
||||||
{
|
{
|
||||||
var currentPointer = txdPointer.Value;
|
var currentPointer = txdPointer.Value;
|
||||||
// The TXD.PTR register has been copied to internal double-buffers
|
// The TXD.PTR register has been copied to internal double-buffers
|
||||||
eventTxPointerUpdated.Value = true;
|
// eventTxPointerUpdated.Value = true;
|
||||||
UpdateInterrupts();
|
UpdateInterrupts();
|
||||||
|
|
||||||
// RxTxMaxCnt denotes number of DoubleWords, we need to calculate samples number
|
// RxTxMaxCnt denotes number of DoubleWords, we need to calculate samples number
|
||||||
for(var samples = 0u; samples < maxSamplesCount.Value * samplesPerDoubleWord; samples++)
|
for(var samples = 0u; samples < writeCount.Value * samplesPerDoubleWord; samples++)
|
||||||
{
|
{
|
||||||
var thisSample = machine.SystemBus.ReadDoubleWord(currentPointer + samples * sampleWidth / 8);
|
var thisSample = machine.SystemBus.ReadDoubleWord(currentPointer + samples * sampleWidth / 8);
|
||||||
BitHelper.ClearBits(ref thisSample, (int)sampleWidth, (int)(32 - sampleWidth));
|
BitHelper.ClearBits(ref thisSample, (int)sampleWidth, (int)(32 - sampleWidth));
|
||||||
|
|
@ -219,10 +225,10 @@ namespace Antmicro.Renode.Peripherals.Sound
|
||||||
{
|
{
|
||||||
var currentPointer = rxdPointer.Value;
|
var currentPointer = rxdPointer.Value;
|
||||||
// The RXD.PTR register has been copied to internal double-buffers
|
// The RXD.PTR register has been copied to internal double-buffers
|
||||||
eventRxPointerUpdated.Value = true;
|
// eventRxPointerUpdated.Value = true;
|
||||||
UpdateInterrupts();
|
UpdateInterrupts();
|
||||||
|
|
||||||
for(var doubleWords = 0u; doubleWords < maxSamplesCount.Value; doubleWords++)
|
for(var doubleWords = 0u; doubleWords < readCount.Value; doubleWords++)
|
||||||
{
|
{
|
||||||
// Double word may consist on many samples when sampleWidth is not equal 32bit
|
// Double word may consist on many samples when sampleWidth is not equal 32bit
|
||||||
uint valueToStore = 0;
|
uint valueToStore = 0;
|
||||||
|
|
@ -354,7 +360,7 @@ namespace Antmicro.Renode.Peripherals.Sound
|
||||||
return closest;
|
return closest;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateRegisters()
|
private void DefineRegisters()
|
||||||
{
|
{
|
||||||
Registers.EventEnable.Define(this)
|
Registers.EventEnable.Define(this)
|
||||||
.WithFlag(0, out interruptEnableRxReady, changeCallback: (_, __) => UpdateInterrupts(), name: "RX_READY")
|
.WithFlag(0, out interruptEnableRxReady, changeCallback: (_, __) => UpdateInterrupts(), name: "RX_READY")
|
||||||
|
|
@ -374,135 +380,13 @@ namespace Antmicro.Renode.Peripherals.Sound
|
||||||
.WithFlag(2, out eventTxReady, FieldMode.WriteOneToClear, name: "TX_READY")
|
.WithFlag(2, out eventTxReady, FieldMode.WriteOneToClear, name: "TX_READY")
|
||||||
.WithFlag(3, out eventTxError, FieldMode.WriteOneToClear, name: "TX_ERROR")
|
.WithFlag(3, out eventTxError, FieldMode.WriteOneToClear, name: "TX_ERROR")
|
||||||
;
|
;
|
||||||
// Registers.TasksStart.Define(this)
|
Registers.TxCtl.Define32(this)
|
||||||
// .WithFlag(0, FieldMode.Write, writeCallback: (_, val) => { if(val) Start(); }, name: "TASKS_START")
|
.WithFlag(0, writeCallback: (_, val) => { if (val) StartTx(); }, name: "tx_enable")
|
||||||
// .WithReservedBits(1,31);
|
;
|
||||||
// Registers.TasksStop.Define(this)
|
|
||||||
// .WithFlag(0, FieldMode.Write, writeCallback: (_, val) => { if(val) Stop(); }, name: "TASKS_STOP")
|
Registers.RxCtl.Define32(this)
|
||||||
// .WithReservedBits(1,31);
|
.WithFlag(0, writeCallback: (_, val) => { if (val) StartRx(); }, name: "rx_enable")
|
||||||
// Registers.EventsRxptrUpdated .Define(this)
|
;
|
||||||
// .WithFlag(0, out eventRxPointerUpdated, changeCallback: (_, __) => UpdateInterrupts(), name: "EVENTS_RXPTRUPD")
|
|
||||||
// .WithReservedBits(1,31);
|
|
||||||
// Registers.EventsStopped.Define(this)
|
|
||||||
// .WithFlag(0, out eventStopped, changeCallback: (_, __) => UpdateInterrupts(), name: "EVENTS_STOPPED")
|
|
||||||
// .WithReservedBits(1,31);
|
|
||||||
// Registers.EventsTxptrUpdated.Define(this)
|
|
||||||
// .WithFlag(0, out eventTxPointerUpdated, changeCallback: (_, __) => UpdateInterrupts(), name: "EVENTS_TXPTRUPD")
|
|
||||||
// .WithReservedBits(1,31);
|
|
||||||
// Registers.InterruptEnable.Define(this)
|
|
||||||
// .WithReservedBits(0,1)
|
|
||||||
// .WithFlag(1, out interruptEnableRxPointerUpdated, name: "RXPTRUPD")
|
|
||||||
// .WithFlag(2, out interruptEnableStopped, name: "STOPPED")
|
|
||||||
// .WithReservedBits(3,2)
|
|
||||||
// .WithFlag(5, out interruptEnableTxPointerUpdated, name: "TXPTRUPD")
|
|
||||||
// .WithReservedBits(6,25);
|
|
||||||
// Registers.InterruptEnableSet.Define(this)
|
|
||||||
// .WithReservedBits(0,1)
|
|
||||||
// .WithFlag(1,
|
|
||||||
// writeCallback: (_, val) => { interruptEnableRxPointerUpdated.Value |= val; },
|
|
||||||
// valueProviderCallback: (_) => { return interruptEnableRxPointerUpdated.Value; },
|
|
||||||
// name: "RXPTRUPD")
|
|
||||||
// .WithFlag(2,
|
|
||||||
// writeCallback: (_, val) => { interruptEnableStopped.Value |= val; },
|
|
||||||
// valueProviderCallback: (_) => { return interruptEnableStopped.Value; },
|
|
||||||
// name: "STOPPED")
|
|
||||||
// .WithReservedBits(3,2)
|
|
||||||
// .WithFlag(5,
|
|
||||||
// writeCallback: (_, val) => { interruptEnableTxPointerUpdated.Value |= val; },
|
|
||||||
// valueProviderCallback: (_) => { return interruptEnableTxPointerUpdated.Value; },
|
|
||||||
// name: "TXPTRUPD")
|
|
||||||
// .WithReservedBits(6,25);
|
|
||||||
// Registers.InterruptEnableClear.Define(this)
|
|
||||||
// .WithReservedBits(0,1)
|
|
||||||
// .WithFlag(1,
|
|
||||||
// writeCallback: (_, val) => { interruptEnableRxPointerUpdated.Value &= !val; },
|
|
||||||
// valueProviderCallback: (_) => { return interruptEnableRxPointerUpdated.Value; },
|
|
||||||
// name: "RXPTRUPD")
|
|
||||||
// .WithFlag(2,
|
|
||||||
// writeCallback: (_, val) => { interruptEnableStopped.Value &= !val; },
|
|
||||||
// valueProviderCallback: (_) => { return interruptEnableStopped.Value; },
|
|
||||||
// name: "STOPPED")
|
|
||||||
// .WithReservedBits(3,2)
|
|
||||||
// .WithFlag(5,
|
|
||||||
// writeCallback: (_, val) => { interruptEnableTxPointerUpdated.Value &= !val; },
|
|
||||||
// valueProviderCallback: (_) => { return interruptEnableTxPointerUpdated.Value; },
|
|
||||||
// name: "TXPTRUPD")
|
|
||||||
// .WithReservedBits(6,25);
|
|
||||||
// Registers.Enable.Define(this)
|
|
||||||
// .WithFlag(0, out enableI2S, name: "ENABLE")
|
|
||||||
// .WithReservedBits(1,31);
|
|
||||||
// Registers.ConfigMode.Define(this)
|
|
||||||
// .WithValueField(0, 1,
|
|
||||||
// writeCallback: (_, val) =>
|
|
||||||
// {
|
|
||||||
// if((Mode)val == Mode.Slave)
|
|
||||||
// {
|
|
||||||
// //This requires ability to use master device clock configuration and handling alignment / format properly
|
|
||||||
// this.Log(LogLevel.Error, "Slave mode unimplemented");
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// name: "MODE")
|
|
||||||
// .WithReservedBits(1,31);
|
|
||||||
// Registers.ConfigRxEnable.Define(this)
|
|
||||||
// .WithFlag(0, out enableRx, name: "RXEN")
|
|
||||||
// .WithReservedBits(1,31);
|
|
||||||
// Registers.ConfigTxEnable.Define(this, 0x1)
|
|
||||||
// .WithFlag(0, out enableTx, name: "TXEN")
|
|
||||||
// .WithReservedBits(1,31);
|
|
||||||
// Registers.ConfigMasterClockEnable.Define(this, 0x1)
|
|
||||||
// .WithFlag(0, name: "MCKEN")
|
|
||||||
// .WithReservedBits(1,31);
|
|
||||||
// Registers.ConfigMasterClockFrequency.Define(this, 0x20000000)
|
|
||||||
// .WithValueField(0, 32, writeCallback: (_, val) => SetMasterClockFrequency(val), name: "MCKFREQ");
|
|
||||||
// Registers.ConfigRatio.Define(this, 0x6)
|
|
||||||
// .WithValueField(0, 4, writeCallback: (_, val) => SetMasterClockLrckRatio(val), name: "RATIO")
|
|
||||||
// .WithReservedBits(4,28);
|
|
||||||
// Registers.ConfigSwidth.Define(this, 0x1)
|
|
||||||
// .WithValueField(0, 2, writeCallback: (_, val) => SetSampleWidth(val), name: "SWIDTH")
|
|
||||||
// .WithReservedBits(2,30);
|
|
||||||
// Registers.ConfigAlign.Define(this)
|
|
||||||
// .WithTaggedFlag("ALIGN", 0)
|
|
||||||
// .WithReservedBits(1, 31);
|
|
||||||
// Registers.ConfigFormat.Define(this)
|
|
||||||
// .WithTaggedFlag("FORMAT",0)
|
|
||||||
// .WithReservedBits(1, 31);
|
|
||||||
// Registers.ConfigChannels.Define(this)
|
|
||||||
// .WithValueField(0, 2,
|
|
||||||
// writeCallback: (_, val) => { numberOfChannels = (Channels)val == Channels.Stereo ? 2u : 1u;},
|
|
||||||
// name: "CHANNELS")
|
|
||||||
// .WithReservedBits(2, 30);
|
|
||||||
// Registers.RxdPointer.Define(this)
|
|
||||||
// .WithValueField(0, 32, out rxdPointer, name: "PTR");
|
|
||||||
// Registers.TxdPointer.Define(this)
|
|
||||||
// .WithValueField(0, 32, out txdPointer, name: "PTR");
|
|
||||||
// Registers.RxTxBufferSize.Define(this)
|
|
||||||
// .WithValueField(0, 14, out maxSamplesCount, name: "MAXCNT")
|
|
||||||
// .WithReservedBits(14, 18);
|
|
||||||
// Registers.PinSelectMasterClock.Define(this, 0xFFFFFFFF)
|
|
||||||
// .WithTag("PIN", 0, 5)
|
|
||||||
// .WithTag("PORT", 5, 1)
|
|
||||||
// .WithReservedBits(6, 25)
|
|
||||||
// .WithTaggedFlag("CONNECT", 31);
|
|
||||||
// Registers.PinSelectSCK.Define(this, 0xFFFFFFFF)
|
|
||||||
// .WithTag("PIN", 0, 5)
|
|
||||||
// .WithTag("PORT", 5, 1)
|
|
||||||
// .WithReservedBits(6, 25)
|
|
||||||
// .WithTaggedFlag("CONNECT", 31);
|
|
||||||
// Registers.PinSelectLRCK.Define(this, 0xFFFFFFFF)
|
|
||||||
// .WithTag("PIN", 0, 5)
|
|
||||||
// .WithTag("PORT", 5, 1)
|
|
||||||
// .WithReservedBits(6, 25)
|
|
||||||
// .WithTaggedFlag("CONNECT", 31);
|
|
||||||
// Registers.PinSelectSDIN.Define(this, 0xFFFFFFFF)
|
|
||||||
// .WithTag("PIN", 0, 5)
|
|
||||||
// .WithTag("PORT", 5, 1)
|
|
||||||
// .WithReservedBits(6, 25)
|
|
||||||
// .WithTag("CONNECT", 31, 1);
|
|
||||||
// Registers.PinSelectSDOUT.Define(this, 0xFFFFFFFF)
|
|
||||||
// .WithValueField(0, 5, name: "PIN")
|
|
||||||
// .WithValueField(5, 1, name: "PORT")
|
|
||||||
// .WithReservedBits(6, 25)
|
|
||||||
// .WithTaggedFlag("CONNECT", 31);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IFlagRegisterField enableI2S;
|
private IFlagRegisterField enableI2S;
|
||||||
|
|
@ -529,7 +413,8 @@ namespace Antmicro.Renode.Peripherals.Sound
|
||||||
private uint samplesPerDoubleWord;
|
private uint samplesPerDoubleWord;
|
||||||
private uint sampleWidth;
|
private uint sampleWidth;
|
||||||
|
|
||||||
private IManagedThread rxTxThread;
|
private IManagedThread rxThread;
|
||||||
|
private IManagedThread txThread;
|
||||||
private PCMDecoder decoder;
|
private PCMDecoder decoder;
|
||||||
private PCMEncoder encoder;
|
private PCMEncoder encoder;
|
||||||
private AudioRam audioRam;
|
private AudioRam audioRam;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
// Full license text is available in 'licenses/MIT.txt'.
|
// Full license text is available in 'licenses/MIT.txt'.
|
||||||
//
|
//
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using Antmicro.Renode.Core.Structure.Registers;
|
using Antmicro.Renode.Core.Structure.Registers;
|
||||||
using Antmicro.Renode.Exceptions;
|
using Antmicro.Renode.Exceptions;
|
||||||
using Antmicro.Renode.Logging;
|
using Antmicro.Renode.Logging;
|
||||||
|
|
@ -139,6 +140,90 @@ namespace Antmicro.Renode.Peripherals.SPI
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string InternalBackingFileName;
|
||||||
|
private FileStream InternalBackingFile;
|
||||||
|
public string BackingFile
|
||||||
|
{
|
||||||
|
get { return InternalBackingFileName; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
// If the user passes an empty string, don't do anything.
|
||||||
|
if (string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
this.Log(LogLevel.Error, "Unconfiguring backing file");
|
||||||
|
if (InternalBackingFile != null)
|
||||||
|
{
|
||||||
|
InternalBackingFile.Close();
|
||||||
|
}
|
||||||
|
InternalBackingFileName = null;
|
||||||
|
InternalBackingFile = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the path name is fully-qualified, using the current working
|
||||||
|
// directory if necessary.
|
||||||
|
if (System.IO.Path.IsPathRooted(value))
|
||||||
|
{
|
||||||
|
InternalBackingFileName = value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
InternalBackingFileName = System.IO.Path.Combine(Environment.CurrentDirectory, value);
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.Log(LogLevel.Debug, "Trying to load or create backing file {0}", InternalBackingFileName);
|
||||||
|
InternalBackingFile = new FileStream(InternalBackingFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
||||||
|
byte[] copyBuffer = new byte[4096];
|
||||||
|
var currentOffset = 0;
|
||||||
|
|
||||||
|
// Assume that if the length is 0, then the file was just created and we need
|
||||||
|
// to copy RAM into the newly-created file.
|
||||||
|
if (InternalBackingFile.Length == 0)
|
||||||
|
{
|
||||||
|
this.Log(LogLevel.Debug, "Backing file {0} was created, dumping {1} bytes of ROM to backing file", InternalBackingFileName, underlyingMemory.Size);
|
||||||
|
// 4096 is a safe size, since that is the page size.
|
||||||
|
for (currentOffset = 0; currentOffset < underlyingMemory.Size; currentOffset += copyBuffer.Length)
|
||||||
|
{
|
||||||
|
underlyingMemory.ReadBytes(currentOffset, copyBuffer.Length, copyBuffer, 0);
|
||||||
|
InternalBackingFile.Write(copyBuffer, 0, copyBuffer.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If the length is NOT 0, read data from the backing file
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.Log(LogLevel.Debug, "Backing file {0} was loaded, restoring {1} bytes (vs ROM: {2}) of ROM from file", InternalBackingFileName, InternalBackingFile.Length, underlyingMemory.Size);
|
||||||
|
InternalBackingFile.Seek(0, SeekOrigin.Begin);
|
||||||
|
if (InternalBackingFile.Length != underlyingMemory.Size)
|
||||||
|
{
|
||||||
|
this.Log(LogLevel.Warning, "Backing file {0} was a different size than ROM (file was {1} bytes, ROM is {2} bytes) -- resizing backing file to match ROM size", InternalBackingFileName, InternalBackingFile.Length, underlyingMemory.Size);
|
||||||
|
InternalBackingFile.SetLength(underlyingMemory.Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4096 is a safe size, since that is the page size.
|
||||||
|
for (currentOffset = 0;
|
||||||
|
(currentOffset < underlyingMemory.Size) && (currentOffset < InternalBackingFile.Length);
|
||||||
|
currentOffset += copyBuffer.Length)
|
||||||
|
{
|
||||||
|
InternalBackingFile.Read(copyBuffer, 0, copyBuffer.Length);
|
||||||
|
underlyingMemory.WriteBytes(currentOffset, copyBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
if (InternalBackingFile != null)
|
||||||
|
{
|
||||||
|
InternalBackingFile.Close();
|
||||||
|
}
|
||||||
|
InternalBackingFileName = null;
|
||||||
|
InternalBackingFile = null;
|
||||||
|
throw new RecoverableException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public MappedMemory UnderlyingMemory => underlyingMemory;
|
public MappedMemory UnderlyingMemory => underlyingMemory;
|
||||||
|
|
||||||
private void AccumulateAddressBytes(byte addressByte, DecodedOperation.OperationState nextState)
|
private void AccumulateAddressBytes(byte addressByte, DecodedOperation.OperationState nextState)
|
||||||
|
|
@ -537,6 +622,11 @@ namespace Antmicro.Renode.Peripherals.SPI
|
||||||
var length = (int)Math.Min(SegmentSize, underlyingMemory.Size - position);
|
var length = (int)Math.Min(SegmentSize, underlyingMemory.Size - position);
|
||||||
|
|
||||||
underlyingMemory.WriteBytes(position, segment, length);
|
underlyingMemory.WriteBytes(position, segment, length);
|
||||||
|
if (InternalBackingFile != null)
|
||||||
|
{
|
||||||
|
InternalBackingFile.Seek(position, SeekOrigin.Begin);
|
||||||
|
InternalBackingFile.Write(segment, 0, length);
|
||||||
|
}
|
||||||
position += length;
|
position += length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -553,6 +643,11 @@ namespace Antmicro.Renode.Peripherals.SPI
|
||||||
|
|
||||||
var position = SegmentSize * (currentOperation.ExecutionAddress / SegmentSize);
|
var position = SegmentSize * (currentOperation.ExecutionAddress / SegmentSize);
|
||||||
underlyingMemory.WriteBytes(position, segment);
|
underlyingMemory.WriteBytes(position, segment);
|
||||||
|
if (InternalBackingFile != null)
|
||||||
|
{
|
||||||
|
InternalBackingFile.Seek(position, SeekOrigin.Begin);
|
||||||
|
InternalBackingFile.Write(segment, 0, segment.Length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EraseSubsector4K()
|
private void EraseSubsector4K()
|
||||||
|
|
@ -567,6 +662,11 @@ namespace Antmicro.Renode.Peripherals.SPI
|
||||||
|
|
||||||
var position = 4.KB() * (currentOperation.ExecutionAddress / 4.KB());
|
var position = 4.KB() * (currentOperation.ExecutionAddress / 4.KB());
|
||||||
underlyingMemory.WriteBytes(position, segment);
|
underlyingMemory.WriteBytes(position, segment);
|
||||||
|
if (InternalBackingFile != null)
|
||||||
|
{
|
||||||
|
InternalBackingFile.Seek(position, SeekOrigin.Begin);
|
||||||
|
InternalBackingFile.Write(segment, 0, segment.Length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteToMemory(byte val)
|
private void WriteToMemory(byte val)
|
||||||
|
|
@ -579,6 +679,13 @@ namespace Antmicro.Renode.Peripherals.SPI
|
||||||
|
|
||||||
var position = currentOperation.ExecutionAddress + currentOperation.CommandBytesHandled;
|
var position = currentOperation.ExecutionAddress + currentOperation.CommandBytesHandled;
|
||||||
underlyingMemory.WriteByte(position, val);
|
underlyingMemory.WriteByte(position, val);
|
||||||
|
if (InternalBackingFile != null)
|
||||||
|
{
|
||||||
|
var tmp_byte = new byte[1];
|
||||||
|
tmp_byte[0] = val;
|
||||||
|
InternalBackingFile.Seek(position, SeekOrigin.Begin);
|
||||||
|
InternalBackingFile.Write(tmp_byte, 0, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte ReadFromMemory()
|
private byte ReadFromMemory()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue