2023-08-16 22:25:30 +08:00
|
|
|
package BACK
|
|
|
|
|
|
|
|
|
|
import chisel3._
|
|
|
|
|
import chisel3.util._
|
|
|
|
|
|
|
|
|
|
|
2023-08-31 17:39:12 +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-31 17:39:12 +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-31 17:39:12 +08:00
|
|
|
// val clock = Input(Bool())
|
|
|
|
|
// val reset = Input(Bool())
|
|
|
|
|
// })
|
2023-08-18 12:10:47 +00:00
|
|
|
|
|
|
|
|
|
2023-08-31 17:39:12 +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-31 17:39:12 +08:00
|
|
|
// io.datar := DontCare
|
|
|
|
|
// when( io.enr ) {
|
|
|
|
|
// io.datar := mem.read( io.addrr )
|
|
|
|
|
// }
|
|
|
|
|
// when( io.enw ) {
|
|
|
|
|
// mem.write( io.addrw, io.dataw )
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// val addrr = Input(UInt(line_w.W))
|
|
|
|
|
// val addrw = Input(UInt(line_w.W))
|
|
|
|
|
|
|
|
|
|
// 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-31 17:39:12 +08:00
|
|
|
// val clock = Input(Bool())
|
|
|
|
|
// val reset = Input(Bool())
|
2023-08-16 22:25:30 +08:00
|
|
|
|
|
|
|
|
|
2024-01-08 18:01:29 +08:00
|
|
|
// class MirrorSRAM(dw: Int, cl: Int) extends BlackBox with HasBlackBoxInline {
|
|
|
|
|
// require(dw == 8)
|
|
|
|
|
// require(cl == 2048)
|
|
|
|
|
// class MirrorSRAMIO extends Bundle{
|
|
|
|
|
// val addrr = Input(UInt(11.W))
|
|
|
|
|
// val addrw = Input(UInt(11.W))
|
2023-08-31 17:39:12 +08:00
|
|
|
|
2024-01-08 18:01:29 +08:00
|
|
|
// val dataw = Input( UInt(8.W) )
|
|
|
|
|
// val datar = Output( UInt(8.W) )
|
|
|
|
|
// val enw = Input(Bool())
|
|
|
|
|
// val enr = Input(Bool())
|
2023-08-31 17:39:12 +08:00
|
|
|
|
2024-01-08 18:01:29 +08:00
|
|
|
// val clockr = Input(Bool())
|
|
|
|
|
// val clockw = Input(Bool())
|
2023-08-31 17:39:12 +08:00
|
|
|
|
2024-01-08 18:01:29 +08:00
|
|
|
// }
|
|
|
|
|
// val io: MirrorSRAMIO = IO(new MirrorSRAMIO)
|
|
|
|
|
|
|
|
|
|
// setInline("MirrorSRAM.v",
|
|
|
|
|
// """
|
|
|
|
|
// | module MirrorSRAM(
|
|
|
|
|
// | input [7:0] dataw,
|
|
|
|
|
// | input [10:0] addrw,
|
|
|
|
|
// | input enw,
|
|
|
|
|
// |
|
|
|
|
|
// | output [7:0] datar,
|
|
|
|
|
// | input [10:0] addrr,
|
|
|
|
|
// | input enr,
|
|
|
|
|
// |
|
|
|
|
|
// | input clockr,
|
|
|
|
|
// | input clockw
|
|
|
|
|
// | );
|
|
|
|
|
// |
|
|
|
|
|
// | reg [7:0] ram[0:2047];
|
|
|
|
|
// | reg [7:0] data_r_reg;
|
|
|
|
|
// |
|
|
|
|
|
// | always @(posedge clockw) begin
|
|
|
|
|
// | if(enw) begin
|
|
|
|
|
// | ram[addrw] <= #1 dataw;
|
|
|
|
|
// | end
|
|
|
|
|
// | end
|
|
|
|
|
// |
|
|
|
|
|
// | always @(posedge clockr) begin
|
|
|
|
|
// | if(enr) begin
|
|
|
|
|
// | data_r_reg <= #1 ram[addrr];
|
|
|
|
|
// | end
|
|
|
|
|
// | end
|
|
|
|
|
// |
|
|
|
|
|
// | assign datar = data_r_reg;
|
|
|
|
|
// |
|
|
|
|
|
// | initial begin
|
|
|
|
|
// | for ( integer i = 0; i < 2048; i = i + 1 ) begin
|
|
|
|
|
// | ram[i] = $random;
|
|
|
|
|
// | end
|
|
|
|
|
// |
|
|
|
|
|
// | data_r_reg = $random;
|
|
|
|
|
// | end
|
|
|
|
|
// |
|
|
|
|
|
// |endmodule
|
|
|
|
|
// """.stripMargin)
|
|
|
|
|
// }
|
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-09-08 16:37:31 +08:00
|
|
|
class MirrorSRAMDown() extends BlackBox with HasBlackBoxInline {
|
|
|
|
|
class MirrorSRAMDownIO extends Bundle{
|
2024-01-08 18:01:29 +08:00
|
|
|
val addrr = Input(UInt(11.W))
|
|
|
|
|
val addrw = Input(UInt(10.W))
|
2023-08-23 19:32:41 +08:00
|
|
|
|
2023-09-08 16:37:31 +08:00
|
|
|
val dataw = Input( UInt(16.W) )
|
|
|
|
|
val datar = Output( UInt(8.W) )
|
|
|
|
|
val enw = Input(Bool())
|
|
|
|
|
val enr = Input(Bool())
|
2023-08-23 19:32:41 +08:00
|
|
|
|
2023-09-08 16:37:31 +08:00
|
|
|
val clockr = Input(Bool())
|
|
|
|
|
val clockw = Input(Bool())
|
2023-08-31 17:39:12 +08:00
|
|
|
|
2023-09-08 16:37:31 +08:00
|
|
|
}
|
|
|
|
|
val io: MirrorSRAMDownIO = IO(new MirrorSRAMDownIO)
|
|
|
|
|
|
|
|
|
|
setInline("MirrorSRAMDown.v",
|
|
|
|
|
"""
|
|
|
|
|
| module MirrorSRAMDown(
|
|
|
|
|
| input [15:0] dataw,
|
2024-01-08 18:01:29 +08:00
|
|
|
| input [9:0] addrw,
|
2023-09-08 16:37:31 +08:00
|
|
|
| input enw,
|
|
|
|
|
|
|
|
|
|
|
| output [7:0] datar,
|
2024-01-08 18:01:29 +08:00
|
|
|
| input [10:0] addrr,
|
2023-09-08 16:37:31 +08:00
|
|
|
| input enr,
|
|
|
|
|
|
|
|
|
|
|
| input clockr,
|
|
|
|
|
| input clockw
|
|
|
|
|
| );
|
|
|
|
|
|
|
2024-01-08 18:01:29 +08:00
|
|
|
| reg [15:0] ram[0:1023];
|
2023-09-08 16:37:31 +08:00
|
|
|
| reg [7:0] data_r_reg;
|
|
|
|
|
|
|
|
|
|
|
| always @(posedge clockw) begin
|
|
|
|
|
| if(enw) begin
|
|
|
|
|
| ram[addrw] <= #1 dataw;
|
|
|
|
|
| end
|
|
|
|
|
| end
|
|
|
|
|
|
|
|
|
|
|
| always @(posedge clockr) begin
|
|
|
|
|
| if(enr) begin
|
2024-01-08 18:01:29 +08:00
|
|
|
| data_r_reg <= #1 addrr[0] ? ram[addrr[10:1]][15:8] : ram[addrr[10:1]][7:0];
|
2023-09-08 16:37:31 +08:00
|
|
|
| end
|
|
|
|
|
| end
|
|
|
|
|
|
|
|
|
|
|
| assign datar = data_r_reg;
|
|
|
|
|
|
|
|
|
|
|
| initial begin
|
2024-01-08 18:01:29 +08:00
|
|
|
| for ( integer i = 0; i < 1024; i = i + 1 ) begin
|
2023-09-08 16:37:31 +08:00
|
|
|
| ram[i] = $random;
|
|
|
|
|
| end
|
|
|
|
|
|
|
|
|
|
|
| data_r_reg = $random;
|
|
|
|
|
| end
|
|
|
|
|
|
|
|
|
|
|
|endmodule
|
|
|
|
|
""".stripMargin)
|
|
|
|
|
}
|
2023-08-31 17:39:12 +08:00
|
|
|
|
|
|
|
|
|
2023-09-08 16:37:31 +08:00
|
|
|
class MirrorSRAMUp extends BlackBox with HasBlackBoxInline {
|
2023-08-31 17:39:12 +08:00
|
|
|
|
2023-09-08 16:37:31 +08:00
|
|
|
class MirrorSRAMUpIO extends Bundle{
|
2024-01-08 18:01:29 +08:00
|
|
|
val addrr = Input(UInt(10.W))
|
|
|
|
|
val addrw = Input(UInt(11.W))
|
2023-08-31 17:39:12 +08:00
|
|
|
|
2023-09-08 16:37:31 +08:00
|
|
|
val dataw = Input( UInt(8.W) )
|
|
|
|
|
val datar = Output( UInt(16.W) )
|
|
|
|
|
val enw = Input(Bool())
|
|
|
|
|
val enr = Input(Bool())
|
2023-08-31 17:39:12 +08:00
|
|
|
|
2023-09-08 16:37:31 +08:00
|
|
|
val clockr = Input(Bool())
|
|
|
|
|
val clockw = Input(Bool())
|
2023-08-31 17:39:12 +08:00
|
|
|
|
2023-09-08 16:37:31 +08:00
|
|
|
}
|
|
|
|
|
val io: MirrorSRAMUpIO = IO(new MirrorSRAMUpIO)
|
2023-08-31 17:39:12 +08:00
|
|
|
|
2023-09-08 16:37:31 +08:00
|
|
|
setInline("MirrorSRAMUp.v",
|
|
|
|
|
"""
|
|
|
|
|
| module MirrorSRAMUp(
|
|
|
|
|
| input [7:0] dataw,
|
2024-01-08 18:01:29 +08:00
|
|
|
| input [10:0] addrw,
|
2023-09-08 16:37:31 +08:00
|
|
|
| input enw,
|
|
|
|
|
|
|
|
|
|
|
| output [15:0] datar,
|
2024-01-08 18:01:29 +08:00
|
|
|
| input [9:0] addrr,
|
2023-09-08 16:37:31 +08:00
|
|
|
| input enr,
|
|
|
|
|
|
|
|
|
|
|
| input clockr,
|
|
|
|
|
| input clockw
|
|
|
|
|
| );
|
|
|
|
|
|
|
2024-03-27 17:25:53 +08:00
|
|
|
| reg [7:0] ram[0:2047] /* synthesis syn_ramstyle="block_ram" */;
|
2023-09-08 16:37:31 +08:00
|
|
|
| reg [15:0] data_r_reg;
|
|
|
|
|
|
|
2023-09-11 17:39:19 +08:00
|
|
|
| always @(posedge clockw) begin
|
|
|
|
|
| if(enw) begin
|
2024-03-27 17:25:53 +08:00
|
|
|
| ram[addrw] <= #1 dataw;
|
|
|
|
|
| end
|
2023-09-11 17:39:19 +08:00
|
|
|
| end
|
2023-09-08 16:37:31 +08:00
|
|
|
|
|
2024-03-27 17:25:53 +08:00
|
|
|
| always @(posedge clockr) begin
|
|
|
|
|
| if(enr) begin
|
|
|
|
|
| data_r_reg <= #1 { ram[2*addrr+1], ram[2*addrr] };
|
|
|
|
|
| end
|
|
|
|
|
| end
|
2023-09-08 16:37:31 +08:00
|
|
|
|
|
|
|
|
|
| assign datar = data_r_reg;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|endmodule
|
|
|
|
|
""".stripMargin)
|
|
|
|
|
}
|
2023-08-31 17:39:12 +08:00
|
|
|
|
|
|
|
|
|
2023-08-23 19:32:41 +08:00
|
|
|
|
|
|
|
|
|
2023-08-16 22:25:30 +08:00
|
|
|
|