2023-11-06 18:56:02 +08:00
|
|
|
|
|
|
|
|
package Switch
|
|
|
|
|
|
|
|
|
|
import chisel3._
|
|
|
|
|
import chisel3.util._
|
|
|
|
|
import chisel3.util.random._
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.chipsalliance.cde.config._
|
|
|
|
|
import freechips.rocketchip.diplomacy._
|
|
|
|
|
import freechips.rocketchip.tilelink._
|
|
|
|
|
|
|
|
|
|
import MAC._
|
|
|
|
|
|
2023-11-08 16:06:26 +08:00
|
|
|
class Robin_Bundle(implicit p: Parameters) extends SwitchBundle{
|
2023-11-06 18:56:02 +08:00
|
|
|
val rx = Decoupled(new Mac_Stream_Bundle)
|
|
|
|
|
val mInfo = new Rx_MuxInfo_Bundle
|
2023-11-08 16:06:26 +08:00
|
|
|
|
2023-11-06 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Robin(implicit p: Parameters) extends SwitchModule{
|
|
|
|
|
class RobinIO extends Bundle{
|
|
|
|
|
val enq = Vec( chn+1, Flipped(new Robin_Bundle) )
|
2023-11-08 16:06:26 +08:00
|
|
|
val deq = new Robin_Bundle
|
|
|
|
|
val sel = Output(UInt( (log2Ceil(chn+1)).W ))
|
2023-11-06 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val io: RobinIO = IO(new RobinIO)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val isLock = RegInit(false.B)
|
2023-11-08 15:41:21 +08:00
|
|
|
val lockChn = Reg(UInt((log2Ceil(chn+1)).W))
|
2023-11-08 16:06:26 +08:00
|
|
|
io.sel := lockChn
|
2023-11-06 18:56:02 +08:00
|
|
|
|
2023-11-10 15:47:43 +08:00
|
|
|
val lfsr = ~LFSR( (log2Ceil(chn+1)+1), ~isLock)
|
2023-11-06 18:56:02 +08:00
|
|
|
|
|
|
|
|
for( i <- 0 until chn+1 ) {
|
|
|
|
|
when( i.U === lfsr ){
|
|
|
|
|
when( io.enq(i).mInfo.dest.valid ){
|
|
|
|
|
assert( ~isLock )
|
2023-11-08 15:41:21 +08:00
|
|
|
isLock := true.B
|
|
|
|
|
lockChn := lfsr
|
2023-11-06 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
when( io.deq.rx.fire & io.deq.rx.bits.isLast ){
|
|
|
|
|
assert( isLock )
|
|
|
|
|
isLock := false.B
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for( i <- 0 until chn+1 ) {
|
|
|
|
|
io.enq(i).rx.ready := false.B
|
|
|
|
|
}
|
|
|
|
|
when( ~isLock ){
|
|
|
|
|
io.deq.rx.valid := false.B
|
|
|
|
|
io.deq.rx.bits := 0.U.asTypeOf(new Mac_Stream_Bundle)
|
|
|
|
|
io.deq.mInfo.dest.valid := false.B
|
|
|
|
|
io.deq.mInfo.dest.bits := 0.U
|
|
|
|
|
io.deq.mInfo.source.valid := false.B
|
|
|
|
|
io.deq.mInfo.source.bits := 0.U
|
|
|
|
|
} .otherwise{
|
2023-11-08 15:41:21 +08:00
|
|
|
io.deq <> io.enq(lockChn)
|
2023-11-06 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|