2023-06-28 23:43:03 +08:00
|
|
|
package MAC
|
|
|
|
|
|
|
|
|
|
import chisel3._
|
|
|
|
|
import chisel3.util._
|
2023-10-17 16:38:18 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
abstract class MacTileLinkBase() extends Module{
|
2023-07-04 15:40:51 +08:00
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
class MacTileLinkIO extends Bundle{
|
2023-07-04 15:40:51 +08:00
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
val r_RxEn = Input(Bool()) // Receive enable
|
|
|
|
|
val RxDataLatched2_rxclk = Input(UInt(32.W))
|
|
|
|
|
val WriteRxDataToFifoSync = Input(Bool())
|
|
|
|
|
val RxAbortSync = Input(Bool())
|
|
|
|
|
val LatchedRxLength_rxclk = Input(UInt(16.W))
|
|
|
|
|
val RxStatusInLatched_rxclk = Input(UInt(9.W))
|
|
|
|
|
val ShiftEndedSync = Input(Bool())
|
|
|
|
|
val RxReady = Output(Bool())
|
2023-07-03 16:25:41 +08:00
|
|
|
|
|
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
val TxStartFrm_wb = Output(Bool())
|
|
|
|
|
val TxStartFrm_syncb = Input(Bool())
|
|
|
|
|
val TxEndFrm_wb = Output(Bool())
|
|
|
|
|
|
|
|
|
|
val TxData_wb = Output(UInt(32.W))
|
|
|
|
|
val ReadTxDataFromFifo_sync = Input(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
|
|
|
|
|
|
2023-07-20 10:35:56 +08:00
|
|
|
//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-08 11:34:36 +08:00
|
|
|
val TxValidBytesLatched = Output(UInt(2.W))
|
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-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-17 16:38:18 +08:00
|
|
|
val txBuff = Module(new TxBuff)
|
|
|
|
|
val rxBuff = Module(new RxBuff)
|
2023-06-30 16:00:02 +08:00
|
|
|
|
2023-10-08 18:27:49 +08:00
|
|
|
val ShiftEndedSyncPluse = io.ShiftEndedSync & ~RegNext(io.ShiftEndedSync, false.B)
|
|
|
|
|
val RxAbortPluse = io.RxAbortSync & ~RegNext(io.RxAbortSync, false.B)
|
|
|
|
|
val WriteRxDataToFifoSyncPluse = io.WriteRxDataToFifoSync & ~RegNext(io.WriteRxDataToFifoSync, false.B)
|
2023-06-28 23:43:03 +08:00
|
|
|
|
2023-10-11 18:48:05 +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
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
val rxBuffCtrlValid = RegInit(false.B)
|
|
|
|
|
rxBuff.io.enq.ctrl.valid := rxBuffCtrlValid
|
|
|
|
|
rxBuff.io.enq.ctrl.bits.LatchedRxLength := RegEnable(io.LatchedRxLength_rxclk, ShiftEndedSyncPluse | RxAbortPluse)
|
|
|
|
|
rxBuff.io.enq.ctrl.bits.RxStatusInLatched := RegEnable(io.RxStatusInLatched_rxclk, ShiftEndedSyncPluse | RxAbortPluse)
|
|
|
|
|
rxBuff.io.enq.ctrl.bits.isRxAbort := RegEnable(RxAbortPluse, false.B, ShiftEndedSyncPluse | RxAbortPluse)
|
2023-06-28 23:43:03 +08:00
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
when( rxBuff.io.enq.ctrl.fire ){
|
|
|
|
|
rxBuffCtrlValid := false.B
|
2023-10-12 15:42:49 +08:00
|
|
|
} .elsewhen( ShiftEndedSyncPluse | RxAbortPluse ){
|
2023-10-17 16:38:18 +08:00
|
|
|
rxBuffCtrlValid := true.B
|
2023-10-12 15:42:49 +08:00
|
|
|
}
|
2023-06-28 23:43:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-11 18:48:05 +08:00
|
|
|
// RxReady generation
|
2023-10-12 15:42:49 +08:00
|
|
|
when(ShiftEndedSyncPluse | RxAbortPluse ){
|
2023-10-11 18:48:05 +08:00
|
|
|
RxReady := false.B
|
2023-10-17 16:38:18 +08:00
|
|
|
} .elsewhen( io.r_RxEn & (rxBuff.io.enq.data.ready) ){
|
2023-10-11 18:48:05 +08:00
|
|
|
RxReady := true.B
|
|
|
|
|
}
|
2023-06-28 23:43:03 +08:00
|
|
|
|
|
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
rxBuff.io.enq.data.bits := io.RxDataLatched2_rxclk
|
|
|
|
|
rxBuff.io.enq.data.valid := WriteRxDataToFifoSyncPluse
|
2023-06-28 23:43:03 +08:00
|
|
|
|
2023-10-18 17:11:56 +08:00
|
|
|
assert( ~(rxBuff.io.enq.data.valid & ~rxBuff.io.enq.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-11 18:48:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-12 18:37:12 +08:00
|
|
|
val TxStartFrm_wb = RegInit(false.B); io.TxStartFrm_wb := TxStartFrm_wb
|
2023-10-14 12:36:37 +08:00
|
|
|
val TxEndFrm_wb = RegInit(false.B); io.TxEndFrm_wb := TxEndFrm_wb
|
|
|
|
|
|
|
|
|
|
val TxLength = RegInit(0.U(16.W))
|
|
|
|
|
val LatchedTxLength = RegInit(0.U(16.W))
|
2023-10-11 18:48:05 +08:00
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
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
|
|
|
val ReadTxDataFromFifoSyncPluse = io.ReadTxDataFromFifo_sync & ~RegNext(io.ReadTxDataFromFifo_sync, false.B)
|
|
|
|
|
|
|
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
io.PerPacketPad := RegEnable(txBuff.io.deq.req.bits.PerPacketPad, false.B, txBuff.io.deq.req.fire)
|
|
|
|
|
io.PerPacketCrcEn := RegEnable(txBuff.io.deq.req.bits.PerPacketCrcEn, false.B, txBuff.io.deq.req.fire)
|
2023-10-11 18:48:05 +08:00
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
when( txBuff.io.deq.req.fire ){
|
2023-10-12 18:37:12 +08:00
|
|
|
TxStartFrm_wb := true.B
|
|
|
|
|
} .elsewhen(io.TxStartFrm_syncb){
|
|
|
|
|
TxStartFrm_wb := false.B
|
|
|
|
|
}
|
2023-10-11 18:48:05 +08:00
|
|
|
|
|
|
|
|
|
2023-10-13 15:21:53 +08:00
|
|
|
when((TxLength === 0.U) & io.TxUsedData){
|
|
|
|
|
TxEndFrm_wb := true.B
|
2023-10-17 16:38:18 +08:00
|
|
|
} .elsewhen(txRetryPulse | txDonePulse | txAbortPulse){
|
2023-10-13 15:21:53 +08:00
|
|
|
TxEndFrm_wb := false.B
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
when( txBuff.io.deq.req.fire ){
|
|
|
|
|
|
|
|
|
|
TxLength := txBuff.io.deq.req.bits.txLength
|
|
|
|
|
LatchedTxLength := txBuff.io.deq.req.bits.txLength
|
|
|
|
|
} .elsewhen( txBuff.io.deq.data.fire ){
|
2023-10-13 15:21:53 +08:00
|
|
|
when( TxLength < 4.U ){
|
|
|
|
|
TxLength := 0.U
|
|
|
|
|
} .otherwise{
|
|
|
|
|
TxLength := TxLength - 4.U // Length is subtracted at the data request
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 18:48:05 +08:00
|
|
|
|
2023-10-14 12:36:37 +08:00
|
|
|
val txRespValid = RegInit(false.B)
|
2023-10-17 16:38:18 +08:00
|
|
|
val txRespBits = Reg(new Transmit_Deq_Resp_Bundle)
|
2023-10-11 18:48:05 +08:00
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
txBuff.io.deq.resp.valid := txRespValid
|
|
|
|
|
txBuff.io.deq.resp.bits := txRespBits
|
2023-10-11 18:48:05 +08:00
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
when( txBuff.io.deq.resp.fire ){
|
2023-10-13 18:18:02 +08:00
|
|
|
txRespValid := false.B
|
2023-10-17 16:38:18 +08:00
|
|
|
} .elsewhen( txRetryPulse | txDonePulse | txAbortPulse ){
|
2023-10-13 18:18:02 +08:00
|
|
|
txRespValid := true.B
|
2023-10-17 16:38:18 +08:00
|
|
|
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-13 18:18:02 +08:00
|
|
|
}
|
2023-10-11 18:48:05 +08:00
|
|
|
|
2023-10-12 18:37:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-11 18:48:05 +08:00
|
|
|
|
|
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
val isTxBusy = RegInit(false.B); txBuff.io.deq.req.ready := ~isTxBusy & io.r_TxEn
|
2023-10-11 18:48:05 +08:00
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
when(txBuff.io.deq.req.fire){
|
2023-10-14 12:36:37 +08:00
|
|
|
isTxBusy := true.B
|
|
|
|
|
} .elsewhen(txRetryPulse | txDonePulse | txAbortPulse){
|
|
|
|
|
isTxBusy := false.B
|
2023-10-13 18:18:02 +08:00
|
|
|
}
|
2023-10-11 18:48:05 +08:00
|
|
|
|
|
|
|
|
|
2023-06-30 14:46:23 +08:00
|
|
|
|
2023-06-28 23:43:03 +08:00
|
|
|
|
|
|
|
|
|
2023-10-11 18:48:05 +08:00
|
|
|
|
|
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
txBuff.io.deq.data.ready := ReadTxDataFromFifoSyncPluse
|
|
|
|
|
assert( ~(txBuff.io.deq.data.ready & ~txBuff.io.deq.data.valid), "Assert Failed, Tx should never under run!" )
|
2023-06-28 23:43:03 +08:00
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
io.TxData_wb := txBuff.io.deq.data.bits
|
2023-10-08 15:13:35 +08:00
|
|
|
|
2023-06-28 23:43:03 +08:00
|
|
|
|
2023-07-07 21:43:06 +08:00
|
|
|
|
2023-06-28 23:43:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-26 21:41:19 +08:00
|
|
|
|
2023-10-13 18:18:02 +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-10-13 18:18:02 +08:00
|
|
|
}
|
2023-06-28 23:43:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-07-07 21:43:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-28 23:43:03 +08:00
|
|
|
// Marks which bytes are valid within the word.
|
2023-10-08 11:34:36 +08:00
|
|
|
val TxValidBytesLatched = RegInit(0.U(2.W)); io.TxValidBytesLatched := TxValidBytesLatched
|
2023-10-14 12:36:37 +08:00
|
|
|
val LatchValidBytes = ShiftRegisters((TxLength < 4.U), 2, false.B, true.B)
|
2023-10-08 18:27:49 +08:00
|
|
|
val LatchValidBytesPluse = LatchValidBytes(0) & ~LatchValidBytes(1)
|
2023-06-28 23:43:03 +08:00
|
|
|
|
|
|
|
|
// Latching valid bytes
|
2023-10-08 18:27:49 +08:00
|
|
|
when(LatchValidBytesPluse){
|
|
|
|
|
TxValidBytesLatched := Mux(TxLength < 4.U, TxLength(1,0), 0.U)
|
2023-10-17 16:38:18 +08:00
|
|
|
} .elsewhen(txRetryPulse | txDonePulse | txAbortPulse){
|
2023-06-28 23:43:03 +08:00
|
|
|
TxValidBytesLatched := 0.U
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-10-14 12:36:37 +08:00
|
|
|
|
2023-06-28 23:43:03 +08:00
|
|
|
|
2023-10-11 18:48:05 +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
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
class MacTileLink() extends MacTileLinkBase(){
|
|
|
|
|
txBuff.io.enq.ctrl.valid := false.B
|
|
|
|
|
txBuff.io.enq.data.valid := false.B
|
|
|
|
|
txBuff.io.enq.data.bits := 0.U
|
2023-10-07 16:44:13 +08:00
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
rxBuff.io.deq.data.ready := false.B
|
|
|
|
|
rxBuff.io.deq.ctrl.ready := false.B
|
2023-10-18 17:11:56 +08:00
|
|
|
|
2023-10-17 16:38:18 +08:00
|
|
|
}
|
2023-10-07 16:44:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-28 23:43:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|