Using CustomBundle template in chisel inside a class that extends blackbox

Viewed 131

I have a list of signals with bitwidth information and directionality of the signals. I want to create these IOs on the fly and make use of the CustomBundle that extends Record. I was able to do this in a normal class that doesn't extend BlackBox. However when I use CustomBundle inside the class that extends blackboxes I run into errors. Can CustomBundles be used inside a class that extends blackbox? If not are there any workarounds other than scripting so that I can automate the construction of signals inside the blackbox class.

1 Answers

I figured out a way of doing this. Created a class that extends Record for various signal types and then grouped them using a bundle inside the blackbox and made the connection.

UPDATE: I didn't have to rename my signals in the verilog file EDIT: Added example for Record

import chisel3._
import chisel3.stage.ChiselStage
import chisel3.util.{HasBlackBoxInLine}
import scala.collection.immutable.ListMap

class MyBlackBox extends BlackBox with HasBlackBoxInline{
    val io = IO(new MyBundle)
    setInline("My_Verilog.v",
             s"""
             |module MyBlackBox(
             |  input a,
             |  input b,
             | output c
             |);
             |always @* begin
             | c < = a & b
             |end
             |endmodule
             """.stripMargin)
}

class MyBundle extends Record{
    val signalName = Seq(a,b)
    val elements_i = ListMap(Seq.tabulate(2){i => signalName(i) -> Input(UInt(1.W))}:_*)
    val elements_o = ListMap(Seq.tabulate(1){i => c -> Output(UInt(1.W))}:_*)
    val elements = elements_i ++ elements_o
    override def cloneType: this.type = (new MyBundle).asInstanceOf[this.type]
}
Related