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 System;
9 using Antmicro.Renode.Logging;
10 using Antmicro.Renode.Peripherals.Bus;
11 using Antmicro.Renode.Utilities;
12 
13 namespace Antmicro.Renode.Peripherals
14 {
15     [AllowedTranslations(AllowedTranslation.DoubleWordToWord)]
16     public class EfmSystemDevice: IBytePeripheral, IWordPeripheral
17     {
EfmSystemDevice(byte family, ushort partNo, ushort flash, ushort ram, byte rev)18         public EfmSystemDevice(byte family, ushort partNo, ushort flash, ushort ram, byte rev)
19         {
20             familyName = family;
21             flashSize = flash;
22             ramSize = ram;
23             productRevision = rev;
24             partNumber = partNo;
25         }
26 
Reset()27         public void Reset()
28         {
29             // nothing happens
30         }
31 
ReadByte(long offset)32         public byte ReadByte(long offset)
33         {
34             switch((EFMOffset)offset)
35             {
36             case EFMOffset.FamilyNameAdr:
37                 return familyName;
38             case EFMOffset.ProductRevisionAdr:
39                 return productRevision;
40             default:
41                 this.LogUnhandledRead(offset);
42                 return 0;
43             }
44         }
45 
WriteByte(long offset, byte value)46         public void WriteByte(long offset, byte value)
47         {
48             throw new NotImplementedException();
49         }
50 
ReadWord(long offset)51         public ushort ReadWord(long offset)
52         {
53             switch((EFMOffset)offset)
54             {
55             case EFMOffset.PartNumberAdr:
56                 return partNumber;
57             case EFMOffset.FlashSizeAdr:
58                 return flashSize;
59             case EFMOffset.RamSizeAdr:
60                 return ramSize;
61             default:
62                 this.LogUnhandledRead(offset);
63                 return 0;
64             }
65         }
66 
WriteWord(long offset, ushort value)67         public void WriteWord(long offset, ushort value)
68         {
69             throw new NotImplementedException();
70         }
71 
72         private byte familyName;
73         private ushort flashSize;
74         private ushort ramSize;
75         private byte productRevision;
76         private ushort partNumber;
77 
78         private enum EFMOffset:long
79         {
80             FamilyNameAdr      = 0xe,
81             FlashSizeAdr       = 0x8,
82             RamSizeAdr         = 0xa,
83             ProductRevisionAdr = 0xf,
84             PartNumberAdr      = 0xc
85         }
86     }
87 }
88