2023-08-01 14:44:05 +08:00
|
|
|
package BACK
|
|
|
|
|
|
|
|
|
|
import chisel3._
|
|
|
|
|
import chisel3.util._
|
|
|
|
|
|
|
|
|
|
class BackPlaneMstTestIO extends Bundle{
|
|
|
|
|
|
2023-08-07 11:40:14 +08:00
|
|
|
// val SCK = Input(Bool())
|
2023-08-01 14:44:05 +08:00
|
|
|
val interrupt = Output(Bool())
|
|
|
|
|
val clk4 = Input( Bool() )
|
|
|
|
|
val reset = Input(Bool())
|
|
|
|
|
|
|
|
|
|
val downStreamRespdat = Output(Bool())
|
|
|
|
|
|
|
|
|
|
val req = Flipped(Decoupled(new CDRData))
|
|
|
|
|
val spi = Flipped(Decoupled(new CDR_Master_Interface_Bundle))
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class BackPlaneMstTest extends RawModule{
|
|
|
|
|
val io: BackPlaneMstTestIO = IO(new BackPlaneMstTestIO)
|
|
|
|
|
|
2023-08-07 11:40:14 +08:00
|
|
|
withClockAndReset( io.clk4.asClock, io.reset.asAsyncReset ){
|
2023-08-01 14:44:05 +08:00
|
|
|
val dut = Module(new BackBoardMst)
|
|
|
|
|
|
|
|
|
|
io.downStreamRespdat := dut.io.downStreamRespdat
|
|
|
|
|
|
|
|
|
|
// dut.io.CS := io.CS
|
|
|
|
|
// io.MISO := dut.io.MISO
|
|
|
|
|
// dut.io.MOSI := io.MOSI
|
2023-08-07 11:40:14 +08:00
|
|
|
// dut.io.SCK := io.SCK
|
2023-08-01 14:44:05 +08:00
|
|
|
|
|
|
|
|
dut.io.clk4 := io.clk4
|
|
|
|
|
io.interrupt := dut.io.interrupt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-07 11:40:14 +08:00
|
|
|
|
2023-08-01 14:44:05 +08:00
|
|
|
|
|
|
|
|
io.spi.ready := true.B
|
|
|
|
|
val cnt = RegInit(0.U(7.W))
|
|
|
|
|
val spiInfo = Reg( new CDR_Master_Interface_Bundle )
|
2023-08-07 11:40:14 +08:00
|
|
|
dut.io.MOSI := spiInfo.asUInt().extract( 6+8+32+2+16-1 )
|
2023-08-01 14:44:05 +08:00
|
|
|
val cs = RegInit(true.B); dut.io.CS := cs
|
2023-08-07 11:40:14 +08:00
|
|
|
val sckCnt = RegInit(1.U(2.W)); dut.io.SCK := sckCnt.extract(1) === 1.U
|
|
|
|
|
|
|
|
|
|
when( ~cs ){
|
|
|
|
|
sckCnt := sckCnt + 1.U
|
|
|
|
|
}
|
2023-08-01 14:44:05 +08:00
|
|
|
|
|
|
|
|
when( io.spi.fire ){
|
|
|
|
|
cs := false.B
|
|
|
|
|
cnt := 0.U
|
|
|
|
|
spiInfo := io.spi.bits
|
2023-08-07 11:40:14 +08:00
|
|
|
} .elsewhen( cnt =/= 63.U & sckCnt === "b11".U ){
|
2023-08-01 14:44:05 +08:00
|
|
|
cnt := cnt + 1.U
|
|
|
|
|
spiInfo := Cat(spiInfo.asUInt( 6+8+32+2+16-2, 0 ), dut.io.MISO).asTypeOf(new CDR_Master_Interface_Bundle)
|
2023-08-07 11:40:14 +08:00
|
|
|
} .elsewhen( cnt === 63.U & sckCnt === "b11".U ){
|
2023-08-01 14:44:05 +08:00
|
|
|
cs := true.B
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-07 11:40:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
io.req.ready := true.B
|
|
|
|
|
val reqDat = RegInit(false.B); dut.io.downStreamReqDat := reqDat
|
|
|
|
|
val reqInfo = RegInit(0.U((new CDRData).getWidth.W))
|
|
|
|
|
val datCnt = RegInit( 0.U(2.W) )
|
|
|
|
|
|
|
|
|
|
datCnt := datCnt + 1.U
|
|
|
|
|
|
|
|
|
|
when( datCnt === "b11".U ) {
|
|
|
|
|
when( io.req.fire ){
|
|
|
|
|
reqInfo := io.req.bits.asUInt
|
|
|
|
|
reqDat := true.B
|
|
|
|
|
} .otherwise{
|
|
|
|
|
reqDat := reqInfo.extract( 6+8+32+16-1 )
|
|
|
|
|
reqInfo := Cat( reqInfo( 6+8+32+16-2,0 ), 0.U(1.W) )
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-08-01 14:44:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|