diff --git a/2.6_chiseltest.ipynb b/2.6_chiseltest.ipynb index d4b4e7e..d00de66 100644 --- a/2.6_chiseltest.ipynb +++ b/2.6_chiseltest.ipynb @@ -420,26 +420,26 @@ " val x = Reg(UInt())\n", " val y = Reg(UInt())\n", " val busy = RegInit(false.B)\n", - " val resultValid = RegInit(false.B)\n", "\n", " input.ready := ! busy\n", - " output.valid := resultValid\n", " output.bits := DontCare\n", + " output.valid := false.B\n", "\n", " when(busy) {\n", " // during computation keep subtracting the smaller from the larger\n", - " when(x > y) {\n", - " x := x - y\n", + " when(y > 0.U) {\n", + " when(x > y) {\n", + " x := x - y\n", + " }.otherwise {\n", + " y := y - x\n", + " }\n", " }.otherwise {\n", - " y := y - x\n", - " }\n", - " when(y === 0.U) {\n", " // when y becomes zero computation is over, signal valid data to output\n", " output.bits.value1 := xInitial\n", " output.bits.value2 := yInitial\n", " output.bits.gcd := x\n", " output.valid := true.B\n", - " busy := false.B\n", + " busy := ! output.ready\n", " }\n", " }.otherwise {\n", " when(input.valid) {\n", @@ -450,7 +450,7 @@ " xInitial := bundle.value1\n", " yInitial := bundle.value2\n", " busy := true.B\n", - " resultValid := false.B\n", + " output.valid := false.B\n", " }\n", " }\n", "}\n" @@ -483,9 +483,19 @@ "metadata": {}, "outputs": [], "source": [ - "test(new DecoupledGcd(16)) { dut =>\n", + "\n", + "test(new MultiIOModule {\n", + " val input = IO(Flipped(Decoupled(new GcdInputBundle(16))))\n", + " val output = IO(Decoupled(new GcdOutputBundle(16)))\n", + " val clk8to1 = IO(Output(Clock()))\n", + " val gcd = Module(new DecoupledGcd(16))\n", + " gcd.input := input\n", + " output := gcd.output\n", + " val cnt = Counter(true.B, 16)\n", + " clk8to1 := cnt._1(3).asClock\n", + "}) { dut =>\n", " dut.input.initSource().setSourceClock(dut.clock)\n", - " dut.output.initSink().setSinkClock(dut.clock)\n", + " dut.output.initSink().setSinkClock(dut.clk8to1) // the sink uses a slower clock so that backpressure is more likely\n", "\n", " val testValues = for { x <- 1 to 10; y <- 1 to 10} yield (x, y)\n", " val inputSeq = testValues.map { case (x, y) =>\n", @@ -500,7 +510,7 @@ " }.fork {\n", " dut.output.expectDequeueSeq(resultSeq)\n", " }.join()\n", - "}\n" + "}" ] }, { @@ -531,4 +541,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} +} \ No newline at end of file