Hi
I have a Switch with 8 inputs and a Mux with 7 inputs. The concept is that is Switch output will be from one of the remaining 7 inputs of the Switch and for that the Mux is required to be only 7 to 1 if the switch has 8 inputs.
I have created the Switch using the following Chisel code
class Switch[T <: Data] ( gen: T, ports : Int, widthParam : Int, nConfig: Int) extends Module{
val io = new Bundle{
val inPort = Vec.fill(ports){gen.clone.asInput}
val outPort = Vec.fill(ports){gen.clone.asOutput}
}
For designing the Mux I have used the following code
class MuxSwitch[T <: Data] (gen : T, ports: Int, widthParam : Int) extends Module{
val io = new Bundle{
val inMuxPort = Vec.fill(ports){gen.clone.asInput}
val sel = UInt(INPUT, width = log2Up(ports))
val outMuxPort = UInt(OUTPUT, width = widthParam)
}
io.outMuxPort := io.inMuxPort(io.sel)
}
Now for instantiating the same mux multiple times, as many times as the outputs of the Switch, which are 8 in this case , I am using two approaches.
Fist approach
val mux = Vec.fill(ports){Module(new MuxSwitch[UInt](UInt(width=widthParam),(ports-1), widthParam)).io}
Second approach
for(i<- 0 until ports)
{
val mux = Chisel.Module (
new MuxSwitch[UInt](UInt(width=widthParam),(ports-1), widthParam)
)
}
The problem I am facing is in making the interconnections of the input ports inMuxPort to inPort of the switch. Mind it that the Switch has one less input port as compared to the input ports of the switch so I have to skip one port while making interconnections. But for the purpose I am not able to find any appropriate method and also I am not sure which of the above methods will work better for me while instantiaing the Mux modules.