OpenCores
URL https://opencores.org/ocsvn/openhmc/openhmc/trunk

Subversion Repositories openhmc

[/] [openhmc/] [trunk/] [openHMC/] [rtl/] [building_blocks/] [fifos/] [sync/] [openhmc_sync_fifo.v] - Blame information for rev 11

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 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
39
 *
40
 */
41
 
42
`default_nettype none
43
 
44
module openhmc_sync_fifo #(
45
`ifdef CAG_ASSERTIONS
46
        parameter DISABLE_EMPTY_ASSERT      = 0,
47
        parameter DISABLE_SHIFT_OUT_ASSERT  = 0,
48
        parameter DISABLE_XCHECK_ASSERT     = 0,
49
`endif
50
        parameter DATASIZE                  = 8,
51
        parameter ADDRSIZE                  = 8
52
    ) (
53
        //----------------------------------
54
        //----SYSTEM INTERFACE
55
        //----------------------------------
56
        input wire                  clk,
57
        input wire                  res_n,
58
 
59
        //----------------------------------
60
        //----Signals
61
        //----------------------------------
62
        input wire [DATASIZE-1:0]   d_in,
63
        input wire                  shift_in,
64
        input wire                  shift_out,
65
        input wire                  next_stage_full, // Set to 1 if not chained
66
        output wire [DATASIZE-1:0]  d_out,
67
        output wire                 empty
68
    );
69
 
70
//=====================================================================================================
71
//-----------------------------------------------------------------------------------------------------
72
//---------WIRING AND SIGNAL STUFF---------------------------------------------------------------------
73
//-----------------------------------------------------------------------------------------------------
74
//=====================================================================================================
75
 
76
wire si, so;    // internal gated shift signals
77
reg full_r1, full_r2;
78
wire full_1, full_2, full_3;
79
reg full_m2, full_m1;
80
 
81
reg [DATASIZE-1:0] d_out_r1, d_out_r2;
82
wire [DATASIZE-1:0] d_out_m2, d_out_2, d_out_3;
83
wire mux_rm_2;
84
 
85
reg [ADDRSIZE -1:0] ra_m, wa_m; //addr after register similar to signal internal to sram
86
reg [ADDRSIZE -1:0] ra, wa; // address calculated for the next read
87
wire wen, ren;
88
 
89
wire m_empty;
90
 
91
assign full_1 = full_r1 || full_m1 || (full_m2 && full_r2);
92
assign full_2 = full_r2 || full_m2;
93
 
94
//=====================================================================================================
95
//-----------------------------------------------------------------------------------------------------
96
//---------LOGIC STARTS HERE---------------------------------------------------------------------------
97
//-----------------------------------------------------------------------------------------------------
98
//=====================================================================================================
99
 
100
always @ (posedge clk or negedge res_n) begin
101
    if (!res_n) begin
102
        d_out_r1 <= {DATASIZE {1'b0}};
103
        d_out_r2 <= {DATASIZE {1'b0}};
104
        full_r1 <= 1'b0;
105
        full_r2 <= 1'b0;
106
    end else begin
107
 
108
        // Register stage 1 (conditions shouldn't overlap)
109
        if ((full_2 && !full_1 && si && !so) ||         // fill stage
110
            (full_1 && m_empty && si && so)) begin      // shift through
111
            d_out_r1 <= d_in;
112
            full_r1 <= 1'b1;
113
        end
114
        if (full_r1 && so && (!si || !m_empty)) begin   // shift out
115
            full_r1 <= 1'b0;
116
        end
117
 
118
        // Register stage 2 (conditions shouldn't overlap)
119
        if (full_3 && ((!full_2 && si && !so) ||        // fill stage
120
                (full_2 && !full_1 && si && so))) begin // shift through
121
            d_out_r2 <= d_in;
122
            full_r2 <= 1'b1;
123
        end
124
        if (full_r1 && so) begin                        // shift through
125
            d_out_r2 <= d_out_r1;
126
            full_r2 <= 1'b1;
127
        end
128
        if (full_m2 && ((!full_r2 && !so) ||            // Rescue
129
                        (full_r2 && so))) begin
130
            d_out_r2 <= d_out_m2;
131
            full_r2 <= 1'b1;
132
        end
133
        if (full_r2 &&
134
                ((!full_r1 && !full_m2 && so && !si) || // shift out
135
                (full_m1 && si && so))) begin           // shift through with RAM
136
            full_r2 <= 1'b0;
137
        end
138
    end
139
end
140
 
141
// assign outputs and inputs to module interface
142
    assign d_out = d_out_3;
143
 
144
    assign empty = !full_3; // if the last stage is empty, the fifo is empty
145
 
146
    assign si = shift_in;
147
    assign so = shift_out;
148
 
149
    wire [ADDRSIZE:0] fifo_ram_count = wa_m - ra_m;
150
 
151
    assign mux_rm_2 = full_r2;          // mux control of SRAM data bypass if only one value in stage r2
152
    assign d_out_2 = mux_rm_2 ? d_out_r2 : d_out_m2;    // additional data mux for SRAM bypass
153
 
154
    // write port control of SRAM
155
    assign wen = si && !so && full_1    // enter new value into SRAM, because regs are filled
156
                || si && !m_empty;  // if a value is in the SRAM, then we have to shift through or shift in
157
 
158
    // read port control of SRAM
159
    assign ren = so && !m_empty;
160
 
161
    assign m_empty = (wa_m == ra_m);
162
 
163
    always @ (posedge clk or negedge res_n) begin
164
        if (!res_n) begin
165
            full_m1 <= 1'b0;
166
            full_m2 <= 1'b0;
167
        end else begin
168
            full_m1 <= ren; // no control of m1
169
            full_m2 <= full_m1
170
                    || full_m2 && !so && full_r2;       // no rescue possible
171
        end
172
    end
173
 
174
// pointer management
175
    always @(*) begin
176
        wa = wa_m + 1'b1; // wa_m is the address stored in mem addr register
177
        ra = ra_m + 1'b1;
178
    end
179
 
180
    always @ (posedge clk or negedge res_n) begin
181
        if (!res_n) begin
182
            wa_m <= {ADDRSIZE {1'b0}};
183
            ra_m <= {ADDRSIZE {1'b0}};
184
        end else begin
185
            if (wen) begin
186
                wa_m <= wa; // next mem write addr to mem addr register
187
            end
188
 
189
            if (ren) begin
190
                ra_m <= ra;
191
            end
192
        end
193
    end
194
 
195
//=====================================================================================================
196
//-----------------------------------------------------------------------------------------------------
197
//---------INSTANTIATIONS HERE-------------------------------------------------------------------------
198
//-----------------------------------------------------------------------------------------------------
199
//=====================================================================================================
200
openhmc_sync_fifo_reg_stage #(.DWIDTH(DATASIZE))
201
    sync_fifo_reg_stage_3_I (
202
        .clk(clk),
203
        .res_n(res_n),
204
        .d_in(d_in),
205
        .d_in_p(d_out_2),
206
        .p_full(full_2),
207
        .n_full(1'b1),
208
        .si(si),
209
        .so(so),
210
        .full(full_3),
211
        .d_out(d_out_3)
212
    );
213
 
214
openhmc_ram #(
215
    .DATASIZE(DATASIZE),    // Memory data word width
216
    .ADDRSIZE(ADDRSIZE),    // Number of memory address bits
217
    .PIPELINED(1)
218
    )
219
    ram(
220
        .clk(clk),
221
        .wen(wen),
222
        .wdata(d_in),
223
        .waddr(wa),
224
        .ren(ren),
225
        .raddr(ra),
226
        .rdata(d_out_m2)
227
        );
228
 
229
 
230
`ifdef CAG_ASSERTIONS
231
 
232
    if (DISABLE_SHIFT_OUT_ASSERT == 0)
233
        shift_out_and_empty:    assert property (@(posedge clk) disable iff(!res_n) (shift_out |-> !empty));
234
 
235
    if (DISABLE_XCHECK_ASSERT == 0)
236
    dout_known:                 assert property (@(posedge clk) disable iff(!res_n) (!empty |-> !$isunknown(d_out)));
237
 
238
    final
239
    begin
240
        if (DISABLE_EMPTY_ASSERT == 0)
241
        begin
242
            empty_not_set_assert:           assert (empty);
243
        end
244
    end
245
 
246
`endif // CAG_ASSERTIONS
247
 
248
endmodule
249
 
250
`default_nettype wire
251
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.