classQueueTestextendsModule{ val io = IO(newBundle { val in = Flipped(Decoupled(UInt(8.W))) val out = Decoupled(UInt(8.W)) }) val queue = Queue(io.in,2) //创建一个Queue io.out <> queue }
objecttestMainextendsApp{ test(newQueueTest) { c => c.io.out.ready.poke(false.B) c.io.in.valid.poke(true.B) // Enqueue an element c.io.in.bits.poke(42.U) println(s"Starting:") println(s"\tio.in: ready=${c.io.in.ready.peek().litValue}") println(s"\tio.out: valid=${c.io.out.valid.peek().litValue}, bits=${c.io.out.bits.peek().litValue}") c.clock.step(1)
c.io.in.valid.poke(true.B) // Enqueue another element c.io.in.bits.poke(43.U) // What do you think io.out.valid and io.out.bits will be? println(s"After first enqueue:") println(s"\tio.in: ready=${c.io.in.ready.peek().litValue}") println(s"\tio.out: valid=${c.io.out.valid.peek().litValue}, bits=${c.io.out.bits.peek().litValue}") c.clock.step(1)
c.io.in.valid.poke(true.B) // Read a element, attempt to enqueue c.io.in.bits.poke(44.U) c.io.out.ready.poke(true.B) // What do you think io.in.ready will be, and will this enqueue succeed, and what will be read? println(s"On first read:") println(s"\tio.in: ready=${c.io.in.ready.peek()}") println(s"\tio.out: valid=${c.io.out.valid.peek()}, bits=${c.io.out.bits.peek()}") c.clock.step(1)
c.io.in.valid.poke(false.B) // Read elements out c.io.out.ready.poke(true.B) // What do you think will be read here? println(s"On second read:") println(s"\tio.in: ready=${c.io.in.ready.peek()}") println(s"\tio.out: valid=${c.io.out.valid.peek()}, bits=${c.io.out.bits.peek()}") c.clock.step(1)
// Will a third read produce anything? println(s"On third read:") println(s"\tio.in: ready=${c.io.in.ready.peek()}") println(s"\tio.out: valid=${c.io.out.valid.peek()}, bits=${c.io.out.bits.peek()}") c.clock.step(1) } Driver.execute(args, () => newQueueTest) //生成 .v文件 }
Starting: io.in: ready=1 io.out: valid=0, bits=0 After first enqueue: io.in: ready=1 io.out: valid=1, bits=42 On first read: io.in: ready=Bool(false) io.out: valid=Bool(true), bits=UInt<8>(42) On second read: io.in: ready=Bool(true) io.out: valid=Bool(true), bits=UInt<8>(43) On third read: io.in: ready=Bool(true) io.out: valid=Bool(false), bits=UInt<8>(42)