diff --git a/src/Emulator/Peripherals/Peripherals/Mocks/DummySPISlave.cs b/src/Emulator/Peripherals/Peripherals/Mocks/DummySPISlave.cs index c2809026e..ec9de0a45 100644 --- a/src/Emulator/Peripherals/Peripherals/Mocks/DummySPISlave.cs +++ b/src/Emulator/Peripherals/Peripherals/Mocks/DummySPISlave.cs @@ -11,6 +11,15 @@ namespace Antmicro.Renode.Peripherals.Mocks { + /// + /// A dummy SPI slave peripheral implementing for mocking communication and testing SPI controllers. + /// Model supports queuing data to its buffer, that will be return upon SPI Transmit. Additionally it exposes events that allow mocking more complex models. + /// Example: + /// python """ + /// dummy = monitor.Machine["sysbus.spi.dummy"] + /// dummy.DataReceived += lambda data: dummy.EnqueueValue(data) + /// """ + /// public class DummySPISlave : ISPIPeripheral { public DummySPISlave() @@ -25,6 +34,7 @@ public void EnqueueValue(byte val) public void FinishTransmission() { + TransmissionFinished?.Invoke(); idx = 0; } @@ -34,8 +44,16 @@ public void Reset() idx = 0; } + /// + /// Implements . + /// Logs the received . + /// + /// + /// This method invokes event. + /// public byte Transmit(byte data) { + DataReceived?.Invoke(data); this.Log(LogLevel.Debug, "Data received: 0x{0:X} (idx: {1})", data, idx); idx++; if(buffer.Count == 0) @@ -46,8 +64,17 @@ public byte Transmit(byte data) return buffer.Dequeue(); } - private int idx; + /// + /// Informs about the method being called with the first argument being the data written to the model. + /// + public event Action DataReceived; + + /// + /// Informs about the method being called. + /// + public event Action TransmissionFinished; + private int idx; private readonly Queue buffer; } } \ No newline at end of file