You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.6 KiB
Coq

// : din dout, dindout
// : dindout, , dout
// : dindout
// ram, 0~15, 0~7(0~7), 8~15()
module ram(
(*mark_debug="true"*)input wire sys_clk, // U18
(*mark_debug="true"*)input wire sys_rst //J15
);
(*mark_debug="true"*)reg [2:0]ram_addr; // 8, 0~7, 1, 0
(*mark_debug="true"*)reg [2:0]in_ram_data; // 3, , 0~7, ram_rw
(*mark_debug="true"*)wire [2:0]out_ram_data;
reg ram_en;
always @(posedge sys_clk or negedge sys_rst) begin
if (!sys_rst) begin
ram_en <= 1'b0;
end
// , ram
else begin
ram_en <= 1'b1;
end
end
(*mark_debug="true"*)reg [7:0]counter; // 15 , 0~15, 0~7, 8~15
wire ram_rw; // /
(*mark_debug="true"*)assign ram_rw = ram_en && (counter <= 8'b111); //
always @(posedge sys_clk or negedge sys_rst) begin
if (!sys_rst) begin
counter <= 8'b0;
end
// ram
else if (ram_en == 1'b0 || counter == 8'b1111) begin
counter <= 8'b0;
end
else begin
counter <= counter + 8'b1;
end
end
always @(posedge sys_clk or negedge sys_rst) begin
if (!sys_rst) begin
ram_addr <= 3'b0;
end
else if (ram_en && ram_addr < 3'b111) begin
ram_addr <= ram_addr + 3'b1;
end
else begin
ram_addr <= 3'b0;
end
end
always @(posedge sys_clk or negedge sys_rst) begin
if (!sys_rst) begin
in_ram_data <= 3'b0;
end
// ,
else if (ram_rw && in_ram_data < 3'b111) begin
in_ram_data <= in_ram_data + 3'b1;
end
else begin
in_ram_data <= 3'b0;
end
end
blk_mem_gen_0 _blk_mem_gen_0 (
.clka(sys_clk), // input wire clka
.ena(ram_en), // input wire ena
.wea(ram_rw), // input wire [0 : 0] wea
.addra(ram_addr), // input wire [2 : 0] addra
.dina(in_ram_data), // input wire [2 : 0] dina
.douta(out_ram_data) // output wire [2 : 0] douta
);
endmodule