1 |
15 |
juko |
/*
|
2 |
|
|
* .--------------. .----------------. .------------.
|
3 |
|
|
* | .------------. | .--------------. | .----------. |
|
4 |
|
|
* | | ____ ____ | | | ____ ____ | | | ______ | |
|
5 |
|
|
* | ||_ || _|| | ||_ \ / _|| | | .' ___ || |
|
6 |
|
|
* ___ _ __ ___ _ __ | | | |__| | | | | | \/ | | | |/ .' \_|| |
|
7 |
|
|
* / _ \| '_ \ / _ \ '_ \ | | | __ | | | | | |\ /| | | | || | | |
|
8 |
|
|
* (_) | |_) | __/ | | || | _| | | |_ | | | _| |_\/_| |_ | | |\ `.___.'\| |
|
9 |
|
|
* \___/| .__/ \___|_| |_|| ||____||____|| | ||_____||_____|| | | `._____.'| |
|
10 |
|
|
* | | | | | | | | | | | |
|
11 |
|
|
* |_| | '------------' | '--------------' | '----------' |
|
12 |
|
|
* '--------------' '----------------' '------------'
|
13 |
|
|
*
|
14 |
|
|
* openHMC - An Open Source Hybrid Memory Cube Controller
|
15 |
|
|
* (C) Copyright 2014 Computer Architecture Group - University of Heidelberg
|
16 |
|
|
* www.ziti.uni-heidelberg.de
|
17 |
|
|
* B6, 26
|
18 |
|
|
* 68159 Mannheim
|
19 |
|
|
* Germany
|
20 |
|
|
*
|
21 |
|
|
* Contact: openhmc@ziti.uni-heidelberg.de
|
22 |
|
|
* http://ra.ziti.uni-heidelberg.de/openhmc
|
23 |
|
|
*
|
24 |
|
|
* This source file is free software: you can redistribute it and/or modify
|
25 |
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
26 |
|
|
* the Free Software Foundation, either version 3 of the License, or
|
27 |
|
|
* (at your option) any later version.
|
28 |
|
|
*
|
29 |
|
|
* This source file is distributed in the hope that it will be useful,
|
30 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
31 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
32 |
|
|
* GNU Lesser General Public License for more details.
|
33 |
|
|
*
|
34 |
|
|
* You should have received a copy of the GNU Lesser General Public License
|
35 |
|
|
* along with this source file. If not, see <http://www.gnu.org/licenses/>.
|
36 |
|
|
*
|
37 |
|
|
*
|
38 |
|
|
* Module name: openhmc_sync_fifo_reg_based
|
39 |
|
|
*
|
40 |
|
|
*/
|
41 |
|
|
|
42 |
|
|
`default_nettype none
|
43 |
|
|
|
44 |
|
|
module openhmc_sync_fifo_reg_based #(
|
45 |
|
|
`ifdef CAG_ASSERTIONS
|
46 |
|
|
parameter DISABLE_EMPTY_ASSERT = 0,
|
47 |
|
|
parameter DISABLE_FULL_ASSERT = 0,
|
48 |
|
|
parameter DISABLE_SHIFT_OUT_ASSERT = 0,
|
49 |
|
|
parameter DISABLE_XCHECK_ASSERT = 0,
|
50 |
|
|
`endif
|
51 |
|
|
parameter DWIDTH = 8,
|
52 |
|
|
parameter ENTRIES = 4
|
53 |
|
|
) (
|
54 |
|
|
input wire clk,
|
55 |
|
|
input wire res_n,
|
56 |
|
|
input wire shift_in,
|
57 |
|
|
input wire shift_out,
|
58 |
|
|
input wire [DWIDTH-1:0] d_in,
|
59 |
|
|
|
60 |
|
|
output wire[DWIDTH-1:0] d_out,
|
61 |
|
|
output reg full,
|
62 |
|
|
output reg empty,
|
63 |
|
|
output reg almost_full,
|
64 |
|
|
output reg almost_empty
|
65 |
|
|
);
|
66 |
|
|
|
67 |
|
|
//the fifo_reg can currently only have up to 2047 entries
|
68 |
|
|
localparam LG_ENTRIES = (ENTRIES <= 2) ? 1 :
|
69 |
|
|
(ENTRIES <= 4) ? 2 :
|
70 |
|
|
(ENTRIES <= 8) ? 3 :
|
71 |
|
|
(ENTRIES <= 16) ? 4 :
|
72 |
|
|
(ENTRIES <= 32) ? 5 :
|
73 |
|
|
(ENTRIES <= 64) ? 6 : 7;
|
74 |
|
|
|
75 |
|
|
reg [DWIDTH-1:0] entry [0:ENTRIES-1];
|
76 |
|
|
reg [LG_ENTRIES:0] wp;
|
77 |
|
|
|
78 |
|
|
integer i;
|
79 |
|
|
|
80 |
|
|
wire shiftout_clean, shiftin_clean;
|
81 |
|
|
|
82 |
|
|
// first stage of fifo is output
|
83 |
|
|
assign d_out = entry[0];
|
84 |
|
|
|
85 |
|
|
assign shiftout_clean = shift_out && !empty;
|
86 |
|
|
assign shiftin_clean = shift_in && !full;
|
87 |
|
|
|
88 |
|
|
`ifdef ASYNC_RES
|
89 |
|
|
always @(posedge clk or negedge res_n) `else
|
90 |
|
|
always @(posedge clk) `endif
|
91 |
|
|
begin
|
92 |
|
|
|
93 |
|
|
if(!res_n) begin
|
94 |
|
|
wp <= {LG_ENTRIES+1 {1'b0}};
|
95 |
|
|
full <= 1'b0;
|
96 |
|
|
empty <= 1'b1;
|
97 |
|
|
almost_empty <= 1'b1;
|
98 |
|
|
almost_full <= 1'b0;
|
99 |
|
|
`ifdef FULL_RES
|
100 |
|
|
for (i=0; i<ENTRIES; i=i+1)
|
101 |
|
|
entry[i] <= {DWIDTH {1'b0}};
|
102 |
|
|
`endif
|
103 |
|
|
end else begin
|
104 |
|
|
case ({shiftin_clean, shiftout_clean})
|
105 |
|
|
2'b01: // only shift-out, move entries, decrement WP if not already 0 and check status signals
|
106 |
|
|
begin
|
107 |
|
|
for (i=1; i<ENTRIES; i=i+1)
|
108 |
|
|
entry[i-1] <= entry[i];
|
109 |
|
|
|
110 |
|
|
if (|wp)
|
111 |
|
|
wp <= wp - 1'b1;
|
112 |
|
|
|
113 |
|
|
empty <= (wp == {{LG_ENTRIES {1'b0}}, 1'b1});
|
114 |
|
|
full <= 1'b0;
|
115 |
|
|
almost_full <= (wp >= ENTRIES+1-1);
|
116 |
|
|
almost_empty <= (wp < 1 + 2);
|
117 |
|
|
end
|
118 |
|
|
|
119 |
|
|
2'b10: // only shift-in, write at next free entry, increment WP and check status signals
|
120 |
|
|
begin
|
121 |
|
|
entry[wp[LG_ENTRIES-1:0]] <= d_in;
|
122 |
|
|
wp <= wp + 1'b1;
|
123 |
|
|
empty <= 1'b0;
|
124 |
|
|
full <= (wp >= ENTRIES - 1);
|
125 |
|
|
almost_full <= (wp >= ENTRIES-1-1);
|
126 |
|
|
almost_empty <= (wp < 1);
|
127 |
|
|
end
|
128 |
|
|
|
129 |
|
|
2'b11: //simultaneous shift-in and -out, move entries through shift registers
|
130 |
|
|
begin
|
131 |
|
|
for (i=1; i<ENTRIES; i=i+1)
|
132 |
|
|
entry[i-1] <= entry[i];
|
133 |
|
|
|
134 |
|
|
entry[wp[LG_ENTRIES-1:0]-1'b1] <= d_in;
|
135 |
|
|
end
|
136 |
|
|
default: begin
|
137 |
|
|
end
|
138 |
|
|
endcase
|
139 |
|
|
end
|
140 |
|
|
end
|
141 |
|
|
|
142 |
|
|
`ifdef CAG_COVERAGE
|
143 |
|
|
full_cov: cover property (@(posedge clk) disable iff(!res_n) (full == 1'b1));
|
144 |
|
|
almost_full_cov: cover property (@(posedge clk) disable iff(!res_n) (almost_full == 1'b1));
|
145 |
|
|
empty_cov: cover property (@(posedge clk) disable iff(!res_n) (empty == 1'b1));
|
146 |
|
|
almost_empty_cov: cover property (@(posedge clk) disable iff(!res_n) (almost_empty == 1'b1));
|
147 |
|
|
|
148 |
|
|
covergroup shift_in_and_out @(posedge clk);
|
149 |
|
|
shift_in_and_out_cp: coverpoint ({shift_in, shift_out}) iff (shift_in || shift_out)
|
150 |
|
|
{
|
151 |
|
|
bins count[] = {[1:3]};
|
152 |
|
|
}
|
153 |
|
|
endgroup
|
154 |
|
|
shift_in_and_out shift_in_and_out_I;
|
155 |
|
|
initial begin
|
156 |
|
|
shift_in_and_out_I = new();
|
157 |
|
|
shift_in_and_out_I.set_inst_name("shift_in_and_out_I");
|
158 |
|
|
end
|
159 |
|
|
`endif // CAG_COVERAGE
|
160 |
|
|
|
161 |
|
|
`ifdef CAG_ASSERTIONS
|
162 |
|
|
|
163 |
|
|
// when the FIFO signals empty, it must logically also be almost empty
|
164 |
|
|
empty_means_aempty : assert property (@(posedge clk) disable iff(!res_n) empty |-> almost_empty);
|
165 |
|
|
|
166 |
|
|
wp_eq_0_means_empty_A : assert property (@(posedge clk) disable iff(!res_n) (wp==0) |-> empty);
|
167 |
|
|
wp_eq_0_means_empty_B : assert property (@(posedge clk) disable iff(!res_n) empty |-> (wp==0));
|
168 |
|
|
|
169 |
|
|
aempty_condition_A : assert property (@(posedge clk) disable iff(!res_n) (wp>1) |-> !almost_empty);
|
170 |
|
|
aempty_condition_B : assert property (@(posedge clk) disable iff(!res_n) !almost_empty |-> (wp>1));
|
171 |
|
|
|
172 |
|
|
shift_in_and_full: assert property (@(posedge clk) disable iff(!res_n) (shift_in |-> !full));
|
173 |
|
|
|
174 |
|
|
if (DISABLE_SHIFT_OUT_ASSERT == 0)
|
175 |
|
|
shift_out_and_empty: assert property (@(posedge clk) disable iff(!res_n) (shift_out |-> !empty));
|
176 |
|
|
|
177 |
|
|
if (DISABLE_XCHECK_ASSERT == 0)
|
178 |
|
|
dout_known: assert property (@(posedge clk) disable iff(!res_n) (!empty |-> !$isunknown(d_out)));
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
final
|
182 |
|
|
begin
|
183 |
|
|
if (DISABLE_FULL_ASSERT == 0)
|
184 |
|
|
begin
|
185 |
|
|
assert_full_set: assert (!full);
|
186 |
|
|
assert_almost_full_set: assert (!almost_full);
|
187 |
|
|
end
|
188 |
|
|
|
189 |
|
|
if (DISABLE_EMPTY_ASSERT == 0)
|
190 |
|
|
begin
|
191 |
|
|
assert_write_pointer_not_zero: assert (wp == 0);
|
192 |
|
|
assert_almost_empty_not_set: assert (almost_empty);
|
193 |
|
|
assert_empty_not_set: assert (empty);
|
194 |
|
|
end
|
195 |
|
|
end
|
196 |
|
|
`endif // CAG_ASSERTIONS
|
197 |
|
|
|
198 |
|
|
endmodule
|
199 |
|
|
|
200 |
|
|
`default_nettype wire
|