summaryrefslogtreecommitdiff
path: root/src/test/scala/cookbook/UInt2Bundle.scala
diff options
context:
space:
mode:
authorJim Lawson2016-10-06 11:15:08 -0700
committerJim Lawson2016-10-06 11:15:08 -0700
commitd9e46d06522102634b04a187d5e89fe84b94678a (patch)
tree3f44fc56acc334c1ffa7340583b29ad44ff8740b /src/test/scala/cookbook/UInt2Bundle.scala
parentf98171296f821034cf66ace070bcf179183e833d (diff)
parent7aea39d4deac62d5477904f4bf4381c3482c41d0 (diff)
Merge branch 'master' into buildinfo
Diffstat (limited to 'src/test/scala/cookbook/UInt2Bundle.scala')
-rw-r--r--src/test/scala/cookbook/UInt2Bundle.scala30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/test/scala/cookbook/UInt2Bundle.scala b/src/test/scala/cookbook/UInt2Bundle.scala
new file mode 100644
index 00000000..fbf7fe8a
--- /dev/null
+++ b/src/test/scala/cookbook/UInt2Bundle.scala
@@ -0,0 +1,30 @@
+// See LICENSE for license details.
+
+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(0) {
+ // Example
+ class MyBundle extends Bundle {
+ val foo = UInt(width = 4)
+ val bar = UInt(width = 4)
+ }
+ val uint = UInt(0xb4)
+ val bundle = (new MyBundle).fromBits(uint)
+ printf(p"$bundle") // Bundle(foo -> 11, bar -> 4)
+
+ // Test
+ assert(bundle.foo === UInt(0xb))
+ assert(bundle.bar === UInt(0x4))
+}
+
+class UInt2BundleSpec extends CookbookSpec {
+ "UInt2Bundle" should "work" in {
+ assertTesterPasses { new UInt2Bundle }
+ }
+}