diff options
| author | Aditya Naik | 2023-11-23 03:11:56 -0800 |
|---|---|---|
| committer | Aditya Naik | 2023-11-23 03:11:56 -0800 |
| commit | af415532cf160e63e971ceb301833b8433c18a50 (patch) | |
| tree | 1fef70139846f57298c8e24a590490a74249f7dd /src/test/scala/cookbook | |
| parent | 8200c0cdf1d471453946d5ae24bc99757b2ef02d (diff) | |
cleanup
Diffstat (limited to 'src/test/scala/cookbook')
| -rw-r--r-- | src/test/scala/cookbook/Bundle2UInt.scala | 31 | ||||
| -rw-r--r-- | src/test/scala/cookbook/CookbookSpec.scala | 22 | ||||
| -rw-r--r-- | src/test/scala/cookbook/FSM.scala | 66 | ||||
| -rw-r--r-- | src/test/scala/cookbook/RegOfVec.scala | 33 | ||||
| -rw-r--r-- | src/test/scala/cookbook/UInt2Bundle.scala | 30 | ||||
| -rw-r--r-- | src/test/scala/cookbook/UInt2VecOfBool.scala | 29 | ||||
| -rw-r--r-- | src/test/scala/cookbook/VecOfBool2UInt.scala | 28 |
7 files changed, 0 insertions, 239 deletions
diff --git a/src/test/scala/cookbook/Bundle2UInt.scala b/src/test/scala/cookbook/Bundle2UInt.scala deleted file mode 100644 index 21d06df7..00000000 --- a/src/test/scala/cookbook/Bundle2UInt.scala +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -package cookbook - -import chisel3._ - -/* ### How do I create a UInt from an instance of a Bundle? - * - * Call asUInt on the Bundle instance - */ -class Bundle2UInt extends CookbookTester(1) { - // Example - class MyBundle extends Bundle { - val foo = UInt(4.W) - val bar = UInt(4.W) - } - val bundle = Wire(new MyBundle) - bundle.foo := 0xc.U - bundle.bar := 0x3.U - val uint = bundle.asUInt - printf(p"$uint") // 195 - - // Test - assert(uint === 0xc3.U) -} - -class Bundle2UIntSpec extends CookbookSpec { - "Bundle2UInt" should "work" in { - assertTesterPasses { new Bundle2UInt } - } -} diff --git a/src/test/scala/cookbook/CookbookSpec.scala b/src/test/scala/cookbook/CookbookSpec.scala deleted file mode 100644 index 7d6c9726..00000000 --- a/src/test/scala/cookbook/CookbookSpec.scala +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -package cookbook - -import chisel3._ -import chisel3.util._ -import chisel3.testers.BasicTester - -import chiselTests.ChiselFlatSpec - -/** Tester for concise cookbook tests - * - * Provides a length of test after which the test will pass - */ -abstract class CookbookTester(length: Int) extends BasicTester { - require(length >= 0, "Simulation length must be non-negative!") - - val (cycle, done) = Counter(true.B, length + 1) // + 1 cycle because done is actually wrap - when(done) { stop() } -} - -abstract class CookbookSpec extends ChiselFlatSpec diff --git a/src/test/scala/cookbook/FSM.scala b/src/test/scala/cookbook/FSM.scala deleted file mode 100644 index 40f8abc7..00000000 --- a/src/test/scala/cookbook/FSM.scala +++ /dev/null @@ -1,66 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -package cookbook - -import chisel3._ -import chisel3.util._ - -/* ### How do I create a finite state machine? - * - * Use ChiselEnum to construct the states and switch & is to construct the FSM - * control logic - */ - -class DetectTwoOnes extends Module { - val io = IO(new Bundle { - val in = Input(Bool()) - val out = Output(Bool()) - }) - - object State extends ChiselEnum { - val sNone, sOne1, sTwo1s = Value - } - - val state = RegInit(State.sNone) - - io.out := (state === State.sTwo1s) - - switch(state) { - is(State.sNone) { - when(io.in) { - state := State.sOne1 - } - } - is(State.sOne1) { - when(io.in) { - state := State.sTwo1s - }.otherwise { - state := State.sNone - } - } - is(State.sTwo1s) { - when(!io.in) { - state := State.sNone - } - } - } -} - -class DetectTwoOnesTester extends CookbookTester(10) { - - val dut = Module(new DetectTwoOnes) - - // Inputs and expected results - val inputs: Vec[Bool] = VecInit(false.B, true.B, false.B, true.B, true.B, true.B, false.B, true.B, true.B, false.B) - val expected: Vec[Bool] = - VecInit(false.B, false.B, false.B, false.B, false.B, true.B, true.B, false.B, false.B, true.B) - - dut.io.in := inputs(cycle) - assert(dut.io.out === expected(cycle)) -} - -class FSMSpec extends CookbookSpec { - "DetectTwoOnes" should "work" in { - assertTesterPasses { new DetectTwoOnesTester } - } -} diff --git a/src/test/scala/cookbook/RegOfVec.scala b/src/test/scala/cookbook/RegOfVec.scala deleted file mode 100644 index ddb615c7..00000000 --- a/src/test/scala/cookbook/RegOfVec.scala +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -package cookbook - -import chisel3._ - -/* ### How do I create a Reg of type Vec? - * - * For information, please see the API documentation for Vec - * (https://chisel.eecs.berkeley.edu/api/index.html#chisel3.Vec) - */ -class RegOfVec extends CookbookTester(2) { - // Reg of Vec of 32-bit UInts without initialization - val regOfVec = Reg(Vec(4, UInt(32.W))) - regOfVec(0) := 123.U // a couple of assignments - regOfVec(2) := regOfVec(0) - - // Reg of Vec of 32-bit UInts initialized to zero - // Note that Seq.fill constructs 4 32-bit UInt literals with the value 0 - // Vec(...) then constructs a Wire of these literals - // The Reg is then initialized to the value of the Wire (which gives it the same type) - val initRegOfVec = RegInit(VecInit(Seq.fill(4)(0.U(32.W)))) - - // Simple test (cycle comes from superclass) - when(cycle === 2.U) { assert(regOfVec(2) === 123.U) } - for (elt <- initRegOfVec) { assert(elt === 0.U) } -} - -class RegOfVecSpec extends CookbookSpec { - "RegOfVec" should "work" in { - assertTesterPasses { new RegOfVec } - } -} diff --git a/src/test/scala/cookbook/UInt2Bundle.scala b/src/test/scala/cookbook/UInt2Bundle.scala deleted file mode 100644 index f5180c90..00000000 --- a/src/test/scala/cookbook/UInt2Bundle.scala +++ /dev/null @@ -1,30 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -package cookbook - -import chisel3._ - -/* ### How do I create a Bundle from a UInt? - * - * On an instance of the Bundle, call the method fromBits with the UInt as the argument - */ -class UInt2Bundle extends CookbookTester(1) { - // Example - class MyBundle extends Bundle { - val foo = UInt(4.W) - val bar = UInt(4.W) - } - val uint = 0xb4.U - val bundle = uint.asTypeOf(new MyBundle) - printf(p"$bundle") // Bundle(foo -> 11, bar -> 4) - - // Test - assert(bundle.foo === 0xb.U) - assert(bundle.bar === 0x4.U) -} - -class UInt2BundleSpec extends CookbookSpec { - "UInt2Bundle" should "work" in { - assertTesterPasses { new UInt2Bundle } - } -} diff --git a/src/test/scala/cookbook/UInt2VecOfBool.scala b/src/test/scala/cookbook/UInt2VecOfBool.scala deleted file mode 100644 index 9aaf63e9..00000000 --- a/src/test/scala/cookbook/UInt2VecOfBool.scala +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -package cookbook - -import chisel3._ - -/* ### How do I create a Vec of Bools from a UInt? - * - * Use the builtin function [[chisel3.Bits.asBools]] to create a Scala Seq of Bool, - * then wrap the resulting Seq in Vec(...) - */ -class UInt2VecOfBool extends CookbookTester(1) { - // Example - val uint = 0xc.U - val vec = VecInit(uint.asBools) - printf(p"$vec") // Vec(0, 0, 1, 1) - - // Test - assert(vec(0) === false.B) - assert(vec(1) === false.B) - assert(vec(2) === true.B) - assert(vec(3) === true.B) -} - -class UInt2VecOfBoolSpec extends CookbookSpec { - "UInt2VecOfBool" should "work" in { - assertTesterPasses { new UInt2VecOfBool } - } -} diff --git a/src/test/scala/cookbook/VecOfBool2UInt.scala b/src/test/scala/cookbook/VecOfBool2UInt.scala deleted file mode 100644 index ca1413dc..00000000 --- a/src/test/scala/cookbook/VecOfBool2UInt.scala +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -package cookbook - -import chisel3._ - -/* ### How do I create a UInt from a Vec of Bool? - * - * Use the builtin function asUInt - */ -class VecOfBool2UInt extends CookbookTester(1) { - // Example - val vec = VecInit(true.B, false.B, true.B, true.B) - val uint = vec.asUInt - printf(p"$uint") // 13 - - /* Test - * - * (remember leftmost Bool in Vec is low order bit) - */ - assert(0xd.U === uint) -} - -class VecOfBool2UIntSpec extends CookbookSpec { - "VecOfBool2UInt" should "work" in { - assertTesterPasses { new VecOfBool2UInt } - } -} |
