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/AsyncFifoReadSide.lvt
namespace Livt.Collections
/**
* Internal read-clock owner constructed by AsyncFifo.
* Uses its supplied context and coordinated local clear; not an application API.
*/
component AsyncFifoReadSide<T, CAPACITY: int>
{
// Address and wrap-bit widths for power-of-two storage.
const ADDRESS_BITS: int = Bits.RequiredFor(CAPACITY - 1)
const POINTER_BITS: int = ADDRESS_BITS + 1
// Constructor-bound requests and remote pointer/storage signals.
flush: bool
pop: bool
remote: logic[POINTER_BITS]
inputData: T
// Signal-level pointer: scheduled accessors would add an address cycle.
public binary: out logic[POINTER_BITS]
public gray: out logic[POINTER_BITS]
public address: out logic[ADDRESS_BITS]
// Destination-clock samples of the remote Gray pointer.
stage1: logic[POINTER_BITS]
stage2: logic[POINTER_BITS]
// Registered read response, exposed combinationally to avoid accessor latency.
response: T
responseValid: bool
public data: out T
public valid: out bool
// Local clear state and transfer status.
clearSeen: bool
public cleared: out bool
public accepted: out bool
public empty: out bool
/**
* Binds the supplied clock/reset context and live input signals.
* source identifies the write-domain pointer and stored payload; the local
* two-register receiver and FIFO ownership protocol implement their crossing.
* The caller must coordinate reset/clear in both domains before traffic.
*/
new(
domain: IContext,
source: IContext,
flush: in bool,
pop: in bool,
@RefContext(source) remote: in logic[POINTER_BITS],
@RefContext(source) inputData: in T
)
{
context = domain
this.flush = flush
this.pop = pop
this.remote = remote
this.inputData = inputData
}
/**
* Computes local status without adding clocked accessor latency.
*/
process Status[]()
{
cleared = clearSeen
data = response
valid = responseValid && !flush && context.rst == 0b0
empty = gray == stage2
address = (binary as uint) as logic[ADDRESS_BITS]
accepted = !flush && context.rst == 0b0 && pop && !empty
}
/**
* Advances local state once per clock edge; preserves two synchronizer stages.
*/
process Update()
{
state {
if (flush) {
clearSeen = true
binary = 0
gray = 0
stage1 = 0
stage2 = 0
responseValid = false
} else {
clearSeen = false
// Advance the synchronizer using its previous first-stage sample.
var previous = stage1
stage1 = remote
stage2 = previous
responseValid = accepted
if (accepted) {
// FIFO pointer synchronization makes this stored word safe to capture.
response = inputData
var next = ((binary as uint) + 1) & (((2 * CAPACITY) - 1) as uint)
binary = next as logic[POINTER_BITS]
gray = (next ^ (next >> 1)) as logic[POINTER_BITS]
}
}
}
}
}