增加加密特性(未测试)

This commit is contained in:
Ruige Lee
2025-05-22 16:53:42 +08:00
parent d14254f79a
commit 944255978a
4 changed files with 32 additions and 12 deletions

View File

@@ -9,6 +9,8 @@ class CDRInIO extends Bundle{
val axis = Decoupled(new AXIS_Bundle(8))
val serDat = Input(Bool())
val overCLK = Input(Bool())
val initEncryptor = Flipped(Valid(UInt(128.W)))
}
@@ -17,6 +19,9 @@ abstract class CDRInBase extends Module{
val io: CDRInIO = IO(new CDRInIO)
val encryptor = Module(new Encryptor)
encryptor.io.init := io.initEncryptor
encryptor.io.op.ready := io.axis.fire
}
@@ -116,9 +121,9 @@ trait CDRInAxis{ this: CDRInBase =>
val payloadLen = RegInit(0.U(12.W))
when( byteCnt === 0.U & bitCnt === 9.U & stateCurr === STATE_HEADER ){
payloadLen := Cat( shiftData, 0.U(4.W) )
payloadLen := Cat( shiftData ^ Mux( encryptor.io.op.valid, encryptor.io.op.bits, 0.U ), 0.U(4.W) )
} .elsewhen( byteCnt === 1.U & bitCnt === 9.U & stateCurr === STATE_HEADER ){
payloadLen := Cat( payloadLen(11,4), shiftData(7,4) )
payloadLen := Cat( payloadLen(11,4), shiftData(7,4) ^ Mux( encryptor.io.op.valid, encryptor.io.op.bits, 0.U ) )
}
stateNext :=
@@ -159,7 +164,7 @@ trait CDRInAxis{ this: CDRInBase =>
val axis_valid = RegInit(false.B)
val axis_tdata = RegEnable( shiftData, bitCnt === 9.U & ( stateCurr === STATE_HEADER | stateCurr === STATE_PAYLOAD ) )
val axis_tdata = RegEnable( shiftData ^ Mux( encryptor.io.op.valid, encryptor.io.op.bits, 0.U ), bitCnt === 9.U & ( stateCurr === STATE_HEADER | stateCurr === STATE_PAYLOAD ) )
val axis_tuser = false.B
val axis_tlast = RegNext( stateCurr === STATE_PAYLOAD & stateNext === STATE_IDLE, false.B )

View File

@@ -13,13 +13,20 @@ class AXIS_Bundle(dw: Int) extends Bundle{
class CDROutIO extends Bundle{
val axis = Flipped(Decoupled(new AXIS_Bundle(8)))
val serDat = Output(Bool())
}
val initEncryptor = Flipped(Valid(UInt(128.W)))
}
class CDROut extends Module{
val io: CDROutIO = IO(new CDROutIO)
val encryptor = Module(new Encryptor)
encryptor.io.init := io.initEncryptor
encryptor.io.op.ready := io.axis.fire
def STATE_IDLE = 0.U
def STATE_PREAMBLE = 1.U
def STATE_PAYLOAD = 2.U
@@ -62,10 +69,10 @@ class CDROut extends Module{
when( stateCurr === STATE_PREAMBLE ){
shiftData := MuxCase( ETH_PRE, Array(
( byteCnt === 6.U ) -> ETH_SFD,
( byteCnt === 7.U ) -> Dualb4b5Encoder(io.axis.bits.tdata),
( byteCnt === 7.U ) -> Dualb4b5Encoder( io.axis.bits.tdata ^ Mux( encryptor.io.op.valid, encryptor.io.op.bits, 0.U ) ),
))
} .elsewhen( stateCurr === STATE_PAYLOAD ){
shiftData := Dualb4b5Encoder(io.axis.bits.tdata)
shiftData := Dualb4b5Encoder(io.axis.bits.tdata ^ Mux( encryptor.io.op.valid, encryptor.io.op.bits, 0.U ) )
}
}
}