测试Chisel3模块时如何重新解释IO信号

时间:2019-11-18 06:43:58

标签: chisel

我有一个带数据总线IO的chisel3模块,可以将其重新解释为某些指令/命令 使用捆绑包,又名(在模块中):

......
 //io.data is for example UInt(64.W)
 val cmdInterface = new CommandInterface() // this is a bundle of signals
 val cmd = io.data.asTypeof(cmdInterface)
......

我可以在Module定义中进行重新解释,但这在PeekPokeTester中是不可能的:

//using the tester:
poke(c.io.data.asTypeof(cmdInterface).cmd, 1) // this is not ok

编译给出: chisel3.internal.ChiselException: Error: Not in a UserModule. Likely cause: Missed Module() wrap, bare chisel API call, or attempting to construct hardware inside a BlackBox. 在asTypeOf(xxxx)的行

那么,如何在测试时重新解释IO信号?

2 个答案:

答案 0 :(得分:1)

这不是直接答案,但是chisel-testers2旨在解决此难题。这是来自其单元测试BundleLiteralsSpec

的示例
  it should "roundtrip Bundle literals" in {
    test(new PassthroughModule(new DoubleElements)) { c =>
      c.in.poke(chiselTypeOf(c.in).Lit(_.a -> 0.U, _.b -> 1.U))
      c.in.poke(c.out.peek())
      c.out.expect(chiselTypeOf(c.in).Lit(_.a -> 0.U, _.b -> 1.U))
    }
  }

在此示例中,它是从输入本身获取BundleType的,但是可以通过直接的BundleReferences轻松重写,例如

c.in.poke((new DoubleElements).Lit(_.a -> 0.U, _.b -> 1.U))

答案 1 :(得分:0)

val cmdInterface = Module(new CommandInterface()) // this is a bundle of signals

试试看。应该可以。