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.

73 lines
1.7 KiB
Coq

`timescale 1ns/1ns
module tb_ram();
reg sys_clk;
reg sys_rst;
always #10 sys_clk = ~sys_clk;
initial begin
sys_clk <= 1'b0;
sys_rst <= 1'b0;
#50
sys_rst <= 1'b1;
end
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
reg [7:0]counter; // 15 , 0~15
wire ram_rw;
assign ram_rw = ram_en && (counter <= 8'b111); // , 0~7, 8~15
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
reg [2:0]ram_addr; // 0~7
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
reg [2:0]ram_data; // , 0~7, ram_rw
always @(posedge sys_clk or negedge sys_rst) begin
if (!sys_rst) begin
ram_data <= 3'b0;
end
// ,
else if (ram_rw && ram_data < 3'b111) begin
ram_data <= ram_data + 3'b1;
end
else begin
ram_data <= 3'b0;
end
end
endmodule