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

993 lines
26 KiB
Scala
Raw Normal View History

2023-06-28 23:43:03 +08:00
package MAC
import chisel3._
import chisel3.util._
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-07-11 17:45:32 +08:00
abstract class MacTileLinkBase(edgeIn: TLEdgeIn, edgeOut: TLEdgeOut) extends Module{
2023-07-04 15:40:51 +08:00
class MacTileLinkSlaveIO extends Bundle{
2023-07-11 17:38:18 +08:00
val A = Flipped(Decoupled(new TLBundleA(edgeIn.bundle)))
val D = Decoupled(new TLBundleD(edgeIn.bundle))
2023-07-04 15:40:51 +08:00
}
class MacTileLinkMasterIO extends Bundle{
val A = Decoupled(new TLBundleA(edgeOut.bundle))
val D = Flipped(Decoupled(new TLBundleD(edgeOut.bundle)))
}
2023-07-03 16:25:41 +08:00
2023-07-11 17:45:32 +08:00
class MacTileLinkIO extends Bundle{
2023-07-03 16:25:41 +08:00
2023-07-11 17:38:18 +08:00
val tlSlv = new MacTileLinkSlaveIO
val tlMst = new MacTileLinkMasterIO
2023-07-03 16:25:41 +08:00
// Rx Status signals
val InvalidSymbol = Input(Bool()) // Invalid symbol was received during reception in 100 Mbps mode
val LatchedCrcError = Input(Bool()) // CRC error
val RxLateCollision = Input(Bool()) // Late collision occured while receiving frame
val ShortFrame = Input(Bool()) // Frame shorter then the minimum size (r_MinFL) was received while small packets are enabled (r_RecSmall)
val DribbleNibble = Input(Bool()) // Extra nibble received
val ReceivedPacketTooBig = Input(Bool()) // Received packet is bigger than r_MaxFL
val ReceivedPacketGood = Input(Bool()) // Received packet's length and CRC are good
val AddressMiss = Input(Bool()) // When a packet is received AddressMiss status is written to the Rx BD
val r_RxFlow = Input(Bool())
val r_PassAll = Input(Bool())
2023-07-03 16:25:41 +08:00
val ReceivedPauseFrm = Input(Bool())
// 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
// Tx
val TxUsedData = Input(Bool()) // Transmit packet used data
2023-10-08 11:34:36 +08:00
val TxUnderRun = Input(Bool()) // Transmit packet under-run
2023-07-03 16:25:41 +08:00
val PerPacketCrcEn = Output(Bool()) // Per packet crc enable
val PerPacketPad = Output(Bool()) // Per packet pading
//Register
val r_TxEn = Input(Bool()) // Transmit enable
val r_RxEn = Input(Bool()) // Receive enable
val r_TxBDNum = Input(UInt(8.W)) // Receive buffer descriptor number
// Interrupts
val TxB_IRQ = Output(Bool())
val TxE_IRQ = Output(Bool())
val RxB_IRQ = Output(Bool())
val RxE_IRQ = Output(Bool())
val Busy_IRQ = Output(Bool())
2023-10-08 11:34:36 +08:00
val BlockingTxStatusWrite = Output(Bool())
val TxStartFrm_wb = Output(Bool())
val ReadTxDataFromFifo_sync = Input(Bool())
val TxStartFrm_syncb = Input(Bool())
val TxUnderRun_wb = Output(Bool())
val TxData_wb = Output(UInt(32.W))
val TxValidBytesLatched = Output(UInt(2.W))
val TxEndFrm_wb = Output(Bool())
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
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())
2023-10-08 18:27:49 +08:00
val LatchedRxStartFrmSync = Input(Bool())
2023-10-08 15:13:35 +08:00
val Busy_IRQ_sync = Input(Bool())
val RxReady = Output(Bool())
val RxStatusIn = Output(UInt(9.W))
2023-10-08 15:30:08 +08:00
val RxStatusWriteLatched = Output(Bool())
val RxStatusWriteLatchedSyncb = Input(Bool())
2023-07-03 16:25:41 +08:00
}
2023-07-04 15:40:51 +08:00
val io = IO(new MacTileLinkIO)
2023-10-08 18:27:49 +08:00
val tx_fifo = Module( new MacFifo(dw = 32, dp = 16) )
val rx_fifo = Module(new MacFifo(dw = 32, dp = 16))
2023-07-11 17:38:18 +08:00
val (_, _, isLastD, transDCnt) = edgeOut.count(io.tlMst.D)
2023-06-28 23:43:03 +08:00
val TxB_IRQ = RegInit(false.B); io.TxB_IRQ := TxB_IRQ
val TxE_IRQ = RegInit(false.B); io.TxE_IRQ := TxE_IRQ
val RxB_IRQ = RegInit(false.B); io.RxB_IRQ := RxB_IRQ
val RxE_IRQ = RegInit(false.B); io.RxE_IRQ := RxE_IRQ
2023-06-28 23:43:03 +08:00
2023-06-29 18:29:54 +08:00
2023-10-08 11:34:36 +08:00
val TxUnderRun_wb = RegInit(false.B); io.TxUnderRun_wb := TxUnderRun_wb
2023-06-28 23:43:03 +08:00
val TxBDRead = RegInit(true.B)
val TxStatusWrite = Wire(Bool())
2023-06-29 18:29:54 +08:00
val TxLength = RegInit(0.U(16.W))
val LatchedTxLength = RegInit(0.U(16.W))
val TxStatus = RegInit(0.U(4.W)) //[14:11]
val RxStatus = RegInit(0.U(2.W)) //[14:13]
2023-06-28 23:43:03 +08:00
2023-06-30 16:00:02 +08:00
2023-06-28 23:43:03 +08:00
2023-10-08 11:34:36 +08:00
val TxStartFrm_wb = RegInit(false.B); io.TxStartFrm_wb := TxStartFrm_wb
2023-06-30 16:00:02 +08:00
2023-09-26 21:41:19 +08:00
// Signals used for various purposes
2023-10-08 18:27:49 +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)
val ShiftEndedSyncPluse = io.ShiftEndedSync & ~RegNext(io.ShiftEndedSync, false.B)
val ReadTxDataFromFifoSyncPluse = io.ReadTxDataFromFifo_sync & ~RegNext(io.ReadTxDataFromFifo_sync, false.B)
val RxAbortPluse = io.RxAbortSync & ~RegNext(io.RxAbortSync, false.B)
val WriteRxDataToFifoSyncPluse = io.WriteRxDataToFifoSync & ~RegNext(io.WriteRxDataToFifoSync, false.B)
val LatchedRxStartFrmSyncPluse = io.LatchedRxStartFrmSync & ~RegNext(io.LatchedRxStartFrmSync, false.B)
val Busy_IRQ_syncPluse = io.Busy_IRQ_sync & ~RegNext(io.Busy_IRQ_sync)
2023-09-26 21:41:19 +08:00
2023-06-28 23:43:03 +08:00
val TxRetryPacket = RegInit(false.B)
val TxRetryPacket_NotCleared = RegInit(false.B)
val TxDonePacket = RegInit(false.B)
val TxDonePacket_NotCleared = RegInit(false.B)
2023-06-29 18:29:54 +08:00
val TxAbortPacket = RegInit(false.B)
2023-06-28 23:43:03 +08:00
val TxAbortPacket_NotCleared = RegInit(false.B)
val RxBDReady = RegInit(false.B)
2023-10-08 15:13:35 +08:00
val RxReady = RegInit(false.B); io.RxReady := RxReady
2023-06-28 23:43:03 +08:00
val TxBDReady = RegInit(false.B)
val RxBDRead = RegInit(false.B)
2023-06-29 18:29:54 +08:00
2023-06-28 23:43:03 +08:00
2023-10-08 11:34:36 +08:00
val BlockingTxStatusWrite = RegInit(false.B); io.BlockingTxStatusWrite := BlockingTxStatusWrite
2023-06-28 23:43:03 +08:00
val BlockingTxBDRead = RegInit(false.B)
val RxBDAddress = RegInit(0.U(7.W)) //[7:1]
val TxBDAddress = RegInit(0.U(7.W)) //[7:1]
val ShiftEnded = RegInit(false.B)
val RxOverrun = RegInit(false.B)
2023-10-08 15:37:54 +08:00
val BDWrite = RegInit(0.U(4.W)) // BD Write Enable for access from WISHBONE side
val BDRead = RegInit(false.B) // BD Read access from WISHBONE side
2023-06-28 23:43:03 +08:00
2023-10-08 11:34:36 +08:00
val TxEndFrm_wb = RegInit(false.B); io.TxEndFrm_wb := TxEndFrm_wb
2023-06-28 23:43:03 +08:00
2023-09-26 21:41:19 +08:00
2023-06-28 23:43:03 +08:00
val RxStatusWrite = Wire(Bool())
2023-10-08 18:27:49 +08:00
2023-06-29 18:29:54 +08:00
2023-06-28 23:43:03 +08:00
// Delayed stage signals
val r_TxEn_q = RegNext(io.r_TxEn, false.B)
val r_RxEn_q = RegNext(io.r_RxEn, false.B)
2023-06-28 23:43:03 +08:00
2023-09-26 21:41:19 +08:00
def StateIdle = 0.U(3.W)
def StateWB = 1.U(3.W)
def StateTX = 2.U(3.W)
def StateRX = 3.U(3.W)
val stateNxt = RegInit( StateWB )
val stateCur = RegNext( stateNxt, StateIdle )
2023-06-28 23:43:03 +08:00
val ram_addr = RegInit(0.U(8.W))
val ram_di = RegInit(0.U(32.W))
2023-10-08 18:27:49 +08:00
2023-06-28 23:43:03 +08:00
2023-06-30 14:46:23 +08:00
2023-06-28 23:43:03 +08:00
val TxPointerRead = RegInit(false.B)
val TxEn_needed = RegInit(false.B)
val RxEn_needed = RegInit(false.B)
2023-06-29 18:29:54 +08:00
val RxPointerRead = RegInit(false.B)
2023-06-28 23:43:03 +08:00
2023-06-29 18:29:54 +08:00
// RX shift ending signals
val ShiftEndedSync3 = RegInit(false.B)
2023-06-28 23:43:03 +08:00
2023-10-08 15:13:35 +08:00
2023-06-28 23:43:03 +08:00
2023-07-04 15:40:51 +08:00
2023-06-28 23:43:03 +08:00
2023-06-29 18:29:54 +08:00
val StartOccured = RegInit(false.B)
2023-10-07 16:44:13 +08:00
2023-06-29 18:29:54 +08:00
val BlockReadTxDataFromMemory = RegInit(false.B)
2023-06-28 23:43:03 +08:00
2023-06-29 18:29:54 +08:00
val ReadTxDataFromMemory = RegInit(false.B)
2023-06-28 23:43:03 +08:00
2023-06-29 18:29:54 +08:00
val MasterWbTX = RegInit(false.B)
val MasterWbRX = RegInit(false.B)
2023-06-28 23:43:03 +08:00
2023-06-29 18:29:54 +08:00
val TxPointerMSB = RegInit(0.U(30.W)) //[31:2]
val RxPointerMSB = RegInit(0.U(30.W)) //[31:2]
2023-06-28 23:43:03 +08:00
2023-10-08 15:30:08 +08:00
val RxStatusWriteLatched = RegInit(false.B); io.RxStatusWriteLatched := RxStatusWriteLatched
2023-06-28 23:43:03 +08:00
2023-06-28 23:43:03 +08:00
// Generic synchronous single-port RAM interface
2023-06-29 18:29:54 +08:00
val bd_ram = Module(new MacSRAM)
2023-10-08 18:27:49 +08:00
val txBuffDesc = bd_ram.io.dato.asTypeOf(new TxBuffDesc)
val rxBuffDesc = bd_ram.io.dato.asTypeOf(new RxBuffDesc)
2023-06-28 23:43:03 +08:00
2023-10-08 18:27:49 +08:00
bd_ram.io.we :=
Mux1H(Seq(
(stateNxt === StateWB & stateCur === StateWB) -> BDWrite,
(TxStatusWrite | RxStatusWrite) -> "b1111".U
)).asBools
2023-06-28 23:43:03 +08:00
2023-10-08 18:27:49 +08:00
bd_ram.io.oe :=
Mux1H(Seq(
(( stateNxt === StateWB ) & ( stateCur === StateWB )) -> BDRead,
(( stateNxt === StateTX ) & ( stateCur === StateTX )) -> (TxBDRead | TxPointerRead),
(( stateNxt === StateRX ) & ( stateCur === StateRX )) -> (RxBDRead | RxPointerRead),
))
2023-06-28 23:43:03 +08:00
2023-06-29 18:29:54 +08:00
bd_ram.io.addr := ram_addr
bd_ram.io.di := ram_di
2023-06-28 23:43:03 +08:00
2023-09-26 21:41:19 +08:00
when(~TxBDReady & io.r_TxEn & stateNxt === StateWB & stateCur =/= StateWB){
2023-06-28 23:43:03 +08:00
TxEn_needed := true.B
2023-09-26 21:41:19 +08:00
} .elsewhen(TxPointerRead & stateNxt === StateTX & stateCur === StateTX){
2023-06-28 23:43:03 +08:00
TxEn_needed := false.B
}
2023-06-29 18:29:54 +08:00
2023-10-08 18:27:49 +08:00
Fill(4, io.tlSlv.A.valid & io.tlSlv.A.bits.mask.orR & io.tlSlv.A.bits.address(10)) & io.tlSlv.A.bits.mask
2023-06-28 23:43:03 +08:00
// Enabling access to the RAM for three devices.
2023-06-29 18:29:54 +08:00
// Switching between three stages depends on enable signals
2023-09-26 21:41:19 +08:00
switch( stateCur ){
is(StateIdle){
when( RxEn_needed === false.B & TxEn_needed === false.B ){
stateNxt := StateWB // Idle state. We go to WbEn access stage.
ram_addr := io.tlSlv.A.bits.address(9,2) // [11:2 ] -> [9:2]
ram_di := io.tlSlv.A.bits.data
2023-10-08 18:27:49 +08:00
BDWrite := io.tlSlv.A.bits.mask & Fill(4, io.tlSlv.A.valid & io.tlSlv.A.bits.address(10) & ((io.tlSlv.A.bits.opcode === 0.U) || (io.tlSlv.A.bits.opcode === 1.U)) )
BDRead := io.tlSlv.A.bits.mask.orR & io.tlSlv.A.valid & io.tlSlv.A.bits.address(10) & (io.tlSlv.A.bits.opcode === 4.U) // 0x400 - 0x7FF
2023-09-26 21:41:19 +08:00
}
}
is(StateWB){
when( RxEn_needed ){ // synopsys parallel_case
stateNxt := StateRX // wb access stage and r_RxEn is enabled
ram_addr := Cat(RxBDAddress, RxPointerRead)
2023-10-08 18:27:49 +08:00
ram_di := Cat(io.LatchedRxLength_rxclk, 0.U(1.W), RxStatus, 0.U(4.W), io.RxStatusInLatched_rxclk)
2023-09-26 21:41:19 +08:00
} .elsewhen( TxEn_needed ){
stateNxt := StateTX // wb access stage, r_RxEn is disabled but r_TxEn is enabled
ram_addr := Cat(TxBDAddress, TxPointerRead) //[7,1] + [0]
2023-10-08 18:27:49 +08:00
ram_di := Cat(LatchedTxLength, 0.U(1.W), TxStatus, 0.U(2.W), io.TxUnderRun, io.RetryCntLatched, io.RetryLimit, io.LateCollLatched, io.DeferLatched, io.CarrierSenseLost)
2023-09-26 21:41:19 +08:00
} .otherwise{
stateNxt := StateIdle // WbEn access stage and there is no need for other stages. WbEn needs to be switched off for a bit
}
}
is(StateRX){
when( TxEn_needed ){
stateNxt := StateTX // RxEn access stage and r_TxEn is enabled
ram_addr := Cat(TxBDAddress, TxPointerRead)
2023-10-08 18:27:49 +08:00
ram_di := Cat(LatchedTxLength, 0.U(1.W), TxStatus, 0.U(2.W), io.TxUnderRun, io.RetryCntLatched, io.RetryLimit, io.LateCollLatched, io.DeferLatched, io.CarrierSenseLost)
2023-09-26 21:41:19 +08:00
} .otherwise{
stateNxt := StateWB // RxEn access stage and r_TxEn is disabled
ram_addr := io.tlSlv.A.bits.address(9,2) // [11:2 ] -> [9:2];
ram_di := io.tlSlv.A.bits.data
2023-10-08 18:27:49 +08:00
BDWrite := io.tlSlv.A.bits.mask & Fill(4, io.tlSlv.A.valid & io.tlSlv.A.bits.address(10) & ((io.tlSlv.A.bits.opcode === 0.U) || (io.tlSlv.A.bits.opcode === 1.U)) )
BDRead := io.tlSlv.A.bits.mask.orR & io.tlSlv.A.valid & io.tlSlv.A.bits.address(10) & (io.tlSlv.A.bits.opcode === 4.U)
2023-09-26 21:41:19 +08:00
}
}
is(StateTX){
when( true.B ){
stateNxt := StateWB // TxEn access stage (we always go to wb access stage)
ram_addr := io.tlSlv.A.bits.address(9,2) //[11:2 ] ->[9:2]
ram_di := io.tlSlv.A.bits.data
2023-10-08 18:27:49 +08:00
BDWrite := io.tlSlv.A.bits.mask & Fill(4, io.tlSlv.A.valid & io.tlSlv.A.bits.address(10) & ((io.tlSlv.A.bits.opcode === 0.U) || (io.tlSlv.A.bits.opcode === 1.U)) )
BDRead := io.tlSlv.A.bits.mask.orR & io.tlSlv.A.valid & io.tlSlv.A.bits.address(10) & (io.tlSlv.A.bits.opcode === 4.U)
2023-09-26 21:41:19 +08:00
}
}
2023-06-29 18:29:54 +08:00
}
2023-09-26 21:41:19 +08:00
2023-06-30 16:00:02 +08:00
val ResetTxBDReady = TxDonePulse | TxAbortPulse | TxRetryPulse
2023-06-28 23:43:03 +08:00
2023-06-29 18:29:54 +08:00
2023-06-28 23:43:03 +08:00
// Latching READY status of the Tx buffer descriptor
2023-09-26 21:41:19 +08:00
when(stateNxt === StateTX & stateCur === StateTX & TxBDRead){ // TxBDReady is sampled only once at the beginning.
2023-06-29 23:28:05 +08:00
TxBDReady := txBuffDesc.rd & (txBuffDesc.len > 4.U)
2023-06-28 23:43:03 +08:00
} .elsewhen(ResetTxBDReady){ // Only packets larger then 4 bytes are transmitted.
TxBDReady := false.B
}
2023-06-30 14:46:23 +08:00
val StartTxBDRead = (TxRetryPacket_NotCleared | TxStatusWrite) & ~BlockingTxBDRead & ~TxBDReady // Reading the Tx buffer descriptor
2023-06-28 23:43:03 +08:00
when(StartTxBDRead){
TxBDRead := true.B
} .elsewhen(TxBDReady){
TxBDRead := false.B
}
// Reading Tx BD Pointer
2023-10-08 18:27:49 +08:00
when(TxBDRead & TxBDReady){
2023-06-28 23:43:03 +08:00
TxPointerRead := true.B
2023-09-26 21:41:19 +08:00
} .elsewhen(stateCur === StateTX){
2023-06-28 23:43:03 +08:00
TxPointerRead := false.B
}
// Writing status back to the Tx buffer descriptor
2023-09-26 21:41:19 +08:00
TxStatusWrite := (TxDonePacket_NotCleared | TxAbortPacket_NotCleared) & stateNxt === StateTX & stateCur === StateTX & ~BlockingTxStatusWrite
2023-06-28 23:43:03 +08:00
2023-06-30 16:00:02 +08:00
// Status writing must occur only once. Meanwhile it is blocked.
2023-10-08 11:34:36 +08:00
when(~io.TxDoneSync & ~io.TxAbortSync){
2023-06-28 23:43:03 +08:00
BlockingTxStatusWrite := false.B
} .elsewhen(TxStatusWrite){
BlockingTxStatusWrite := true.B
}
2023-06-28 23:43:03 +08:00
// TxBDRead state is activated only once.
when(StartTxBDRead){
BlockingTxBDRead := true.B
} .elsewhen(~StartTxBDRead & ~TxBDReady){
BlockingTxBDRead := false.B
}
2023-10-08 18:27:49 +08:00
2023-06-28 23:43:03 +08:00
2023-10-08 18:27:49 +08:00
2023-09-26 21:41:19 +08:00
when(stateNxt === StateTX & stateCur === StateTX & TxBDRead){
2023-10-08 18:27:49 +08:00
TxStatus := Cat(txBuffDesc.irq, txBuffDesc.wr, txBuffDesc.pad, txBuffDesc.crc) // Latching status from the tx buffer descriptor Data is avaliable one cycle after the access is started (at that time signal TxEn is not active)
TxLength := txBuffDesc.len //Latching length from the buffer descriptor;
LatchedTxLength := txBuffDesc.len
} .elsewhen( MasterWbTX & io.tlMst.D.fire ){ //tx tileRead
2023-06-30 14:46:23 +08:00
when( TxLength < 4.U ){
2023-06-28 23:43:03 +08:00
TxLength := 0.U
} .otherwise{
2023-06-28 23:43:03 +08:00
TxLength := TxLength - 4.U // Length is subtracted at the data request
}
}
2023-06-28 23:43:03 +08:00
2023-09-26 21:41:19 +08:00
when(stateNxt === StateTX & stateCur === StateTX & TxPointerRead){
2023-10-08 18:27:49 +08:00
TxPointerMSB := bd_ram.io.dato(31,2) // Latching Tx buffer pointer from buffer descriptor. Only 30 MSB bits are latched because TxPointerMSB is only used for word-aligned accesses.
when( bd_ram.io.dato(1,0) =/= 0.U ){
printf("Warning, force to align at tx ram")
}
2023-07-11 17:38:18 +08:00
} .elsewhen( io.tlMst.D.fire & io.tlMst.D.bits.opcode === 1.U ){
2023-06-28 23:43:03 +08:00
TxPointerMSB := TxPointerMSB + 1.U // TxPointer is word-aligned
}
2023-06-29 18:29:54 +08:00
2023-06-28 23:43:03 +08:00
val isTlMstBusy = RegInit(false.B)
2023-06-28 23:43:03 +08:00
2023-06-30 14:46:23 +08:00
when( (TxLength === 0.U) | TxAbortPulse | TxRetryPulse){
2023-06-28 23:43:03 +08:00
ReadTxDataFromMemory := false.B
2023-09-26 21:41:19 +08:00
} .elsewhen(stateNxt === StateTX & stateCur === StateTX & TxPointerRead){
2023-06-28 23:43:03 +08:00
ReadTxDataFromMemory := true.B
}
val ReadTxDataFromMemory_2 = ReadTxDataFromMemory & ~BlockReadTxDataFromMemory;
2023-06-28 23:43:03 +08:00
when(
2023-10-08 18:27:49 +08:00
(tx_fifo.io.almost_full | TxLength <= 4.U) & MasterWbTX & isTlMstBusy & (~(TxAbortPacket_NotCleared | TxRetryPacket_NotCleared))){
2023-06-28 23:43:03 +08:00
BlockReadTxDataFromMemory := true.B
2023-10-08 18:27:49 +08:00
} .elsewhen(ReadTxDataFromFifoSyncPluse | TxDonePacket | TxAbortPacket | TxRetryPacket){
2023-06-28 23:43:03 +08:00
BlockReadTxDataFromMemory := false.B
}
2023-06-28 23:43:03 +08:00
2023-10-08 18:27:49 +08:00
tx_fifo.io.data_in := io.tlMst.D.bits.data
tx_fifo.io.write := io.tlMst.D.fire & io.tlMst.D.bits.opcode === 1.U
2023-10-08 18:27:49 +08:00
tx_fifo.io.read := ReadTxDataFromFifoSyncPluse & ~tx_fifo.io.empty
tx_fifo.io.clear := TxAbortPacket | TxRetryPacket
2023-10-08 11:34:36 +08:00
io.TxData_wb := tx_fifo.io.data_out
2023-10-08 18:27:49 +08:00
2023-06-28 23:43:03 +08:00
2023-06-30 16:00:02 +08:00
// Start: Generation of the TxStartFrm_wb which is then synchronized to the MTxClk
2023-10-08 18:27:49 +08:00
when(TxBDReady & ~StartOccured & (tx_fifo.io.full | TxLength === 0.U)){
2023-06-28 23:43:03 +08:00
TxStartFrm_wb := true.B
2023-10-08 11:34:36 +08:00
} .elsewhen(io.TxStartFrm_syncb){
2023-06-28 23:43:03 +08:00
TxStartFrm_wb := false.B
}
2023-06-30 16:00:02 +08:00
// StartOccured: TxStartFrm_wb occurs only ones at the beginning. Then it's blocked.
2023-06-28 23:43:03 +08:00
when(TxStartFrm_wb){
StartOccured := true.B
} .elsewhen(ResetTxBDReady){
StartOccured := false.B
}
// TxEndFrm_wb: indicator of the end of frame
2023-10-08 18:27:49 +08:00
when((TxLength === 0.U) & tx_fifo.io.almost_empty & io.TxUsedData){
2023-06-28 23:43:03 +08:00
TxEndFrm_wb := true.B
} .elsewhen(TxRetryPulse | TxDonePulse | TxAbortPulse){
TxEndFrm_wb := false.B
}
// 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-09-26 21:41:19 +08:00
2023-06-28 23:43:03 +08:00
2023-10-08 18:27:49 +08:00
val LatchValidBytes = ShiftRegisters((TxLength < 4.U) & TxBDReady, 2, false.B, true.B)
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-06-28 23:43:03 +08:00
} .elsewhen(TxRetryPulse | TxDonePulse | TxAbortPulse){
TxValidBytesLatched := 0.U
}
2023-06-30 16:00:02 +08:00
val TxIRQEn = TxStatus.extract(3) //[14:11]
val WrapTxStatusBit = TxStatus.extract(2)
2023-06-29 18:29:54 +08:00
io.PerPacketPad := TxStatus.extract(1)
io.PerPacketCrcEn := TxStatus.extract(0)
2023-06-28 23:43:03 +08:00
2023-06-30 16:00:02 +08:00
val RxIRQEn = RxStatus.extract(1) //[14:13]
val WrapRxStatusBit = RxStatus.extract(0)
2023-06-28 23:43:03 +08:00
// Latching Tx buffer descriptor address
when(io.r_TxEn & (~r_TxEn_q)){
2023-06-28 23:43:03 +08:00
TxBDAddress := 0.U
} .elsewhen(TxStatusWrite){
2023-10-08 18:27:49 +08:00
when( TxStatusWrite & ~WrapTxStatusBit ){ //increase
TxBDAddress := TxBDAddress + 1.U
} .otherwise{ //wrap
TxBDAddress := 0.U
}
2023-06-28 23:43:03 +08:00
}
// Latching Rx buffer descriptor address
when(io.r_RxEn & (~r_RxEn_q)){
RxBDAddress := io.r_TxBDNum(6,0)
2023-06-28 23:43:03 +08:00
} .elsewhen(RxStatusWrite){
2023-10-08 18:27:49 +08:00
when( WrapRxStatusBit ) {
RxBDAddress := io.r_TxBDNum(6,0) // Using first Rx BD
} .otherwise{
RxBDAddress := (RxBDAddress + 1.U) //Using next Rx BD
}
2023-06-28 23:43:03 +08:00
}
2023-10-08 15:13:35 +08:00
2023-06-28 23:43:03 +08:00
2023-09-26 21:41:19 +08:00
2023-06-29 18:29:54 +08:00
2023-06-28 23:43:03 +08:00
val TxAbortPacketBlocked = RegInit(false.B)
2023-06-30 16:00:02 +08:00
when(
2023-10-08 11:34:36 +08:00
io.TxAbortSync & (~TxAbortPacketBlocked) & MasterWbTX & io.tlMst.D.fire & isLastD |
io.TxAbortSync & (~TxAbortPacketBlocked) & (~MasterWbTX) ){
2023-06-28 23:43:03 +08:00
TxAbortPacket := true.B
} .otherwise{
TxAbortPacket := false.B
}
2023-09-26 21:41:19 +08:00
when(stateNxt === StateTX & stateCur === StateTX & TxAbortPacket_NotCleared){
2023-06-28 23:43:03 +08:00
TxAbortPacket_NotCleared := false.B
2023-06-30 16:00:02 +08:00
} .elsewhen(
2023-10-08 11:34:36 +08:00
io.TxAbortSync & (~TxAbortPacketBlocked) & MasterWbTX & io.tlMst.D.fire & isLastD |
io.TxAbortSync & (~TxAbortPacketBlocked) & (~MasterWbTX) ){
2023-06-28 23:43:03 +08:00
TxAbortPacket_NotCleared := true.B
}
2023-10-08 11:34:36 +08:00
when(~io.TxAbortSync & RegNext(io.TxAbortSync, false.B)){
2023-06-28 23:43:03 +08:00
TxAbortPacketBlocked := false.B
} .elsewhen(TxAbortPacket){
TxAbortPacketBlocked := true.B
}
val TxRetryPacketBlocked = RegInit(false.B)
when(
2023-10-08 11:34:36 +08:00
io.TxRetrySync & ~TxRetryPacketBlocked & MasterWbTX & io.tlMst.D.fire & isLastD |
io.TxRetrySync & ~TxRetryPacketBlocked & ~MasterWbTX ){
2023-06-28 23:43:03 +08:00
TxRetryPacket := true.B
} .otherwise{
TxRetryPacket := false.B
}
when(StartTxBDRead){
TxRetryPacket_NotCleared := false.B
} .elsewhen(
2023-10-08 11:34:36 +08:00
io.TxRetrySync & ~TxRetryPacketBlocked & MasterWbTX & io.tlMst.D.fire & isLastD |
io.TxRetrySync & ~TxRetryPacketBlocked & ~MasterWbTX ){
2023-06-28 23:43:03 +08:00
TxRetryPacket_NotCleared := true.B
}
2023-10-08 11:34:36 +08:00
when( ~io.TxRetrySync & RegNext(io.TxRetrySync, false.B) ){
2023-06-28 23:43:03 +08:00
TxRetryPacketBlocked := false.B
} .elsewhen(TxRetryPacket){
TxRetryPacketBlocked := true.B
}
val TxDonePacketBlocked = RegInit(false.B)
when(
2023-10-08 11:34:36 +08:00
io.TxDoneSync & ~TxDonePacketBlocked & MasterWbTX & io.tlMst.D.fire & isLastD |
io.TxDoneSync & ~TxDonePacketBlocked & ~MasterWbTX ){
2023-06-28 23:43:03 +08:00
TxDonePacket := true.B
}.otherwise{
TxDonePacket := false.B
}
2023-09-26 21:41:19 +08:00
when(stateNxt === StateTX & stateCur === StateTX & TxDonePacket_NotCleared){
2023-06-28 23:43:03 +08:00
TxDonePacket_NotCleared := false.B
} .elsewhen(
2023-10-08 11:34:36 +08:00
io.TxDoneSync & ~TxDonePacketBlocked & MasterWbTX & io.tlMst.D.fire & isLastD |
io.TxDoneSync & ~TxDonePacketBlocked & ~MasterWbTX ){
2023-06-28 23:43:03 +08:00
TxDonePacket_NotCleared := true.B
}
2023-10-08 11:34:36 +08:00
when(~io.TxDoneSync & RegNext(io.TxDoneSync, false.B)){
2023-06-28 23:43:03 +08:00
TxDonePacketBlocked := false.B
} .elsewhen(TxDonePacket){
TxDonePacketBlocked := true.B
}
2023-06-29 18:29:54 +08:00
2023-06-28 23:43:03 +08:00
// Tx under run
when(TxAbortPulse){
TxUnderRun_wb := false.B
2023-10-08 18:27:49 +08:00
} .elsewhen(tx_fifo.io.empty & ReadTxDataFromFifoSyncPluse){
2023-06-28 23:43:03 +08:00
TxUnderRun_wb := true.B
}
2023-10-08 18:27:49 +08:00
2023-06-28 23:43:03 +08:00
// Reading the Rx buffer descriptor
2023-10-08 18:27:49 +08:00
when( (RxStatusWrite | RegNext(RxAbortPluse, false.B) | (io.r_RxEn & ~r_RxEn_q)) & ~RxReady){
2023-06-28 23:43:03 +08:00
RxBDRead := true.B
} .elsewhen(RxBDReady){
RxBDRead := false.B
}
// Latching READY status of the Rx buffer descriptor
when(RxPointerRead){
RxBDReady := false.B
2023-09-26 21:41:19 +08:00
} .elsewhen(stateNxt === StateRX & stateCur === StateRX & RxBDRead){
2023-10-08 18:27:49 +08:00
RxBDReady := rxBuffDesc.e // RxBDReady is sampled only once at the beginning
RxStatus := Cat(rxBuffDesc.irq, rxBuffDesc.wrap) // Latching Rx buffer descriptor status Data is avaliable one cycle after the access is started (at that time signal RxEn is not active)
2023-06-28 23:43:03 +08:00
}
// RxReady generation
2023-10-08 15:13:35 +08:00
when(ShiftEnded | RxAbortPluse | ~io.r_RxEn & r_RxEn_q){
2023-06-28 23:43:03 +08:00
RxReady := false.B
2023-09-26 21:41:19 +08:00
} .elsewhen(stateNxt === StateRX & stateCur === StateRX & RxPointerRead){
2023-06-28 23:43:03 +08:00
RxReady := true.B
}
// Reading Tx BD Pointer
2023-10-08 18:27:49 +08:00
when(RxBDRead & RxBDReady){
2023-06-28 23:43:03 +08:00
RxPointerRead := true.B
2023-09-26 21:41:19 +08:00
} .elsewhen(stateNxt === StateRX & stateCur === StateRX){
2023-06-28 23:43:03 +08:00
RxPointerRead := false.B
}
//Latching Rx buffer pointer from buffer descriptor;
2023-09-26 21:41:19 +08:00
when(stateNxt === StateRX & stateCur === StateRX & RxPointerRead){
2023-10-08 18:27:49 +08:00
RxPointerMSB := bd_ram.io.dato(31,2)
2023-07-11 17:38:18 +08:00
} .elsewhen(MasterWbRX & io.tlMst.A.fire ){
2023-06-28 23:43:03 +08:00
RxPointerMSB := RxPointerMSB + 1.U // Word access (always word access. m_wb_sel_o are used for selecting bytes)
}
2023-09-26 21:41:19 +08:00
when(~RxReady & io.r_RxEn & stateNxt === StateWB & stateCur =/= StateWB){
2023-06-28 23:43:03 +08:00
RxEn_needed := true.B
2023-09-26 21:41:19 +08:00
} .elsewhen(RxPointerRead & stateNxt === StateRX & stateCur === StateRX){
2023-06-28 23:43:03 +08:00
RxEn_needed := false.B
}
// Reception status is written back to the buffer descriptor after the end of frame is detected.
2023-09-26 21:41:19 +08:00
RxStatusWrite := ShiftEnded & stateNxt === StateRX & stateCur === StateRX
2023-06-28 23:43:03 +08:00
2023-10-08 15:13:35 +08:00
2023-06-29 18:29:54 +08:00
2023-10-08 18:27:49 +08:00
rx_fifo.io.data_in := io.RxDataLatched2_rxclk
rx_fifo.io.write := WriteRxDataToFifoSyncPluse & ~rx_fifo.io.full
rx_fifo.io.read := MasterWbRX & io.tlMst.A.fire
rx_fifo.io.clear := LatchedRxStartFrmSyncPluse
2023-06-29 18:29:54 +08:00
2023-06-29 18:29:54 +08:00
2023-10-08 18:27:49 +08:00
when( ShiftEndedSyncPluse ){
2023-06-29 18:29:54 +08:00
ShiftEndedSync3 := true.B
} .elsewhen(ShiftEnded){
ShiftEndedSync3 := false.B
}
// Generation of the end-of-frame signal
2023-10-08 18:27:49 +08:00
when(ShiftEndedSync3 & MasterWbRX & io.tlMst.A.fire & rx_fifo.io.almost_empty & ~ShiftEnded){
2023-06-29 18:29:54 +08:00
ShiftEnded := true.B
} .elsewhen(RxStatusWrite){
ShiftEnded := false.B
}
2023-10-08 15:13:35 +08:00
io.RxStatusIn := Cat(io.ReceivedPauseFrm, io.AddressMiss, RxOverrun, io.InvalidSymbol, io.DribbleNibble, io.ReceivedPacketTooBig, io.ShortFrame, io.LatchedCrcError, io.RxLateCollision)
2023-06-29 18:29:54 +08:00
// Rx overrun
when(RxStatusWrite){
RxOverrun := false.B
2023-10-08 18:27:49 +08:00
} .elsewhen(rx_fifo.io.full & WriteRxDataToFifoSyncPluse){
2023-06-29 18:29:54 +08:00
RxOverrun := true.B
}
2023-10-08 18:27:49 +08:00
2023-06-29 18:29:54 +08:00
// Latching and synchronizing RxStatusWrite signal. This signal is used for clearing the ReceivedPauseFrm signal
2023-10-08 15:30:08 +08:00
when(io.RxStatusWriteLatchedSyncb){
2023-06-29 18:29:54 +08:00
RxStatusWriteLatched := false.B
} .elsewhen(RxStatusWrite){
RxStatusWriteLatched := true.B
}
2023-10-08 18:27:49 +08:00
// ShortFrame (RxStatusInLatched[2]) can not set an error because short frames are aborted when signal r_RecSmall is set to 0 in MODER register.
// AddressMiss is identifying that a frame was received because of the promiscous mode and is not an error
val RxError = (io.RxStatusInLatched_rxclk(6,3).orR) | (io.RxStatusInLatched_rxclk(1,0).orR)
2023-06-29 18:29:54 +08:00
2023-10-08 18:27:49 +08:00
val TxError = io.TxUnderRun | io.RetryLimit | io.LateCollLatched | io.CarrierSenseLost
2023-06-29 18:29:54 +08:00
// Tx Done Interrupt
when(TxStatusWrite & TxIRQEn){
TxB_IRQ := ~TxError
} .otherwise{
TxB_IRQ := false.B
}
// Tx Error Interrupt
when(TxStatusWrite & TxIRQEn){
TxE_IRQ := TxError
} .otherwise{
TxE_IRQ := false.B
}
// Rx Done Interrupt
when(RxStatusWrite & RxIRQEn & io.ReceivedPacketGood & (~io.ReceivedPauseFrm | io.ReceivedPauseFrm & io.r_PassAll & (~io.r_RxFlow))){
2023-06-29 18:29:54 +08:00
RxB_IRQ := (~RxError)
} .otherwise{
RxB_IRQ := false.B
}
// Rx Error Interrupt
when(RxStatusWrite & RxIRQEn & (~io.ReceivedPauseFrm | io.ReceivedPauseFrm & io.r_PassAll & (~io.r_RxFlow))){
2023-06-29 18:29:54 +08:00
RxE_IRQ := RxError
} .otherwise{
RxE_IRQ := false.B
}
2023-10-08 18:27:49 +08:00
io.Busy_IRQ := Busy_IRQ_syncPluse
2023-06-29 18:29:54 +08:00
2023-10-08 18:27:49 +08:00
val slvAInfo = RegEnable( io.tlSlv.A.bits, io.tlSlv.A.fire )
val slvDValid = RegInit(false.B); io.tlSlv.D.valid := slvDValid
val slvDDat = Reg(UInt(32.W))
2023-06-30 20:21:03 +08:00
2023-10-08 18:27:49 +08:00
when( io.tlSlv.D.fire ){
slvDValid := false.B
} .elsewhen(io.tlSlv.A.fire){
slvDValid := true.B
slvDDat := bd_ram.io.dato
}
2023-07-03 16:25:41 +08:00
2023-10-08 18:27:49 +08:00
when(slvAInfo.opcode === 4.U) {
io.tlSlv.D.bits := edgeIn.AccessAck(slvAInfo, slvDDat)
} .otherwise {
io.tlSlv.D.bits := edgeIn.AccessAck(slvAInfo)
}
2023-06-29 18:29:54 +08:00
2023-10-08 18:27:49 +08:00
io.tlSlv.A.ready := RegNext(stateNxt === StateWB & Mux( stateCur === StateWB , BDWrite.orR, BDRead ))
assert( ~(io.tlSlv.A.ready & ~io.tlSlv.A.valid) )
2023-07-04 17:37:41 +08:00
val mstAValid = RegInit(false.B)
val mstABits = Reg(new TLBundleA(edgeOut.bundle))
2023-07-11 17:38:18 +08:00
when( io.tlMst.A.fire ){
mstAValid := false.B
}
.elsewhen( MasterWbRX & ~isTlMstBusy ) {
mstAValid := true.B
mstABits :=
edgeOut.Put(
fromSource = 0.U,
2023-07-11 00:00:26 +08:00
toAddress = RxPointerMSB << 2,
lgSize = log2Ceil(32/8).U,
data = rx_fifo.io.data_out,
mask = "b1111".U,
)._2
}
.elsewhen( MasterWbTX & ~isTlMstBusy ){
mstAValid := true.B
mstABits :=
edgeOut.Get(
fromSource = 0.U,
2023-07-11 00:00:26 +08:00
toAddress = TxPointerMSB << 2,
lgSize = log2Ceil(32/8).U,
)._2
}
2023-07-11 17:38:18 +08:00
when( io.tlMst.A.fire ){
isTlMstBusy := true.B
2023-07-11 17:38:18 +08:00
} .elsewhen( io.tlMst.D.fire ){
isTlMstBusy := false.B
}
when( ~MasterWbTX & ~MasterWbRX ){
2023-10-08 18:27:49 +08:00
when( ~rx_fifo.io.empty ){
MasterWbRX := true.B
} .elsewhen(ReadTxDataFromMemory_2) {
MasterWbTX := true.B
}
} .elsewhen( ~MasterWbTX & MasterWbRX){ //1.4A + 1D fifo to memory
2023-10-08 18:27:49 +08:00
when( io.tlMst.D.fire & isLastD & rx_fifo.io.empty ){
MasterWbRX := false.B
}
} .elsewhen( MasterWbTX & ~MasterWbRX){ //1 A + 1.4D memory to fifo
2023-07-11 17:38:18 +08:00
when( io.tlMst.D.fire & isLastD & ~ReadTxDataFromMemory_2 ){
MasterWbTX := false.B
}
}
2023-07-11 17:38:18 +08:00
when(io.tlMst.D.fire & io.tlMst.D.bits.opcode === 1.U) { assert( MasterWbTX ) }
when(io.tlMst.D.fire & io.tlMst.D.bits.opcode === 0.U) { assert( MasterWbRX ) }
2023-10-08 18:27:49 +08:00
val tlMstAValid_dbg = RegInit(true.B)
io.tlMst.A.valid := mstAValid & tlMstAValid_dbg
io.tlMst.A.bits := mstABits
2023-10-08 18:27:49 +08:00
val tlMstDReady = RegInit(true.B)
2023-07-11 00:00:26 +08:00
2023-10-08 18:27:49 +08:00
dontTouch(tlMstDReady)
dontTouch(tlMstAValid_dbg)
io.tlMst.D.ready := tlMstDReady
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-08 15:37:54 +08:00
class MacTileLink(edgeIn: TLEdgeIn, edgeOut: TLEdgeOut) extends MacTileLinkBase(edgeIn, edgeOut)
2023-10-07 16:44:13 +08:00
2023-06-28 23:43:03 +08:00