1
0

expose a count in MultiWidthFifo

This commit is contained in:
Howard Mao 2016-02-17 13:35:03 -08:00
parent 5241ee6442
commit fbd66ac87b

View File

@ -224,10 +224,14 @@ class MultiWidthFifo(inW: Int, outW: Int, n: Int) extends Module {
val io = new Bundle { val io = new Bundle {
val in = Decoupled(Bits(width = inW)).flip val in = Decoupled(Bits(width = inW)).flip
val out = Decoupled(Bits(width = outW)) val out = Decoupled(Bits(width = outW))
val count = UInt(OUTPUT, log2Up(n + 1))
} }
if (inW == outW) { if (inW == outW) {
io.out <> Queue(io.in, n) val q = Module(new Queue(Bits(width = inW), n))
q.io.enq <> io.in
io.out <> q.io.deq
io.count := q.io.count
} else if (inW > outW) { } else if (inW > outW) {
val nBeats = inW / outW val nBeats = inW / outW
@ -257,6 +261,7 @@ class MultiWidthFifo(inW: Int, outW: Int, n: Int) extends Module {
io.out.valid := size > UInt(0) io.out.valid := size > UInt(0)
io.out.bits := rdata(tail) io.out.bits := rdata(tail)
io.in.ready := size < UInt(n) io.in.ready := size < UInt(n)
io.count := size
} else { } else {
val nBeats = outW / inW val nBeats = outW / inW
@ -282,7 +287,8 @@ class MultiWidthFifo(inW: Int, outW: Int, n: Int) extends Module {
io.in.fire() -> (size + UInt(1)), io.in.fire() -> (size + UInt(1)),
io.out.fire() -> (size - UInt(nBeats)))) io.out.fire() -> (size - UInt(nBeats))))
io.out.valid := size >= UInt(nBeats) io.count := size >> UInt(log2Up(nBeats))
io.out.valid := io.count > UInt(0)
io.out.bits := rdata(tail) io.out.bits := rdata(tail)
io.in.ready := size < UInt(n * nBeats) io.in.ready := size < UInt(n * nBeats)
} }