fifo完成了, 准备上板子实验

main
阳光少年 8 months ago
parent 26044eecd5
commit c81d916a28

@ -0,0 +1,47 @@
// fifo, ,
module fifo_rd(
input rd_clk,
input rst,
input [7:0] fifo_rd_data, // fifo
input is_full, // ,
input is_almost_empty, //
input is_rd_rst_busy, //
output reg fifo_rd_en //
);
reg is_full_0;
reg is_full_1;
always @(posedge rd_clk or negedge rst) begin
if (!rst) begin
is_full_0 <= 1'b0;
is_full_1 <= 1'b0;
end
else begin
is_full_0 <= is_full;
is_full_1 <= is_full_0;
end
end
//
always @(posedge rd_clk or negedge rst) begin
if (!rst) begin
fifo_rd_en <= 1'b0;
end
else if (!is_rd_rst_busy) begin //
if (is_full_1) begin // ,
fifo_rd_en <= 1'b1;
end
else if(is_almost_empty) begin // ,
fifo_rd_en <= 1'b0;
end
else begin
end
end
else begin
end
end
endmodule

@ -0,0 +1,94 @@
#! /usr/local/Cellar/icarus-verilog/12.0/bin/vvp
:ivl_version "12.0 (stable)";
:ivl_delay_selection "TYPICAL";
:vpi_time_precision + 0;
:vpi_module "/usr/local/Cellar/icarus-verilog/12.0/lib/ivl/system.vpi";
:vpi_module "/usr/local/Cellar/icarus-verilog/12.0/lib/ivl/vhdl_sys.vpi";
:vpi_module "/usr/local/Cellar/icarus-verilog/12.0/lib/ivl/vhdl_textio.vpi";
:vpi_module "/usr/local/Cellar/icarus-verilog/12.0/lib/ivl/v2005_math.vpi";
:vpi_module "/usr/local/Cellar/icarus-verilog/12.0/lib/ivl/va_math.vpi";
S_0x7f7d3cf06130 .scope module, "fifo_rd" "fifo_rd" 2 3;
.timescale 0 0;
.port_info 0 /INPUT 1 "rd_clk";
.port_info 1 /INPUT 1 "rst";
.port_info 2 /INPUT 8 "fifo_rd_data";
.port_info 3 /INPUT 1 "is_full";
.port_info 4 /INPUT 1 "is_almost_empty";
.port_info 5 /INPUT 1 "is_rd_rst_busy";
.port_info 6 /OUTPUT 1 "fifo_rd_en";
o0x7f7d3dc32008 .functor BUFZ 8, C4<zzzzzzzz>; HiZ drive
v0x7f7d3cf06980_0 .net "fifo_rd_data", 7 0, o0x7f7d3dc32008; 0 drivers
v0x7f7d3cf16970_0 .var "fifo_rd_en", 0 0;
o0x7f7d3dc32068 .functor BUFZ 1, C4<z>; HiZ drive
v0x7f7d3cf16a10_0 .net "is_almost_empty", 0 0, o0x7f7d3dc32068; 0 drivers
o0x7f7d3dc32098 .functor BUFZ 1, C4<z>; HiZ drive
v0x7f7d3cf16aa0_0 .net "is_full", 0 0, o0x7f7d3dc32098; 0 drivers
v0x7f7d3cf16b40_0 .var "is_full_0", 0 0;
v0x7f7d3cf16c20_0 .var "is_full_1", 0 0;
o0x7f7d3dc32128 .functor BUFZ 1, C4<z>; HiZ drive
v0x7f7d3cf16cc0_0 .net "is_rd_rst_busy", 0 0, o0x7f7d3dc32128; 0 drivers
o0x7f7d3dc32158 .functor BUFZ 1, C4<z>; HiZ drive
v0x7f7d3cf16d60_0 .net "rd_clk", 0 0, o0x7f7d3dc32158; 0 drivers
o0x7f7d3dc32188 .functor BUFZ 1, C4<z>; HiZ drive
v0x7f7d3cf16e00_0 .net "rst", 0 0, o0x7f7d3dc32188; 0 drivers
E_0x7f7d3cf06390/0 .event negedge, v0x7f7d3cf16e00_0;
E_0x7f7d3cf06390/1 .event posedge, v0x7f7d3cf16d60_0;
E_0x7f7d3cf06390 .event/or E_0x7f7d3cf06390/0, E_0x7f7d3cf06390/1;
.scope S_0x7f7d3cf06130;
T_0 ;
%wait E_0x7f7d3cf06390;
%load/vec4 v0x7f7d3cf16e00_0;
%nor/r;
%flag_set/vec4 8;
%jmp/0xz T_0.0, 8;
%pushi/vec4 0, 0, 1;
%assign/vec4 v0x7f7d3cf16b40_0, 0;
%pushi/vec4 0, 0, 1;
%assign/vec4 v0x7f7d3cf16c20_0, 0;
%jmp T_0.1;
T_0.0 ;
%load/vec4 v0x7f7d3cf16aa0_0;
%assign/vec4 v0x7f7d3cf16b40_0, 0;
%load/vec4 v0x7f7d3cf16b40_0;
%assign/vec4 v0x7f7d3cf16c20_0, 0;
T_0.1 ;
%jmp T_0;
.thread T_0;
.scope S_0x7f7d3cf06130;
T_1 ;
%wait E_0x7f7d3cf06390;
%load/vec4 v0x7f7d3cf16e00_0;
%nor/r;
%flag_set/vec4 8;
%jmp/0xz T_1.0, 8;
%pushi/vec4 0, 0, 1;
%assign/vec4 v0x7f7d3cf16970_0, 0;
%jmp T_1.1;
T_1.0 ;
%load/vec4 v0x7f7d3cf16cc0_0;
%nor/r;
%flag_set/vec4 8;
%jmp/0xz T_1.2, 8;
%load/vec4 v0x7f7d3cf16c20_0;
%flag_set/vec4 8;
%jmp/0xz T_1.4, 8;
%pushi/vec4 1, 0, 1;
%assign/vec4 v0x7f7d3cf16970_0, 0;
%jmp T_1.5;
T_1.4 ;
%load/vec4 v0x7f7d3cf16a10_0;
%flag_set/vec4 8;
%jmp/0xz T_1.6, 8;
%pushi/vec4 0, 0, 1;
%assign/vec4 v0x7f7d3cf16970_0, 0;
T_1.6 ;
T_1.5 ;
T_1.2 ;
T_1.1 ;
%jmp T_1;
.thread T_1;
# The file index is used to find the file name in the following table.
:file_names 3;
"N/A";
"<interactive>";
"fifo_rd.v";

@ -0,0 +1,66 @@
// fifo, fifo
// , fifo, ,
module fifo_wr(
input wr_clk,
input rst,
input is_empty, // fifo, wr_clk,
input is_almost_full, //
input is_wr_rst_busy, // ,
//
output reg fifo_wr_en, //
output reg [7:0] fifo_wr_data //
);
// , is_empty , is_empty
reg is_empty_0;
reg is_empty_1;
always @(posedge wr_clk or negedge rst) begin
if (!rst) begin
is_empty_0 <= 1'b0;
is_empty_1 <= 1'b0;
end
else begin
is_empty_0 <= is_empty;
is_empty_1 <= is_empty_0;
end
end
// ,
always @(posedge wr_clk or negedge rst) begin
if (!rst) begin
fifo_wr_en <= 1'b0;
end
else if (!is_wr_rst_busy) begin // fifo
if (is_empty_1) begin // // ,
fifo_wr_en <= 1'b1;
end
else if(is_almost_full) begin // ,1,
// , ,
fifo_wr_en <= 1'b0;
end
else begin
end
end
else begin
end
end
//
always @(posedge wr_clk or negedge rst) begin
if (!rst) begin
fifo_wr_data <= 8'b0;
end
else if(fifo_wr_en && fifo_wr_data < 8'd254) begin // ip256, 255, 0~254
fifo_wr_data <= fifo_wr_data + 8'b1; // 253, 1 254, 0~254
end
else begin
fifo_wr_data <= 8'b0;
end
end
endmodule

@ -0,0 +1,126 @@
#! /usr/local/Cellar/icarus-verilog/12.0/bin/vvp
:ivl_version "12.0 (stable)";
:ivl_delay_selection "TYPICAL";
:vpi_time_precision + 0;
:vpi_module "/usr/local/Cellar/icarus-verilog/12.0/lib/ivl/system.vpi";
:vpi_module "/usr/local/Cellar/icarus-verilog/12.0/lib/ivl/vhdl_sys.vpi";
:vpi_module "/usr/local/Cellar/icarus-verilog/12.0/lib/ivl/vhdl_textio.vpi";
:vpi_module "/usr/local/Cellar/icarus-verilog/12.0/lib/ivl/v2005_math.vpi";
:vpi_module "/usr/local/Cellar/icarus-verilog/12.0/lib/ivl/va_math.vpi";
S_0x7fde7b104830 .scope module, "fifo_wr" "fifo_wr" 2 3;
.timescale 0 0;
.port_info 0 /INPUT 1 "wr_clk";
.port_info 1 /INPUT 1 "rst";
.port_info 2 /INPUT 1 "is_empty";
.port_info 3 /INPUT 1 "is_almost_full";
.port_info 4 /INPUT 1 "is_wr_rst_busy";
.port_info 5 /OUTPUT 1 "fifo_wr_en";
.port_info 6 /OUTPUT 8 "fifo_wr_data";
v0x7fde7b104b00_0 .var "fifo_wr_data", 7 0;
v0x7fde7b114bc0_0 .var "fifo_wr_en", 0 0;
o0x7fde7b232068 .functor BUFZ 1, C4<z>; HiZ drive
v0x7fde7b114c60_0 .net "is_almost_full", 0 0, o0x7fde7b232068; 0 drivers
o0x7fde7b232098 .functor BUFZ 1, C4<z>; HiZ drive
v0x7fde7b114cf0_0 .net "is_empty", 0 0, o0x7fde7b232098; 0 drivers
v0x7fde7b114d90_0 .var "is_empty_0", 0 0;
v0x7fde7b114e70_0 .var "is_empty_1", 0 0;
o0x7fde7b232128 .functor BUFZ 1, C4<z>; HiZ drive
v0x7fde7b114f10_0 .net "is_wr_rst_busy", 0 0, o0x7fde7b232128; 0 drivers
o0x7fde7b232158 .functor BUFZ 1, C4<z>; HiZ drive
v0x7fde7b114fb0_0 .net "rst", 0 0, o0x7fde7b232158; 0 drivers
o0x7fde7b232188 .functor BUFZ 1, C4<z>; HiZ drive
v0x7fde7b115050_0 .net "wr_clk", 0 0, o0x7fde7b232188; 0 drivers
E_0x7fde7b104aa0/0 .event negedge, v0x7fde7b114fb0_0;
E_0x7fde7b104aa0/1 .event posedge, v0x7fde7b115050_0;
E_0x7fde7b104aa0 .event/or E_0x7fde7b104aa0/0, E_0x7fde7b104aa0/1;
.scope S_0x7fde7b104830;
T_0 ;
%wait E_0x7fde7b104aa0;
%load/vec4 v0x7fde7b114fb0_0;
%nor/r;
%flag_set/vec4 8;
%jmp/0xz T_0.0, 8;
%pushi/vec4 0, 0, 1;
%assign/vec4 v0x7fde7b114d90_0, 0;
%pushi/vec4 0, 0, 1;
%assign/vec4 v0x7fde7b114e70_0, 0;
%jmp T_0.1;
T_0.0 ;
%load/vec4 v0x7fde7b114cf0_0;
%assign/vec4 v0x7fde7b114d90_0, 0;
%load/vec4 v0x7fde7b114d90_0;
%assign/vec4 v0x7fde7b114e70_0, 0;
T_0.1 ;
%jmp T_0;
.thread T_0;
.scope S_0x7fde7b104830;
T_1 ;
%wait E_0x7fde7b104aa0;
%load/vec4 v0x7fde7b114fb0_0;
%nor/r;
%flag_set/vec4 8;
%jmp/0xz T_1.0, 8;
%pushi/vec4 0, 0, 1;
%assign/vec4 v0x7fde7b114bc0_0, 0;
%jmp T_1.1;
T_1.0 ;
%load/vec4 v0x7fde7b114f10_0;
%nor/r;
%flag_set/vec4 8;
%jmp/0xz T_1.2, 8;
%load/vec4 v0x7fde7b114e70_0;
%flag_set/vec4 8;
%jmp/0xz T_1.4, 8;
%pushi/vec4 1, 0, 1;
%assign/vec4 v0x7fde7b114bc0_0, 0;
%jmp T_1.5;
T_1.4 ;
%load/vec4 v0x7fde7b114c60_0;
%flag_set/vec4 8;
%jmp/0xz T_1.6, 8;
%pushi/vec4 0, 0, 1;
%assign/vec4 v0x7fde7b114bc0_0, 0;
T_1.6 ;
T_1.5 ;
T_1.2 ;
T_1.1 ;
%jmp T_1;
.thread T_1;
.scope S_0x7fde7b104830;
T_2 ;
%wait E_0x7fde7b104aa0;
%load/vec4 v0x7fde7b114fb0_0;
%nor/r;
%flag_set/vec4 8;
%jmp/0xz T_2.0, 8;
%pushi/vec4 0, 0, 8;
%assign/vec4 v0x7fde7b104b00_0, 0;
%jmp T_2.1;
T_2.0 ;
%load/vec4 v0x7fde7b114bc0_0;
%flag_set/vec4 9;
%flag_get/vec4 9;
%jmp/0 T_2.4, 9;
%load/vec4 v0x7fde7b104b00_0;
%cmpi/u 254, 0, 8;
%flag_get/vec4 5;
%and;
T_2.4;
%flag_set/vec4 8;
%jmp/0xz T_2.2, 8;
%load/vec4 v0x7fde7b104b00_0;
%addi 1, 0, 8;
%assign/vec4 v0x7fde7b104b00_0, 0;
%jmp T_2.3;
T_2.2 ;
%pushi/vec4 0, 0, 8;
%assign/vec4 v0x7fde7b104b00_0, 0;
T_2.3 ;
T_2.1 ;
%jmp T_2;
.thread T_2;
# The file index is used to find the file name in the following table.
:file_names 3;
"N/A";
"<interactive>";
"fifo_wr.v";

@ -0,0 +1,22 @@
`timescale 1ns/1ns
module tb_fifo()
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
test_fifo u_test_fifo(
.sys_clk(sys_clk),
.sys_rst(sys_rst)
);
endmodule

@ -0,0 +1,79 @@
// , fifo, fifoip
// : , , ,
// : , ,
// , ,
// /, , 1, /
// , 0, fullemtpy,
module test_fifo(
input wire sys_clk, // U18
input wire sys_rst //J15
);
wire clk_100m;
wire clk_50m;
wire locked;
wire logic_rst;
assign logic_rst = sys_rst && locked; // ()
wire is_empty;
wire is_almost_full;
wire is_wr_rst_busy;
wire fifo_wr_en;
wire fifo_wr_data;
fifo_wr u_fifo_wr(
.wr_clk(clk_50m),
.rst(logic_rst),
.is_empty(is_empty),
.is_almost_full(is_almost_full),
.is_wr_rst_busy(is_wr_rst_busy),
.fifo_wr_en(fifo_wr_en),
.fifo_wr_data(fifo_wr_data)
);
wire is_full;
wire is_almost_empty;
wire is_rd_rst_busy;
wire fifo_rd_en;
wire fifo_rd_data;
fifo_rd u_fifo_rd(
.rd_clk(clk_100m),
.rst(logic_rst),
.is_full(is_full),
.is_almost_empty(is_almost_empty),
.is_rd_rst_busy(is_rd_rst_busy),
.fifo_rd_en(fifo_rd_en),
.fifo_rd_data(fifo_rd_data)
);
clk_wiz_0 u_clk_wiz_0(
.clk_in1(sys_clk),
.clk_out1(clk_100m),
.clk_out2(clk_50m),
.locked(locked)
);
wire [7:0]rd_data_count;
wire [7:0]wr_data_count;
fifo_generator_0 u_fifo_generator_0(
.rst(~logic_rst), // ip, , logic_rst()
.wr_clk(clk_50m),
.rd_clk(clk_100m),
.din(fifo_wr_data),
.wr_en(fifo_wr_en),
.rd_en(fifo_rd_en),
.dout(fifo_rd_data),
.full(is_full),
.almost_full(is_almost_empty),
.rd_data_count(rd_data_count),
.wr_data_count(wr_data_count),
.wr_rst_busy(is_wr_rst_busy),
.rd_rst_busy(is_rd_rst_busy)
);
endmodule
Loading…
Cancel
Save