1 //
2 // Copyright (c) 2010-2018 Antmicro
3 // Copyright (c) 2011-2015 Realtime Embedded
4 //
5 // This file is licensed under the MIT License.
6 // Full license text is available in 'licenses/MIT.txt'.
7 //
8 using Antmicro.Renode.Logging;
9 
10 namespace Antmicro.Renode.Peripherals.USBDeprecated
11 {
12     public class Ulpi : IPhysicalLayer<byte>
13     {
Ulpi(long baseAddress)14         public Ulpi(long baseAddress)
15         {
16             BaseAddress = baseAddress;
17         }
18 
Read(byte offset)19         public byte Read(byte offset)
20         {
21             switch((Registers)offset)
22             {
23             case Registers.VendorIDLow:
24                 LastReadValue = (byte)(vendorID & 0xFF);
25                 break;
26             case Registers.VendorIDHigh:
27                 LastReadValue = (byte)((vendorID & 0xFF00) >> 8);
28                 break;
29             case Registers.ProductIDLow:
30                 LastReadValue = (byte)(productID & 0xFF);
31                 break;
32             case Registers.ProductIDHigh:
33                 LastReadValue = (byte)((productID & 0xFF00) >> 8);
34                 break;
35             case Registers.Scratch:
36                 LastReadValue = scratchRegister;
37                 break;
38             default:
39                 this.LogUnhandledRead(offset);
40                 LastReadValue = 0;
41                 break;
42             }
43 
44             return LastReadValue;
45         }
46 
Write(byte offset, byte value)47         public void Write(byte offset, byte value)
48         {
49             switch((Registers)offset)
50             {
51             case Registers.Scratch:
52                 scratchRegister = value;
53                 break;
54             default:
55                 this.LogUnhandledWrite(offset, value);
56                 break;
57             }
58         }
59 
Reset()60         public void Reset()
61         {
62             scratchRegister = 0;
63             LastReadValue = 0;
64         }
65 
66         public long BaseAddress { get; private set; }
67 
68         public byte LastReadValue { get; private set; }
69 
70         private byte scratchRegister;
71 
72         private enum Registers : uint
73         {
74             VendorIDLow = 0x0,
75             VendorIDHigh = 0x1,
76             ProductIDLow = 0x2,
77             ProductIDHigh = 0x3,
78             Scratch = 0x16
79         }
80 
81         private const uint vendorID = 0x04cc;
82         private const uint productID = 0x1504;
83     }
84 }
85 
86