summaryrefslogtreecommitdiff
path: root/src/test/scala/cookbook/RegOfVec.scala
diff options
context:
space:
mode:
authorJack Koenig2016-12-12 16:44:33 -0800
committerGitHub2016-12-12 16:44:33 -0800
commitc5b39d05dc723daf4297c7b016de745ce4712460 (patch)
tree476ca92c86d4a1a89b1924d0886684aad1c75268 /src/test/scala/cookbook/RegOfVec.scala
parent45eed2ceb4543875a991e40ec6082e3645158801 (diff)
Add Cookbook examples Reg of Vec and FSM (#404)
Diffstat (limited to 'src/test/scala/cookbook/RegOfVec.scala')
-rw-r--r--src/test/scala/cookbook/RegOfVec.scala33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/scala/cookbook/RegOfVec.scala b/src/test/scala/cookbook/RegOfVec.scala
new file mode 100644
index 00000000..3e55acff
--- /dev/null
+++ b/src/test/scala/cookbook/RegOfVec.scala
@@ -0,0 +1,33 @@
+// See LICENSE for license details.
+
+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.core.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 = Reg(init = Vec(Seq.fill(4)(0.asUInt(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 }
+ }
+}