Bundle using Mux

91 views Asked by At

I want to use Mux to choose bundle enter code here class ComIO extends Bunlde { val in = Input(UInt(32.W) val in = Input(UInt(32.W) }

class EntIO extends Bundle {
  val com = new ComIO
}
class Ent extends Module {
  val io = IO(new EntIO)
  ...
}
class DemoIO extends Bundle {
  val com1 = new ComIO
  val com2 = new ComIO
  val en = Input(Bool())
}

class Demo extends Module {
  val io = IO(new DemoIO)
  val ent = Module(new Ent)

  ent.io <> Mux(io.en,io.com1,io.com2)
}

enter code here

The Error is flowing

enter image description here

1

There are 1 answers

0
Jack Koenig On

Muxes are unidirectional, you can't use them for bidirectional things. Try using a when:

class Demo extends Module {
  val io = IO(new DemoIO)
  val ent = Module(new Ent)

  when (io.en) {
    ent.io <> io.com1
  } .otherwise {
    ent.io <> io.com2
  }
}