Hoohoo
Hoohoo

Reputation: 451

How to reinterpret IO signal when testing chisel3 modules

I have a chisel3 module with a data bus IO that can be reinterpreted to some instruction/command using bundle, aka(in the module):

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

I can do the reinterpretation inside Module definition but this is not possible inside the PeekPokeTester:

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

the compiling gives: 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. at the line of the asTypeOf(xxxx)

So, how to reinterpret IO signals when testing?

Upvotes: 1

Views: 286

Answers (2)

Chick Markley
Chick Markley

Reputation: 4051

This is not a direct answer, but chisel-testers2 is designed to resolve this difficulty. Here is an example from its unit tests 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))
    }
  }

In this example it is getting the BundleType from the input itself but could as easily be re-written with direct BundleReferences e.g.

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

Upvotes: 1

CV_Ruddha
CV_Ruddha

Reputation: 406

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

Try this instead. It should work.

Upvotes: 0

Related Questions