Skip to content

Commit 3c1c804

Browse files
committed
Add Makefile to run the tool and clean the folder
1 parent d882f08 commit 3c1c804

File tree

3 files changed

+59
-44
lines changed

3 files changed

+59
-44
lines changed

sim/test/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
UT="*unit_test.sv"
2+
3+
test:
4+
@svutRun.py
5+
6+
gui:
7+
@svutRun.py -gui
8+
9+
clean:
10+
@-rm -f *.vcd
11+
@-rm -f *.lxt*
12+
@-rm -f *.vvp*
13+

sim/test/async_fifo_unit_test.sv

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ module async_fifo_unit_test;
66

77
`SVUT_SETUP
88

9-
parameter WIDTH = 8;
10-
parameter POINTER = 4;
9+
parameter WIDTH = 8;
10+
parameter POINTER = 4;
1111

1212
reg wr_clk;
1313
reg awresetn;
@@ -22,8 +22,8 @@ module async_fifo_unit_test;
2222

2323
async_fifo
2424
#(
25-
.WIDTH (WIDTH),
26-
.POINTER (POINTER)
25+
,
26+
POINTER
2727
)
2828
dut
2929
(
@@ -39,10 +39,12 @@ module async_fifo_unit_test;
3939
rd_empty
4040
);
4141

42-
initial wr_clk = 0;
43-
initial rd_clk = 0;
44-
always #2 wr_clk <= ~wr_clk;
45-
always #2 rd_clk <= ~rd_clk;
42+
// An example to create a clock
43+
// initial aclk = 0;
44+
// always #2 aclk <= ~aclk;
45+
46+
// An example to dump data for visualization
47+
// initial $dumpvars(0,async_fifo_unit_test);
4648

4749
task setup();
4850
begin

src/vlog/async_fifo.v

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
Copyright 2017 Damien Pretet ThotIP
3-
3+
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
7-
7+
88
http://www.apache.org/licenses/LICENSE-2.0
9-
9+
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,
1212
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,36 +19,36 @@
1919

2020
module async_fifo
2121

22-
#(
23-
parameter WIDTH = 8,
24-
parameter POINTER = 4
25-
)(
22+
#(
23+
parameter WIDTH = 8,
24+
parameter POINTER = 4
25+
)(
2626
// Write side of the FIFO
27-
input wire wr_clk,
28-
input wire awresetn,
29-
input wire wren,
30-
input wire [WIDTH-1:0] data_in,
31-
output wire wr_full,
27+
input wire wr_clk,
28+
input wire awresetn,
29+
input wire wren,
30+
input wire [WIDTH-1:0] data_in,
31+
output wire wr_full,
3232
// Read side of the FIFO
33-
input wire rd_clk,
34-
input wire arresetn,
35-
input wire rden,
36-
output wire [WIDTH-1:0] data_out,
37-
output wire rd_empty
38-
);
33+
input wire rd_clk,
34+
input wire arresetn,
35+
input wire rden,
36+
output wire [WIDTH-1:0] data_out,
37+
output wire rd_empty
38+
);
3939

4040
localparam DEPTH = 1 << POINTER;
4141

4242
reg [POINTER-1 : 0] rd_pointer, rd_sync_1, rd_sync_2;
4343
reg [POINTER-1 : 0] wr_pointer, wr_sync_1, wr_sync_2;
4444
wire [POINTER-1 : 0] rd_pointer_g;
4545
wire [POINTER-1 : 0] wr_pointer_g;
46-
46+
4747
reg [WIDTH-1 : 0] mem [DEPTH-1 : 0];
48-
48+
4949
wire [POINTER-1 : 0] rd_pointer_sync;
5050
wire [POINTER-1 : 0] wr_pointer_sync;
51-
51+
5252
// Write logic management
5353
always @(posedge wr_clk or posedge awresetn) begin
5454
if (awresetn == 1'b0) begin
@@ -59,13 +59,13 @@ module async_fifo
5959
mem[wr_pointer[POINTER-1 : 0]] <= data_in;
6060
end
6161
end
62-
62+
6363
// Synchronization of read pointer with write clock
6464
always @(posedge wr_clk) begin
6565
rd_sync_1 <= rd_pointer_g;
6666
rd_sync_2 <= rd_sync_1;
6767
end
68-
68+
6969
// Read logic management
7070
always @(posedge rd_clk or posedge arresetn) begin
7171
if (arresetn == 1'b0) begin
@@ -75,40 +75,40 @@ module async_fifo
7575
rd_pointer <= rd_pointer + 1;
7676
end
7777
end
78-
78+
7979
assign data_out = mem[rd_pointer[POINTER-1 : 0]];
80-
80+
8181
// Write pointer synchronization with read clock
8282
always @(posedge rd_clk) begin
8383
wr_sync_1 <= wr_pointer_g;
8484
wr_sync_2 <= wr_sync_1;
8585
end
86-
86+
8787
// Binary pointer comparaison
8888
assign wr_full = ((wr_pointer[POINTER-1 : 0] == rd_pointer_sync[POINTER-1 : 0]) &&
8989
(wr_pointer[POINTER] != rd_pointer_sync[POINTER] ));
90-
90+
9191
// Gray counter comparaison
9292
//assign wr_full = ((wr_pointer[POINTER-2 : 0] == rd_pointer_sync[POINTER-2 : 0]) &&
9393
// (wr_pointer[POINTER-1] != rd_pointer_sync[POINTER-1]) &&
9494
// (wr_pointer[POINTER] != rd_pointer_sync[POINTER]));
95-
95+
9696
// The FIFO is considered as empty when pointer match the same address
97-
// No more data remains to read
97+
// No more data remains to read
9898
assign rd_empty = ((wr_pointer_sync == rd_pointer) == 0) ? 1'b1 : 1'b0;
99-
100-
101-
// Convert to gray before moving the pointers
99+
100+
101+
// Convert to gray before moving the pointers
102102
// to the destination clock domain
103103
assign wr_pointer_g = wr_pointer ^ (wr_pointer >> 1);
104104
assign rd_pointer_g = rd_pointer ^ (rd_pointer >> 1);
105-
106-
107-
// Convert back to binary after the synchronization from
105+
106+
107+
// Convert back to binary after the synchronization from
108108
// the source domain
109109
assign wr_pointer_sync = wr_sync_2 ^ (wr_sync_2 >> 1) ^
110110
(wr_sync_2 >> 2) ^ (wr_sync_2 >> 3);
111-
111+
112112
assign rd_pointer_sync = rd_sync_2 ^ (rd_sync_2 >> 1) ^
113113
(rd_sync_2 >> 2) ^ (rd_sync_2 >> 3);
114114

0 commit comments

Comments
 (0)