From d5db3aebdb06a50f8fca6649504eb8a7728c22d9 Mon Sep 17 00:00:00 2001 From: Ruige Lee Date: Fri, 16 May 2025 14:51:52 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=EF=BC=9A=E5=8D=95?= =?UTF-8?q?=E5=86=99=E5=8D=95=E8=AF=BB=E4=BB=8E=E7=AB=99=E5=86=99=E5=85=A5?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E6=97=B6=E5=BA=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scala/backBoard/shin/SlaveParser.scala | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/scala/backBoard/shin/SlaveParser.scala b/src/main/scala/backBoard/shin/SlaveParser.scala index cb90c5d..4253fce 100644 --- a/src/main/scala/backBoard/shin/SlaveParser.scala +++ b/src/main/scala/backBoard/shin/SlaveParser.scala @@ -406,27 +406,27 @@ trait SlaveParserRW{ this: SlaveParserBase => when( downRecParser.io.subMsgReq.fire & downRecParser.io.subMsgReq.bits.devIndex === localDevIndex ){ addrw := downRecParser.io.subMsgReq.bits.address - } .elsewhen( isWrite ){ + } .elsewhen( isWrite & downRecParser.io.data.fire ){ addrw := addrw + 1.U } - io.lvds.isEnW := isWrite & isWRReg + io.lvds.isEnW := isWrite & isWRReg & downRecParser.io.data.fire io.lvds.dataw := downRecParser.io.data.bits - io.sram_w(0).enw := isWrite & isWRSM0 + io.sram_w(0).enw := isWrite & isWRSM0 & downRecParser.io.data.fire io.sram_w(0).addrw := addrw(10,0) io.sram_w(0).dataw := downRecParser.io.data.bits - io.sram_w(1).enw := isWrite & isWRSM2 + io.sram_w(1).enw := isWrite & isWRSM2 & downRecParser.io.data.fire io.sram_w(1).addrw := addrw(10,0) io.sram_w(1).dataw := downRecParser.io.data.bits - io.sram_w(2).enw := isWrite & isWRSM4 + io.sram_w(2).enw := isWrite & isWRSM4 & downRecParser.io.data.fire io.sram_w(2).addrw := addrw(10,0) io.sram_w(2).dataw := downRecParser.io.data.bits - io.sram_w(3).enw := isWrite & isWRSM6 + io.sram_w(3).enw := isWrite & isWRSM6 & downRecParser.io.data.fire io.sram_w(3).addrw := addrw(10,0) io.sram_w(3).dataw := downRecParser.io.data.bits @@ -480,7 +480,7 @@ trait SlaveParserRW{ this: SlaveParserBase => when( upRecParser.io.subMsgReq.fire & upRecParser.io.subMsgReq.bits.devIndex === localDevIndex ){ addrr := upRecParser.io.subMsgReq.bits.address - } .elsewhen( isRead ){ + } .elsewhen( isRead & upRecParser.io.data.fire ){ addrr := addrr + 1.U } @@ -513,20 +513,20 @@ trait SlaveParserRW{ this: SlaveParserBase => } - io.lvds.isEnR := isRead & isRDReg + io.lvds.isEnR := isRead & isRDReg & ( upRecParser.io.subMsgReq.fire | upRecParser.io.data.fire ) io.lvds.addrSel := Mux1H(Seq( - isRead -> readSMAddr(10,0) - isWrite -> addrw(10,0) + isRead -> readSMAddr(10,0), + isWrite -> addrw(10,0), )) assert( ~(isRead & isWrite) ) - io.sram_r(0).enr := isRead & isRDSM1 - io.sram_r(1).enr := isRead & isRDSM3 - io.sram_r(2).enr := isRead & isRDSM5 - io.sram_r(3).enr := isRead & isRDSM7 + io.sram_r(0).enr := isRead & isRDSM1 & ( upRecParser.io.subMsgReq.fire | upRecParser.io.data.fire ) + io.sram_r(1).enr := isRead & isRDSM3 & ( upRecParser.io.subMsgReq.fire | upRecParser.io.data.fire ) + io.sram_r(2).enr := isRead & isRDSM5 & ( upRecParser.io.subMsgReq.fire | upRecParser.io.data.fire ) + io.sram_r(3).enr := isRead & isRDSM7 & ( upRecParser.io.subMsgReq.fire | upRecParser.io.data.fire ) io.sram_r(0).addrr := readSMAddr(10,0) io.sram_r(1).addrr := readSMAddr(10,0) From 23fdd91ba394fa163e0bf30cb3c3d27bb6076f84 Mon Sep 17 00:00:00 2001 From: Ruige Lee Date: Fri, 16 May 2025 15:39:17 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E5=9C=B0=E5=9D=80=E9=94=99=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/scala/backBoard/shin/SlaveParser.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/backBoard/shin/SlaveParser.scala b/src/main/scala/backBoard/shin/SlaveParser.scala index 4253fce..bf9ee1d 100644 --- a/src/main/scala/backBoard/shin/SlaveParser.scala +++ b/src/main/scala/backBoard/shin/SlaveParser.scala @@ -479,7 +479,7 @@ trait SlaveParserRW{ this: SlaveParserBase => val isRDSM7 = (readSMAddr(14,11) === "b1000".U) when( upRecParser.io.subMsgReq.fire & upRecParser.io.subMsgReq.bits.devIndex === localDevIndex ){ - addrr := upRecParser.io.subMsgReq.bits.address + addrr := upRecParser.io.subMsgReq.bits.address + 1.U } .elsewhen( isRead & upRecParser.io.data.fire ){ addrr := addrr + 1.U } From 3f1fdc725ade74c65a223beabaa15fb6d61da52f Mon Sep 17 00:00:00 2001 From: Ruige Lee Date: Fri, 16 May 2025 15:39:48 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:SM=20fifo=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/scala/backBoard/shin/SMUnit.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/scala/backBoard/shin/SMUnit.scala b/src/main/scala/backBoard/shin/SMUnit.scala index 12b61f8..b0a407e 100644 --- a/src/main/scala/backBoard/shin/SMUnit.scala +++ b/src/main/scala/backBoard/shin/SMUnit.scala @@ -66,11 +66,11 @@ abstract class SMUnitBase(depth: Int = 4) extends Module { } for( i <- 0 until depth ){ - when( wPtr === i.U & ~isFull ){ + when( (wPtr(log2Ceil(depth)-1, 0)) === i.U & ~isFull ){ io.sram(i).wr <> io.sram_w } - when( rPtr === i.U & ~isEmpty){ + when( (rPtr(log2Ceil(depth)-1, 0)) === i.U & ~isEmpty){ io.sram(i).rd.addrr := io.sram_r.addrr io.sram(i).rd.enr := io.sram_r.enr } @@ -79,7 +79,7 @@ abstract class SMUnitBase(depth: Int = 4) extends Module { io.sram_r.datar := Mux1H( ( 0 until depth).map{ i => - ( rPtr === i.U ) -> io.sram(i).rd.datar + ( (rPtr(log2Ceil(depth)-1, 0)) === i.U ) -> io.sram(i).rd.datar }) From 58fbbdd1fcc5ae3d4b4ca195f858d362b6a1ecd5 Mon Sep 17 00:00:00 2001 From: Ruige Lee Date: Fri, 16 May 2025 16:05:38 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E8=84=89=E5=86=B2?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E6=B5=8B=E8=AF=95=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/scala/backBoard/shin/Interface.scala | 21 ++-- .../scala/backBoard/shin/SlaveParser.scala | 6 +- tb/shinTest/ShinTopSpiTb.v | 99 ++++++++++++++++++- 3 files changed, 114 insertions(+), 12 deletions(-) diff --git a/src/main/scala/backBoard/shin/Interface.scala b/src/main/scala/backBoard/shin/Interface.scala index 2943612..23dd643 100644 --- a/src/main/scala/backBoard/shin/Interface.scala +++ b/src/main/scala/backBoard/shin/Interface.scala @@ -138,9 +138,9 @@ class SlaveRegisterBundle extends Bundle{ class InterfaceIO extends Bundle{ val ospi = new SSPIInterfaceIO val oqspi = new QSPIInterfaceIO - val iqspi = Flipped(new QSPIInterfaceIO) + val iqspi = new QSPIInterfaceIO - val lvds = new RegAccessInterfaceIO + val lvds = Flipped(new RegAccessInterfaceIO) @@ -188,7 +188,7 @@ abstract class InterfaceBase extends Module{ val cReg = Wire(new CommonRegisterBundle); io.cReg := cReg val mReg = Wire(new MasterRegisterBundle); io.mReg := mReg - val sReg = Wire(new SlaveRegisterBundle) + val sReg = Wire(new SlaveRegisterBundle); io.sReg := sReg val syncCfg = RegInit(0.U(8.W)); sReg.syncCfg := syncCfg @@ -562,7 +562,7 @@ trait InterfaceLVDSop{ this: InterfaceBase => // io.lvds.isEnW = Output(Bool()) // io.lvds.isEnR = Output(Bool()) - io.lvds.datar = RegEnable( AcquireReg(addr = io.lvds.addrSel), 0.U, io.lvds.isEnR ) + io.lvds.datar := RegEnable( AcquireReg(addr = io.lvds.addrSel), 0.U, io.lvds.isEnR ) when( io.lvds.isEnW & isSlvMode ){ @@ -643,7 +643,7 @@ trait InterfaceSync{ this: InterfaceBase => when( cReg.syncPoint === sReg.recoTimeStamp ){ //时间到达sync0时间点 syncSign(0) := true.B - cReg.syncPoint := cReg.syncPoint + cReg.syncPeroid + syncPoint := syncPoint + cReg.syncPeroid } .elsewhen( ~sReg.syncCfg(4+0) & syncResetCnt(0) === sReg.syncWidth(0) ){ syncSign(0) := false.B } .elsewhen( sReg.syncCfg(4+0) & isEnW & addrSel === "h122".U ){ @@ -654,7 +654,7 @@ trait InterfaceSync{ this: InterfaceBase => when( cReg.syncPoint === sReg.recoTimeStamp ){ //时间到达sync0时间点 syncOffsetCnt(i) := 0.U - } .elsewhen( syncOffsetCnt(i) < sReg.syncOffset(i) ){ + } .elsewhen( syncOffsetCnt(i) <= sReg.syncOffset(i) ){ syncOffsetCnt(i) := syncOffsetCnt(i) + 1.U } @@ -669,9 +669,14 @@ trait InterfaceSync{ this: InterfaceBase => } for( i <- 0 until 4 ){ - when( ~sReg.syncCfg(4+i) & syncSign(i) ){ - syncResetCnt(i) := syncResetCnt(i) + 1.U + when( ~sReg.syncCfg(4+i) ){ + when( syncSign(i) ){ + syncResetCnt(i) := syncResetCnt(i) + 1.U + } .otherwise{ + syncResetCnt(i) := 0.U + } } + } diff --git a/src/main/scala/backBoard/shin/SlaveParser.scala b/src/main/scala/backBoard/shin/SlaveParser.scala index bf9ee1d..f06b3fe 100644 --- a/src/main/scala/backBoard/shin/SlaveParser.scala +++ b/src/main/scala/backBoard/shin/SlaveParser.scala @@ -47,7 +47,7 @@ class SlaveParserIO extends Bundle{ val trigAddr = Input( Vec(8, UInt(15.W)) ) val mstDeltaTimeStamp = Output(UInt(32.W)) - val slvDeltaTimeStamp = Output(UInt(32.W)) + val slvDeltaTime = Output(UInt(32.W)) val deltaFinal = Output(UInt(32.W)) val isLoop = Output(Bool()) @@ -472,6 +472,8 @@ trait SlaveParserRW{ this: SlaveParserBase => ( upRecParser.io.stateCurr === STATE_PAYLOAD_DATA ) -> addrr, )) + + val isRDReg = (readSMAddr(14,11) === "b0000".U) val isRDSM1 = (readSMAddr(14,11) === "b0010".U) val isRDSM3 = (readSMAddr(14,11) === "b0100".U) @@ -552,7 +554,7 @@ trait SlaveParserSync{ this: SlaveParserBase => val upTimeStamp = Reg(UInt(64.W)) //上行本地时间戳寄存器 val mstTimeStamp = Reg(UInt(64.W)) //主站时间戳 val mstDeltaTimeStamp = Reg(UInt(32.W)); io.mstDeltaTimeStamp := mstDeltaTimeStamp //主站时间戳差值 - val slvDeltaTimeStamp = Reg(UInt(32.W)); io.slvDeltaTime := slvDeltaTime //从站时间戳差值 + val slvDeltaTimeStamp = Reg(UInt(32.W)); io.slvDeltaTime := slvDeltaTimeStamp //从站时间戳差值 val mstSlvDeltaTimeStamp = Reg(UInt(32.W)) //主发从接时间差(中间变量) val deltaMstSlvDeltaTimeStamp = Reg(UInt(32.W)) //主差从差时间差(中间变量) diff --git a/tb/shinTest/ShinTopSpiTb.v b/tb/shinTest/ShinTopSpiTb.v index d3d43a7..47047c7 100644 --- a/tb/shinTest/ShinTopSpiTb.v +++ b/tb/shinTest/ShinTopSpiTb.v @@ -517,7 +517,7 @@ initial begin //子报文 txBuf[132+3] = 8'h0; txBuf[133+3] = 8'hc; //index = 3 - txBuf[134+3] = 8'h09; //地址 //SM1 + txBuf[134+3] = 8'h10; //地址 //SM1 txBuf[135+3] = 8'h40; //地址 //偏置 txBuf[136+3] = 8'h00; //命令0 长度56 txBuf[137+3] = 8'd56; //长度 @@ -624,7 +624,7 @@ initial begin //写入替换时间戳替换地址 txBuf[0+3] = 8'h0c; txBuf[1+3] = 8'hc0; - spi_trans( (16'h25), (`SPI_WRITE), (2), (0) ); //写入SM1 + spi_trans( (16'h25), (`SPI_WRITE), (2), (0) ); //写入替换时间戳替换地址寄存器 //发布请求 txBuf[0+3] = 8'h18; @@ -635,6 +635,101 @@ initial begin spi_trans( (16'h20), (`SPI_WRITE), (1), (0) );//发送SM0 接收SM0, 请求发送 @(posedge isResp) #5 begin end + //清除替换时间戳替换地址 + txBuf[0+3] = 8'h00; + txBuf[1+3] = 8'h00; + spi_trans( (16'h25), (`SPI_WRITE), (2), (0) ); //清除替换时间戳替换地址寄存器 + + + + //设定sync信号 + + //设置SM1在写入51地址触发enq + txBuf[0+3] = 8'd51; + txBuf[1+3] = 8'h00; + spi_trans( (16'h0202), (`SPI_WRITE), (2), (0) ); + + //header + txBuf[0+3] = 8'h03; + txBuf[1+3] = 8'h00;//heeader length 48 + txBuf[2+3] = 8'h00; + txBuf[3+3] = 8'h00; + + //子报文 + //设置同步相关寄存器 + txBuf[4+3] = 8'h0; //设备索引 + txBuf[5+3] = 8'h08; //设备索引、类型 //2号设备 + txBuf[6+3] = 8'h01; //地址 + txBuf[7+3] = 8'h20; //地址 0x120 + txBuf[8+3] = 8'h10; //命令1 写入寄存器 负载长度2 + txBuf[9+3] = 8'h28; //负载长度0x28 + txBuf[10+3] = 8'h0; //工作计数0 + txBuf[11+3] = 8'h0; //工作计数0 + + txBuf[12+3] = 8'h0f; //负载0x120 0x0f 全部脉冲,全部使能 + txBuf[13+3] = 0; //负载0x121 + txBuf[14+3] = 10; //负载0x122 sync0脉冲宽度 10 + txBuf[15+3] = 0; //负载0x123 + txBuf[16+3] = 0; //负载0x124 sync1脉冲宽度 0 + txBuf[17+3] = 0; //负载0x125 + txBuf[18+3] = 1; //负载0x126 sync2脉冲宽度 1 + txBuf[19+3] = 0; //负载0x127 + txBuf[20+3] = 8'hff; //负载0x128 sync3脉冲宽度 最大 + txBuf[21+3] = 8'hff; //负载0x129 + + txBuf[22+3] = 0; //负载0x12a empty + txBuf[23+3] = 0; //负载0x12b + txBuf[24+3] = 0; //负载0x12c + txBuf[25+3] = 0; //负载0x12d + txBuf[26+3] = 0; //负载0x12e + txBuf[27+3] = 0; //负载0x12f + + //同步点 + txBuf[28+3] = 8'h90; //负载0x130 同步点 + txBuf[29+3] = 8'h88; //负载0x131 + txBuf[30+3] = 0; //负载0x132 + txBuf[31+3] = 0; //负载0x133 + txBuf[32+3] = 0; //负载0x134 + txBuf[33+3] = 0; //负载0x135 + txBuf[34+3] = 0; //负载0x136 + txBuf[35+3] = 0; //负载0x137 + + //周期 + txBuf[36+3] = 8'hff; //负载0x138 + txBuf[37+3] = 0; //负载0x139 + txBuf[38+3] = 0; //负载0x13a + txBuf[39+3] = 0; //负载0x13b + + //0ffset sync1 + txBuf[40+3] = 8'ha; //负载0x13c + txBuf[41+3] = 0; //负载0x13d + txBuf[42+3] = 0; //负载0x13e + txBuf[43+3] = 0; //负载0x13f + + //0ffset sync2 + txBuf[44+3] = 8'h0; //负载0x140 + txBuf[45+3] = 0; //负载0x141 + txBuf[46+3] = 0; //负载0x142 + txBuf[47+3] = 0; //负载0x143 + + //0ffset sync3 + txBuf[48+3] = 8'h0; //负载0x144 + txBuf[49+3] = 8'h01; //负载0x145 + txBuf[50+3] = 0; //负载0x146 + txBuf[51+3] = 0; //负载0x147 + + + spi_trans( (16'h1000), (`SPI_WRITE), (52), (0) ); //写入SM1 + + //发布请求 + txBuf[0+3] = 8'd52; + txBuf[1+3] = 8'h00; + spi_trans( (16'h21), (`SPI_WRITE), (2), (0) );//写入长度 + + txBuf[0+3] = 8'h01; + spi_trans( (16'h20), (`SPI_WRITE), (1), (0) );//发送SM0 接收SM0, 请求发送 + @(posedge isResp) #5 begin end + end From 0a772e4efcd6b04179828a50c80db16f912b9330 Mon Sep 17 00:00:00 2001 From: Ruige Lee Date: Fri, 16 May 2025 16:42:07 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E8=84=89=E5=86=B2=E7=94=B5=E5=B9=B3spi?= =?UTF-8?q?=E6=B8=85=E9=9B=B6=E6=B5=8B=E8=AF=95=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tb/shinTest/ShinTopSpiTb.v | 40 +++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/tb/shinTest/ShinTopSpiTb.v b/tb/shinTest/ShinTopSpiTb.v index 47047c7..0d96e6c 100644 --- a/tb/shinTest/ShinTopSpiTb.v +++ b/tb/shinTest/ShinTopSpiTb.v @@ -666,16 +666,29 @@ initial begin txBuf[10+3] = 8'h0; //工作计数0 txBuf[11+3] = 8'h0; //工作计数0 - txBuf[12+3] = 8'h0f; //负载0x120 0x0f 全部脉冲,全部使能 + // txBuf[12+3] = 8'h0f; //负载0x120 0x0f 全部脉冲,全部使能 + // txBuf[13+3] = 0; //负载0x121 + // txBuf[14+3] = 10; //负载0x122 sync0脉冲宽度 10 + // txBuf[15+3] = 0; //负载0x123 + // txBuf[16+3] = 0; //负载0x124 sync1脉冲宽度 0 + // txBuf[17+3] = 0; //负载0x125 + // txBuf[18+3] = 1; //负载0x126 sync2脉冲宽度 1 + // txBuf[19+3] = 0; //负载0x127 + // txBuf[20+3] = 8'hff; //负载0x128 sync3脉冲宽度 最大 + // txBuf[21+3] = 8'hff; //负载0x129 + + + txBuf[12+3] = 8'hff; //负载0x120 0xff 全部电平,全部使能 txBuf[13+3] = 0; //负载0x121 - txBuf[14+3] = 10; //负载0x122 sync0脉冲宽度 10 + + txBuf[14+3] = 0; //负载0x122 sync0脉冲宽度 txBuf[15+3] = 0; //负载0x123 - txBuf[16+3] = 0; //负载0x124 sync1脉冲宽度 0 + txBuf[16+3] = 0; //负载0x124 sync1脉冲宽度 txBuf[17+3] = 0; //负载0x125 - txBuf[18+3] = 1; //负载0x126 sync2脉冲宽度 1 + txBuf[18+3] = 0; //负载0x126 sync2脉冲宽度 txBuf[19+3] = 0; //负载0x127 - txBuf[20+3] = 8'hff; //负载0x128 sync3脉冲宽度 最大 - txBuf[21+3] = 8'hff; //负载0x129 + txBuf[20+3] = 0; //负载0x128 sync3脉冲宽度 + txBuf[21+3] = 0; //负载0x129 txBuf[22+3] = 0; //负载0x12a empty txBuf[23+3] = 0; //负载0x12b @@ -696,7 +709,7 @@ initial begin //周期 txBuf[36+3] = 8'hff; //负载0x138 - txBuf[37+3] = 0; //负载0x139 + txBuf[37+3] = 8'hf; //负载0x139 txBuf[38+3] = 0; //负载0x13a txBuf[39+3] = 0; //负载0x13b @@ -732,6 +745,19 @@ initial begin end + //清脉冲 + //设置SM1在写入19地址触发enq + txBuf[0+3] = 0; //负载0x122 sync0脉冲宽度 + txBuf[1+3] = 0; //负载0x123 + txBuf[2+3] = 0; //负载0x124 sync1脉冲宽度 + txBuf[3+3] = 0; //负载0x125 + txBuf[4+3] = 0; //负载0x126 sync2脉冲宽度 + txBuf[5+3] = 0; //负载0x127 + txBuf[6+3] = 0; //负载0x128 sync3脉冲宽度 + txBuf[7+3] = 0; //负载0x129 + spi_trans( (16'h0122), (`SPI_WRITE), (8), (2) ); //slv2 + + end