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.Collections.Generic; 9 using Antmicro.Renode.Backends.Terminals; 10 using Antmicro.Renode.Logging; 11 12 namespace Antmicro.Renode.Peripherals.SPI 13 { 14 public class FakeEfmSPITransmitter : BackendTerminal 15 { FakeEfmSPITransmitter()16 public FakeEfmSPITransmitter() 17 { 18 responses = new Dictionary<int, byte>(); 19 } 20 AddResponse(int byteNumber, byte data)21 public void AddResponse(int byteNumber, byte data) 22 { 23 responses.Add(byteNumber, data); 24 } 25 WriteChar(byte data)26 public override void WriteChar(byte data) 27 { 28 // write the response char 29 responses.TryGetValue(currentByteNo, out data); 30 CallCharReceived(data); 31 this.Log(LogLevel.Info, "Sent 0x{0:X} in {1} turn.", data, currentByteNo); 32 currentByteNo++; 33 } 34 35 private int currentByteNo; 36 private readonly Dictionary<int, byte> responses; 37 } 38 } 39 40