blob: d74218a82899e07abc359f16ddaea7ce65484a74 (
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
31
|
// See LICENSE for license details.
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(0) {
// Example
class MyBundle extends Bundle {
val foo = UInt(width = 4)
val bar = UInt(width = 4)
}
val bundle = Wire(new MyBundle)
bundle.foo := UInt(0xc)
bundle.bar := UInt(0x3)
val uint = bundle.asUInt
printf(p"$uint") // 195
// Test
assert(uint === UInt(0xc3))
}
class Bundle2UIntSpec extends CookbookSpec {
"Bundle2UInt" should "work" in {
assertTesterPasses { new Bundle2UInt }
}
}
|