Files
eb001/src/main/scala/backBoard/shin/MasterParser.scala

204 lines
6.3 KiB
Scala
Raw Normal View History

2025-04-27 14:56:07 +08:00
package BACK
2025-04-02 16:40:25 +08:00
2025-04-27 14:56:07 +08:00
import chisel3._
import chisel3.util._
2025-04-02 16:40:25 +08:00
2025-04-27 16:56:35 +08:00
class MasterParserIO extends Bundle{
2025-04-27 14:56:07 +08:00
val downOut = Decoupled(new AXIS_Bundle(8))
val upIn = Flipped( Decoupled(new AXIS_Bundle(8)) )
2025-04-02 16:40:25 +08:00
2025-04-27 16:56:35 +08:00
val sram_w = Flipped(new SRAM2kWRIO)
val sram_r = Flipped(new SRAM2kRDIO)
2025-04-02 16:40:25 +08:00
val req = Input(Bool())
2025-04-27 14:56:07 +08:00
val rsp = Valid(new Bundle{
val isError = Bool()
})
2025-04-02 16:40:25 +08:00
2025-04-27 14:56:07 +08:00
val rxEnq = Output( Bool())
val txDeq = Output( Bool())
2025-04-02 16:40:25 +08:00
2025-05-15 14:57:58 +08:00
val cReg = Input(new CommonRegisterBundle)
val mReg = Input(new MasterRegisterBundle)
val deltaTimeStamp = Output(UInt(32.W))
2025-04-02 16:40:25 +08:00
2025-04-27 14:56:07 +08:00
}
2025-04-02 16:40:25 +08:00
2025-04-27 14:56:07 +08:00
abstract class MasterParserBase extends Module{
val io: MasterParserIO = IO(new MasterParserIO)
2025-04-16 16:49:42 +08:00
val txCnt = Reg(UInt(12.W))
2025-04-27 16:56:35 +08:00
val txLen = Reg(UInt(11.W))
2025-04-27 14:56:07 +08:00
val txAddr = Reg(UInt(15.W))
2025-04-16 16:49:42 +08:00
val rxCnt = Reg(UInt(12.W))
val rxLen = Reg(UInt(11.W))
2025-04-27 14:56:07 +08:00
val rxAddr = Reg(UInt(15.W))
2025-04-16 16:49:42 +08:00
2025-04-27 14:56:07 +08:00
val reqReady = RegInit(true.B)
2025-04-16 16:49:42 +08:00
2025-04-27 16:56:35 +08:00
val txcrc = Module(new crc32_8)
val rxcrc = Module(new crc32_8)
2025-04-27 16:56:35 +08:00
// io.req.ready := reqReady
2025-04-16 16:49:42 +08:00
when( io.req ){
2025-04-27 14:56:07 +08:00
reqReady := false.B
} .elsewhen( io.downOut.fire & txCnt === txLen + (4-1).U ){
2025-04-27 14:56:07 +08:00
reqReady := true.B
}
2025-04-16 16:49:42 +08:00
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),
))
2025-04-27 16:56:35 +08:00
txCnt := 0.U
2025-04-27 14:56:07 +08:00
} .elsewhen( io.downOut.fire ){
2025-04-27 16:56:35 +08:00
txCnt := txCnt + 1.U
2025-04-27 14:56:07 +08:00
}
2025-04-16 16:49:42 +08:00
when( io.req ){
txAddr := 0.U
2025-04-27 14:56:07 +08:00
} .elsewhen( io.downOut.fire ){
txAddr := txAddr + 1.U
}
2025-04-16 16:49:42 +08:00
when( io.req ){
rxAddr := 0.U
2025-04-27 14:56:07 +08:00
} .elsewhen( io.upIn.fire ){
rxAddr := rxAddr + 1.U
}
2025-04-16 16:49:42 +08:00
2025-04-27 16:56:35 +08:00
2025-04-16 16:49:42 +08:00
2025-04-27 14:56:07 +08:00
io.sram_r.enr :=
io.req | io.downOut.fire
2025-04-16 16:49:42 +08:00
io.sram_r.addrr := Mux( io.req, 0.U, txAddr + 1.U )
2025-04-16 16:49:42 +08:00
2025-04-27 14:56:07 +08:00
io.downOut.valid := ~reqReady
2025-05-15 14:57:58 +08:00
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(
2025-05-15 14:57:58 +08:00
( 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),
))
2025-04-27 14:56:07 +08:00
io.downOut.bits.tuser := false.B
io.downOut.bits.tlast := txCnt === (txLen + 3.U)
2025-04-16 16:49:42 +08:00
val recCrcCheck = Reg(UInt(32.W))
2025-04-16 16:49:42 +08:00
when( io.req ){
2025-04-27 14:56:07 +08:00
rxCnt := 0.U
} .elsewhen( io.upIn.fire ){
rxCnt := rxCnt + 1.U
}
2025-04-16 16:49:42 +08:00
2025-04-27 14:56:07 +08:00
io.upIn.ready := true.B
2025-04-16 16:49:42 +08:00
2025-04-27 14:56:07 +08:00
io.sram_w.enw := io.upIn.fire
2025-04-27 16:56:35 +08:00
io.sram_w.addrw := rxAddr
2025-04-27 14:56:07 +08:00
io.sram_w.dataw := io.upIn.bits.tdata
2025-04-16 16:49:42 +08:00
2025-04-27 14:56:07 +08:00
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
2025-04-16 16:49:42 +08:00
io.rxEnq := io.upIn.fire & io.upIn.bits.tlast
io.txDeq := io.downOut.fire & io.downOut.bits.tlast
2025-04-16 16:49:42 +08:00
2025-04-27 14:56:07 +08:00
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 )
}
}
2025-04-27 14:56:07 +08:00
}
class MasterParser extends MasterParserBase{
2025-04-30 17:09:30 +08:00
val deltaTimeStamp = Reg(UInt(32.W))
2025-05-15 14:57:58 +08:00
// dontTouch(deltaTimeStamp)
io.deltaTimeStamp := deltaTimeStamp
2025-04-27 14:56:07 +08:00
2025-04-30 17:09:30 +08:00
val txStamps = Reg(UInt(32.W))
when( io.downOut.fire & io.downOut.bits.tlast ){
2025-05-15 14:57:58 +08:00
txStamps := io.cReg.timeStamp(31,0)
2025-04-30 17:09:30 +08:00
} .elsewhen( io.upIn.fire & io.upIn.bits.tlast & ~io.upIn.bits.tuser ){
2025-05-15 14:57:58 +08:00
deltaTimeStamp := io.cReg.timeStamp(31,0) - txStamps
2025-04-30 17:09:30 +08:00
}
2025-04-27 14:56:07 +08:00
}