Livt packages
Livt.Collections
Version 1.4.5
Fixed-capacity FIFOs, queues, stacks, circular buffers, lists, and bit sets for Livt hardware.
Published files (69)
src/fifo/AsyncFifo.lvt
namespace Livt.Collections
/**
* Two-clock FIFO owning a compile-time-selected payload store.
* Power-of-two CAPACITY >= 2; opaque payload T. Default storage is Auto array.
* pushAccepted/popAccepted are pre-edge decisions in their own contexts.
* popData/popValid are the registered read response after the accepting edge.
* Storage inherits writeContext; the FIFO owns readContext response registration.
* Clear both endpoints while traffic is stopped; wait for both cleared flags.
* See docs/async-fifo.md for reset, CDC constraints and read reservation.
*/
component AsyncFifo<
T,
CAPACITY: int = 256,
STORAGE: IFifoStorage<T, FifoStorageGeometry<CAPACITY>> & new() = AsyncFifoArray<T, CAPACITY>
>
{
static assert CAPACITY >= 2, "AsyncFifo capacity must be at least two"
static assert CAPACITY <= 1048576, "AsyncFifo capacity exceeds supported pointer arithmetic"
static assert (CAPACITY & (CAPACITY - 1)) == 0, "AsyncFifo capacity must be a power of two"
// Owned provider; payload and capacity checked by its constraint.
storage: STORAGE
inputData: T
selectedData: T
// Owned endpoints with independently bound clocks.
writeSide: AsyncFifoWriteSide<T, CAPACITY>
readSide: AsyncFifoReadSide<T, CAPACITY>
readOrigin: IContext
// Write/read transfer decisions and registered read response.
public pushAccepted: out bool
@RefContext(readOrigin)
public popAccepted: out bool
@RefContext(readOrigin)
public popValid: out bool
@RefContext(readOrigin)
public popData: out T
public full: out bool
@RefContext(readOrigin)
public empty: out bool
// Local clear acknowledgments; callers must coordinate both domains.
public writeCleared: out bool
@RefContext(readOrigin)
public readCleared: out bool
/**
* Owns selected storage in writeContext and endpoints in both clock contexts.
* The caller must coordinate reset/clear in both domains before traffic.
*/
new(
writeContext: IContext,
readContext: IContext,
@RefContext(writeContext) writeClear: in bool,
@RefContext(readContext) readClear: in bool,
@RefContext(writeContext) push: in bool,
@RefContext(writeContext) data: in T,
@RefContext(readContext) pop: in bool
)
{
// Bind storage inheritance to the write context; the read endpoint is explicit.
context = writeContext
readOrigin = readContext
storage = new STORAGE()
inputData = data
writeSide = new AsyncFifoWriteSide<T, CAPACITY>(
writeContext,
readContext,
writeClear,
push,
readSide.gray
)
readSide = new AsyncFifoReadSide<T, CAPACITY>(
readContext,
writeContext,
readClear,
pop,
writeSide.gray,
selectedData
)
}
/**
* Exposes each owned endpoint in its respective clock domain.
*/
process Wire[]()
{
selectedData = storage.readData
storage.writeEnable = writeSide.accepted
storage.writeAddress = writeSide.address as uint
storage.writeData = inputData
storage.readAddress = (cross readSide.address) as uint
pushAccepted = writeSide.accepted
popAccepted = readSide.accepted
popValid = readSide.valid
popData = readSide.data
writeCleared = writeSide.cleared
readCleared = readSide.cleared
full = writeSide.full
empty = readSide.empty
}
}