Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NRF52840_ECB: Add peripheral model
Browse files Browse the repository at this point in the history
grifcj committed Nov 7, 2021
1 parent b70d144 commit 37d4d74
Showing 2 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Emulator/Peripherals/Peripherals.csproj
Original file line number Diff line number Diff line change
@@ -344,6 +344,7 @@
<Compile Include="Peripherals\ATAPI\CDROM.cs" />
<Compile Include="Peripherals\Miscellaneous\STM32F4_RCC.cs" />
<Compile Include="Peripherals\Miscellaneous\NRF52840_CLOCK.cs" />
<Compile Include="Peripherals\Miscellaneous\NRF52840_ECB.cs" />
<Compile Include="Peripherals\Miscellaneous\NRF52840_PPI.cs" />
<Compile Include="Peripherals\Miscellaneous\NRF52840_RNG.cs" />
<Compile Include="Peripherals\Miscellaneous\INRFEventProvider.cs" />
84 changes: 84 additions & 0 deletions src/Emulator/Peripherals/Peripherals/Miscellaneous/NRF52840_ECB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// 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 Antmicro.Renode.Core;
using Antmicro.Renode.Core.Structure.Registers;
using Antmicro.Renode.Logging;

namespace Antmicro.Renode.Peripherals.Miscellaneous
{
public sealed class NRF52840_ECB : BasicDoubleWordPeripheral, IKnownSize, INRFEventProvider
{
public NRF52840_ECB(Machine machine) : base(machine)
{
IRQ = new GPIO();
DefineRegisters();
}

public override void Reset()
{
base.Reset();
IRQ.Unset();
}

public long Size => 0x1000;

public GPIO IRQ { get; }

public event Action<uint> EventTriggered;

private void DefineRegisters()
{
Registers.Start.Define(this)
.WithFlag(0, FieldMode.Write, name: "TASKS_START",
writeCallback: (_, __) => {
eventEnd.Value = true;
EventTriggered?.Invoke((uint)Registers.EventEnd);
IRQ.Set(endInterruptEnabled.Value);
})
.WithReservedBits(1, 31)
;

Registers.EventEnd.Define(this, name: "EVENTS_ENDECB")
.WithFlag(0, out eventEnd, name: "ENDECB")
.WithReservedBits(1, 31)
;

Registers.InterruptEnableSet.Define(this, name: "INTENSET")
.WithFlag(0, out endInterruptEnabled, FieldMode.Set | FieldMode.Read, name: "ENDECB")
.WithReservedBits(1, 31)
;

Registers.InterruptEnableClear.Define(this, name: "INTENCLR")
.WithFlag(0,
writeCallback: (_, value) => endInterruptEnabled.Value &= !value,
valueProviderCallback: _ => endInterruptEnabled.Value, name: "ENDECB")
.WithReservedBits(1, 31)
;

Registers.DataPtr.Define(this)
.WithValueField(0, 32, out dataPointer, name: "ECBDATAPTR")
;
}

private IFlagRegisterField eventEnd;
private IFlagRegisterField endInterruptEnabled;
private IValueRegisterField dataPointer;

private enum Registers
{
Start = 0x0,
Stop = 0x4,
EventEnd = 0x100,
EventError = 0x104,
InterruptEnableSet = 0x304,
InterruptEnableClear = 0x308,
DataPtr = 0x504,
}
}
}

0 comments on commit 37d4d74

Please sign in to comment.