Files
eb001/src/main/scala/Switch/mac/MacTilelink.scala

278 lines
5.9 KiB
Scala
Raw Normal View History

2023-06-28 23:43:03 +08:00
package MAC
import chisel3._
import chisel3.util._
import Switch._
2023-06-28 23:43:03 +08:00
2023-07-03 16:25:41 +08:00
import freechips.rocketchip.tilelink._
import freechips.rocketchip.diplomacy._
2023-07-04 15:40:51 +08:00
import org.chipsalliance.cde.config._
2023-07-03 16:25:41 +08:00
2023-06-28 23:43:03 +08:00
2023-07-04 14:26:24 +08:00
2023-06-29 23:28:05 +08:00
2023-06-30 20:21:03 +08:00
abstract class MacTileLinkBase() extends Module{
2023-07-04 15:40:51 +08:00
class MacTileLinkIO extends Bundle{
2023-07-04 15:40:51 +08:00
val r_RxEn = Input(Bool()) // Receive enable
2023-10-23 22:58:36 +08:00
val rxReq = Flipped(Decoupled(new RxFifo_Stream_Bundle))
val rxResp = Decoupled(new Bool())
2023-10-24 15:34:30 +08:00
val RxAbortSync = Input(Bool())
val LatchedRxLength_rxclk = Input(UInt(16.W))
val RxStatusInLatched_rxclk = Input(UInt(9.W))
val RxReady = Output(Bool())
2023-07-03 16:25:41 +08:00
2023-10-23 23:36:01 +08:00
2023-10-24 14:00:51 +08:00
val txReq = Decoupled(new TxFifo_Stream_Bundle)
2023-10-23 23:36:01 +08:00
2023-10-24 16:27:30 +08:00
// val TxEndFrm_wb = Output(Bool())
2023-07-03 16:25:41 +08:00
// Tx Status signals
val RetryCntLatched = Input(UInt(4.W)) // Latched Retry Counter
val RetryLimit = Input(Bool()) // Retry limit reached (Retry Max value +1 attempts were made)
val LateCollLatched = Input(Bool()) // Late collision occured
val DeferLatched = Input(Bool()) // Defer indication (Frame was defered before sucessfully sent)
val CarrierSenseLost = Input(Bool()) // Carrier Sense was lost during the frame transmission
val PerPacketCrcEn = Output(Bool()) // Per packet crc enable
val PerPacketPad = Output(Bool()) // Per packet pading
//Register
val r_TxEn = Input(Bool()) // Transmit enable
2023-10-08 11:34:36 +08:00
val BlockingTxStatusWrite = Output(Bool())
2023-10-13 15:21:53 +08:00
val TxUsedData = Input(Bool()) // Transmit packet used data
2023-10-10 16:48:32 +08:00
2023-10-08 11:34:36 +08:00
val TxRetrySync = Input(Bool())
val TxAbortSync = Input(Bool()) // Transmit packet abort
val TxDoneSync = Input(Bool()) // Transmission ended
2023-10-08 15:13:35 +08:00
2023-10-19 15:24:26 +08:00
val rxEnq = new Receive_Enq_Bundle
2023-10-20 14:42:15 +08:00
val txDeq = Flipped(new Transmit_Bundle)
2023-10-08 15:13:35 +08:00
2023-10-12 18:37:12 +08:00
}
2023-06-28 23:43:03 +08:00
2023-10-12 18:37:12 +08:00
val io = IO(new MacTileLinkIO)
2023-06-30 16:00:02 +08:00
2023-10-19 15:24:26 +08:00
2023-06-30 16:00:02 +08:00
2023-10-23 22:58:36 +08:00
val ShiftEndedSyncPluse = io.rxReq.bits.isLast & io.rxReq.fire
2023-10-08 18:27:49 +08:00
val RxAbortPluse = io.RxAbortSync & ~RegNext(io.RxAbortSync, false.B)
2023-06-28 23:43:03 +08:00
val RxReady = RegInit(false.B); io.RxReady := RxReady
2023-06-29 18:29:54 +08:00
2023-06-28 23:43:03 +08:00
val rxBuffCtrlValid = RegInit(false.B)
2023-10-19 15:24:26 +08:00
io.rxEnq.ctrl.valid := rxBuffCtrlValid
io.rxEnq.ctrl.bits.LatchedRxLength := RegEnable(io.LatchedRxLength_rxclk, ShiftEndedSyncPluse | RxAbortPluse)
io.rxEnq.ctrl.bits.RxStatusInLatched := RegEnable(io.RxStatusInLatched_rxclk, ShiftEndedSyncPluse | RxAbortPluse)
io.rxEnq.ctrl.bits.isRxAbort := RegEnable(RxAbortPluse, false.B, ShiftEndedSyncPluse | RxAbortPluse)
2023-06-28 23:43:03 +08:00
2023-10-19 15:24:26 +08:00
when( io.rxEnq.ctrl.fire ){
rxBuffCtrlValid := false.B
2023-10-12 15:42:49 +08:00
} .elsewhen( ShiftEndedSyncPluse | RxAbortPluse ){
rxBuffCtrlValid := true.B
2023-10-12 15:42:49 +08:00
}
2023-06-28 23:43:03 +08:00
// RxReady generation
2023-10-12 15:42:49 +08:00
when(ShiftEndedSyncPluse | RxAbortPluse ){
RxReady := false.B
2023-10-19 15:24:26 +08:00
} .elsewhen( io.r_RxEn & (io.rxEnq.data.ready) ){
RxReady := true.B
}
2023-06-28 23:43:03 +08:00
2023-10-23 22:58:36 +08:00
io.rxEnq.data.bits := io.rxReq.bits.data
io.rxEnq.data.valid := io.rxReq.valid
io.rxReq.ready := io.rxEnq.data.ready
val rxRespValid = RegInit(false.B)
when( io.rxResp.fire ){
rxRespValid := false.B
} .elsewhen( ShiftEndedSyncPluse ){
rxRespValid := true.B
}
io.rxResp.valid := rxRespValid
io.rxResp.bits := DontCare
2023-06-28 23:43:03 +08:00
2023-10-19 15:24:26 +08:00
assert( ~(io.rxEnq.data.valid & ~io.rxEnq.data.ready), "Assert Failed, rx overrun!" )
2023-06-28 23:43:03 +08:00
2023-09-26 21:41:19 +08:00
2023-06-28 23:43:03 +08:00
2023-10-08 18:27:49 +08:00
2023-10-24 15:34:30 +08:00
val TxStartFrm_wb = RegInit(false.B)
2023-10-24 16:27:30 +08:00
val TxEndFrm_wb = RegInit(false.B)//; io.TxEndFrm_wb := TxEndFrm_wb
2023-10-14 12:36:37 +08:00
val TxLength = RegInit(0.U(16.W))
val LatchedTxLength = RegInit(0.U(16.W))
val txRetryPulse = io.TxRetrySync & ~RegNext(io.TxRetrySync, false.B)
val txDonePulse = io.TxDoneSync & ~RegNext(io.TxDoneSync, false.B)
val txAbortPulse = io.TxAbortSync & ~RegNext(io.TxAbortSync, false.B)
2023-10-14 12:36:37 +08:00
2023-10-19 15:24:26 +08:00
io.PerPacketPad := RegEnable(io.txDeq.req.bits.PerPacketPad, false.B, io.txDeq.req.fire)
io.PerPacketCrcEn := RegEnable(io.txDeq.req.bits.PerPacketCrcEn, false.B, io.txDeq.req.fire)
2023-10-19 15:24:26 +08:00
when( io.txDeq.req.fire ){
2023-10-12 18:37:12 +08:00
TxStartFrm_wb := true.B
2023-10-24 14:00:51 +08:00
} .elsewhen(io.txReq.fire){
2023-10-12 18:37:12 +08:00
TxStartFrm_wb := false.B
}
2023-10-24 16:27:30 +08:00
when(((TxLength - 1.U) === 0.U) & io.TxUsedData){
TxEndFrm_wb := true.B
} .elsewhen(txRetryPulse | txDonePulse | txAbortPulse){
TxEndFrm_wb := false.B
}
2023-10-13 15:21:53 +08:00
2023-10-19 15:24:26 +08:00
when( io.txDeq.req.fire ){
2023-10-19 15:24:26 +08:00
TxLength := io.txDeq.req.bits.txLength
LatchedTxLength := io.txDeq.req.bits.txLength
} .elsewhen( io.txDeq.data.fire ){
when( TxLength < 1.U ){
2023-10-13 15:21:53 +08:00
TxLength := 0.U
} .otherwise{
TxLength := TxLength - 1.U // Length is subtracted at the data request
2023-10-13 15:21:53 +08:00
}
}
2023-10-14 12:36:37 +08:00
val txRespValid = RegInit(false.B)
2023-10-20 14:42:15 +08:00
val txRespBits = Reg(new Transmit_Resp_Bundle)
2023-10-19 15:24:26 +08:00
io.txDeq.resp.valid := txRespValid
io.txDeq.resp.bits := txRespBits
2023-10-19 15:24:26 +08:00
when( io.txDeq.resp.fire ){
txRespValid := false.B
} .elsewhen( txRetryPulse | txDonePulse | txAbortPulse ){
txRespValid := true.B
txRespBits.RetryCntLatched := io.RetryCntLatched
txRespBits.RetryLimit := io.RetryLimit
txRespBits.LateCollLatched := io.LateCollLatched
txRespBits.DeferLatched := io.DeferLatched
txRespBits.CarrierSenseLost := io.CarrierSenseLost
txRespBits.isClear := txAbortPulse | txRetryPulse
}
2023-10-12 18:37:12 +08:00
2023-10-19 15:24:26 +08:00
val isTxBusy = RegInit(false.B); io.txDeq.req.ready := ~isTxBusy & io.r_TxEn
2023-10-19 15:24:26 +08:00
when( io.txDeq.req.fire){
2023-10-14 12:36:37 +08:00
isTxBusy := true.B
} .elsewhen(txRetryPulse | txDonePulse | txAbortPulse){
isTxBusy := false.B
}
2023-06-30 14:46:23 +08:00
2023-10-24 16:27:30 +08:00
io.txReq.bits.isLast := TxEndFrm_wb
2023-10-24 14:00:51 +08:00
io.txReq.bits.data := io.txDeq.data.bits
io.txReq.bits.isStart := TxStartFrm_wb
io.txReq.valid := io.txDeq.data.valid
io.txDeq.data.ready := io.txReq.ready
2023-10-23 23:36:01 +08:00
2023-10-08 15:13:35 +08:00
2023-06-28 23:43:03 +08:00
2023-06-28 23:43:03 +08:00
2023-09-26 21:41:19 +08:00
val BlockingTxStatusWrite = RegInit(false.B); io.BlockingTxStatusWrite := BlockingTxStatusWrite
2023-06-29 18:29:54 +08:00
2023-10-14 12:36:37 +08:00
when(~io.TxDoneSync & ~io.TxAbortSync){
BlockingTxStatusWrite := false.B
} .elsewhen(txDonePulse | txAbortPulse){
BlockingTxStatusWrite := true.B
}
2023-06-28 23:43:03 +08:00
2023-10-07 16:44:13 +08:00
}
2023-06-29 18:29:54 +08:00
2023-10-07 16:44:13 +08:00
class MacTileLink() extends MacTileLinkBase(){
2023-10-07 16:44:13 +08:00
2023-10-19 15:24:26 +08:00
}
2023-10-07 16:44:13 +08:00
2023-06-28 23:43:03 +08:00