1 //
2 // Copyright (c) 2010-2024 Antmicro
3 //
4 // This file is licensed under the MIT License.
5 // Full license text is available in 'licenses/MIT.txt'.
6 //
7 using System.Collections.Generic;
8 using Antmicro.Renode.Peripherals.Bus;
9 using Antmicro.Renode.Core.Structure.Registers;
10 using Antmicro.Renode.Logging;
11 
12 namespace Antmicro.Renode.Peripherals.Mocks
13 {
14     public class MockBytePeripheralWithoutTranslations : IBytePeripheral
15     {
MockBytePeripheralWithoutTranslations()16         public MockBytePeripheralWithoutTranslations()
17         {
18             registers = new ByteRegisterCollection(this, new Dictionary<long, ByteRegister>{
19                 { 0x0, new ByteRegister(this, 0x0).WithValueField(0, 8) },
20                 { 0x1, new ByteRegister(this, 0x0).WithValueField(0, 8) },
21                 { 0x2, new ByteRegister(this, 0x0).WithValueField(0, 8) },
22                 { 0x3, new ByteRegister(this, 0x0).WithValueField(0, 8) },
23                 { 0x4, new ByteRegister(this, 0x0).WithValueField(0, 8) },
24                 { 0x5, new ByteRegister(this, 0x0).WithValueField(0, 8) },
25                 { 0x6, new ByteRegister(this, 0x0).WithValueField(0, 8) },
26                 { 0x7, new ByteRegister(this, 0x0).WithValueField(0, 8) },
27             });
28             regionRegisters = new ByteRegisterCollection(this, new Dictionary<long, ByteRegister>{
29                 { 0x0, new ByteRegister(this, 0x0).WithValueField(0, 8) },
30                 { 0x1, new ByteRegister(this, 0x0).WithValueField(0, 8) },
31                 { 0x2, new ByteRegister(this, 0x0).WithValueField(0, 8) },
32                 { 0x3, new ByteRegister(this, 0x0).WithValueField(0, 8) },
33                 { 0x4, new ByteRegister(this, 0x0).WithValueField(0, 8) },
34                 { 0x5, new ByteRegister(this, 0x0).WithValueField(0, 8) },
35                 { 0x6, new ByteRegister(this, 0x0).WithValueField(0, 8) },
36                 { 0x7, new ByteRegister(this, 0x0).WithValueField(0, 8) },
37             });
38             Reset();
39         }
40 
Reset()41         public void Reset()
42         {
43             registers.Reset();
44             regionRegisters.Reset();
45         }
46 
ReadByte(long offset)47         public virtual byte ReadByte(long offset)
48         {
49             return registers.Read(offset);
50         }
51 
WriteByte(long offset, byte value)52         public virtual void WriteByte(long offset, byte value)
53         {
54             registers.Write(offset, value);
55         }
56 
57         [ConnectionRegion("region")]
ReadByteFromRegion(long offset)58         public byte ReadByteFromRegion(long offset)
59         {
60             return regionRegisters.Read(offset);
61         }
62 
63         [ConnectionRegion("region")]
WriteByteToRegion(long offset, byte value)64         public void WriteByteToRegion(long offset, byte value)
65         {
66             regionRegisters.Write(offset, value);
67         }
68 
69         private readonly ByteRegisterCollection registers;
70         private readonly ByteRegisterCollection regionRegisters;
71     }
72 }
73