Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UARTBase: Implement IUARTWithBufferState #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Emulator/Main/Peripherals/UART/UARTBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Antmicro.Renode.Peripherals.UART
{
public abstract class UARTBase : NullRegistrationPointPeripheralContainer<IUART>, IUART
public abstract class UARTBase : NullRegistrationPointPeripheralContainer<IUART>, IUARTWithBufferState
{
protected UARTBase(IMachine machine) : base(machine)
{
Expand All @@ -34,6 +34,7 @@ public virtual void WriteChar(byte value)
}

queue.Enqueue(value);
BufferStateChanged?.Invoke(BufferState);
CharWritten();
}
}
Expand All @@ -60,6 +61,9 @@ public override void Unregister(IUART uart)
[field: Transient]
public event Action<byte> CharReceived;

public event Action<BufferState> BufferStateChanged;
public BufferState BufferState => Count != 0 ? BufferState.Ready : BufferState.Empty;

protected abstract void CharWritten();
protected abstract void QueueEmptied();

Expand All @@ -75,6 +79,7 @@ protected bool TryGetCharacter(out byte character)
character = queue.Dequeue();
if(queue.Count == 0)
{
BufferStateChanged?.Invoke(BufferState);
QueueEmptied();
}
return true;
Expand All @@ -91,6 +96,7 @@ protected void ClearBuffer()
lock(innerLock)
{
queue.Clear();
BufferStateChanged?.Invoke(BufferState);
QueueEmptied();
}
}
Expand Down