2025-04-02 16:40:25 +08:00
|
|
|
|
package BACK
|
|
|
|
|
|
|
|
|
|
|
|
import chisel3._
|
|
|
|
|
|
import chisel3.util._
|
|
|
|
|
|
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
|
|
|
|
|
class FrameHeader extends Bundle{
|
|
|
|
|
|
val frameLenAim = UInt(12.W) //帧长度目标
|
|
|
|
|
|
val frameStyle = UInt(2.W) //包类型
|
2025-04-22 17:32:05 +08:00
|
|
|
|
val frameInfo = UInt(16.W) //其它信息,如probe
|
2025-04-07 17:39:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class SubMsgHeader extends Bundle{
|
2025-04-08 17:29:45 +08:00
|
|
|
|
val devIndex = UInt(14.W) // 子报文中设备索引
|
|
|
|
|
|
val style = UInt(2.W) // 子报文类型
|
|
|
|
|
|
val address = UInt(16.W) //子报文地址
|
|
|
|
|
|
val operator = UInt(4.W) //子报文命令类型
|
|
|
|
|
|
val length = UInt(12.W) //子报文负载长度
|
|
|
|
|
|
val workCnt = UInt(16.W) //子报文工作计数
|
2025-04-07 17:39:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-17 15:16:42 +08:00
|
|
|
|
// class ShareSRAMIO extends Bundle{
|
|
|
|
|
|
// val addr = Input(UInt(15.W))
|
|
|
|
|
|
// val dataw = Input( UInt(8.W) )
|
|
|
|
|
|
// val datar = Output( UInt(8.W) )
|
|
|
|
|
|
// val enw = Input(Bool())
|
|
|
|
|
|
// val enr = Input(Bool())
|
|
|
|
|
|
// }
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-11 17:57:47 +08:00
|
|
|
|
class SlaveParserIO extends Bundle{
|
2025-04-03 17:49:33 +08:00
|
|
|
|
val downIn = Flipped( Decoupled(new AXIS_Bundle(8)) )
|
2025-04-07 17:39:44 +08:00
|
|
|
|
val downOut = Decoupled(new AXIS_Bundle(8))
|
2025-04-02 16:40:25 +08:00
|
|
|
|
|
2025-04-03 17:49:33 +08:00
|
|
|
|
val upIn = Flipped( Decoupled(new AXIS_Bundle(8)) )
|
2025-04-07 17:39:44 +08:00
|
|
|
|
val upOut = Decoupled(new AXIS_Bundle(8))
|
2025-04-03 17:49:33 +08:00
|
|
|
|
|
2025-04-24 16:18:33 +08:00
|
|
|
|
val sram_w = Vec( 4, Flipped(new SRAM2kWRIO))
|
|
|
|
|
|
val sram_r = Vec( 4, Flipped(new SRAM2kRDIO))
|
2025-04-17 15:16:42 +08:00
|
|
|
|
|
2025-04-24 16:18:33 +08:00
|
|
|
|
val dSMenq = Output( Vec(4, Bool()) )
|
|
|
|
|
|
val uSMdeq = Output( Vec(4, Bool()) )
|
2025-04-23 17:57:38 +08:00
|
|
|
|
|
2025-05-20 11:32:03 +08:00
|
|
|
|
|
2025-04-21 18:48:29 +08:00
|
|
|
|
|
2025-05-16 20:17:02 +08:00
|
|
|
|
|
|
|
|
|
|
val localDevIndex = Output(UInt(16.W))
|
|
|
|
|
|
|
2025-05-16 18:56:49 +08:00
|
|
|
|
//开放链路寄存器组给interface
|
|
|
|
|
|
// val isDevOnLeft = Output(UInt(2.W))
|
2025-05-21 16:50:20 +08:00
|
|
|
|
// val isDevOnLeftModify = Output(Bool())
|
|
|
|
|
|
// val indexOfLeftDev = Output(UInt(14.W))
|
2025-05-16 18:56:49 +08:00
|
|
|
|
val isDevOnRight = Output(UInt(2.W))
|
|
|
|
|
|
val isDevOnRightModify = Output(Bool())
|
|
|
|
|
|
val indexOfRightDev = Output(UInt(14.W))
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-15 14:57:58 +08:00
|
|
|
|
val mstDeltaTimeStamp = Output(UInt(32.W))
|
2025-05-16 16:05:38 +08:00
|
|
|
|
val slvDeltaTime = Output(UInt(32.W))
|
2025-05-15 18:40:01 +08:00
|
|
|
|
val deltaFinal = Output(UInt(32.W))
|
|
|
|
|
|
|
2025-05-07 18:12:01 +08:00
|
|
|
|
val isLoop = Output(Bool())
|
2025-05-15 14:57:58 +08:00
|
|
|
|
|
|
|
|
|
|
val cReg = Input(new CommonRegisterBundle)
|
2025-05-15 18:40:01 +08:00
|
|
|
|
|
|
|
|
|
|
val lvds = new RegAccessInterfaceIO
|
2025-05-26 11:52:40 +08:00
|
|
|
|
|
|
|
|
|
|
val intHWTrig = Output(Vec(2, Bool()))
|
|
|
|
|
|
val intHWClr = Input (Vec(2, Bool()))
|
2025-04-02 16:40:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
abstract class SlaveParserBase extends Module{
|
|
|
|
|
|
val io: SlaveParserIO = IO(new SlaveParserIO)
|
|
|
|
|
|
|
2025-04-17 15:16:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-11 17:57:47 +08:00
|
|
|
|
val FRAME_STYLE_COMMON = 0.U
|
|
|
|
|
|
val FRAME_STYLE_PROBE = 1.U
|
|
|
|
|
|
|
2025-05-22 11:21:41 +08:00
|
|
|
|
val SUBMSG_OPERATOR_UNIREAD = 0.U
|
|
|
|
|
|
val SUBMSG_OPERATOR_UNIWRITE = 1.U
|
|
|
|
|
|
val SUBMSG_OPERATOR_UNIRDWR = 2.U
|
|
|
|
|
|
val SUBMSG_OPERATOR_INDEX = "hb".U
|
|
|
|
|
|
val SUBMSG_OPERATOR_SYNC = "hc".U
|
|
|
|
|
|
val SUBMSG_OPERATOR_BOARDREAD = "hd".U
|
|
|
|
|
|
val SUBMSG_OPERATOR_BOARDWRITE = "he".U
|
|
|
|
|
|
val SUBMSG_OPERATOR_BOARDRDWR = "hf".U
|
|
|
|
|
|
|
2025-05-06 17:39:52 +08:00
|
|
|
|
|
2025-04-11 17:57:47 +08:00
|
|
|
|
val STATE_IDLE = 0.U //空闲
|
|
|
|
|
|
val STATE_HEADER = 1.U //长度/ /保留2bits //包类型
|
2025-05-06 17:39:52 +08:00
|
|
|
|
val STATE_SUBMSG_HEADER = 2.U //子报文头
|
|
|
|
|
|
val STATE_PAYLOAD_DATA = 3.U //子报文数据
|
|
|
|
|
|
val STATE_CRC = 4.U //CRC校验
|
|
|
|
|
|
val STATE_ERROR = 5.U //
|
|
|
|
|
|
val STATE_WAIT = 6.U
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-05 09:27:15 +08:00
|
|
|
|
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
|
|
|
|
|
val downRecParser = Module(new SlaveRecParser)
|
|
|
|
|
|
val upRecParser = Module(new SlaveRecParser)
|
|
|
|
|
|
val downSendGen = Module(new SlaveSendGen)
|
|
|
|
|
|
val upSendGen = Module(new SlaveSendGen)
|
|
|
|
|
|
|
2025-04-29 17:48:57 +08:00
|
|
|
|
val isReadyToProbe = RegInit(false.B)
|
|
|
|
|
|
val isAckProbe = RegInit(false.B)
|
2025-04-29 16:02:01 +08:00
|
|
|
|
val isLastDevice: Bool = RegInit(true.B)
|
2025-05-16 18:56:49 +08:00
|
|
|
|
|
|
|
|
|
|
// val isDevOnLeft = RegInit(0.U(2.W)); io.isDevOnLeft := isDevOnLeft
|
2025-05-21 16:50:20 +08:00
|
|
|
|
// val isDevOnLeftModify = RegInit(false.B); io.isDevOnLeftModify := isDevOnLeftModify
|
|
|
|
|
|
// val indexOfLeftDev = RegInit(0.U(14.W)); io.indexOfLeftDev := indexOfLeftDev
|
2025-05-16 20:22:51 +08:00
|
|
|
|
io.isDevOnRight := Mux( isLastDevice, "b00".U, "b01".U )
|
2025-05-16 18:56:49 +08:00
|
|
|
|
val isDevOnRightModify = RegInit(false.B); io.isDevOnRightModify := isDevOnRightModify
|
|
|
|
|
|
val indexOfRightDev = RegInit(0.U(14.W)); io.indexOfRightDev := indexOfRightDev
|
|
|
|
|
|
|
2025-05-16 20:17:02 +08:00
|
|
|
|
val localDevIndex = RegInit(0.U(14.W)); io.localDevIndex := localDevIndex //当前设备索引
|
2025-04-08 17:29:45 +08:00
|
|
|
|
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-21 18:48:29 +08:00
|
|
|
|
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
|
|
|
|
|
|
//处理主报文
|
2025-04-11 17:57:47 +08:00
|
|
|
|
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-05-20 11:35:11 +08:00
|
|
|
|
downSendGen.io.frameReq.valid := downRecParser.io.frameReq.fire
|
|
|
|
|
|
assert( ~(downSendGen.io.frameReq.valid & ~downSendGen.io.frameReq.ready) )
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-05-21 16:50:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
downSendGen.io.frameReq.bits := downRecParser.io.frameReq.bits
|
|
|
|
|
|
//voerride
|
|
|
|
|
|
downSendGen.io.frameReq.bits.frameInfo := localDevIndex
|
|
|
|
|
|
}
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
val upFrameProbeInfo: FrameHeader = Wire(new FrameHeader)
|
|
|
|
|
|
upFrameProbeInfo.frameLenAim := 0.U //帧长度目标
|
|
|
|
|
|
upFrameProbeInfo.frameStyle := FRAME_STYLE_PROBE //包类型
|
|
|
|
|
|
upFrameProbeInfo.frameInfo := localDevIndex //其它信息,如probe
|
2025-04-05 09:27:15 +08:00
|
|
|
|
|
2025-04-07 17:39:44 +08:00
|
|
|
|
upSendGen.io.frameReq.valid :=
|
2025-05-20 11:35:11 +08:00
|
|
|
|
(upRecParser.io.frameReq.fire & upRecParser.io.frameReq.bits.frameStyle === FRAME_STYLE_COMMON) |
|
|
|
|
|
|
isAckProbe
|
|
|
|
|
|
|
|
|
|
|
|
assert( ~(upSendGen.io.frameReq.valid & ~upSendGen.io.frameReq.ready) )
|
|
|
|
|
|
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-05-20 11:35:11 +08:00
|
|
|
|
assert( ~(upRecParser.io.frameReq.fire & isAckProbe), "Assert Failed, Check Softwave, Probe is Sent while transfering!\n" )
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
|
|
|
|
|
upSendGen.io.frameReq.bits := Mux1H(Seq(
|
2025-05-20 11:35:11 +08:00
|
|
|
|
upRecParser.io.frameReq.fire -> upRecParser.io.frameReq.bits, //上行转发
|
|
|
|
|
|
isAckProbe -> upFrameProbeInfo, //上行探针
|
2025-04-07 17:39:44 +08:00
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-05 09:27:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-03 17:49:33 +08:00
|
|
|
|
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-11 17:57:47 +08:00
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
//子报文
|
2025-04-11 17:57:47 +08:00
|
|
|
|
val isDownSubMsgValid = for( _ <- 0 until 2 ) yield { RegInit(false.B) }
|
|
|
|
|
|
val isUpSubMsgValid = for( _ <- 0 until 2 ) yield { RegInit(false.B) }
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
//接收子报文
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-11 17:57:47 +08:00
|
|
|
|
val downSubMsgInfo = for( _ <- 0 until 2 ) yield { Reg(new SubMsgTxInfo) } //子报文头
|
|
|
|
|
|
val upSubMsgInfo = for( _ <- 0 until 2 ) yield { Reg(new SubMsgTxInfo) }
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-07 18:12:01 +08:00
|
|
|
|
val downRecFifo = for( _ <- 0 until 2 ) yield { Module(new Queue(UInt(8.W), 20)) } //子报文负载
|
|
|
|
|
|
val upRecFifo = for( _ <- 0 until 2 ) yield { Module(new Queue(UInt(8.W), 20)) }
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-11 17:57:47 +08:00
|
|
|
|
val isDownRecPing = RegInit(false.B)
|
|
|
|
|
|
val isUpRecPing = RegInit(false.B)
|
2025-04-08 17:29:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//下行接收
|
|
|
|
|
|
when( downRecParser.io.subMsgReq.fire ){
|
|
|
|
|
|
when( isDownRecPing ){
|
|
|
|
|
|
downSubMsgInfo(0).devIndex := downRecParser.io.subMsgReq.bits.devIndex
|
|
|
|
|
|
downSubMsgInfo(0).style := downRecParser.io.subMsgReq.bits.style
|
|
|
|
|
|
downSubMsgInfo(0).address := downRecParser.io.subMsgReq.bits.address
|
|
|
|
|
|
downSubMsgInfo(0).operator := downRecParser.io.subMsgReq.bits.operator
|
|
|
|
|
|
downSubMsgInfo(0).length := downRecParser.io.subMsgReq.bits.length
|
2025-04-21 18:48:29 +08:00
|
|
|
|
downSubMsgInfo(0).workCnt := downRecParser.io.subMsgReq.bits.workCnt
|
2025-04-08 17:29:45 +08:00
|
|
|
|
downSubMsgInfo(0).source := 0.U
|
2025-04-21 18:48:29 +08:00
|
|
|
|
} .otherwise{ //pong
|
2025-04-08 17:29:45 +08:00
|
|
|
|
downSubMsgInfo(1).devIndex := downRecParser.io.subMsgReq.bits.devIndex
|
|
|
|
|
|
downSubMsgInfo(1).style := downRecParser.io.subMsgReq.bits.style
|
|
|
|
|
|
downSubMsgInfo(1).address := downRecParser.io.subMsgReq.bits.address
|
|
|
|
|
|
downSubMsgInfo(1).operator := downRecParser.io.subMsgReq.bits.operator
|
|
|
|
|
|
downSubMsgInfo(1).length := downRecParser.io.subMsgReq.bits.length
|
2025-04-21 18:48:29 +08:00
|
|
|
|
downSubMsgInfo(1).workCnt := downRecParser.io.subMsgReq.bits.workCnt
|
2025-04-22 17:32:05 +08:00
|
|
|
|
downSubMsgInfo(1).source := 1.U
|
2025-04-08 17:29:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-14 16:43:10 +08:00
|
|
|
|
when( ~isDownRecPing ){ //req fire 后 已经反相
|
2025-04-08 17:29:45 +08:00
|
|
|
|
downRecFifo(0).io.enq.valid := downRecParser.io.data.valid
|
|
|
|
|
|
downRecFifo(0).io.enq.bits := downRecParser.io.data.bits
|
|
|
|
|
|
downRecParser.io.data.ready := downRecFifo(0).io.enq.ready
|
2025-04-11 17:57:47 +08:00
|
|
|
|
|
|
|
|
|
|
downRecFifo(1).io.enq.valid := false.B
|
|
|
|
|
|
downRecFifo(1).io.enq.bits := 0.U
|
|
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
} .otherwise{
|
2025-04-11 17:57:47 +08:00
|
|
|
|
downRecFifo(0).io.enq.valid := false.B
|
|
|
|
|
|
downRecFifo(0).io.enq.bits := 0.U
|
|
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
downRecFifo(1).io.enq.valid := downRecParser.io.data.valid
|
|
|
|
|
|
downRecFifo(1).io.enq.bits := downRecParser.io.data.bits
|
|
|
|
|
|
downRecParser.io.data.ready := downRecFifo(1).io.enq.ready
|
|
|
|
|
|
}
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-11 17:57:47 +08:00
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//上行接收
|
|
|
|
|
|
when( upRecParser.io.subMsgReq.fire ){
|
2025-04-11 17:57:47 +08:00
|
|
|
|
when( isUpRecPing ){
|
2025-04-08 17:29:45 +08:00
|
|
|
|
upSubMsgInfo(0).devIndex := upRecParser.io.subMsgReq.bits.devIndex
|
|
|
|
|
|
upSubMsgInfo(0).style := upRecParser.io.subMsgReq.bits.style
|
|
|
|
|
|
upSubMsgInfo(0).address := upRecParser.io.subMsgReq.bits.address
|
|
|
|
|
|
upSubMsgInfo(0).operator := upRecParser.io.subMsgReq.bits.operator
|
|
|
|
|
|
upSubMsgInfo(0).length := upRecParser.io.subMsgReq.bits.length
|
2025-04-21 18:48:29 +08:00
|
|
|
|
upSubMsgInfo(0).workCnt := upRecParser.io.subMsgReq.bits.workCnt
|
2025-04-08 17:29:45 +08:00
|
|
|
|
upSubMsgInfo(0).source := 0.U
|
|
|
|
|
|
} .otherwise{
|
|
|
|
|
|
upSubMsgInfo(1).devIndex := upRecParser.io.subMsgReq.bits.devIndex
|
|
|
|
|
|
upSubMsgInfo(1).style := upRecParser.io.subMsgReq.bits.style
|
|
|
|
|
|
upSubMsgInfo(1).address := upRecParser.io.subMsgReq.bits.address
|
|
|
|
|
|
upSubMsgInfo(1).operator := upRecParser.io.subMsgReq.bits.operator
|
|
|
|
|
|
upSubMsgInfo(1).length := upRecParser.io.subMsgReq.bits.length
|
2025-04-21 18:48:29 +08:00
|
|
|
|
upSubMsgInfo(1).workCnt := upRecParser.io.subMsgReq.bits.workCnt
|
2025-04-08 17:29:45 +08:00
|
|
|
|
upSubMsgInfo(1).source := 1.U
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-17 15:16:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-11 17:57:47 +08:00
|
|
|
|
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-14 17:53:04 +08:00
|
|
|
|
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
//子报文下行发送
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-11 17:57:47 +08:00
|
|
|
|
val isDownSendPing = RegInit(false.B)
|
|
|
|
|
|
val isUpSendPing = RegInit(false.B)
|
|
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
downSendGen.io.subMsgReq.valid :=
|
|
|
|
|
|
( isDownSendPing & isDownSubMsgValid(0) ) | (~isDownSendPing & isDownSubMsgValid(1))
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
downSendGen.io.subMsgReq.bits := Mux( isDownSendPing, downSubMsgInfo(0), downSubMsgInfo(1) )
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
when( downSendGen.io.subMsgReq.fire ){ //ready
|
|
|
|
|
|
isDownSendPing := ~isDownSendPing
|
|
|
|
|
|
when( isDownSendPing ){
|
2025-04-11 17:57:47 +08:00
|
|
|
|
assert( isDownSubMsgValid(0) )
|
2025-04-08 17:29:45 +08:00
|
|
|
|
isDownSubMsgValid(0) := false.B
|
|
|
|
|
|
} .otherwise{
|
2025-04-11 17:57:47 +08:00
|
|
|
|
assert( isDownSubMsgValid(1) )
|
2025-04-08 17:29:45 +08:00
|
|
|
|
isDownSubMsgValid(1) := false.B
|
|
|
|
|
|
}
|
2025-04-11 17:57:47 +08:00
|
|
|
|
} .elsewhen( downRecParser.io.subMsgReq.fire ){
|
2025-04-14 16:43:10 +08:00
|
|
|
|
isDownRecPing := ~isDownRecPing
|
2025-04-11 17:57:47 +08:00
|
|
|
|
when( isDownRecPing ){
|
|
|
|
|
|
assert( ~isDownSubMsgValid(0) )
|
|
|
|
|
|
isDownSubMsgValid(0) := true.B
|
|
|
|
|
|
} .otherwise{
|
|
|
|
|
|
assert( ~isDownSubMsgValid(1) )
|
|
|
|
|
|
isDownSubMsgValid(1) := true.B
|
|
|
|
|
|
}
|
2025-04-08 17:29:45 +08:00
|
|
|
|
}
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
downRecFifo(0).io.deq <> downSendGen.io.data(0)
|
|
|
|
|
|
downRecFifo(1).io.deq <> downSendGen.io.data(1)
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-11 17:57:47 +08:00
|
|
|
|
downRecParser.io.resp := ( downRecParser.io.stateCurr === STATE_WAIT ) & (~isDownSubMsgValid(0) & ~isDownSubMsgValid(1))
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
//子报文上行发送
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
upSendGen.io.subMsgReq.valid :=
|
2025-04-22 17:32:05 +08:00
|
|
|
|
( isUpSendPing & isUpSubMsgValid(0) ) |
|
|
|
|
|
|
( ~isUpSendPing & isUpSubMsgValid(1) )
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
upSendGen.io.subMsgReq.bits := Mux( isUpSendPing, upSubMsgInfo(0), upSubMsgInfo(1) )
|
2025-04-22 17:32:05 +08:00
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
when( upSendGen.io.subMsgReq.fire ){ //ready
|
|
|
|
|
|
isUpSendPing := ~isUpSendPing
|
|
|
|
|
|
when( isUpSendPing ){
|
2025-04-11 17:57:47 +08:00
|
|
|
|
assert( isUpSubMsgValid(0) )
|
2025-04-08 17:29:45 +08:00
|
|
|
|
isUpSubMsgValid(0) := false.B
|
|
|
|
|
|
} .otherwise{
|
2025-04-11 17:57:47 +08:00
|
|
|
|
assert( isUpSubMsgValid(1) )
|
2025-04-08 17:29:45 +08:00
|
|
|
|
isUpSubMsgValid(1) := false.B
|
|
|
|
|
|
}
|
2025-04-11 17:57:47 +08:00
|
|
|
|
}.elsewhen( upRecParser.io.subMsgReq.fire ){
|
|
|
|
|
|
isUpRecPing := ~isUpRecPing
|
|
|
|
|
|
when( isUpRecPing ){
|
|
|
|
|
|
assert( ~isUpSubMsgValid(0) )
|
|
|
|
|
|
isUpSubMsgValid(0) := true.B
|
|
|
|
|
|
} .otherwise{
|
|
|
|
|
|
assert( ~isUpSubMsgValid(1) )
|
|
|
|
|
|
isUpSubMsgValid(1) := true.B
|
|
|
|
|
|
}
|
2025-04-08 17:29:45 +08:00
|
|
|
|
}
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
upRecFifo(0).io.deq <> upSendGen.io.data(0)
|
|
|
|
|
|
upRecFifo(1).io.deq <> upSendGen.io.data(1)
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-11 17:57:47 +08:00
|
|
|
|
upRecParser.io.resp := ( upRecParser.io.stateCurr === STATE_WAIT ) & (~isUpSubMsgValid(0) & ~isUpSubMsgValid(1))
|
|
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
}
|
2025-04-11 17:57:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-11 17:57:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
trait SlaveParserIndex{ this: SlaveParserBase =>
|
|
|
|
|
|
//下行接收
|
|
|
|
|
|
when( downRecParser.io.subMsgReq.fire &
|
|
|
|
|
|
downRecParser.io.subMsgReq.bits.devIndex === 0.U &
|
|
|
|
|
|
downRecParser.io.subMsgReq.bits.style === 0.U &
|
2025-05-22 11:21:41 +08:00
|
|
|
|
downRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_INDEX ){ //设置顺序地址
|
2025-04-22 17:32:05 +08:00
|
|
|
|
localDevIndex := downRecParser.io.subMsgReq.bits.workCnt + 1.U
|
2025-05-19 15:29:00 +08:00
|
|
|
|
indexOfRightDev := Mux(isLastDevice, 0.U, downRecParser.io.subMsgReq.bits.workCnt + 2.U)
|
2025-04-22 17:32:05 +08:00
|
|
|
|
when( isDownRecPing ){
|
|
|
|
|
|
downSubMsgInfo(0).workCnt := downRecParser.io.subMsgReq.bits.workCnt + 1.U
|
|
|
|
|
|
} .otherwise{ //pong
|
|
|
|
|
|
downSubMsgInfo(1).workCnt := downRecParser.io.subMsgReq.bits.workCnt + 1.U
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-05-19 15:29:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//上行接收 获取右侧索引号
|
|
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
trait SlaveParserRW{ this: SlaveParserBase =>
|
|
|
|
|
|
|
|
|
|
|
|
//下行接收
|
|
|
|
|
|
when( downRecParser.io.subMsgReq.fire ){
|
|
|
|
|
|
when( isDownRecPing ){
|
|
|
|
|
|
//override
|
2025-05-22 11:21:41 +08:00
|
|
|
|
when(
|
|
|
|
|
|
( ( (downRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_UNIWRITE) | (downRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_UNIRDWR) ) & downRecParser.io.subMsgReq.bits.devIndex === localDevIndex ) |
|
|
|
|
|
|
( ( (downRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_BOARDWRITE) | (downRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_BOARDRDWR) ) )
|
|
|
|
|
|
) { //自身包//写操作或读写操作)
|
2025-04-22 17:32:05 +08:00
|
|
|
|
downSubMsgInfo(0).workCnt := downRecParser.io.subMsgReq.bits.workCnt + 1.U
|
|
|
|
|
|
}
|
2025-04-11 17:57:47 +08:00
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
} .otherwise{ //pong
|
|
|
|
|
|
//override
|
2025-05-22 11:21:41 +08:00
|
|
|
|
when(
|
|
|
|
|
|
( ( (downRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_UNIWRITE ) | (downRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_UNIRDWR ) ) & downRecParser.io.subMsgReq.bits.devIndex === localDevIndex ) |
|
|
|
|
|
|
( ( (downRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_BOARDWRITE) | (downRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_BOARDRDWR) ) )
|
|
|
|
|
|
) { //自身包//写操作或读写操作 )
|
2025-04-22 17:32:05 +08:00
|
|
|
|
downSubMsgInfo(1).workCnt := downRecParser.io.subMsgReq.bits.workCnt + 1.U
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
|
//写入 SM或寄存器空间
|
2025-04-22 17:32:05 +08:00
|
|
|
|
|
|
|
|
|
|
val addrw = Reg(UInt(15.W))
|
|
|
|
|
|
|
2025-05-15 18:40:01 +08:00
|
|
|
|
val isWRReg = (addrw(14,11) === "b0000".U)
|
2025-04-23 17:57:38 +08:00
|
|
|
|
val isWRSM0 = (addrw(14,11) === "b0001".U)
|
|
|
|
|
|
val isWRSM2 = (addrw(14,11) === "b0011".U)
|
|
|
|
|
|
val isWRSM4 = (addrw(14,11) === "b0101".U)
|
|
|
|
|
|
val isWRSM6 = (addrw(14,11) === "b0111".U)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-24 16:18:33 +08:00
|
|
|
|
val isWrite = (downRecParser.io.stateCurr === STATE_PAYLOAD_DATA) & ( //req fire 后 已经反相
|
2025-05-22 11:21:41 +08:00
|
|
|
|
( ~isDownRecPing & ( (downSubMsgInfo(0).operator === SUBMSG_OPERATOR_UNIWRITE) | (downSubMsgInfo(0).operator === SUBMSG_OPERATOR_UNIRDWR ) ) & (downSubMsgInfo(0).devIndex === localDevIndex)) |
|
|
|
|
|
|
( isDownRecPing & ( (downSubMsgInfo(1).operator === SUBMSG_OPERATOR_UNIWRITE) | (downSubMsgInfo(1).operator === SUBMSG_OPERATOR_UNIRDWR ) ) & (downSubMsgInfo(1).devIndex === localDevIndex)) |
|
|
|
|
|
|
( ~isDownRecPing & ( (downSubMsgInfo(0).operator === SUBMSG_OPERATOR_BOARDWRITE) | (downSubMsgInfo(0).operator === SUBMSG_OPERATOR_BOARDRDWR) ) ) |
|
|
|
|
|
|
( isDownRecPing & ( (downSubMsgInfo(1).operator === SUBMSG_OPERATOR_BOARDWRITE) | (downSubMsgInfo(1).operator === SUBMSG_OPERATOR_BOARDRDWR) ) )
|
2025-04-22 17:32:05 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-05-23 11:48:12 +08:00
|
|
|
|
when( downRecParser.io.subMsgReq.fire & (
|
|
|
|
|
|
downRecParser.io.subMsgReq.bits.devIndex === localDevIndex |
|
|
|
|
|
|
downRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_BOARDWRITE |
|
|
|
|
|
|
downRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_BOARDRDWR
|
|
|
|
|
|
)
|
|
|
|
|
|
){
|
2025-04-25 17:00:51 +08:00
|
|
|
|
addrw := downRecParser.io.subMsgReq.bits.address
|
2025-05-16 14:51:52 +08:00
|
|
|
|
} .elsewhen( isWrite & downRecParser.io.data.fire ){
|
2025-04-25 17:00:51 +08:00
|
|
|
|
addrw := addrw + 1.U
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-16 14:51:52 +08:00
|
|
|
|
io.lvds.isEnW := isWrite & isWRReg & downRecParser.io.data.fire
|
2025-05-15 18:40:01 +08:00
|
|
|
|
io.lvds.dataw := downRecParser.io.data.bits
|
2025-04-22 17:32:05 +08:00
|
|
|
|
|
2025-05-16 14:51:52 +08:00
|
|
|
|
io.sram_w(0).enw := isWrite & isWRSM0 & downRecParser.io.data.fire
|
2025-04-24 16:18:33 +08:00
|
|
|
|
io.sram_w(0).addrw := addrw(10,0)
|
|
|
|
|
|
io.sram_w(0).dataw := downRecParser.io.data.bits
|
|
|
|
|
|
|
2025-05-16 14:51:52 +08:00
|
|
|
|
io.sram_w(1).enw := isWrite & isWRSM2 & downRecParser.io.data.fire
|
2025-04-24 16:18:33 +08:00
|
|
|
|
io.sram_w(1).addrw := addrw(10,0)
|
|
|
|
|
|
io.sram_w(1).dataw := downRecParser.io.data.bits
|
|
|
|
|
|
|
2025-05-16 14:51:52 +08:00
|
|
|
|
io.sram_w(2).enw := isWrite & isWRSM4 & downRecParser.io.data.fire
|
2025-04-24 16:18:33 +08:00
|
|
|
|
io.sram_w(2).addrw := addrw(10,0)
|
|
|
|
|
|
io.sram_w(2).dataw := downRecParser.io.data.bits
|
|
|
|
|
|
|
2025-05-16 14:51:52 +08:00
|
|
|
|
io.sram_w(3).enw := isWrite & isWRSM6 & downRecParser.io.data.fire
|
2025-04-24 16:18:33 +08:00
|
|
|
|
io.sram_w(3).addrw := addrw(10,0)
|
|
|
|
|
|
io.sram_w(3).dataw := downRecParser.io.data.bits
|
|
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
|
2025-04-24 16:18:33 +08:00
|
|
|
|
|
2025-04-24 17:31:44 +08:00
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
|
2025-05-22 11:21:41 +08:00
|
|
|
|
// val SUBMSG_OPERATOR_BOARDREAD = "hd".U
|
|
|
|
|
|
// val SUBMSG_OPERATOR_BOARDWRITE = "he".U
|
|
|
|
|
|
// val SUBMSG_OPERATOR_BOARDRDWR = "hf".U
|
2025-04-22 17:32:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//上行接收
|
|
|
|
|
|
when( upRecParser.io.subMsgReq.fire ){
|
|
|
|
|
|
when( isUpRecPing ){
|
|
|
|
|
|
//override
|
2025-05-22 11:21:41 +08:00
|
|
|
|
when(
|
|
|
|
|
|
( ( (upRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_UNIREAD ) | (upRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_UNIRDWR ) ) & upRecParser.io.subMsgReq.bits.devIndex === localDevIndex ) |
|
|
|
|
|
|
( ( (upRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_BOARDREAD) | (upRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_BOARDRDWR) ) )
|
|
|
|
|
|
){ //自身包//读或读写
|
2025-04-22 17:32:05 +08:00
|
|
|
|
upSubMsgInfo(0).workCnt := upRecParser.io.subMsgReq.bits.workCnt + 1.U
|
|
|
|
|
|
}
|
|
|
|
|
|
} .otherwise{
|
|
|
|
|
|
//override
|
2025-05-22 11:21:41 +08:00
|
|
|
|
when(
|
|
|
|
|
|
( ( (upRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_UNIREAD ) | (upRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_UNIRDWR ) ) & upRecParser.io.subMsgReq.bits.devIndex === localDevIndex ) |
|
|
|
|
|
|
( ( (upRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_BOARDREAD) | (upRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_BOARDRDWR) ) )
|
|
|
|
|
|
){ //自身包//读或读写 )
|
2025-04-22 17:32:05 +08:00
|
|
|
|
upSubMsgInfo(1).workCnt := upRecParser.io.subMsgReq.bits.workCnt + 1.U
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//读出uSM
|
2025-04-23 17:57:38 +08:00
|
|
|
|
val isRead =
|
2025-04-25 17:00:51 +08:00
|
|
|
|
((upRecParser.io.stateCurr === STATE_PAYLOAD_DATA) & (
|
2025-05-22 11:21:41 +08:00
|
|
|
|
(~isUpRecPing & (upSubMsgInfo(0).operator === SUBMSG_OPERATOR_UNIREAD | upSubMsgInfo(0).operator === SUBMSG_OPERATOR_UNIRDWR ) & upSubMsgInfo(0).devIndex === localDevIndex) |
|
|
|
|
|
|
( isUpRecPing & (upSubMsgInfo(1).operator === SUBMSG_OPERATOR_UNIREAD | upSubMsgInfo(1).operator === SUBMSG_OPERATOR_UNIRDWR ) & upSubMsgInfo(1).devIndex === localDevIndex) |
|
|
|
|
|
|
(~isUpRecPing & (upSubMsgInfo(0).operator === SUBMSG_OPERATOR_BOARDREAD | upSubMsgInfo(0).operator === SUBMSG_OPERATOR_BOARDRDWR ) ) |
|
|
|
|
|
|
( isUpRecPing & (upSubMsgInfo(1).operator === SUBMSG_OPERATOR_BOARDREAD | upSubMsgInfo(1).operator === SUBMSG_OPERATOR_BOARDRDWR ) )
|
2025-05-20 17:03:55 +08:00
|
|
|
|
)
|
2025-04-25 17:00:51 +08:00
|
|
|
|
)
|
2025-04-22 17:32:05 +08:00
|
|
|
|
|
|
|
|
|
|
val addrr = Reg(UInt(15.W))
|
2025-05-16 16:05:38 +08:00
|
|
|
|
|
2025-05-20 17:03:55 +08:00
|
|
|
|
val isRDReg = addrr(14,11) === "b0000".U
|
|
|
|
|
|
val isRDSM1 = addrr(14,11) === "b0010".U
|
|
|
|
|
|
val isRDSM3 = addrr(14,11) === "b0100".U
|
|
|
|
|
|
val isRDSM5 = addrr(14,11) === "b0110".U
|
|
|
|
|
|
val isRDSM7 = addrr(14,11) === "b1000".U
|
2025-05-16 16:05:38 +08:00
|
|
|
|
|
2025-05-20 17:03:55 +08:00
|
|
|
|
val isLvdsEnR = isRead & ( ((RegNext(upRecParser.io.stateCurr) =/= STATE_PAYLOAD_DATA) & (upRecParser.io.stateCurr === STATE_PAYLOAD_DATA)) |
|
|
|
|
|
|
upRecParser.io.data.fire )
|
2025-04-22 17:32:05 +08:00
|
|
|
|
|
2025-05-23 11:48:12 +08:00
|
|
|
|
when( upRecParser.io.subMsgReq.fire & (
|
|
|
|
|
|
upRecParser.io.subMsgReq.bits.devIndex === localDevIndex |
|
|
|
|
|
|
upRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_BOARDREAD |
|
|
|
|
|
|
upRecParser.io.subMsgReq.bits.operator === SUBMSG_OPERATOR_BOARDRDWR
|
|
|
|
|
|
)
|
|
|
|
|
|
){
|
2025-05-20 17:03:55 +08:00
|
|
|
|
addrr := upRecParser.io.subMsgReq.bits.address
|
|
|
|
|
|
} .elsewhen( isLvdsEnR ){
|
2025-04-25 17:00:51 +08:00
|
|
|
|
addrr := addrr + 1.U
|
2025-04-22 17:32:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
|
val upStreamData = Mux1H(Seq(
|
2025-05-15 18:40:01 +08:00
|
|
|
|
isRDReg -> io.lvds.datar,
|
2025-04-23 17:57:38 +08:00
|
|
|
|
isRDSM1 -> io.sram_r(0).datar,
|
|
|
|
|
|
isRDSM3 -> io.sram_r(1).datar,
|
|
|
|
|
|
isRDSM5 -> io.sram_r(2).datar,
|
|
|
|
|
|
isRDSM7 -> io.sram_r(3).datar,
|
2025-04-22 17:32:05 +08:00
|
|
|
|
))
|
|
|
|
|
|
|
2025-05-22 11:21:41 +08:00
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
when( ~isUpRecPing ){ //req fire 后 已经反相
|
|
|
|
|
|
upRecFifo(0).io.enq.valid := upRecParser.io.data.valid
|
|
|
|
|
|
upRecFifo(0).io.enq.bits :=
|
2025-05-23 11:48:12 +08:00
|
|
|
|
Mux(
|
2025-05-23 16:13:01 +08:00
|
|
|
|
( upSubMsgInfo(0).operator === SUBMSG_OPERATOR_UNIREAD | upSubMsgInfo(0).operator === SUBMSG_OPERATOR_UNIRDWR ) & upSubMsgInfo(0).devIndex === localDevIndex, upStreamData,
|
|
|
|
|
|
Mux( upSubMsgInfo(0).operator === SUBMSG_OPERATOR_BOARDREAD | upSubMsgInfo(0).operator === SUBMSG_OPERATOR_BOARDRDWR, upStreamData | upRecParser.io.data.bits,
|
|
|
|
|
|
upRecParser.io.data.bits )
|
2025-05-23 11:48:12 +08:00
|
|
|
|
)
|
|
|
|
|
|
upRecParser.io.data.ready := upRecFifo(0).io.enq.ready
|
2025-04-22 17:32:05 +08:00
|
|
|
|
|
|
|
|
|
|
upRecFifo(1).io.enq.valid := false.B
|
|
|
|
|
|
upRecFifo(1).io.enq.bits := 0.U
|
2025-04-11 17:57:47 +08:00
|
|
|
|
} .otherwise{
|
2025-04-22 17:32:05 +08:00
|
|
|
|
upRecFifo(0).io.enq.valid := false.B
|
|
|
|
|
|
upRecFifo(0).io.enq.bits := 0.U
|
|
|
|
|
|
|
|
|
|
|
|
upRecFifo(1).io.enq.valid := upRecParser.io.data.valid
|
|
|
|
|
|
upRecFifo(1).io.enq.bits :=
|
2025-05-23 11:48:12 +08:00
|
|
|
|
Mux(
|
2025-05-23 16:13:01 +08:00
|
|
|
|
( upSubMsgInfo(1).operator === SUBMSG_OPERATOR_UNIREAD | upSubMsgInfo(1).operator === SUBMSG_OPERATOR_UNIRDWR ) & upSubMsgInfo(1).devIndex === localDevIndex, upStreamData,
|
|
|
|
|
|
Mux( upSubMsgInfo(1).operator === SUBMSG_OPERATOR_BOARDREAD | upSubMsgInfo(1).operator === SUBMSG_OPERATOR_BOARDRDWR, upStreamData | upRecParser.io.data.bits,
|
|
|
|
|
|
upRecParser.io.data.bits
|
|
|
|
|
|
)
|
2025-05-23 11:48:12 +08:00
|
|
|
|
)
|
|
|
|
|
|
upRecParser.io.data.ready := upRecFifo(1).io.enq.ready
|
2025-04-11 17:57:47 +08:00
|
|
|
|
|
2025-04-08 17:29:45 +08:00
|
|
|
|
}
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-05-20 17:03:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-21 10:28:36 +08:00
|
|
|
|
|
|
|
|
|
|
io.lvds.addrr := addrr(10,0)
|
|
|
|
|
|
io.lvds.addrw := addrw(10,0)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-15 18:40:01 +08:00
|
|
|
|
assert( ~(isRead & isWrite) )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-20 17:03:55 +08:00
|
|
|
|
io.lvds.isEnR := isRDReg & isLvdsEnR
|
|
|
|
|
|
io.sram_r(0).enr := isRDSM1 & isLvdsEnR
|
|
|
|
|
|
io.sram_r(1).enr := isRDSM3 & isLvdsEnR
|
|
|
|
|
|
io.sram_r(2).enr := isRDSM5 & isLvdsEnR
|
|
|
|
|
|
io.sram_r(3).enr := isRDSM7 & isLvdsEnR
|
2025-05-15 18:40:01 +08:00
|
|
|
|
|
2025-05-20 17:03:55 +08:00
|
|
|
|
io.sram_r(0).addrr := addrr(10,0)
|
|
|
|
|
|
io.sram_r(1).addrr := addrr(10,0)
|
|
|
|
|
|
io.sram_r(2).addrr := addrr(10,0)
|
|
|
|
|
|
io.sram_r(3).addrr := addrr(10,0)
|
2025-04-24 17:31:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-05-22 19:44:25 +08:00
|
|
|
|
io.dSMenq(0) := io.sram_w(0).enw & isWRSM0 & (io.cReg.smTrigLen(0) - 1.U) === addrw(10,0)
|
2025-05-23 10:43:44 +08:00
|
|
|
|
io.uSMdeq(0) := isLvdsEnR & isRDSM1 & (io.cReg.smTrigLen(1) - 1.U + 1.U) === addrr(10,0)
|
2025-05-22 19:44:25 +08:00
|
|
|
|
io.dSMenq(1) := io.sram_w(1).enw & isWRSM2 & (io.cReg.smTrigLen(2) - 1.U) === addrw(10,0)
|
2025-05-23 10:43:44 +08:00
|
|
|
|
io.uSMdeq(1) := isLvdsEnR & isRDSM3 & (io.cReg.smTrigLen(3) - 1.U + 1.U) === addrr(10,0)
|
2025-05-22 19:44:25 +08:00
|
|
|
|
io.dSMenq(2) := io.sram_w(2).enw & isWRSM4 & (io.cReg.smTrigLen(4) - 1.U) === addrw(10,0)
|
2025-05-23 10:43:44 +08:00
|
|
|
|
io.uSMdeq(2) := isLvdsEnR & isRDSM5 & (io.cReg.smTrigLen(5) - 1.U + 1.U) === addrr(10,0)
|
2025-05-22 19:44:25 +08:00
|
|
|
|
io.dSMenq(3) := io.sram_w(3).enw & isWRSM6 & (io.cReg.smTrigLen(6) - 1.U) === addrw(10,0)
|
2025-05-23 10:43:44 +08:00
|
|
|
|
io.uSMdeq(3) := isLvdsEnR & isRDSM7 & (io.cReg.smTrigLen(7) - 1.U + 1.U) === addrr(10,0)
|
2025-04-24 17:31:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-21 18:48:29 +08:00
|
|
|
|
trait SlaveParserSync{ this: SlaveParserBase =>
|
|
|
|
|
|
val downTimeStamp = Reg(UInt(64.W)) //下行本地时间戳寄存器
|
2025-04-24 16:18:33 +08:00
|
|
|
|
val upTimeStamp = Reg(UInt(64.W)) //上行本地时间戳寄存器
|
2025-04-21 18:48:29 +08:00
|
|
|
|
val mstTimeStamp = Reg(UInt(64.W)) //主站时间戳
|
2025-05-15 14:57:58 +08:00
|
|
|
|
val mstDeltaTimeStamp = Reg(UInt(32.W)); io.mstDeltaTimeStamp := mstDeltaTimeStamp //主站时间戳差值
|
2025-05-16 16:05:38 +08:00
|
|
|
|
val slvDeltaTimeStamp = Reg(UInt(32.W)); io.slvDeltaTime := slvDeltaTimeStamp //从站时间戳差值
|
2025-04-21 18:48:29 +08:00
|
|
|
|
|
|
|
|
|
|
val mstSlvDeltaTimeStamp = Reg(UInt(32.W)) //主发从接时间差(中间变量)
|
2025-04-22 17:32:05 +08:00
|
|
|
|
val deltaMstSlvDeltaTimeStamp = Reg(UInt(32.W)) //主差从差时间差(中间变量)
|
2025-05-15 18:40:01 +08:00
|
|
|
|
val deltaFinal = Reg(UInt(32.W)); io.deltaFinal := deltaFinal //当前时间戳与主站时间差
|
2025-04-21 18:48:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-05-15 18:40:01 +08:00
|
|
|
|
// val recoTimeStamp = Reg(UInt(64.W)) //时钟补偿寄存器
|
2025-04-21 18:48:29 +08:00
|
|
|
|
|
2025-05-15 18:40:01 +08:00
|
|
|
|
// dontTouch(recoTimeStamp)
|
2025-04-30 17:09:30 +08:00
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
// recoTimeStamp = io.timeStamp + deltaFinal
|
|
|
|
|
|
// recoTimeStamp = io.timeStamp + mstSlvDeltaTimeStamp + deltaMstSlvDeltaTimeStamp
|
|
|
|
|
|
// recoTimeStamp = io.timeStamp + mstTimeStamp - downTimeStamp + (mstDeltaTimeStamp - slvDeltaTimeStamp ) >> 1
|
|
|
|
|
|
// recoTimeStamp = io.timeStamp + mstTimeStamp - downTimeStamp + (mstDeltaTimeStamp - (upTimeStamp - downTimeStamp)) >> 1
|
2025-04-21 18:48:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//更新下行本地时间戳寄存器
|
|
|
|
|
|
when( downRecParser.io.frameReq.fire ){
|
2025-05-15 14:57:58 +08:00
|
|
|
|
downTimeStamp := io.cReg.timeStamp
|
2025-04-21 18:48:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//更新上行本地时间戳寄存器
|
|
|
|
|
|
when( upRecParser.io.frameReq.fire ){
|
2025-05-15 14:57:58 +08:00
|
|
|
|
upTimeStamp := io.cReg.timeStamp
|
|
|
|
|
|
slvDeltaTimeStamp := io.cReg.timeStamp - downTimeStamp
|
2025-04-21 18:48:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//下行接收
|
2025-04-24 16:18:33 +08:00
|
|
|
|
val isSync = (downRecParser.io.stateCurr === STATE_PAYLOAD_DATA) & ( //req fire 后 已经反相
|
2025-05-26 10:40:41 +08:00
|
|
|
|
( ~isDownRecPing & downSubMsgInfo(0).devIndex === 0.U & downSubMsgInfo(0).operator === SUBMSG_OPERATOR_SYNC ) |
|
|
|
|
|
|
( isDownRecPing & downSubMsgInfo(1).devIndex === 0.U & downSubMsgInfo(1).operator === SUBMSG_OPERATOR_SYNC )
|
2025-04-21 18:48:29 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
val syncCnt = Reg(UInt(4.W))
|
|
|
|
|
|
|
2025-05-08 11:22:04 +08:00
|
|
|
|
when( downRecParser.io.rec.fire ){
|
|
|
|
|
|
when( isSync ){
|
|
|
|
|
|
syncCnt := syncCnt + 1.U
|
|
|
|
|
|
} .otherwise{
|
|
|
|
|
|
syncCnt := 0.U
|
|
|
|
|
|
}
|
2025-04-21 18:48:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-08 11:22:04 +08:00
|
|
|
|
|
|
|
|
|
|
when( isSync & downRecParser.io.rec.fire ){
|
2025-04-21 18:48:29 +08:00
|
|
|
|
when( syncCnt === 0.U ){
|
2025-04-30 17:09:30 +08:00
|
|
|
|
mstTimeStamp := Cat( mstTimeStamp(63, 8), downRecParser.io.data.bits )
|
2025-04-21 18:48:29 +08:00
|
|
|
|
} .elsewhen( syncCnt === 1.U ){
|
2025-04-30 17:09:30 +08:00
|
|
|
|
mstTimeStamp := Cat( mstTimeStamp(63,16), downRecParser.io.data.bits, mstTimeStamp(7,0) )
|
2025-04-21 18:48:29 +08:00
|
|
|
|
} .elsewhen( syncCnt === 2.U ){
|
2025-04-30 17:09:30 +08:00
|
|
|
|
mstTimeStamp := Cat( mstTimeStamp(63,24), downRecParser.io.data.bits, mstTimeStamp(15,0) )
|
2025-04-21 18:48:29 +08:00
|
|
|
|
} .elsewhen( syncCnt === 3.U ){
|
|
|
|
|
|
mstTimeStamp := Cat( mstTimeStamp(63,32), downRecParser.io.data.bits, mstTimeStamp(23,0) )
|
2025-04-30 17:09:30 +08:00
|
|
|
|
} .elsewhen( syncCnt === 4.U ){
|
|
|
|
|
|
mstTimeStamp := Cat( mstTimeStamp(63,40), downRecParser.io.data.bits, mstTimeStamp(31,0) )
|
2025-04-21 18:48:29 +08:00
|
|
|
|
} .elsewhen( syncCnt === 5.U ){
|
2025-04-30 17:09:30 +08:00
|
|
|
|
mstTimeStamp := Cat( mstTimeStamp(63,48), downRecParser.io.data.bits, mstTimeStamp(39,0) )
|
2025-04-21 18:48:29 +08:00
|
|
|
|
} .elsewhen( syncCnt === 6.U ){
|
2025-04-30 17:09:30 +08:00
|
|
|
|
mstTimeStamp := Cat( mstTimeStamp(63,56), downRecParser.io.data.bits, mstTimeStamp(47,0) )
|
2025-04-21 18:48:29 +08:00
|
|
|
|
} .elsewhen( syncCnt === 7.U ){
|
2025-04-30 17:09:30 +08:00
|
|
|
|
mstTimeStamp := Cat( downRecParser.io.data.bits, mstTimeStamp(55,0) )
|
2025-04-21 18:48:29 +08:00
|
|
|
|
} .elsewhen( syncCnt === 8.U ){
|
|
|
|
|
|
mstSlvDeltaTimeStamp := mstTimeStamp - downTimeStamp
|
2025-04-30 17:09:30 +08:00
|
|
|
|
mstDeltaTimeStamp := Cat( mstDeltaTimeStamp(31, 8), downRecParser.io.data.bits )
|
2025-04-21 18:48:29 +08:00
|
|
|
|
} .elsewhen( syncCnt === 9.U ){
|
|
|
|
|
|
mstDeltaTimeStamp := Cat( mstDeltaTimeStamp(31,16), downRecParser.io.data.bits, mstDeltaTimeStamp(7,0) )
|
2025-04-30 17:09:30 +08:00
|
|
|
|
} .elsewhen( syncCnt === 10.U ){
|
|
|
|
|
|
mstDeltaTimeStamp := Cat( mstDeltaTimeStamp(31,24), downRecParser.io.data.bits, mstDeltaTimeStamp(15,0) )
|
2025-04-21 18:48:29 +08:00
|
|
|
|
} .elsewhen( syncCnt === 11.U ){
|
2025-04-30 17:09:30 +08:00
|
|
|
|
mstDeltaTimeStamp := Cat( downRecParser.io.data.bits, mstDeltaTimeStamp(23, 0) )
|
2025-04-21 18:48:29 +08:00
|
|
|
|
} .otherwise{
|
|
|
|
|
|
assert(false.B, "Wrong Sync SubMsg!\n")
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
when( RegNext(isSync) & ~isSync ){
|
|
|
|
|
|
deltaMstSlvDeltaTimeStamp := (mstDeltaTimeStamp - slvDeltaTimeStamp) >> 1
|
|
|
|
|
|
} .elsewhen( RegNext(RegNext(isSync)) & ~RegNext(isSync) ){
|
|
|
|
|
|
deltaFinal := mstSlvDeltaTimeStamp + deltaMstSlvDeltaTimeStamp
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-21 18:48:29 +08:00
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
}
|
2025-04-21 18:48:29 +08:00
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
trait SlaveParserProbe{ this: SlaveParserBase =>
|
2025-04-21 18:48:29 +08:00
|
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
|
|
2025-05-07 18:12:01 +08:00
|
|
|
|
// val ProbeRecAim = 511.U
|
|
|
|
|
|
val probeRecCnt = RegInit(0.U(9.W))
|
|
|
|
|
|
val isWatchDogOverflow = probeRecCnt.andR
|
2025-04-23 17:57:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-20 11:35:11 +08:00
|
|
|
|
// val isReadyToProbe_Pending = RegInit(false.B)
|
2025-04-23 17:57:38 +08:00
|
|
|
|
|
|
|
|
|
|
when( downRecParser.io.frameReq.fire & downRecParser.io.frameReq.bits.frameStyle === FRAME_STYLE_PROBE ){ //下行来了一个嗅探包
|
2025-05-20 11:35:11 +08:00
|
|
|
|
isReadyToProbe := true.B
|
|
|
|
|
|
assert( downSendGen.io.stateCurr === STATE_IDLE )
|
2025-04-23 17:57:38 +08:00
|
|
|
|
} .elsewhen( upRecParser.io.frameReq.fire & upRecParser.io.frameReq.bits.frameStyle === FRAME_STYLE_PROBE ){ //上行来了一个嗅探包
|
2025-05-20 11:35:11 +08:00
|
|
|
|
isReadyToProbe := false.B
|
2025-04-23 17:57:38 +08:00
|
|
|
|
} .elsewhen( isWatchDogOverflow ){
|
2025-05-20 11:35:11 +08:00
|
|
|
|
isReadyToProbe := false.B
|
2025-04-23 17:57:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-29 17:48:57 +08:00
|
|
|
|
when( downRecParser.io.frameReq.fire & downRecParser.io.frameReq.bits.frameStyle === FRAME_STYLE_PROBE ){ //下行来了一个嗅探包
|
|
|
|
|
|
isAckProbe := true.B
|
|
|
|
|
|
} .elsewhen( upSendGen.io.frameReq.fire & upSendGen.io.frameReq.bits.frameStyle === FRAME_STYLE_PROBE ){ //上行发送回复嗅探包
|
|
|
|
|
|
isAckProbe := false.B
|
|
|
|
|
|
}
|
2025-04-23 17:57:38 +08:00
|
|
|
|
|
2025-04-21 18:48:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-05-20 11:35:11 +08:00
|
|
|
|
// val isLastDevice = RegInit(true.B)
|
2025-05-06 17:39:52 +08:00
|
|
|
|
|
|
|
|
|
|
when( upRecParser.io.frameReq.fire & upRecParser.io.frameReq.bits.frameStyle === FRAME_STYLE_PROBE ){ //上行来了一个嗅探包
|
2025-05-20 11:35:11 +08:00
|
|
|
|
isLastDevice := false.B
|
2025-05-06 17:39:52 +08:00
|
|
|
|
} .elsewhen( isWatchDogOverflow ){
|
2025-05-20 11:35:11 +08:00
|
|
|
|
isLastDevice := true.B
|
2025-05-06 17:39:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-21 18:48:29 +08:00
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
|
2025-04-24 17:31:44 +08:00
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
|
when( upRecParser.io.frameReq.fire & upRecParser.io.frameReq.bits.frameStyle === FRAME_STYLE_PROBE ){ //上行来了一个嗅探包
|
2025-04-22 17:32:05 +08:00
|
|
|
|
probeRecCnt := 0.U
|
|
|
|
|
|
} .elsewhen( isWatchDogOverflow ){
|
|
|
|
|
|
probeRecCnt := 0.U
|
2025-04-23 17:57:38 +08:00
|
|
|
|
} .elsewhen( isReadyToProbe ){
|
2025-04-22 17:32:05 +08:00
|
|
|
|
probeRecCnt := probeRecCnt + 1.U
|
2025-04-21 18:48:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-22 17:32:05 +08:00
|
|
|
|
|
|
|
|
|
|
when( upRecParser.io.frameReq.fire & upRecParser.io.frameReq.bits.frameStyle === FRAME_STYLE_PROBE ){ //上行来了一个嗅探包
|
2025-05-21 16:50:20 +08:00
|
|
|
|
indexOfRightDev := upRecParser.io.frameReq.bits.frameInfo
|
2025-04-23 17:57:38 +08:00
|
|
|
|
when( upRecParser.io.frameReq.bits.frameInfo =/= localDevIndex + 1.U ){ //索引不对
|
2025-05-16 18:56:49 +08:00
|
|
|
|
isDevOnRightModify := true.B
|
2025-05-21 16:50:20 +08:00
|
|
|
|
} .otherwise{
|
|
|
|
|
|
isDevOnRightModify := false.B
|
2025-04-22 17:32:05 +08:00
|
|
|
|
}
|
2025-04-21 18:48:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-06 17:39:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-07 18:12:01 +08:00
|
|
|
|
io.upOut <> Queue( upSendGen.io.send, 4, true, false )
|
2025-04-22 17:32:05 +08:00
|
|
|
|
io.downIn <> downRecParser.io.rec
|
|
|
|
|
|
|
2025-05-07 18:12:01 +08:00
|
|
|
|
io.downOut <> Queue( downSendGen.io.send, 4, true, false )
|
|
|
|
|
|
io.upIn <> upRecParser.io.rec
|
2025-04-21 18:48:29 +08:00
|
|
|
|
|
2025-05-07 18:12:01 +08:00
|
|
|
|
io.isLoop := isLastDevice & ~isReadyToProbe
|
2025-04-22 17:32:05 +08:00
|
|
|
|
|
2025-05-06 17:39:52 +08:00
|
|
|
|
|
2025-05-20 11:35:11 +08:00
|
|
|
|
// when( isLastDevice =/= isLastDevice_Pending & ~downSendGen.io.send.valid & ~io.downOut.valid & ~io.upIn.valid ){
|
|
|
|
|
|
// isLastDevice := isLastDevice_Pending
|
|
|
|
|
|
// }
|
2025-05-06 17:39:52 +08:00
|
|
|
|
|
2025-05-20 11:35:11 +08:00
|
|
|
|
// when( isReadyToProbe =/= isReadyToProbe_Pending & ~downSendGen.io.send.valid & ~io.downOut.valid & ~io.upIn.valid ){
|
|
|
|
|
|
// isReadyToProbe := isReadyToProbe_Pending
|
|
|
|
|
|
// }
|
2025-04-22 17:32:05 +08:00
|
|
|
|
}
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
2025-04-11 17:57:47 +08:00
|
|
|
|
class SlaveParser extends SlaveParserBase
|
2025-04-22 17:32:05 +08:00
|
|
|
|
with SlaveParserIndex
|
|
|
|
|
|
with SlaveParserRW
|
2025-04-21 18:48:29 +08:00
|
|
|
|
with SlaveParserSync
|
2025-05-26 11:52:40 +08:00
|
|
|
|
with SlaveParserProbe{
|
|
|
|
|
|
io.intHWTrig(0) := downRecParser.io.isError
|
|
|
|
|
|
io.intHWTrig(1) := upRecParser.io.isError
|
|
|
|
|
|
|
|
|
|
|
|
downRecParser.io.resp := io.intHWClr(0)
|
|
|
|
|
|
upRecParser.io.resp := io.intHWClr(1)
|
|
|
|
|
|
}
|
2025-04-11 17:57:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-07 17:39:44 +08:00
|
|
|
|
|
|
|
|
|
|
|