2023-08-16 22:25:30 +08:00
|
|
|
package BACK
|
|
|
|
|
|
|
|
|
|
import chisel3._
|
|
|
|
|
import chisel3.util._
|
|
|
|
|
|
|
|
|
|
|
2023-08-23 19:32:41 +08:00
|
|
|
class MirrorSRAM(dw: Int, cl: Int) extends RawModule {
|
|
|
|
|
def line_w = log2Ceil(cl)
|
|
|
|
|
val io = IO(new Bundle{
|
|
|
|
|
val addrr = Input(UInt(line_w.W))
|
|
|
|
|
val addrw = Input(UInt(line_w.W))
|
2023-08-16 22:25:30 +08:00
|
|
|
|
2023-08-23 19:32:41 +08:00
|
|
|
val dataw = Input( UInt(dw.W) )
|
|
|
|
|
val datar = Output( UInt(dw.W) )
|
|
|
|
|
val enw = Input(Bool())
|
|
|
|
|
val enr = Input(Bool())
|
2023-08-16 22:25:30 +08:00
|
|
|
|
2023-08-23 19:32:41 +08:00
|
|
|
val clock = Input(Bool())
|
|
|
|
|
val reset = Input(Bool())
|
|
|
|
|
})
|
2023-08-18 12:10:47 +00:00
|
|
|
|
|
|
|
|
|
2023-08-23 19:32:41 +08:00
|
|
|
withClockAndReset( io.clock.asClock, io.reset ){
|
|
|
|
|
val mem = SyncReadMem( cl, UInt(dw.W) )
|
2023-08-18 12:10:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-16 22:25:30 +08:00
|
|
|
|
2023-08-23 19:32:41 +08:00
|
|
|
io.datar := DontCare
|
|
|
|
|
when( io.enr ) {
|
|
|
|
|
io.datar := mem.read( io.addrr )
|
|
|
|
|
}
|
|
|
|
|
when( io.enw ) {
|
|
|
|
|
mem.write( io.addrw, io.dataw )
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-16 22:25:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-23 19:32:41 +08:00
|
|
|
}
|
2023-08-16 22:25:30 +08:00
|
|
|
|
|
|
|
|
|
2023-08-18 12:10:47 +00:00
|
|
|
|
2023-08-16 22:25:30 +08:00
|
|
|
|
2023-08-23 19:32:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// class MirrorSRAMIO extends Bundle{
|
|
|
|
|
// val datar = Output(UInt(8.W))
|
|
|
|
|
// val dataw = Input(UInt(8.W))
|
|
|
|
|
// val clock = Input(Bool())
|
|
|
|
|
// val reset = Input(Bool())
|
|
|
|
|
// val we = Input(Bool())
|
|
|
|
|
// val addrr = Input(UInt(11.W))
|
|
|
|
|
// val addrw = Input(UInt(11.W))
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// class MirrorSRAM extends BlackBox with HasBlackBoxInline {
|
|
|
|
|
|
|
|
|
|
// val io: MirrorSRAMIO = IO(new MirrorSRAMIO)
|
|
|
|
|
|
|
|
|
|
// setInline("microSRAM.v",
|
|
|
|
|
// """
|
|
|
|
|
// | module MirrorSRAM(
|
|
|
|
|
// | output [7:0] datar,
|
|
|
|
|
// | input [7:0] dataw,
|
|
|
|
|
// |
|
|
|
|
|
// | input clock,
|
|
|
|
|
// | input reset,
|
|
|
|
|
// |
|
|
|
|
|
// | input we,
|
|
|
|
|
// |
|
|
|
|
|
// | input [11:0] addrw,
|
|
|
|
|
// | input [11:0] addrr
|
|
|
|
|
// |
|
|
|
|
|
// | );
|
|
|
|
|
// |
|
|
|
|
|
// | wire [31:0] dout;
|
|
|
|
|
// | assign datar = dout[7:0];
|
|
|
|
|
// |
|
|
|
|
|
// |
|
|
|
|
|
// |SDPB bram_sdpb_0 (
|
|
|
|
|
// | .DO({dout[31:8],dout[7:0]}),
|
|
|
|
|
// | .CLKA(clock),
|
|
|
|
|
// | .CEA(we),
|
|
|
|
|
// | .RESETA(reset),
|
|
|
|
|
// | .CLKB(clock),
|
|
|
|
|
// | .CEB(1'b1),
|
|
|
|
|
// | .RESETB(reset),
|
|
|
|
|
// | .OCE(1'b1),
|
|
|
|
|
// | .BLKSELA(3'b0),
|
|
|
|
|
// | .BLKSELB(3'b0),
|
|
|
|
|
// | .ADA({addrw,3'b0}),
|
|
|
|
|
// | .DI({24'b0, dataw}),
|
|
|
|
|
// | .ADB({addrr,3'b0})
|
|
|
|
|
// | );
|
|
|
|
|
// | defparam bram_sdpb_0.BIT_WIDTH_0 = 8;
|
|
|
|
|
// | defparam bram_sdpb_0.BIT_WIDTH_1 = 8;
|
|
|
|
|
// | defparam bram_sdpb_0.RESET_MODE = "SYNC";
|
|
|
|
|
// |
|
|
|
|
|
// |endmodule
|
|
|
|
|
// """.stripMargin)
|
|
|
|
|
// }
|
2023-08-16 22:25:30 +08:00
|
|
|
|