增加中断

This commit is contained in:
Ruige Lee
2025-05-23 17:22:59 +08:00
parent 15596ce478
commit 41f0b5b057
3 changed files with 98 additions and 9 deletions

View File

@@ -16,6 +16,10 @@ class CommonRegisterBundle extends Bundle{
val encryptKey = UInt(128.W)
val isEncrypt = Bool()
val intEnable = UInt(16.W)
val intStatus = UInt(16.W)
// val upRecErrorCnt = UInt(32.W)
// val downRecErrorCnt = UInt(32.W)
// val upForwardErrorCnt = UInt(32.W)
@@ -58,10 +62,6 @@ class MasterRegisterBundle extends Bundle{
val rplTimeStampTx = UInt(16.W)
// val intEnable = UInt(8.W)
// val intMask = UInt(8.W)
// val intStatus = UInt(8.W)
}
@@ -171,6 +171,10 @@ class InterfaceIO extends Bundle{
val initEncryptor = Valid(UInt(128.W))
val isSoftReset = Output(Bool())
val intMstTrig = Input(Vec(2, Bool()))
val intSlvTrig = Input(Vec(8, Bool()))
val interrupt = Output(Bool())
}
@@ -249,6 +253,10 @@ abstract class InterfaceBase extends Module{
Seq(
(addr === "h60".U ) -> cReg.isEncrypt,
(addr === "h70".U ) -> cReg.intEnable(7,0),
(addr === "h71".U ) -> cReg.intEnable(15,8),
(addr === "h72".U ) -> cReg.intStatus(7,0),
(addr === "h73".U ) -> cReg.intStatus(15,8),
(addr === "hc0".U ) -> Cat( sReg.isDevOnRightModify, sReg.isDevOnRight, 0.U(3.W) ),
(addr === "hc2".U ) -> sReg.indexOfRightDev(7,0),
(addr === "hc3".U ) -> sReg.indexOfRightDev(13,8),
@@ -728,6 +736,55 @@ trait InterfaceSync{ this: InterfaceBase =>
trait InterfaceSystem{ this: InterfaceBase =>
io.isSoftReset := ShiftRegister( isEnW & addrw === "h40".U, 16, false.B, true.B )
cReg.intEnable :=
Cat(
RegEnable( dataw, 0.U, isEnW & addrw === "h71".U ),
RegEnable( dataw, 0.U, isEnW & addrw === "h70".U )
)
val intStatus = for( _ <- 0 until 16 ) yield { RegInit(false.B) }
cReg.intStatus := Cat( intStatus.reverse )
val intMstTrig = Input(Vec(2, Bool()))
val intSlvTrig = Input(Vec(8, Bool()))
//主站发送完成
when( io.intMstTrig(0) ){
intStatus(0) := true.B
}
//主站接收完成
when( io.intMstTrig(1) ){
intStatus(1) := true.B
}
//主站发送周期到了
//主站接收看门狗溢出
//从站SM请求
for( i <- 0 until 8 ){
when( io.intSlvTrig(i) ){
intStatus(8+i) := true.B
}
}
for( i <- 0 until 8 ){
when( dataw.extract(i) & isEnW & addrw === "h74".U ){
intStatus(i) := false.B
}
when( dataw.extract(i) & isEnW & addrw === "h75".U ){
intStatus(i+8) := false.B
}
}
io.interrupt := intStatus.reduce(_|_)
}
class Interface extends InterfaceBase