SlowQueue.scala 823 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package chisel.miscutils
import  chisel3._
import  chisel3.util._

/** A slow queue which delays each element by a configurable delay. */
class SlowQueue(width: Int, val delay: Int = 10) extends Module {
  val io = IO(new Bundle {
    val enq = Flipped(Decoupled(UInt(width.W)))
    val deq = Decoupled(UInt(width.W))
    val dly = Input(UInt(log2Ceil(delay).W))
  })

  val waiting :: ready :: Nil = Enum(2)
  val state = RegInit(ready)

16
  val wr = RegInit(UInt(log2Ceil(delay).W), io.dly)
17
18
19
20
21

  io.deq.bits  := io.enq.bits
  io.enq.ready := io.deq.ready && state === ready
  io.deq.valid := io.enq.valid && state === ready

22
23
24
  when (state === ready && io.enq.ready && io.deq.valid) {
    state := waiting
    wr    := io.dly
25
  }
26
27
28
  when (state === waiting) {
    wr := wr - 1.U
    when (wr === 0.U) { state := ready }
29
30
31
  }
}