2023-08-16 22:25:30 +08:00
|
|
|
package BACK
|
|
|
|
|
|
|
|
|
|
import chisel3._
|
|
|
|
|
import chisel3.util._
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2024-03-27 19:37:54 +08:00
|
|
|
class MirrorSRAMDP extends BlackBox with HasBlackBoxInline {
|
|
|
|
|
|
|
|
|
|
class MirrorSRAMDPIO extends Bundle{
|
|
|
|
|
|
|
|
|
|
val addrA = Input(UInt(10.W))
|
|
|
|
|
val datawA = Input( UInt(16.W) )
|
|
|
|
|
val datarA = Output( UInt(16.W) )
|
|
|
|
|
val enwA = Input(Bool())
|
2024-03-28 15:09:48 +08:00
|
|
|
val enrA = Input(Bool())
|
2024-03-27 19:37:54 +08:00
|
|
|
val clockA = Input(Bool())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val addrB = Input(UInt(10.W))
|
|
|
|
|
val datawB = Input( UInt(16.W) )
|
|
|
|
|
val datarB = Output( UInt(16.W) )
|
|
|
|
|
val enwB = Input(Bool())
|
2024-03-28 15:09:48 +08:00
|
|
|
val enrB = Input(Bool())
|
2024-03-27 19:37:54 +08:00
|
|
|
val clockB = Input(Bool())
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
val io: MirrorSRAMDPIO = IO(new MirrorSRAMDPIO)
|
|
|
|
|
|
|
|
|
|
setInline("MirrorSRAMDP.v",
|
|
|
|
|
"""
|
|
|
|
|
| module MirrorSRAMDP(
|
|
|
|
|
| input [15:0] datawA,
|
|
|
|
|
| input [9:0] addrA,
|
|
|
|
|
| input enwA,
|
2024-03-28 15:09:48 +08:00
|
|
|
| input enrA,
|
2024-03-27 19:37:54 +08:00
|
|
|
| output [15:0] datarA,
|
|
|
|
|
| input clockA,
|
|
|
|
|
|
|
|
|
|
|
| input [15:0] datawB,
|
|
|
|
|
| input [9:0] addrB,
|
2024-03-28 15:09:48 +08:00
|
|
|
| input enwB,
|
|
|
|
|
| input enrB,
|
2024-03-27 19:37:54 +08:00
|
|
|
| output [15:0] datarB,
|
|
|
|
|
| input clockB
|
|
|
|
|
| );
|
|
|
|
|
|
|
2024-03-28 15:09:48 +08:00
|
|
|
| reg [15:0] mem[0:1023];
|
|
|
|
|
| reg [15:0] data_outa_reg = 16'b0;
|
|
|
|
|
| reg [15:0] data_outb_reg = 16'b0;
|
|
|
|
|
|
|
|
|
|
|
| assign datarA = data_outa_reg;
|
|
|
|
|
| assign datarB = data_outb_reg;
|
|
|
|
|
|
|
|
|
|
|
| always@( posedge clockA ) begin
|
|
|
|
|
| if( enrA ) begin
|
|
|
|
|
| end
|
|
|
|
|
|
|
|
|
|
|
| if( enwA ) begin
|
|
|
|
|
| mem[addrA] <= datawA;
|
|
|
|
|
| end else begin
|
|
|
|
|
| data_outa_reg <= mem[addrA];
|
|
|
|
|
| end
|
|
|
|
|
| end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| always@( posedge clockB ) begin
|
|
|
|
|
| if(enrB) begin
|
|
|
|
|
| end
|
|
|
|
|
|
|
|
|
|
|
| if( enwB ) begin
|
|
|
|
|
| mem[addrB] <= datawB;
|
|
|
|
|
| end else begin
|
|
|
|
|
| data_outb_reg <= mem[addrB];
|
|
|
|
|
| end
|
|
|
|
|
| end
|
|
|
|
|
|
|
2024-10-17 15:32:16 +08:00
|
|
|
| initial begin
|
|
|
|
|
| for( integer i = 0; i < 1024; i = i + 1 ) begin
|
|
|
|
|
| mem[i] = $random;
|
|
|
|
|
| end
|
|
|
|
|
| end
|
2024-03-28 15:09:48 +08:00
|
|
|
|
|
|
|
|
|
| //Gowin_DPB your_instance_name(
|
|
|
|
|
| // .douta(datarA), //output [15:0] douta
|
|
|
|
|
| // .doutb(datarB), //output [15:0] doutb
|
|
|
|
|
| // .clka(clockA), //input clka
|
|
|
|
|
| // .ocea(1'b1), //input ocea
|
|
|
|
|
| // .cea(1'b1), //input cea
|
|
|
|
|
| // .reseta(1'b0), //input reseta
|
|
|
|
|
| // .wrea(enwA), //input wrea
|
|
|
|
|
| // .clkb(clockB), //input clkb
|
|
|
|
|
| // .oceb(1'b1), //input oceb
|
|
|
|
|
| // .ceb(1'b1), //input ceb
|
|
|
|
|
| // .resetb(1'b0), //input resetb
|
|
|
|
|
| // .wreb(enwB), //input wreb
|
|
|
|
|
| // .ada(addrA), //input [3:0] ada
|
|
|
|
|
| // .dina(datawA), //input [15:0] dina
|
|
|
|
|
| // .adb(addrB), //input [3:0] adb
|
|
|
|
|
| // .dinb(datawB) //input [15:0] dinb
|
|
|
|
|
| //);
|
2024-03-27 19:37:54 +08:00
|
|
|
|
|
|
|
|
|
|endmodule
|
|
|
|
|
""".stripMargin)
|
|
|
|
|
}
|
2023-08-23 19:32:41 +08:00
|
|
|
|
2023-08-16 22:25:30 +08:00
|
|
|
|
2024-06-28 10:27:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-06-28 18:39:35 +08:00
|
|
|
|
|
|
|
|
class SpiSRAMDown() extends BlackBox with HasBlackBoxInline {
|
|
|
|
|
class SpiSRAMDownIO extends Bundle{
|
|
|
|
|
val addrr = Input(UInt(9.W))
|
|
|
|
|
val addrw = Input(UInt(9.W))
|
|
|
|
|
|
|
|
|
|
val dataw = Input( UInt(8.W) )
|
|
|
|
|
val datar = Output( UInt(8.W) )
|
2024-06-28 10:27:32 +08:00
|
|
|
val enw = Input(Bool())
|
|
|
|
|
val enr = Input(Bool())
|
|
|
|
|
|
|
|
|
|
val clockr = Input(Bool())
|
|
|
|
|
val clockw = Input(Bool())
|
|
|
|
|
|
|
|
|
|
}
|
2024-06-28 18:39:35 +08:00
|
|
|
val io: SpiSRAMDownIO = IO(new SpiSRAMDownIO)
|
2024-06-28 10:27:32 +08:00
|
|
|
|
2024-06-28 18:39:35 +08:00
|
|
|
setInline("SpiSRAMDown.v",
|
2024-06-28 10:27:32 +08:00
|
|
|
"""
|
2024-06-28 18:39:35 +08:00
|
|
|
| module SpiSRAMDown(
|
|
|
|
|
| input [7:0] dataw,
|
|
|
|
|
| input [8:0] addrw,
|
2024-06-28 10:27:32 +08:00
|
|
|
| input enw,
|
2024-06-28 18:39:35 +08:00
|
|
|
|
|
|
|
|
|
| output [7:0] datar,
|
|
|
|
|
| input [8:0] addrr,
|
2024-06-28 10:27:32 +08:00
|
|
|
| input enr,
|
|
|
|
|
|
|
|
|
|
|
| input clockr,
|
2024-06-28 18:39:35 +08:00
|
|
|
| input clockw
|
2024-06-28 10:27:32 +08:00
|
|
|
| );
|
|
|
|
|
|
|
2024-06-28 18:39:35 +08:00
|
|
|
| reg [7:0] ram[0:511];
|
|
|
|
|
| reg [7:0] data_r_reg;
|
2024-06-28 10:27:32 +08:00
|
|
|
|
|
2024-06-28 18:39:35 +08:00
|
|
|
| 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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|endmodule
|
|
|
|
|
""".stripMargin)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SpiSRAMUp extends BlackBox with HasBlackBoxInline {
|
|
|
|
|
|
|
|
|
|
class SpiSRAMUpIO extends Bundle{
|
|
|
|
|
val addrr = Input(UInt(9.W))
|
|
|
|
|
val addrw = Input(UInt(9.W))
|
|
|
|
|
|
|
|
|
|
val dataw = Input( UInt(8.W) )
|
|
|
|
|
val datar = Output( UInt(8.W) )
|
|
|
|
|
val enw = Input(Bool())
|
|
|
|
|
val enr = Input(Bool())
|
|
|
|
|
|
|
|
|
|
val clockr = Input(Bool())
|
|
|
|
|
val clockw = Input(Bool())
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
val io: SpiSRAMUpIO = IO(new SpiSRAMUpIO)
|
|
|
|
|
|
|
|
|
|
setInline("SpiSRAMUp.v",
|
|
|
|
|
"""
|
|
|
|
|
| module SpiSRAMUp(
|
|
|
|
|
| input [7:0] dataw,
|
|
|
|
|
| input [8:0] addrw,
|
|
|
|
|
| input enw,
|
|
|
|
|
|
|
|
|
|
|
| output [7:0] datar,
|
|
|
|
|
| input [8:0] addrr,
|
|
|
|
|
| input enr,
|
|
|
|
|
|
|
|
|
|
|
| input clockr,
|
|
|
|
|
| input clockw
|
|
|
|
|
| );
|
|
|
|
|
|
|
|
|
|
|
| reg [7:0] ram[0:511];
|
|
|
|
|
| reg [7:0] data_r_reg;
|
|
|
|
|
|
|
|
|
|
|
| always @(posedge clockw) begin
|
|
|
|
|
| if(enw) begin
|
|
|
|
|
| ram[addrw] <= #1 dataw;
|
2024-06-28 10:27:32 +08:00
|
|
|
| end
|
|
|
|
|
| end
|
|
|
|
|
|
|
2024-06-28 18:39:35 +08:00
|
|
|
| always @(posedge clockr) begin
|
|
|
|
|
| if(enr) begin
|
|
|
|
|
| data_r_reg <= #1 ram[addrr];
|
|
|
|
|
| end
|
|
|
|
|
| end
|
2024-06-28 10:27:32 +08:00
|
|
|
|
|
|
|
|
|
| assign datar = data_r_reg;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|endmodule
|
|
|
|
|
""".stripMargin)
|
|
|
|
|
}
|