diff --git a/assertion/src/main/scala/mainOneHot.scala b/assertion/src/main/scala/mainOneHot.scala index ff30678..16c438e 100644 --- a/assertion/src/main/scala/mainOneHot.scala +++ b/assertion/src/main/scala/mainOneHot.scala @@ -15,15 +15,23 @@ class mainOneHot extends Module { val decode :: encode :: Nil = Enum(2) val stateReg = RegInit(decode) + io.dout := 0.U + when(stateReg === decode) { + io.dout := 1.U << io.data when(io.enc) { - io.dec := false.B - io.dout := 1.U << io.data + stateReg := encode + } + }. elsewhen (stateReg === encode) { + switch (io.data) { + is ("b0001".U) { io.dout := "b00".U} + is ("b0010".U) { io.dout := "b01".U} + is ("b0100".U) { io.dout := "b10".U} + is ("b1000".U) { io.dout := "b11".U} } - }.elsewhen(stateReg === encode) { when(io.dec) { - io.enc := false.B - io.dout := (1.U << 4) >> io.data + stateReg := decode } + }. otherwise { } -} \ No newline at end of file +} diff --git a/assertion/src/test/scala/fifoConcurrentAssertionTest.scala b/assertion/src/test/scala/fifoConcurrentAssertionTest.scala index 5282b46..1c62ad0 100644 --- a/assertion/src/test/scala/fifoConcurrentAssertionTest.scala +++ b/assertion/src/test/scala/fifoConcurrentAssertionTest.scala @@ -124,7 +124,6 @@ it should "writes and reads data concurrently" in { } assertEventuallyAlwaysEvent(dut, () => deq.notReady == true.B, enq.busy == true.B) receiver() - } } } diff --git a/assertion/src/test/scala/oneHotTest.scala b/assertion/src/test/scala/oneHotTest.scala index aafdd66..1d9a350 100644 --- a/assertion/src/test/scala/oneHotTest.scala +++ b/assertion/src/test/scala/oneHotTest.scala @@ -1,4 +1,4 @@ -/*import org.scalatest._ +import org.scalatest._ import assertionTiming._ import chisel3._ import chiseltest._ @@ -7,29 +7,39 @@ import chiseltest._ class oneHotTest extends FlatSpec with ChiselScalatestTester with Matchers { behavior of "assertOneHot" - it should "test count of bitset in binary" in { + it should "test decoding" in { test(new mainOneHot()) { dut => { - dut.io.s.poke("b10".U) + dut.io.dec.poke(true.B) + dut.io.data.poke("b01".U) dut.clock.step(1) - assertOneHot("b1000".U, "Error") - dut.io.c.expect("b0100".U) + assertOneHot("b0010".U) + } + } + } +it should "test decoding and FAIL" in { + test(new mainOneHot()) { + dut => { + dut.io.dec.poke(true.B) + dut.io.data.poke("b01".U) + dut.clock.step(1) + assertOneHot("b0110".U, "Decoding yields " + dut.io.dout.peek) } } } - it should "test count of bitset in binary concurrently" in { + + it should "test encoding" in { test(new mainOneHot()) { dut => { - dut.io.s.poke("b10".U) + dut.io.enc.poke(true.B) + dut.clock.step(1) + dut.io.data.poke("b0100".U) dut.clock.step(1) - assertAlways(dut, () => assertOneHot(dut.io.c.peek), 10) - dut.clock.step(2) - dut.io.s.poke("b11".U) - dut.clock.step(2) - dut.io.s.poke("b00".U) + dut.io.dout.expect("b10".U) + //assertOneHot("b10".U) } } } -}*/ +}