2023-10-19 18:31:26 +08:00
|
|
|
package Switch
|
|
|
|
|
|
|
|
|
|
import chisel3._
|
|
|
|
|
import chisel3.util._
|
|
|
|
|
|
|
|
|
|
|
2023-10-20 14:42:15 +08:00
|
|
|
import org.chipsalliance.cde.config._
|
|
|
|
|
import freechips.rocketchip.tilelink._
|
2023-10-19 18:31:26 +08:00
|
|
|
|
|
|
|
|
|
2023-11-01 14:48:03 +08:00
|
|
|
abstract class DMAMstBase(val edgeOut: TLEdgeOut)(implicit p: Parameters) extends SwitchNode{
|
2023-10-19 18:31:26 +08:00
|
|
|
class MacTileLinkMasterIO extends Bundle{
|
|
|
|
|
val A = Decoupled(new TLBundleA(edgeOut.bundle))
|
|
|
|
|
val D = Flipped(Decoupled(new TLBundleD(edgeOut.bundle)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class SwitchMuxIO(implicit p: Parameters) extends SwitchBundle{
|
|
|
|
|
val dmaMst = new MacTileLinkMasterIO
|
|
|
|
|
|
2023-11-07 15:45:31 +08:00
|
|
|
val sel = Vec( chn, Flipped(new DMA_Register_Bundle) )
|
2023-11-01 14:48:03 +08:00
|
|
|
|
2023-10-19 18:31:26 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val io: SwitchMuxIO = IO(new SwitchMuxIO)
|
2023-10-20 14:42:15 +08:00
|
|
|
val (_, _, isLastD, transDCnt) = edgeOut.count(io.dmaMst.D)
|
|
|
|
|
|
2023-11-01 16:22:46 +08:00
|
|
|
val rxBuff = Module(new RxBuff(8))
|
|
|
|
|
val txBuff = Module(new TxBuff(0))
|
2023-11-06 18:56:02 +08:00
|
|
|
|
2023-11-01 14:48:03 +08:00
|
|
|
|
2023-10-19 18:31:26 +08:00
|
|
|
|
|
|
|
|
def stateIdle = 0.U
|
|
|
|
|
def stateRx = 1.U
|
|
|
|
|
def stateTx = 2.U
|
|
|
|
|
|
|
|
|
|
val stateNxt = Wire(UInt(2.W))
|
|
|
|
|
val stateCur = RegNext(stateNxt, stateIdle)
|
2023-10-27 18:27:58 +08:00
|
|
|
val stateDMA = RegInit(0.U(2.W))
|
|
|
|
|
|
|
|
|
|
val dmaAValid = RegInit(false.B)
|
|
|
|
|
val dmaABits = Reg(new TLBundleA(edgeOut.bundle))
|
|
|
|
|
val dmaAddress = Reg( UInt(32.W) )
|
2023-11-07 15:45:31 +08:00
|
|
|
|
|
|
|
|
val trigRxNum = Reg(UInt((log2Ceil(chn)).W))
|
|
|
|
|
val trigTxNum = Reg(UInt((log2Ceil(chn)).W))
|
|
|
|
|
|
|
|
|
|
val rxLength = RegInit(0.U)
|
2023-10-27 18:27:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trait DMAMstFSM{ this: DMAMstBase =>
|
2023-10-19 18:31:26 +08:00
|
|
|
|
|
|
|
|
stateNxt :=
|
|
|
|
|
Mux1H(Seq(
|
2023-11-07 15:45:31 +08:00
|
|
|
( stateCur === stateIdle ) -> Mux( (0 until chn).map{i => (io.sel(i).triTx & io.sel(i).r_TxLen > 32.U)}.foldLeft(false.B)(_|_) , stateTx, Mux( rxBuff.mInfo.source.valid, stateRx, stateIdle ) ),
|
2023-10-30 17:32:55 +08:00
|
|
|
( stateCur === stateRx ) -> Mux( stateDMA === 0.U, stateIdle, stateRx ),
|
|
|
|
|
( stateCur === stateTx ) -> Mux( stateDMA === 0.U, stateIdle, stateTx ),
|
2023-10-19 18:31:26 +08:00
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
2023-10-27 18:27:58 +08:00
|
|
|
when( stateNxt =/= stateIdle && stateCur === stateIdle ){
|
|
|
|
|
stateDMA := 1.U
|
|
|
|
|
} .elsewhen( io.dmaMst.A.fire ){
|
|
|
|
|
stateDMA := 2.U
|
|
|
|
|
} .elsewhen( io.dmaMst.D.fire & isLastD ){
|
2023-11-07 15:45:31 +08:00
|
|
|
when( stateCur === stateTx & dmaAddress === (io.sel(trigTxNum).r_TxPtr + io.sel(trigTxNum).r_TxLen) ){
|
2023-10-27 18:27:58 +08:00
|
|
|
stateDMA := 0.U
|
2023-10-30 17:32:55 +08:00
|
|
|
} .elsewhen( stateCur === stateRx & ~rxBuff.io.deq.valid ){
|
2023-10-27 18:27:58 +08:00
|
|
|
stateDMA := 0.U
|
|
|
|
|
} .otherwise{
|
|
|
|
|
stateDMA := 1.U
|
|
|
|
|
}
|
2023-10-19 18:31:26 +08:00
|
|
|
}
|
|
|
|
|
|
2023-10-27 18:27:58 +08:00
|
|
|
}
|
2023-10-19 18:31:26 +08:00
|
|
|
|
|
|
|
|
|
2023-10-27 18:27:58 +08:00
|
|
|
trait DMAMstTileLink{ this: DMAMstBase =>
|
2023-10-19 18:31:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-07 15:45:31 +08:00
|
|
|
val mInfoValid = stateCur === stateTx
|
|
|
|
|
|
|
|
|
|
when( rxBuff.mInfo.source.valid & stateCur === stateIdle & stateNxt === stateRx ){
|
|
|
|
|
assert( rxBuff.mInfo.source.bits(48) === 1.U )
|
|
|
|
|
trigRxNum := rxBuff.mInfo.source.bits
|
|
|
|
|
dmaAddress := io.sel(rxBuff.mInfo.source.bits( log2Ceil(chn)-1, 0 )).r_RxPtr
|
|
|
|
|
}
|
2023-10-19 18:31:26 +08:00
|
|
|
|
2023-11-07 15:45:31 +08:00
|
|
|
for( i <- 0 until chn ){
|
|
|
|
|
io.sel(i).triRx := rxBuff.io.deq.fire & rxBuff.io.deq.bits.isLast & trigRxNum === i.U
|
|
|
|
|
io.sel(i).r_RxLen := RegEnable( rxLength + 1.U, io.sel(i).triRx )
|
|
|
|
|
}
|
2023-10-19 18:31:26 +08:00
|
|
|
|
2023-11-07 15:45:31 +08:00
|
|
|
for( i <- 0 until chn ){
|
|
|
|
|
when( io.sel(i).triTx & io.sel(i).r_TxLen > 32.U & stateCur === stateIdle ){
|
|
|
|
|
trigTxNum := i.U
|
|
|
|
|
dmaAddress := io.sel(i).r_TxPtr
|
|
|
|
|
assert( stateNxt === stateTx )
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
when( io.dmaMst.A.fire ){
|
2023-10-21 21:08:40 +08:00
|
|
|
dmaAddress := dmaAddress + 1.U
|
2023-10-19 18:31:26 +08:00
|
|
|
}
|
|
|
|
|
|
2023-10-30 17:32:55 +08:00
|
|
|
rxBuff.io.deq.ready := io.dmaMst.A.fire & (stateCur === stateRx)
|
|
|
|
|
assert( ~(rxBuff.io.deq.ready & ~rxBuff.io.deq.valid) )
|
2023-10-20 15:49:24 +08:00
|
|
|
|
|
|
|
|
when( io.dmaMst.A.fire ){
|
2023-10-27 18:27:58 +08:00
|
|
|
dmaAValid := false.B
|
|
|
|
|
}.elsewhen( stateDMA === 1.U & ~io.dmaMst.A.valid & stateCur === stateTx ){
|
|
|
|
|
dmaAValid := true.B
|
|
|
|
|
dmaABits :=
|
2023-10-19 18:31:26 +08:00
|
|
|
edgeOut.Get(
|
|
|
|
|
fromSource = 0.U,
|
2023-10-21 21:08:40 +08:00
|
|
|
toAddress = dmaAddress,
|
|
|
|
|
lgSize = log2Ceil(8/8).U,
|
2023-10-19 18:31:26 +08:00
|
|
|
)._2
|
2023-10-27 18:27:58 +08:00
|
|
|
} .elsewhen( stateDMA === 1.U & ~io.dmaMst.A.valid & stateCur === stateRx ) {
|
|
|
|
|
dmaAValid := true.B
|
|
|
|
|
dmaABits :=
|
2023-10-19 18:31:26 +08:00
|
|
|
edgeOut.Put(
|
|
|
|
|
fromSource = 0.U,
|
2023-10-21 21:08:40 +08:00
|
|
|
toAddress = dmaAddress,
|
|
|
|
|
lgSize = log2Ceil(8/8).U,
|
2023-10-30 17:32:55 +08:00
|
|
|
data = rxBuff.io.deq.bits.data,
|
2023-10-21 21:08:40 +08:00
|
|
|
mask = "b1".U,
|
2023-10-20 15:49:24 +08:00
|
|
|
)._2
|
2023-10-19 18:31:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-10-27 18:27:58 +08:00
|
|
|
io.dmaMst.A.valid := dmaAValid
|
|
|
|
|
io.dmaMst.A.bits := dmaABits
|
2023-10-19 18:31:26 +08:00
|
|
|
|
|
|
|
|
|
2023-10-20 14:42:15 +08:00
|
|
|
io.dmaMst.D.ready :=
|
2023-10-19 18:31:26 +08:00
|
|
|
Mux1H(Seq(
|
2023-10-20 14:42:15 +08:00
|
|
|
( stateCur === stateRx ) -> true.B,
|
2023-10-30 17:32:55 +08:00
|
|
|
( stateCur === stateTx ) -> txBuff.io.enq.ready,
|
2023-10-19 18:31:26 +08:00
|
|
|
))
|
2023-10-27 18:27:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trait DMAMstBuff{ this: DMAMstBase =>
|
|
|
|
|
|
2023-11-07 15:45:31 +08:00
|
|
|
|
2023-10-19 18:31:26 +08:00
|
|
|
|
2023-10-30 17:32:55 +08:00
|
|
|
when( rxBuff.io.deq.fire ){
|
|
|
|
|
when( rxBuff.io.deq.bits.isStart ){
|
2023-10-27 18:27:58 +08:00
|
|
|
rxLength := 0.U
|
|
|
|
|
} .otherwise{
|
|
|
|
|
rxLength := rxLength + 1.U
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-19 18:31:26 +08:00
|
|
|
|
2023-11-06 18:56:02 +08:00
|
|
|
|
2023-10-19 18:31:26 +08:00
|
|
|
|
2023-10-27 18:27:58 +08:00
|
|
|
|
2023-10-30 17:32:55 +08:00
|
|
|
txBuff.io.enq.valid := io.dmaMst.D.valid & stateCur === stateTx
|
|
|
|
|
txBuff.io.enq.bits.data := io.dmaMst.D.bits.data
|
2023-11-07 15:45:31 +08:00
|
|
|
txBuff.io.enq.bits.isStart := RegEnable( dmaAddress === io.sel(trigTxNum).r_TxPtr, io.dmaMst.A.fire)
|
|
|
|
|
txBuff.io.enq.bits.isLast := dmaAddress === (io.sel(trigTxNum).r_TxPtr + io.sel(trigTxNum).r_TxLen)
|
2023-11-06 18:56:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-19 18:31:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-11-01 14:48:03 +08:00
|
|
|
abstract class DMAMst(edgeOut: TLEdgeOut)(implicit p: Parameters) extends DMAMstBase(edgeOut)
|
2023-10-27 18:27:58 +08:00
|
|
|
with DMAMstFSM
|
|
|
|
|
with DMAMstTileLink
|
|
|
|
|
with DMAMstBuff
|