-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesign.sv
More file actions
119 lines (86 loc) · 4.86 KB
/
Copy pathdesign.sv
File metadata and controls
119 lines (86 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
module my_fifo #(
parameter DATA_W = 128 , // Data width
parameter DEPTH = 1024 , // Depth of FIFO
parameter UPP_TH = 4 , // Upper threshold to generate Almost-full
parameter LOW_TH = 2 // Lower threshold to generate Almost-empty
)
(
input clk , // Clock
input rstn , // Active-low Synchronous Reset
input i_wren , // Write Enable
input [DATA_W - 1 : 0] i_wrdata , // Write-data
output o_alm_full , // Almost-full signal
output o_full , // Full signal
input i_rden , // Read Enable
output [DATA_W - 1 : 0] o_rddata , // Read-data
output o_alm_empty , // Almost-empty signal
output o_empty // Empty signal
);
/*-------------------------------------------------------------------------------------------------------------------------------
Internal Registers/Signals
-------------------------------------------------------------------------------------------------------------------------------*/
logic [DATA_W - 1 : 0] data_rg [DEPTH] ; // Data array
logic [$clog2(DEPTH) - 1 : 0] wrptr_rg ; // Write pointer
logic [$clog2(DEPTH) - 1 : 0] rdptr_rg ; // Read pointer
logic [$clog2(DEPTH) : 0] dcount_rg ; // Data counter
logic wren_s ; // Write Enable signal generated iff FIFO is not full
logic rden_s ; // Read Enable signal generated iff FIFO is not empty
logic full_s ; // Full signal
logic empty_s ; // Empty signal
/*-------------------------------------------------------------------------------------------------------------------------------
Synchronous logic to write to and read from FIFO
-------------------------------------------------------------------------------------------------------------------------------*/
always @ (posedge clk) begin
if (!rstn) begin
data_rg <= '{default: '0} ;
wrptr_rg <= 0 ;
rdptr_rg <= 0 ;
dcount_rg <= 0 ;
end
else begin
/* FIFO write logic */
if (wren_s) begin
data_rg [wrptr_rg] <= i_wrdata ; // Data written to FIFO
if (wrptr_rg == DEPTH - 1) begin
wrptr_rg <= 0 ; // Reset write pointer
end
else begin
wrptr_rg <= wrptr_rg + 1 ; // Increment write pointer
end
end
/* FIFO read logic */
if (rden_s) begin
if (rdptr_rg == DEPTH - 1) begin
rdptr_rg <= 0 ; // Reset read pointer
end
else begin
rdptr_rg <= rdptr_rg + 1 ; // Increment read pointer
end
end
/* FIFO data counter update logic */
if (wren_s && !rden_s) begin // Write operation
dcount_rg <= dcount_rg + 1 ;
end
else if (!wren_s && rden_s) begin // Read operation
dcount_rg <= dcount_rg - 1 ;
end
end
end
/*-------------------------------------------------------------------------------------------------------------------------------
Continuous Assignments
-------------------------------------------------------------------------------------------------------------------------------*/
// Full and Empty internal
assign full_s = (dcount_rg == DEPTH) ? 1'b1 : 0 ;
assign empty_s = (dcount_rg == 0 ) ? 1'b1 : 0 ;
// Write and Read Enables internal
assign wren_s = i_wren & !full_s ;
assign rden_s = i_rden & !empty_s ;
// Full and Empty to output
assign o_full = full_s ;
assign o_empty = empty_s ;
// Almost-full and Almost-empty to output
assign o_alm_full = ((dcount_rg > UPP_TH) ? 1'b1 : 0) ;
assign o_alm_empty = (dcount_rg < LOW_TH) ? 1'b1 : 0 ;
// Read-data to output
assign o_rddata = data_rg [rdptr_rg] ;
endmodule