diff --git a/src/Emulator/Main/Peripherals/UART/UARTBase.cs b/src/Emulator/Main/Peripherals/UART/UARTBase.cs index 8df4b367d..950387258 100644 --- a/src/Emulator/Main/Peripherals/UART/UARTBase.cs +++ b/src/Emulator/Main/Peripherals/UART/UARTBase.cs @@ -15,7 +15,7 @@ namespace Antmicro.Renode.Peripherals.UART { - public abstract class UARTBase : NullRegistrationPointPeripheralContainer, IUART + public abstract class UARTBase : NullRegistrationPointPeripheralContainer, IUARTWithBufferState { protected UARTBase(IMachine machine) : base(machine) { @@ -34,6 +34,7 @@ public virtual void WriteChar(byte value) } queue.Enqueue(value); + BufferStateChanged?.Invoke(BufferState); CharWritten(); } } @@ -60,6 +61,9 @@ public override void Unregister(IUART uart) [field: Transient] public event Action CharReceived; + public event Action BufferStateChanged; + public BufferState BufferState => Count != 0 ? BufferState.Ready : BufferState.Empty; + protected abstract void CharWritten(); protected abstract void QueueEmptied(); @@ -75,6 +79,7 @@ protected bool TryGetCharacter(out byte character) character = queue.Dequeue(); if(queue.Count == 0) { + BufferStateChanged?.Invoke(BufferState); QueueEmptied(); } return true; @@ -91,6 +96,7 @@ protected void ClearBuffer() lock(innerLock) { queue.Clear(); + BufferStateChanged?.Invoke(BufferState); QueueEmptied(); } }