blob: f5180c90edb97acbfb16f60589d268a1e4ba973f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
// 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 }
}
}
|