1 // 2 // Copyright (c) 2010-2021 Antmicro 3 // 4 // This file is licensed under the MIT License. 5 // Full license text is available in 'licenses/MIT.txt'. 6 // 7 using Antmicro.Renode.Logging; 8 using Antmicro.Renode.Peripherals.SPI; 9 using System.Collections.Generic; 10 11 namespace Antmicro.Renode.Peripherals.Mocks 12 { 13 public class DummySPISlave : ISPIPeripheral 14 { DummySPISlave()15 public DummySPISlave() 16 { 17 buffer = new Queue<byte>(); 18 } 19 EnqueueValue(byte val)20 public void EnqueueValue(byte val) 21 { 22 buffer.Enqueue(val); 23 } 24 FinishTransmission()25 public void FinishTransmission() 26 { 27 idx = 0; 28 } 29 Reset()30 public void Reset() 31 { 32 buffer.Clear(); 33 idx = 0; 34 } 35 Transmit(byte data)36 public byte Transmit(byte data) 37 { 38 this.Log(LogLevel.Debug, "Data received: 0x{0:X} (idx: {1})", data, idx); 39 idx++; 40 if(buffer.Count == 0) 41 { 42 this.Log(LogLevel.Debug, "No data left in buffer, returning 0."); 43 return 0; 44 } 45 return buffer.Dequeue(); 46 } 47 48 private int idx; 49 50 private readonly Queue<byte> buffer; 51 } 52 } 53