forked from aws/aws-fpga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrl_fifo.sv
162 lines (129 loc) · 4.64 KB
/
srl_fifo.sv
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Amazon FPGA Hardware Development Kit
//
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Amazon Software License (the "License"). You may not use
// this file except in compliance with the License. A copy of the License is
// located at
//
// http://aws.amazon.com/asl/
//
// or in the "license" file accompanying this file. This file is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or
// implied. See the License for the specific language governing permissions and
// limitations under the License.
// Descriptions:
// A 32 deep synchronous FIFO with parameterized width built from SRL32E configured LUTs
// and flops
//
//-----------------------------------------------------------------------------
//Module Declaration
module srl_fifo #(parameter WIDTH = 64,
parameter DEPTH = 8,
parameter WATERMARK = DEPTH-1, // Should be minus1 of the actual watermark (for eg. if Depth = 4 and watermark = 3, then watermark is asserted when occupancy reaches 4)
parameter bit PIPELINE = 1
)
(
input clk,
input rst_n,
input [WIDTH-1:0] push_data,
input push,
input pop,
output logic [WIDTH-1:0] pop_data,
output logic data_valid,
output logic watermark = 0,
output logic empty = 1
);
localparam WATERMARK_MINUS1 = WATERMARK - 1;
localparam PTR_WIDTH = DEPTH > 16 ? 5 : 4;
logic rd_stall;
logic rd_en;
logic [PTR_WIDTH-1:0] rd_ptr = '1;
logic [WIDTH-1:0] srl_q;
logic data_valid_p = 0;
assign rd_stall = (PIPELINE == 1) ? data_valid & ~pop : ~pop;
assign rd_en = ~empty & ~rd_stall;
always @(posedge clk)
if (!rst_n) begin
rd_ptr <= '{default:'1};
watermark <= 0;
empty <= 1;
data_valid_p <= 0;
end
else begin
rd_ptr <= push & ~rd_en ? rd_ptr + 1 :
~push & rd_en ? rd_ptr - 1 : rd_ptr;
watermark <= push & ~rd_en ? (rd_ptr == WATERMARK_MINUS1) :
~push & rd_en ? 0 :
watermark;
empty <= push & ~rd_en ? 0 :
~push & rd_en ? (rd_ptr == 0) :
empty;
data_valid_p <= pop || ~data_valid_p ? rd_en :
data_valid_p;
end // else: !if(!rst_n)
genvar bit_idx;
generate
for (bit_idx = 0; bit_idx < WIDTH; bit_idx++) begin : srl_pipe
if (WIDTH > 16) begin: srl32
SRLC32E
#(.INIT (32'h00000000),
.IS_CLK_INVERTED (1'b0)
) SRL
(.CLK (clk),
.D (push_data[bit_idx]),
.CE (push),
.A (rd_ptr[PTR_WIDTH-1:0]),
.Q (srl_q[bit_idx]),
.Q31 ()
);
end // block: srl_instance
else begin : srl16
SRL16E
#(.INIT (16'h0000),
.IS_CLK_INVERTED (1'b0)
) SRL
(.CLK (clk),
.D (push_data[bit_idx]),
.CE (push),
.A3 (rd_ptr[3]),
.A2 (rd_ptr[2]),
.A1 (rd_ptr[1]),
.A0 (rd_ptr[0]),
.Q (srl_q[bit_idx])
);
end // block: srl16
if (PIPELINE == 1) begin : out_data_reg
FDRE #(.INIT (1'b0),
.IS_C_INVERTED (1'b0),
.IS_D_INVERTED (1'b0),
.IS_R_INVERTED (1'b1)
)
OUT_DATA_REG (.C (clk),
.R (rst_n),
.CE (rd_en),
.D (srl_q[bit_idx]),
.Q (pop_data[bit_idx])
);
end // block: out_data_reg
else begin : out_data_wire
assign pop_data[bit_idx] = srl_q[bit_idx];
end
end // block: srl_pipe
endgenerate
assign data_valid = (PIPELINE == 1) ? data_valid_p : ~empty;
//Simulation checks
//synopsys translate_off
always @(posedge clk)
if (rst_n) begin
if (DEPTH > 32) begin
$display ("%m: *** ERROR ***: Maximum Supported Depth is 32");
$finish;
end
if (DEPTH < 2) begin
$display ("%m: *** ERROR ***: Minimum Supported Depth is 2");
$finish;
end
end
//synopsys translate_on
endmodule // srl_fifo