Chisel language how to best use Queues?

十年热恋 提交于 2019-12-02 11:29:21

问题


I'm new in chisel, if someone can explain the role of:

1- Queue 2- DecoupledIO 3- Decoupled 3- ValidIO 4- Valid

Is this piece of chisel code correct?


...

val a = Decoupled()
val b = Decoupled()
val c = Decoupled()

...

val Reg_a = Reg(UInt())
val Reg_b = Reg(UInt())

...

when(io.a.valid && io.a.ready && io.b.valid && io.b.ready && io.c.valid &&     io.c.ready)
{

  Reg_a := io.a.bits.data
  Reg_b := io.b.bits.data
}

io.c.bits := Reg_a & Reg_b

...

Module.io.a    <>    Queue(Module_1.io.a_1)
Module.io.b    <>    Queue(Module_1.io.b_1)
Module_1.io.c_1 <>   Queue(Module.io.c)

regards!


回答1:


  1. Queue is a hardware module that implements a first in, first out queue with DecoupledIO inputs and outputs
  2. DecoupledIO is a ready/valid interface type with members ready, valid, and bits
  3. Decoupled is a helper to construct DecoupledIO from some other type
  4. ValidIO is similar to DecoupledIO except that it only has valid and bits
  5. Valid is similar to Decoupled for constructing ValidIOs

I can't tell what the code is trying to do, but here's an example of a Module that has 2 DecoupledIO inputs and 1 DecoupledIO output. It buffers the inputs with queues and then connects the output to the sum of the inputs:

import chisel3._
import chisel3.util._

class QueueModule extends Module {
  val io = IO(new Bundle {
    val a = Flipped(Decoupled(UInt(32.W))) // valid and bits are inputs
    val b = Flipped(Decoupled(UInt(32.W)))
    val z = Decoupled(UInt(32.W)) // valid and bits are outputs
  })
  // Note that a, b, and z are all of type DecoupledIO

  // Buffer the inputs with queues
  val qa = Queue(io.a) // io.a is the input to the FIFO
                       // qa is DecoupledIO output from FIFO
  val qb = Queue(io.b)

  // We only dequeue when io.z is ready
  qa.nodeq() // equivalent to qa.ready := false.B
  qb.nodeq()

  // When qa and qb have valid inputs and io.z is ready for an output
  when (qa.valid && qb.valid && io.z.ready) {
    io.z.enq(qa.deq() + qb.deq())
    /* The above is short for
      io.z.valid := true.B
      io.z.bits := qa.bits + qb.bits
      qa.ready := true.B
      qb.ready := true.B
    */
  }
}

Hope this helps!



来源:https://stackoverflow.com/questions/41122480/chisel-language-how-to-best-use-queues

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!