Skip to content

Commit

Permalink
[#46710] nvic: Get CPUID and NumberOfMPURegions from the CPU
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoscik committed Sep 28, 2023
1 parent 1297090 commit 212ff2e
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/Emulator/Cores/Arm-M/NVIC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ namespace Antmicro.Renode.Peripherals.IRQControllers
[AllowedTranslations(AllowedTranslation.ByteToDoubleWord | AllowedTranslation.WordToDoubleWord)]
public class NVIC : IDoubleWordPeripheral, IHasFrequency, IKnownSize, IIRQController
{
public NVIC(IMachine machine, long systickFrequency = 50 * 0x800000, byte priorityMask = 0xFF, uint cpuId = DefaultCpuId, uint numberOfMPURegions = 8, bool haltSystickOnDeepSleep = true)
public NVIC(IMachine machine, long systickFrequency = 50 * 0x800000, byte priorityMask = 0xFF, bool haltSystickOnDeepSleep = true)
{
priorities = new byte[IRQCount];
activeIRQs = new Stack<int>();
pendingIRQs = new SortedSet<int>();
systick = new LimitTimer(machine.ClockSource, systickFrequency, this, nameof(systick), uint.MaxValue, Direction.Descending, false, eventEnabled: true, autoUpdate: true);
this.machine = machine;
this.priorityMask = priorityMask;
this.cpuId = cpuId;
this.numberOfMPURegions = numberOfMPURegions;
this.haltSystickOnDeepSleep = haltSystickOnDeepSleep;
irqs = new IRQState[IRQCount];
IRQ = new GPIO();
Expand All @@ -50,6 +48,7 @@ public NVIC(IMachine machine, long systickFrequency = 50 * 0x800000, byte priori
public void AttachCPU(CortexM cpu)
{
this.cpu = cpu;
this.cpuId = cpu.ID;
mpuVersion = cpu.IsV8 ? MPUVersion.PMSAv8 : MPUVersion.PMSAv7;
}

Expand Down Expand Up @@ -681,7 +680,7 @@ private uint HandleMPUReadV7(long offset)
switch((RegistersV7)offset)
{
case RegistersV7.Type:
value = (numberOfMPURegions & 0xFF) << 8;
value = (cpu.NumberOfMPURegions & 0xFF) << 8;
break;
case RegistersV7.Control:
value = mpuControlRegister;
Expand Down Expand Up @@ -715,7 +714,7 @@ private uint HandleMPUReadV8(long offset)
switch((RegistersV8)offset)
{
case RegistersV8.Type:
value = (numberOfMPURegions & 0xFF) << 8;
value = (cpu.NumberOfMPURegions & 0xFF) << 8;
break;
case RegistersV8.Control:
value = cpu.PmsaV8Ctrl;
Expand Down Expand Up @@ -956,8 +955,6 @@ public byte BASEPRI
}
}

private uint numberOfMPURegions;

[Flags]
private enum IRQState : byte
{
Expand Down Expand Up @@ -1062,7 +1059,7 @@ private enum MPUVersion
private CortexM cpu;
private readonly LimitTimer systick;
private readonly IMachine machine;
private readonly uint cpuId;
private uint cpuId;

private const int MPUStart = 0xD90;
private const int MPUEnd = 0xDC4; // resized for compat. with V8 MPU
Expand Down

0 comments on commit 212ff2e

Please sign in to comment.