-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/Emulator/Peripherals/Peripherals/Miscellaneous/NRF52840_ECB.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} | ||
} |