204 lines
6.3 KiB
Scala
204 lines
6.3 KiB
Scala
package BACK
|
|
|
|
import chisel3._
|
|
import chisel3.util._
|
|
|
|
class MasterParserIO extends Bundle{
|
|
val downOut = Decoupled(new AXIS_Bundle(8))
|
|
val upIn = Flipped( Decoupled(new AXIS_Bundle(8)) )
|
|
|
|
val sram_w = Flipped(new SRAM2kWRIO)
|
|
val sram_r = Flipped(new SRAM2kRDIO)
|
|
|
|
val req = Input(Bool())
|
|
val rsp = Valid(new Bundle{
|
|
val isError = Bool()
|
|
})
|
|
|
|
val rxEnq = Output( Bool())
|
|
val txDeq = Output( Bool())
|
|
|
|
val cReg = Input(new CommonRegisterBundle)
|
|
val mReg = Input(new MasterRegisterBundle)
|
|
|
|
val deltaTimeStamp = Output(UInt(32.W))
|
|
|
|
}
|
|
|
|
abstract class MasterParserBase extends Module{
|
|
val io: MasterParserIO = IO(new MasterParserIO)
|
|
|
|
val txCnt = Reg(UInt(12.W))
|
|
val txLen = Reg(UInt(11.W))
|
|
val txAddr = Reg(UInt(15.W))
|
|
|
|
val rxCnt = Reg(UInt(12.W))
|
|
val rxLen = Reg(UInt(11.W))
|
|
val rxAddr = Reg(UInt(15.W))
|
|
|
|
val reqReady = RegInit(true.B)
|
|
|
|
|
|
val txcrc = Module(new crc32_8)
|
|
val rxcrc = Module(new crc32_8)
|
|
|
|
|
|
|
|
|
|
// io.req.ready := reqReady
|
|
|
|
when( io.req ){
|
|
reqReady := false.B
|
|
} .elsewhen( io.downOut.fire & txCnt === txLen + (4-1).U ){
|
|
reqReady := true.B
|
|
}
|
|
|
|
when( io.req ){
|
|
txLen := Mux1H(Seq(
|
|
( io.mReg.txSM === 0.U ) -> io.cReg.smTrigLen(1),
|
|
( io.mReg.txSM === 1.U ) -> io.cReg.smTrigLen(3),
|
|
( io.mReg.txSM === 2.U ) -> io.cReg.smTrigLen(5),
|
|
( io.mReg.txSM === 3.U ) -> io.cReg.smTrigLen(7),
|
|
))
|
|
rxLen := Mux1H(Seq(
|
|
( io.mReg.rxSM === 0.U ) -> io.cReg.smTrigLen(0),
|
|
( io.mReg.rxSM === 1.U ) -> io.cReg.smTrigLen(2),
|
|
( io.mReg.rxSM === 2.U ) -> io.cReg.smTrigLen(4),
|
|
( io.mReg.rxSM === 3.U ) -> io.cReg.smTrigLen(6),
|
|
))
|
|
txCnt := 0.U
|
|
} .elsewhen( io.downOut.fire ){
|
|
txCnt := txCnt + 1.U
|
|
}
|
|
|
|
when( io.req ){
|
|
txAddr := 0.U
|
|
} .elsewhen( io.downOut.fire ){
|
|
txAddr := txAddr + 1.U
|
|
}
|
|
|
|
when( io.req ){
|
|
rxAddr := 0.U
|
|
} .elsewhen( io.upIn.fire ){
|
|
rxAddr := rxAddr + 1.U
|
|
}
|
|
|
|
|
|
|
|
io.sram_r.enr :=
|
|
io.req | io.downOut.fire
|
|
|
|
io.sram_r.addrr := Mux( io.req, 0.U, txAddr + 1.U )
|
|
|
|
io.downOut.valid := ~reqReady
|
|
|
|
|
|
val isRplTimeStamp = io.mReg.rplTimeStampTx.extract(15)
|
|
val isRplDeltaStamp = io.mReg.rplTimeStampTx.extract(14)
|
|
val rplCnt0 = io.mReg.rplTimeStampTx(10,0) + 0.U
|
|
val rplCnt1 = io.mReg.rplTimeStampTx(10,0) + 1.U
|
|
val rplCnt2 = io.mReg.rplTimeStampTx(10,0) + 2.U
|
|
val rplCnt3 = io.mReg.rplTimeStampTx(10,0) + 3.U
|
|
val rplCnt4 = io.mReg.rplTimeStampTx(10,0) + 4.U
|
|
val rplCnt5 = io.mReg.rplTimeStampTx(10,0) + 5.U
|
|
val rplCnt6 = io.mReg.rplTimeStampTx(10,0) + 6.U
|
|
val rplCnt7 = io.mReg.rplTimeStampTx(10,0) + 7.U
|
|
val rplCnt8 = io.mReg.rplTimeStampTx(10,0) + 8.U
|
|
val rplCnt9 = io.mReg.rplTimeStampTx(10,0) + 9.U
|
|
val rplCnt10 = io.mReg.rplTimeStampTx(10,0) + 10.U
|
|
val rplCnt11 = io.mReg.rplTimeStampTx(10,0) + 11.U
|
|
|
|
|
|
io.downOut.bits.tdata := Mux1H(Seq(
|
|
( txCnt < txLen ) ->
|
|
MuxCase( io.sram_r.datar, Array(
|
|
( isRplTimeStamp & ( txCnt === rplCnt0 ) ) -> io.cReg.timeStamp(7,0),
|
|
( isRplTimeStamp & ( txCnt === rplCnt1 ) ) -> RegEnable(io.cReg.timeStamp(15,8), io.downOut.fire & txCnt === rplCnt0 ),
|
|
( isRplTimeStamp & ( txCnt === rplCnt2 ) ) -> RegEnable(io.cReg.timeStamp(23,16), io.downOut.fire & txCnt === rplCnt0 ),
|
|
( isRplTimeStamp & ( txCnt === rplCnt3 ) ) -> RegEnable(io.cReg.timeStamp(31,24), io.downOut.fire & txCnt === rplCnt0 ),
|
|
( isRplTimeStamp & ( txCnt === rplCnt4 ) ) -> RegEnable(io.cReg.timeStamp(39,32), io.downOut.fire & txCnt === rplCnt0 ),
|
|
( isRplTimeStamp & ( txCnt === rplCnt5 ) ) -> RegEnable(io.cReg.timeStamp(47,40), io.downOut.fire & txCnt === rplCnt0 ),
|
|
( isRplTimeStamp & ( txCnt === rplCnt6 ) ) -> RegEnable(io.cReg.timeStamp(55,48), io.downOut.fire & txCnt === rplCnt0 ),
|
|
( isRplTimeStamp & ( txCnt === rplCnt7 ) ) -> RegEnable(io.cReg.timeStamp(63,56), io.downOut.fire & txCnt === rplCnt0 ),
|
|
( isRplDeltaStamp & ( txCnt === rplCnt8 ) ) -> io.cReg.mstDeltaTime(7,0),
|
|
( isRplDeltaStamp & ( txCnt === rplCnt9 ) ) -> io.cReg.mstDeltaTime(15,8),
|
|
( isRplDeltaStamp & ( txCnt === rplCnt10 ) ) -> io.cReg.mstDeltaTime(23,16),
|
|
( isRplDeltaStamp & ( txCnt === rplCnt11 ) ) -> io.cReg.mstDeltaTime(31,24),
|
|
)),
|
|
( txCnt === txLen + 0.U ) -> txcrc.io.crc(31,24),
|
|
( txCnt === txLen + 1.U ) -> txcrc.io.crc(23,16),
|
|
( txCnt === txLen + 2.U ) -> txcrc.io.crc(15, 8),
|
|
( txCnt === txLen + 3.U ) -> txcrc.io.crc( 7, 0),
|
|
))
|
|
io.downOut.bits.tuser := false.B
|
|
io.downOut.bits.tlast := txCnt === (txLen + 3.U)
|
|
|
|
|
|
|
|
val recCrcCheck = Reg(UInt(32.W))
|
|
|
|
when( io.req ){
|
|
rxCnt := 0.U
|
|
} .elsewhen( io.upIn.fire ){
|
|
rxCnt := rxCnt + 1.U
|
|
}
|
|
|
|
|
|
io.upIn.ready := true.B
|
|
|
|
io.sram_w.enw := io.upIn.fire
|
|
io.sram_w.addrw := rxAddr
|
|
io.sram_w.dataw := io.upIn.bits.tdata
|
|
|
|
|
|
io.rsp.valid := io.upIn.fire & io.upIn.bits.tlast
|
|
io.rsp.bits.isError := io.upIn.fire & io.upIn.bits.tlast & recCrcCheck =/= rxcrc.io.crc
|
|
// io.rsp.bits.length := rxCnt + 1.U
|
|
|
|
|
|
|
|
io.rxEnq := io.upIn.fire & io.upIn.bits.tlast
|
|
io.txDeq := io.downOut.fire & io.downOut.bits.tlast
|
|
|
|
|
|
|
|
|
|
txcrc.io.isEnable := io.downOut.fire & txCnt < txLen
|
|
txcrc.io.dataIn := io.downOut.bits.tdata
|
|
txcrc.reset := reset.asBool | reqReady
|
|
|
|
rxcrc.io.isEnable := io.upIn.fire & rxCnt < rxLen
|
|
rxcrc.io.dataIn := io.upIn.bits.tdata
|
|
rxcrc.reset := reset.asBool | io.rsp.fire
|
|
|
|
|
|
|
|
when( io.upIn.fire ){
|
|
when( rxCnt === rxLen ){
|
|
recCrcCheck := io.upIn.bits.tdata << 24
|
|
} .elsewhen( rxCnt === (rxLen + 1.U) ){
|
|
recCrcCheck := Cat( recCrcCheck(31,24), io.upIn.bits.tdata, recCrcCheck(15,0) )
|
|
} .elsewhen( rxCnt === (rxLen + 2.U) ){
|
|
recCrcCheck := Cat( recCrcCheck(31,16), io.upIn.bits.tdata, recCrcCheck( 7,0) )
|
|
} .elsewhen( rxCnt === (rxLen + 3.U) ){
|
|
recCrcCheck := Cat( recCrcCheck(31,8), io.upIn.bits.tdata )
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
class MasterParser extends MasterParserBase{
|
|
val deltaTimeStamp = Reg(UInt(32.W))
|
|
// dontTouch(deltaTimeStamp)
|
|
io.deltaTimeStamp := deltaTimeStamp
|
|
|
|
val txStamps = Reg(UInt(32.W))
|
|
|
|
when( io.downOut.fire & io.downOut.bits.tlast ){
|
|
txStamps := io.cReg.timeStamp(31,0)
|
|
} .elsewhen( io.upIn.fire & io.upIn.bits.tlast & ~io.upIn.bits.tuser ){
|
|
deltaTimeStamp := io.cReg.timeStamp(31,0) - txStamps
|
|
}
|
|
} |