Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 7 additions & 24 deletions src/Emulator/Main/Peripherals/Wireless/InterferenceQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,9 @@

namespace Antmicro.Renode.Peripherals.Wireless
{
public interface IInterferenceQueueListener
{
void InteferenceQueueChangedCallback();
}

public static class InterferenceQueue
{
static readonly List<PacketInfo> overTheAirPackets = new List<PacketInfo>();
static readonly List<IInterferenceQueueListener> listeners = new List<IInterferenceQueueListener>();

public static void Subscribe(IInterferenceQueueListener listener)
{
listeners.Add(listener);
}

public static void Add(IRadio sender, RadioPhyId phyId, int channel, int txPowerDbm, byte[] content)
{
Expand All @@ -49,7 +38,7 @@ public static void Add(IRadio sender, RadioPhyId phyId, int channel, int txPower
newEntry.StartTxTimestamp = addTime;
overTheAirPackets.Add(newEntry);
Logger.Log(LogLevel.Noisy, "InterferenceQueue.Add at {0}: [{1}]", addTime, BitConverter.ToString(content));
NotifyListeners();
InterferenceQueueChanged?.Invoke();
}

public static void Remove(IRadio sender)
Expand Down Expand Up @@ -80,7 +69,7 @@ public static void Remove(IRadio sender)
}

overTheAirPackets.Remove(entry);
NotifyListeners();
InterferenceQueueChanged?.Invoke();
}

public static TimeInterval GetTxStartTime(IRadio sender)
Expand All @@ -92,7 +81,6 @@ public static TimeInterval GetTxStartTime(IRadio sender)

if(entry == null)
{
Logger.Log(LogLevel.Error, "InterferenceQueue.GetTxStartTime: entry not found");
return TimeInterval.Empty;
}

Expand All @@ -106,7 +94,7 @@ public static TimeInterval GetTxStartTime(IRadio sender)
// - the sender TX power
// - interference between different PHYs
// - Co-channel interference
public static int GetCurrentRssi(RadioPhyId phyId, int channel)
public static int GetCurrentRssi(IRadio receiver, RadioPhyId phyId, int channel)
{
if(ForceBusyRssi)
{
Expand Down Expand Up @@ -139,16 +127,10 @@ private static PacketInfo PacketLookup(IRadio sender)
return null;
}

private static void NotifyListeners()
{
foreach(IInterferenceQueueListener listener in listeners)
{
listener.InteferenceQueueChangedCallback();
}
}

private const int RssiBusyChannelHardCodedValueDbm = 20;
private const int RssiClearChannelHardCodedValueDbm = -120;

public static event Action InterferenceQueueChanged;
}

public class PacketInfo
Expand Down Expand Up @@ -216,6 +198,7 @@ public TimeInterval StartTxTimestamp
public enum RadioPhyId
{
Phy_802154_2_4GHz_OQPSK = 0,
Phy_BLE_2_4GHz_GFSK = 1,
Phy_BLE_2_4GHz_GFSK = 1,
Phy_SubGHz_GFSK = 2,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

namespace Antmicro.Renode.Peripherals.DMA
{
public class EFR32xG22_LDMA : IBusPeripheral, IGPIOReceiver, IKnownSize
public class SiLabs_LDMA_0_1 : IBusPeripheral, IGPIOReceiver, IKnownSize
{
public EFR32xG22_LDMA(Machine machine)
public SiLabs_LDMA_0_1(Machine machine)
{
this.machine = machine;
engine = new DmaEngine(machine.GetSystemBus(this));
Expand Down Expand Up @@ -68,6 +68,10 @@ public void Reset()
{
channel.Reset();
}

ldmaRegistersCollection.Reset();
ldmaXbarRegistersCollection.Reset();

UpdateInterrupts();
}

Expand Down Expand Up @@ -330,7 +334,6 @@ private void UpdateInterrupts()
private readonly DoubleWordRegisterCollection ldmaRegistersCollection;
private readonly DoubleWordRegisterCollection ldmaXbarRegistersCollection;
private readonly Machine machine;

private readonly DmaEngine engine;
private readonly HashSet<int> signals;
private readonly Channel[] channels;
Expand All @@ -341,7 +344,7 @@ private void UpdateInterrupts()

private class Channel
{
public Channel(EFR32xG22_LDMA parent, int index)
public Channel(SiLabs_LDMA_0_1 parent, int index)
{
this.parent = parent;
Index = index;
Expand All @@ -357,8 +360,8 @@ public Channel(EFR32xG22_LDMA parent, int index)
.WithReservedBits(0, 16)
.WithEnumField<DoubleWordRegister, ArbitrationSlotNumberMode>(16, 2, out arbitrationSlotNumberSelect, name: "ARBSLOTS")
.WithReservedBits(18, 2)
.WithEnumField<DoubleWordRegister, Sign>(20, 1, out sourceAddressIncrementSign, name: "SRCINCSIGN")
.WithEnumField<DoubleWordRegister, Sign>(21, 1, out destinationAddressIncrementSign, name: "DSTINCSIGN")
.WithEnumField<DoubleWordRegister, Sign>(20, 1, out SourceAddressIncrementSign, name: "SRCINCSIGN")
.WithEnumField<DoubleWordRegister, Sign>(21, 1, out DestinationAddressIncrementSign, name: "DSTINCSIGN")
.WithReservedBits(22, 10)
;
LoopCounterRegister = new DoubleWordRegister(parent)
Expand Down Expand Up @@ -443,7 +446,17 @@ public Channel(EFR32xG22_LDMA parent, int index)
name: "LINK")
.WithValueField(2, 30,
writeCallback: (_, value) => descriptor.LinkAddress = (uint)value,
valueProviderCallback: _ => descriptor.LinkAddress,
valueProviderCallback: _ =>
{
if(descriptorAddress.HasValue && descriptor.LinkMode == AddressingMode.Relative)
{
return (LinkStructureAddress + descriptorAddress.Value) >> 2;
}
else
{
return descriptor.LinkAddress;
}
},
name: "LINKADDR")
;

Expand Down Expand Up @@ -493,7 +506,7 @@ public void StartTransfer()
public void Reset()
{
descriptor = default(Descriptor);
pullTimer.Reset();
pullTimer.Enabled = false;
DoneInterrupt = false;
DoneInterruptEnable = false;
descriptorAddress = null;
Expand Down Expand Up @@ -665,7 +678,7 @@ private void Transfer()
if(descriptor.RequestTransferModeSelect == RequestTransferMode.Block)
{
var blockSizeMultiplier = Math.Min(TransferCount, BlockSizeMultiplier);
parent.Log(LogLevel.Debug, "Channel #{0} TransferCount={1} BlockSizeMultiplier={2}", Index, TransferCount, BlockSizeMultiplier);
parent.Log(LogLevel.Debug, "Channel #{0} TransferCount={1} blockSizeMultiplier={2}", Index, TransferCount, blockSizeMultiplier);
if(blockSizeMultiplier == TransferCount)
{
Done = true;
Expand Down Expand Up @@ -856,11 +869,11 @@ private bool SignalIsOn
private readonly IEnumRegisterField<SignalSelect> signalSelect;
private readonly IEnumRegisterField<SourceSelect> sourceSelect;
private readonly IEnumRegisterField<ArbitrationSlotNumberMode> arbitrationSlotNumberSelect;
private readonly IEnumRegisterField<Sign> sourceAddressIncrementSign;
private readonly IEnumRegisterField<Sign> destinationAddressIncrementSign;
private readonly IEnumRegisterField<Sign> SourceAddressIncrementSign;
private readonly IEnumRegisterField<Sign> DestinationAddressIncrementSign;
private readonly IValueRegisterField loopCounter;

private readonly EFR32xG22_LDMA parent;
private readonly SiLabs_LDMA_0_1 parent;
private readonly LimitTimer pullTimer;

protected enum StructureType : uint
Expand Down Expand Up @@ -919,25 +932,25 @@ protected enum AddressingMode : uint
private struct Descriptor
{
public string PrettyString => $@"Descriptor {{
structureType: {StructureType},
structureTransferRequest: {StructureTransferRequest},
transferCount: {TransferCount + 1},
byteSwap: {ByteSwap},
blockSize: {BlockSize},
operationDoneInterruptFlagSetEnable: {OperationDoneInterruptFlagSetEnable},
requestTransferModeSelect: {RequestTransferModeSelect},
decrementLoopCount: {DecrementLoopCount},
ignoreSingleRequests: {IgnoreSingleRequests},
sourceIncrement: {SourceIncrement},
size: {Size},
destinationIncrement: {DestinationIncrement},
sourceAddressingMode: {SourceAddressingMode},
destinationAddressingMode: {DestinationAddressingMode},
sourceAddress: 0x{SourceAddress:X},
destinationAddress: 0x{DestinationAddress:X},
linkMode: {LinkMode},
link: {Link},
linkAddress: 0x{(LinkAddress << 2):X}
StructureType: {StructureType},
StructureTransferRequest: {StructureTransferRequest},
TransferCount: {TransferCount + 1},
ByteSwap: {ByteSwap},
BlockSize: {BlockSize},
OperationDoneInterruptFlagSetEnable: {OperationDoneInterruptFlagSetEnable},
RequestTransferModeSelect: {RequestTransferModeSelect},
DecrementLoopCount: {DecrementLoopCount},
IgnoreSingleRequests: {IgnoreSingleRequests},
SourceIncrement: {SourceIncrement},
Size: {Size},
DestinationIncrement: {DestinationIncrement},
SourceAddressingMode: {SourceAddressingMode},
DestinationAddressingMode: {DestinationAddressingMode},
SourceAddress: 0x{SourceAddress:X},
DestinationAddress: 0x{DestinationAddress:X},
LinkMode: {LinkMode},
Link: {Link},
LinkAddress: 0x{(LinkAddress << 2):X}
}}";

// Some of this fields are read only via sysbus, but can be loaded from memory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

namespace Antmicro.Renode.Peripherals.DMA
{
public class EFR32MG24_LDMA : IBusPeripheral, IGPIOReceiver, IKnownSize
public class SiLabs_LDMA_0_3 : IBusPeripheral, IGPIOReceiver, IKnownSize
{
public EFR32MG24_LDMA(Machine machine)
public SiLabs_LDMA_0_3(Machine machine)
{
this.machine = machine;
engine = new DmaEngine(machine.GetSystemBus(this));
Expand Down Expand Up @@ -68,6 +68,10 @@ public void Reset()
{
channel.Reset();
}

ldmaRegistersCollection.Reset();
ldmaXbarRegistersCollection.Reset();

UpdateInterrupts();
}

Expand Down Expand Up @@ -327,7 +331,6 @@ private void UpdateInterrupts()
private readonly DoubleWordRegisterCollection ldmaRegistersCollection;
private readonly DoubleWordRegisterCollection ldmaXbarRegistersCollection;
private readonly Machine machine;

private readonly DmaEngine engine;
private readonly HashSet<int> signals;
private readonly Channel[] channels;
Expand All @@ -338,7 +341,7 @@ private void UpdateInterrupts()

private class Channel
{
public Channel(EFR32MG24_LDMA parent, int index)
public Channel(SiLabs_LDMA_0_3 parent, int index)
{
this.parent = parent;
Index = index;
Expand All @@ -354,8 +357,8 @@ public Channel(EFR32MG24_LDMA parent, int index)
.WithReservedBits(0, 16)
.WithEnumField<DoubleWordRegister, ArbitrationSlotNumberMode>(16, 2, out arbitrationSlotNumberSelect, name: "ARBSLOTS")
.WithReservedBits(18, 2)
.WithEnumField<DoubleWordRegister, Sign>(20, 1, out sourceAddressIncrementSign, name: "SRCINCSIGN")
.WithEnumField<DoubleWordRegister, Sign>(21, 1, out destinationAddressIncrementSign, name: "DSTINCSIGN")
.WithEnumField<DoubleWordRegister, Sign>(20, 1, out SourceAddressIncrementSign, name: "SRCINCSIGN")
.WithEnumField<DoubleWordRegister, Sign>(21, 1, out DestinationAddressIncrementSign, name: "DSTINCSIGN")
.WithReservedBits(22, 10)
;
LoopCounterRegister = new DoubleWordRegister(parent)
Expand Down Expand Up @@ -440,7 +443,17 @@ public Channel(EFR32MG24_LDMA parent, int index)
name: "LINK")
.WithValueField(2, 30,
writeCallback: (_, value) => descriptor.LinkAddress = (uint)value,
valueProviderCallback: _ => descriptor.LinkAddress,
valueProviderCallback: _ =>
{
if(descriptorAddress.HasValue && descriptor.LinkMode == AddressingMode.Relative)
{
return (LinkStructureAddress + descriptorAddress.Value) >> 2;
}
else
{
return descriptor.LinkAddress;
}
},
name: "LINKADDR")
;

Expand Down Expand Up @@ -490,7 +503,7 @@ public void StartTransfer()
public void Reset()
{
descriptor = default(Descriptor);
pullTimer.Reset();
pullTimer.Enabled = false;
DoneInterrupt = false;
DoneInterruptEnable = false;
descriptorAddress = null;
Expand Down Expand Up @@ -662,7 +675,7 @@ private void Transfer()
if(descriptor.RequestTransferModeSelect == RequestTransferMode.Block)
{
var blockSizeMultiplier = Math.Min(TransferCount, BlockSizeMultiplier);
parent.Log(LogLevel.Debug, "Channel #{0} TransferCount={1} BlockSizeMultiplier={2}", Index, TransferCount, BlockSizeMultiplier);
parent.Log(LogLevel.Debug, "Channel #{0} TransferCount={1} blockSizeMultiplier={2}", Index, TransferCount, blockSizeMultiplier);
if(blockSizeMultiplier == TransferCount)
{
Done = true;
Expand Down Expand Up @@ -863,11 +876,10 @@ private bool SignalIsOn
private readonly IEnumRegisterField<SignalSelect> signalSelect;
private readonly IEnumRegisterField<SourceSelect> sourceSelect;
private readonly IEnumRegisterField<ArbitrationSlotNumberMode> arbitrationSlotNumberSelect;
private readonly IEnumRegisterField<Sign> sourceAddressIncrementSign;
private readonly IEnumRegisterField<Sign> destinationAddressIncrementSign;
private readonly IEnumRegisterField<Sign> SourceAddressIncrementSign;
private readonly IEnumRegisterField<Sign> DestinationAddressIncrementSign;
private readonly IValueRegisterField loopCounter;

private readonly EFR32MG24_LDMA parent;
private readonly SiLabs_LDMA_0_3 parent;
private readonly LimitTimer pullTimer;

protected enum StructureType : uint
Expand Down Expand Up @@ -926,25 +938,25 @@ protected enum AddressingMode : uint
private struct Descriptor
{
public string PrettyString => $@"Descriptor {{
structureType: {StructureType},
structureTransferRequest: {StructureTransferRequest},
transferCount: {TransferCount + 1},
byteSwap: {ByteSwap},
blockSize: {BlockSize},
operationDoneInterruptFlagSetEnable: {OperationDoneInterruptFlagSetEnable},
requestTransferModeSelect: {RequestTransferModeSelect},
decrementLoopCount: {DecrementLoopCount},
ignoreSingleRequests: {IgnoreSingleRequests},
sourceIncrement: {SourceIncrement},
size: {Size},
destinationIncrement: {DestinationIncrement},
sourceAddressingMode: {SourceAddressingMode},
destinationAddressingMode: {DestinationAddressingMode},
sourceAddress: 0x{SourceAddress:X},
destinationAddress: 0x{DestinationAddress:X},
linkMode: {LinkMode},
link: {Link},
linkAddress: 0x{(LinkAddress << 2):X}
StructureType: {StructureType},
StructureTransferRequest: {StructureTransferRequest},
TransferCount: {TransferCount + 1},
ByteSwap: {ByteSwap},
BlockSize: {BlockSize},
OperationDoneInterruptFlagSetEnable: {OperationDoneInterruptFlagSetEnable},
RequestTransferModeSelect: {RequestTransferModeSelect},
DecrementLoopCount: {DecrementLoopCount},
IgnoreSingleRequests: {IgnoreSingleRequests},
SourceIncrement: {SourceIncrement},
Size: {Size},
DestinationIncrement: {DestinationIncrement},
SourceAddressingMode: {SourceAddressingMode},
DestinationAddressingMode: {DestinationAddressingMode},
SourceAddress: 0x{SourceAddress:X},
DestinationAddress: 0x{DestinationAddress:X},
LinkMode: {LinkMode},
Link: {Link},
LinkAddress: 0x{(LinkAddress << 2):X}
}}";

// Some of this fields are read only via sysbus, but can be loaded from memory
Expand Down
Loading