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.Exceptions; 10 using Antmicro.Renode.Logging; 11 using System.Linq; 12 13 namespace Antmicro.Renode.Peripherals.Miscellaneous 14 { 15 public sealed class PrimeCellIDHelper 16 { PrimeCellIDHelper(int peripheralSize, byte[] data, IPeripheral parent)17 public PrimeCellIDHelper(int peripheralSize, byte[] data, IPeripheral parent) 18 { 19 this.peripheralSize = peripheralSize; 20 this.data = data.ToArray(); // to obtain a copy 21 this.parent = parent; 22 if(data.Length != 8) 23 { 24 throw new RecoverableException("You have to provide full peripheral id and prime cell id (8 bytes)."); 25 } 26 } 27 Read(long offset)28 public byte Read(long offset) 29 { 30 if(offset >= peripheralSize || offset < peripheralSize - 8 * 4) 31 { 32 parent.LogUnhandledRead(offset); 33 return 0; 34 } 35 return data[8 - (peripheralSize - offset)/4]; 36 } 37 38 private readonly int peripheralSize; 39 private readonly IPeripheral parent; 40 private readonly byte[] data; 41 } 42 } 43 44