框架开始收尾,协调流水线

This commit is contained in:
Ruige Lee
2025-04-08 17:29:45 +08:00
parent e34338753a
commit d7b04710ae
3 changed files with 226 additions and 119 deletions

View File

@@ -10,12 +10,12 @@ class FrameHeader extends Bundle{
}
class SubMsgHeader extends Bundle{
val subMsg_devIndex = UInt(14.W) // 子报文中设备索引
val subMsg_style = UInt(2.W) // 子报文类型
val subMsg_address = UInt(16.W) //子报文地址
val subMsg_operator = UInt(4.W) //子报文命令类型
val subMsg_length = UInt(12.W) //子报文负载长度
val subMsg_workCnt = UInt(16.W) //子报文工作计数
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) //子报文工作计数
}
@@ -56,8 +56,7 @@ abstract class SlaveParserBase extends Module{
val upSendGen = Module(new SlaveSendGen)
val downRecFifo = for( i <- 0 until 2 ) yield { Module(new Queue(UInt(8.W), 8)) }
val upRecFifo = for( i <- 0 until 2 ) yield { Module(new Queue(UInt(8.W), 8)) }
val downSinkSel = Reg(Bool())
@@ -76,6 +75,9 @@ abstract class SlaveParserBase extends Module{
val isUpSendPend = RegInit(false.B)
//处理主报文
//同时到来怎么办
when( downRecParser.io.frameReq.fire ){
when(downRecParser.io.frameReq.bits.frameStyle === FRAME_STYLE_PROBE){ //下行来了一个嗅探包
@@ -118,13 +120,14 @@ abstract class SlaveParserBase extends Module{
}
upSendGen.io.frameReq.valid :=
isUpSendPend | isUpSendProbe //上行转发 | 上行探针
isUpSendPend | isUpSendProbe | //上行转发 | 上行探针 | 下行回环
assert( OneHot(isUpSendPend, isUpSendProbe) )
upSendGen.io.frameReq.bits := Mux1H(Seq(
isUpSendPend -> upFrameInfo, //上行转发
isUpSendProbe -> probeFrame, //上行探针
, //下行回环
))
@@ -139,91 +142,217 @@ abstract class SlaveParserBase extends Module{
//子报文
val isDownSubMsgValid = for( i <- 0 until 2 ) yield { RegInit(false.B) }
val isUpSubMsgValid = for( i <- 0 until 2 ) yield { RegInit(false.B) }
//接收子报文
upSendFifo.io.enq.bits := Mux1H(Seq(
( downRecParser.io.frameStyle === FRAME_STYLE_PROBE & downRecParser.io.stateCurr > STATE_HEADER ) -> downRecParser.io.data.bits //嗅探包 bypass到上行
val downSubMsgInfo = for( i <- 0 until 2 ) yield { Reg(new SubMsgHeader) }
val upSubMsgInfo = for( i <- 0 until 2 ) yield { Reg(new SubMsgHeader) }
val downRecFifo = for( i <- 0 until 2 ) yield { Module(new Queue(UInt(8.W), 8)) }
val upRecFifo = for( i <- 0 until 2 ) yield { Module(new Queue(UInt(8.W), 8)) }
val isDownRecPing: Bool
val isUpRecPing: Bool
//下行接收
when( downRecParser.io.subMsgReq.fire ){
when( isDownRecPing ){
isDownSubMsgValid(0) := true.B
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
downSubMsgInfo(0).workCnt := downRecParser.io.subMsgReq.bits.workCnt
downSubMsgInfo(0).source := 0.U
//override 自身包
when( downRecParser.io.subMsgReq.bits.devIndex === localDevIndex ){
when( downRecParser.io.subMsgReq.bits.operator === 1.U ) {//写 sparser -》sram
downSubMsgInfo(0).workCnt := downRecParser.io.subMsgReq.bits.workCnt + 1.U
} .elsewhen( downRecParser.io.subMsgReq.bits.operator === 2.U ) {//读 ram ->fifo
} .elsewhen( downRecParser.io.subMsgReq.bits.operator === 3.U ) {//读写 parser -》sram sram ->fifo
downSubMsgInfo(0).workCnt := downRecParser.io.subMsgReq.bits.workCnt + 1.U
}
}
} .otherwise{
isDownSubMsgValid(1) := true.B
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
downSubMsgInfo(1).workCnt := downRecParser.io.subMsgReq.bits.workCnt
downSubMsgInfo(1).source := 1.U
//override 自身包
when( downRecParser.io.subMsgReq.bits.devIndex === localDevIndex ){
when( downRecParser.io.subMsgReq.bits.operator === 1.U ) {//写 sparser -》sram
downSubMsgInfo(1).workCnt := downRecParser.io.subMsgReq.bits.workCnt + 1.U
} .elsewhen( downRecParser.io.subMsgReq.bits.operator === 2.U ) {//读 ram ->fifo
} .elsewhen( downRecParser.io.subMsgReq.bits.operator === 3.U ) {//读写 parser -》sram sram ->fifo
downSubMsgInfo(1).workCnt := downRecParser.io.subMsgReq.bits.workCnt + 1.U
}
}
}
}
when( isDownRecPing ){
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
} .otherwise{
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
}
//写入sram
sram.io.enw :=
( isDownRecPing & downSubMsgInfo(0).devIndex === localDevIndex & (downSubMsgInfo(0).operator === 1.U | downSubMsgInfo(0).operator === 3.U)) |
(~isDownRecPing & downSubMsgInfo(1).devIndex === localDevIndex & (downSubMsgInfo(1).operator === 1.U | downSubMsgInfo(1).operator === 3.U))
))
upSendFifo.io.enq.valid :=
((downRecParser.io.frameStyle === FRAME_STYLE_PROBE & downRecParser.io.stateCurr > STATE_HEADER ) & downRecParser.io.data.valid) |
downRecParser.io.data.ready :=
((downRecParser.io.frameStyle === FRAME_STYLE_PROBE & downRecParser.io.stateCurr > STATE_HEADER ) & upSendFifo.io.enq.ready ) |
downSendFifo.io.enq.bits := Mux1H(Seq(
( downRecParser.io.frameStyle === FRAME_STYLE_COMMON & downRecParser.io.stateCurr > STATE_HEADER ) ->
))
val isDownIdle
val isDownBypassToDown
val isDownWriteToSRAM
val isDownReadFromSRAM
val isDownLoopBack
val isUpIdle
val isUpBypassToUp
val isUpWriteToSRAM
val isUpReadFromSRAM
val isUpBlackHole
sram.io.addrw :=
sram.io.dataw := downRecParser.io.data.bits
//上行接收
when( upRecParser.io.subMsgReq.fire ){
when( isUpRecFifoPing ){
isUpSubMsgValid(0) := true.B
// val downOutFifo = Module(new Queue(UInt(8.W), 8))
val upInFifo = Module(new Queue(UInt(8.W), 8))
// val upOutFifo = Module(new Queue(UInt(8.W), 8))
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
upSubMsgInfo(0).workCnt := upRecParser.io.subMsgReq.bits.workCnt
upSubMsgInfo(0).source := 0.U
//override 自身包
when( upRecParser.io.subMsgReq.bits.devIndex === localDevIndex ){
when( upRecParser.io.subMsgReq.bits.operator === 1.U ) {//写 sparser -》sram
} .elsewhen( upRecParser.io.subMsgReq.bits.operator === 2.U ) {//读 ram ->fifo
upSubMsgInfo(0).workCnt := upRecParser.io.subMsgReq.bits.workCnt + 1.U
} .elsewhen( upRecParser.io.subMsgReq.bits.operator === 3.U ) {//读写 parser -》sram sram ->fifo
upSubMsgInfo(0).workCnt := upRecParser.io.subMsgReq.bits.workCnt + 1.U
}
}
} .otherwise{
isUpSubMsgValid(1) := true.B
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
upSubMsgInfo(1).workCnt := upRecParser.io.subMsgReq.bits.workCnt
upSubMsgInfo(1).source := 1.U
//override 自身包
when( upRecParser.io.subMsgReq.bits.devIndex === localDevIndex ){
when( upRecParser.io.subMsgReq.bits.operator === 1.U ) {//写 sparser -》sram
} .elsewhen( upRecParser.io.subMsgReq.bits.operator === 2.U ) {//读 ram ->fifo
upSubMsgInfo(1).workCnt := upRecParser.io.subMsgReq.bits.workCnt + 1.U
} .elsewhen( upRecParser.io.subMsgReq.bits.operator === 3.U ) {//读写 parser -》sram sram ->fifo
upSubMsgInfo(1).workCnt := upRecParser.io.subMsgReq.bits.workCnt + 1.U
}
}
}
}
when( isUpRecFifoPing ){
upRecFifo(0).io.enq.valid := upRecParser.io.data.valid
upRecFifo(0).io.enq.bits :=
Mux( upSubMsgInfo(0).devIndex === localDevIndex & (upSubMsgInfo(0).operator === 2.U | upSubMsgInfo(0).operator === 3.U),
sram.io.datar, upRecParser.io.data.bits)
downInFifo.io.enq <> io.downIn
upRecParser.io.data.ready := upRecFifo(0).io.enq.ready
} .otherwise{
upRecFifo(1).io.enq.valid := upRecParser.io.data.valid
upRecFifo(1).io.enq.bits := Mux( upSubMsgInfo(1).devIndex === localDevIndex & (upSubMsgInfo(1).operator === 2.U | upSubMsgInfo(1).operator === 3.U),
sram.io.datar, upRecParser.io.data.bits)
upRecParser.io.data.ready := upRecFifo(1).io.enq.ready
}
io.downOut.valid :=
( === FRAME_STYLE_COMMON ) &
io.upOut.valid :=
( === FRAME_STYLE_PROBE) & |
io.upOut.bits :=
Mux1H(Seq(
( === FRAME_STYLE_PROBE) -> downInFifo.io.deq.bits, //嗅探包情形
-> upInFifo.io.deq.bits, //上行
-> //上行修正数据
))
io.downOut.bits :=
Mux1H(Seq(
-> //自主发送嗅探包
( ) -> downInFifo.io.deq.bits, //下行
( ) -> //下行修正数据
))
downInFifo.io.deq.ready :=
upInFifo.io.deq.ready :=
//读出SRAM
sram.io.enr :=
( isUpRecFifoPing & upSubMsgInfo(0).devIndex === localDevIndex & (upSubMsgInfo(0).operator === 1.U | upSubMsgInfo(0).operator === 3.U)) |
(~isUpRecFifoPing & upSubMsgInfo(1).devIndex === localDevIndex & (upSubMsgInfo(1).operator === 1.U | upSubMsgInfo(1).operator === 3.U))
sram.io.addrr :=
//子报文下行发送
val isDownSendPing: Bool
val isUpSendPing: Bool
val isLastDevice: Bool
downSendGen.io.subMsgReq.valid :=
( isDownSendPing & isDownSubMsgValid(0) ) | (~isDownSendPing & isDownSubMsgValid(1))
downSendGen.io.subMsgReq.bits := Mux( isDownSendPing, downSubMsgInfo(0), downSubMsgInfo(1) )
when( downSendGen.io.subMsgReq.fire ){ //ready
isDownSendPing := ~isDownSendPing
when( isDownSendPing ){
isDownSubMsgValid(0) := false.B
} .otherwise{
isDownSubMsgValid(1) := false.B
}
}
downRecFifo(0).io.deq <> downSendGen.io.data(0)
downRecFifo(1).io.deq <> downSendGen.io.data(1)
//子报文上行发送
upSendGen.io.subMsgReq.valid :=
( isUpSendPing & isUpSubMsgValid(0) ) | (~isUpSendPing & isUpSubMsgValid(1))
upSendGen.io.subMsgReq.bits := Mux( isUpSendPing, upSubMsgInfo(0), upSubMsgInfo(1) )
when( upSendGen.io.subMsgReq.fire ){ //ready
isUpSendPing := ~isUpSendPing
when( isUpSendPing ){
isUpSubMsgValid(0) := false.B
} .otherwise{
isUpSubMsgValid(1) := false.B
}
}
upRecFifo(0).io.deq <> upSendGen.io.data(0)
upRecFifo(1).io.deq <> upSendGen.io.data(1)
when(isLastDevice & downRecParser.io.stateCurr > ){
downSendGen.io.send <> upRecParser.io.rec
}