1 // 2 // Copyright (c) 2010-2023 Antmicro 3 // 4 // This file is licensed under the MIT License. 5 // Full license text is available in 'licenses/MIT.txt'. 6 // 7 8 using System.Collections.Generic; 9 using Antmicro.Renode.Core; 10 using Antmicro.Renode.Core.Structure.Registers; 11 using Antmicro.Renode.Peripherals.Bus; 12 13 namespace Antmicro.Renode.Peripherals 14 { 15 public class SimpleDMA : IDoubleWordPeripheral, IKnownSize 16 { SimpleDMA(IMachine machine)17 public SimpleDMA(IMachine machine) 18 { 19 sysbus = machine.GetSystemBus(this); 20 21 var registersMap = new Dictionary<long, DoubleWordRegister> 22 { 23 {(long)Registers.Data, new DoubleWordRegister(this).WithValueField(0, 32, out data)}, 24 25 {(long)Registers.WriteTo, new DoubleWordRegister(this).WithValueField(0, 32, FieldMode.Write, 26 writeCallback: (_, address) => { 27 sysbus.WriteDoubleWord(address, (uint)data.Value); 28 }) 29 }, 30 31 {(long)Registers.ReadFrom, new DoubleWordRegister(this).WithValueField(0, 32, FieldMode.Write, 32 writeCallback: (_, address) => { 33 data.Value = sysbus.ReadDoubleWord(address); 34 }) 35 } 36 }; 37 38 registers = new DoubleWordRegisterCollection(this, registersMap); 39 } 40 Reset()41 public void Reset() 42 { 43 registers.Reset(); 44 } 45 ReadDoubleWord(long offset)46 public uint ReadDoubleWord(long offset) 47 { 48 return registers.Read(offset); 49 } 50 WriteDoubleWord(long offset, uint value)51 public void WriteDoubleWord(long offset, uint value) 52 { 53 registers.Write(offset, value); 54 } 55 56 public long Size => 0x100; 57 58 private IValueRegisterField data; 59 60 private readonly DoubleWordRegisterCollection registers; 61 private readonly IBusController sysbus; 62 63 private enum Registers : long 64 { 65 Data = 0x0, 66 WriteTo = 0x04, 67 ReadFrom = 0x08 68 } 69 } 70 } 71