Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dynamically add IO ports to a Chisel Bundle?

Tags:

chisel

How can you dynamically add inputs or outputs to a Bundle in order to achieve the equivalent of this pseudocode.

class MyBundle extends Bundle {
  for( i <- 1 to 10) {
     val foo_<i> = UInt(i.W)
  }
}

Note that I would like to not only create 10 dynamic ports but would also like that the index value would be reflected in the port name and port size. I think MixedVec cast to Bundle can potentially offer something similar not quite what I am looking for.

like image 677
caylus Avatar asked Dec 14 '25 15:12

caylus


1 Answers

One way to do it is use Record instead of Bundle. Here's a pointer to the chisel3 test of the Record construct RecordSpec.scala

As an example based on your pseudocode. It would look like this

  class MyBundle extends Record {
    val elements = ListMap(Seq.tabulate(10) { i =>
      s"foo_$i" -> UInt(i.W)
    }:_*)
    override def cloneType: this.type = (new MyBundle).asInstanceOf[this.type]
  }
like image 84
Chick Markley Avatar answered Dec 17 '25 22:12

Chick Markley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!