Search code examples
riscvchisel

What does Queue() function do in Chisel?


I was reading source code of rocket chip, in rocc.scala file in rocket/src/main/scala/ there is an example AccumulatorExample for using rocc. At first part of the code there is a function Queue() that I couldn't figure out what it's doing?

   val n = 4
   val regfile = Mem(UInt(width = params(XprLen)), n)
   val busy = Vec.fill(n){Reg(init=Bool(false))}

  val cmd = Queue(io.cmd)
  val funct = cmd.bits.inst.funct
  val addr = cmd.bits.inst.rs2(log2Up(n)-1,0)
  val doWrite = funct === UInt(0)
  val doRead = funct === UInt(1)
  val doLoad = funct === UInt(2)
  val doAccum = funct === UInt(3)
  val memRespTag = io.mem.resp.bits.tag(log2Up(n)-1,0)

Thanks


Solution

  • Queue is a Module providing a hardware queue. Circle-talk I know but it's the best I can give. Hope this helps! Your code looks like it is setting the source of the queue as the io.cmd.

    Constructor:
    
    Queue(enq:DecoupledIO, entries:Int)
    enq DecoupledIO source for the queue
    entries size of queue
    
    Interface:
    
    .io.enq Decoupled | IO source (flipped)
    .io.deq Decoupled  | IO sink
    .io.count UInt  | count of elements in the queue