问题
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:
- Queue is a hardware module that implements a first in, first out queue with DecoupledIO inputs and outputs
- DecoupledIO is a ready/valid interface type with members ready, valid, and bits
- Decoupled is a helper to construct DecoupledIO from some other type
- ValidIO is similar to DecoupledIO except that it only has valid and bits
- 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