2025-04-16 16:50:36 +08:00
|
|
|
package BACK
|
|
|
|
|
|
|
|
|
|
import chisel3._
|
|
|
|
|
import chisel3.util._
|
|
|
|
|
|
|
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
// class SRAM2kWRIO extends Bundle {
|
|
|
|
|
// val addrw = Output(UInt(11.W))
|
|
|
|
|
// val dataw = Output( UInt(8.W) )
|
|
|
|
|
// val enw = Output(Bool())
|
|
|
|
|
// }
|
2025-04-17 10:55:00 +08:00
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
// class SRAM2kRDIO extends Bundle {
|
|
|
|
|
// val addrr = Output(UInt(11.W))
|
|
|
|
|
// val datar = Input( UInt(8.W) )
|
|
|
|
|
// val enr = Output(Bool())
|
|
|
|
|
// }
|
2025-04-16 16:50:36 +08:00
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
// class SRAM2kIO extends Bundle {
|
|
|
|
|
// val addrr = Output(UInt(11.W))
|
|
|
|
|
// val addrw = Output(UInt(11.W))
|
2025-04-16 16:50:36 +08:00
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
// val dataw = Output( UInt(8.W) )
|
|
|
|
|
// val datar = Input( UInt(8.W) )
|
|
|
|
|
// val enw = Output(Bool())
|
|
|
|
|
// val enr = Output(Bool())
|
|
|
|
|
// }
|
2025-04-16 16:50:36 +08:00
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
class SMUnitIO(depth: Int) extends Bundle {
|
2025-04-16 16:50:36 +08:00
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
val sram_w = Flipped(new SRAM2kWRIO)
|
|
|
|
|
val sram_r = Flipped(new SRAM2kRDIO)
|
2025-04-16 16:50:36 +08:00
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
val enq = Input(Bool())
|
|
|
|
|
val deq = Input(Bool())
|
2025-04-16 16:50:36 +08:00
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
val sram = Vec(depth, new SRAM2kIO)
|
2025-04-16 16:50:36 +08:00
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
}
|
2025-04-16 16:50:36 +08:00
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
abstract class SMUnitBase(depth: Int = 4) extends Module {
|
|
|
|
|
val io: SMUnitIO = IO(new SMUnitIO(depth))
|
|
|
|
|
|
2025-04-17 10:55:00 +08:00
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
val wPtr = RegInit(0.U((log2Ceil(depth)+1).W))
|
|
|
|
|
val rPtr = RegInit(0.U((log2Ceil(depth)+1).W))
|
2025-04-16 16:50:36 +08:00
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
val isFull = (wPtr ^ rPtr) === (1.U << log2Ceil(depth))
|
|
|
|
|
// ( wPtr.extract(2) =/= rPtr.extract(2) ) & ( wPtr(1,0) === rPtr(1,0) )
|
2025-04-16 16:50:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
val isEmpty = ( wPtr === rPtr )
|
|
|
|
|
|
|
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
when( io.enq ){
|
2025-04-16 16:50:36 +08:00
|
|
|
wPtr := wPtr + 1.U
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
when( io.deq ){
|
2025-04-16 16:50:36 +08:00
|
|
|
rPtr := rPtr + 1.U
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
for( i <- 0 until depth ){
|
|
|
|
|
io.sram(i).addrw := 0.U
|
|
|
|
|
io.sram(i).dataw := 0.U
|
|
|
|
|
io.sram(i).enw := false.B
|
2025-04-16 16:50:36 +08:00
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
io.sram(i).addrr := 0.U
|
|
|
|
|
io.sram(i).enr := false.B
|
2025-04-16 16:50:36 +08:00
|
|
|
}
|
|
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
for( i <- 0 until depth ){
|
|
|
|
|
when( wPtr === i.U & ~isFull ){
|
|
|
|
|
io.sram(i).addrw := io.sram_w.addrw
|
|
|
|
|
io.sram(i).dataw := io.sram_w.dataw
|
|
|
|
|
io.sram(i).enw := io.sram_w.enw
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
when( rPtr === i.U & ~isEmpty){
|
|
|
|
|
io.sram(i).addrr := io.sram_r.addrr
|
|
|
|
|
io.sram(i).enr := io.sram_r.enr
|
|
|
|
|
}
|
2025-04-16 16:50:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
io.sram_r.datar := Mux1H( ( 0 until depth).map{ i =>
|
|
|
|
|
( rPtr === i.U ) -> io.sram(i).datar,
|
|
|
|
|
})
|
|
|
|
|
|
2025-04-16 16:50:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-23 17:57:38 +08:00
|
|
|
class SMUnit(depth: Int = 4) extends SMUnitBase(depth) {
|
2025-04-16 16:50:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|