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

Subversion Repositories versatile_library

[/] [versatile_library/] [trunk/] [rtl/] [verilog/] [wb.v] - Blame information for rev 110

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

Line No. Rev Author Line
1 12 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Versatile library, wishbone stuff                           ////
4
////                                                              ////
5
////  Description                                                 ////
6
////  Wishbone compliant modules                                  ////
7
////                                                              ////
8
////                                                              ////
9
////  To Do:                                                      ////
10
////   -                                                          ////
11
////                                                              ////
12
////  Author(s):                                                  ////
13
////      - Michael Unneback, unneback@opencores.org              ////
14
////        ORSoC AB                                              ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
 
43 75 unneback
`ifdef WB_ADR_INC
44
`timescale 1ns/1ns
45
`define MODULE wb_adr_inc
46 84 unneback
module `BASE`MODULE ( cyc_i, stb_i, cti_i, bte_i, adr_i, we_i, ack_o, adr_o, clk, rst);
47 75 unneback
`undef MODULE
48 83 unneback
parameter adr_width = 10;
49
parameter max_burst_width = 4;
50 84 unneback
input cyc_i, stb_i, we_i;
51 83 unneback
input [2:0] cti_i;
52
input [1:0] bte_i;
53
input [adr_width-1:0] adr_i;
54
output [adr_width-1:0] adr_o;
55
output ack_o;
56
input clk, rst;
57 75 unneback
 
58 83 unneback
reg [adr_width-1:0] adr;
59 90 unneback
wire [max_burst_width-1:0] to_adr;
60 91 unneback
reg [max_burst_width-1:0] last_adr;
61 92 unneback
reg last_cycle;
62
localparam idle_or_eoc = 1'b0;
63
localparam cyc_or_ws   = 1'b1;
64 90 unneback
 
65 91 unneback
always @ (posedge clk or posedge rst)
66
if (rst)
67
    last_adr <= {max_burst_width{1'b0}};
68
else
69
    if (stb_i)
70 92 unneback
        last_adr <=adr_o[max_burst_width-1:0];
71 91 unneback
 
72 83 unneback
generate
73
if (max_burst_width==0) begin : inst_0
74 96 unneback
 
75
        reg ack_o;
76
        assign adr_o = adr_i;
77
        always @ (posedge clk or posedge rst)
78
        if (rst)
79
            ack_o <= 1'b0;
80
        else
81
            ack_o <= cyc_i & stb_i & !ack_o;
82
 
83 83 unneback
end else begin
84
 
85
    always @ (posedge clk or posedge rst)
86
    if (rst)
87 92 unneback
        last_cycle <= idle_or_eoc;
88 83 unneback
    else
89 92 unneback
        last_cycle <= (!cyc_i) ? idle_or_eoc : //idle
90
                      (cyc_i & ack_o & (cti_i==3'b000 | cti_i==3'b111)) ? idle_or_eoc : // eoc
91
                      (cyc_i & !stb_i) ? cyc_or_ws : //ws
92
                      cyc_or_ws; // cyc
93
    assign to_adr = (last_cycle==idle_or_eoc) ? adr_i[max_burst_width-1:0] : adr[max_burst_width-1:0];
94 84 unneback
    assign adr_o[max_burst_width-1:0] = (we_i) ? adr_i[max_burst_width-1:0] :
95 91 unneback
                                        (!stb_i) ? last_adr :
96 92 unneback
                                        (last_cycle==idle_or_eoc) ? adr_i[max_burst_width-1:0] :
97 84 unneback
                                        adr[max_burst_width-1:0];
98 92 unneback
    assign ack_o = (last_cycle==cyc_or_ws) & stb_i;
99 96 unneback
 
100 83 unneback
end
101
endgenerate
102
 
103
generate
104
if (max_burst_width==2) begin : inst_2
105
    always @ (posedge clk or posedge rst)
106
    if (rst)
107
        adr <= 2'h0;
108
    else
109
        if (cyc_i & stb_i)
110
            adr[1:0] <= to_adr[1:0] + 2'd1;
111 75 unneback
        else
112 83 unneback
            adr <= to_adr[1:0];
113
end
114
endgenerate
115
 
116
generate
117
if (max_burst_width==3) begin : inst_3
118
    always @ (posedge clk or posedge rst)
119
    if (rst)
120
        adr <= 3'h0;
121
    else
122
        if (cyc_i & stb_i)
123
            case (bte_i)
124
            2'b01: adr[2:0] <= {to_adr[2],to_adr[1:0] + 2'd1};
125
            default: adr[3:0] <= to_adr[2:0] + 3'd1;
126 75 unneback
            endcase
127 83 unneback
        else
128
            adr <= to_adr[2:0];
129
end
130
endgenerate
131
 
132
generate
133
if (max_burst_width==4) begin : inst_4
134
    always @ (posedge clk or posedge rst)
135
    if (rst)
136
        adr <= 4'h0;
137
    else
138 91 unneback
        if (stb_i) // | (!stb_i & last_cycle!=ws)) // for !stb_i restart with adr_i +1, only inc once
139 83 unneback
            case (bte_i)
140
            2'b01: adr[3:0] <= {to_adr[3:2],to_adr[1:0] + 2'd1};
141
            2'b10: adr[3:0] <= {to_adr[3],to_adr[2:0] + 3'd1};
142
            default: adr[3:0] <= to_adr + 4'd1;
143
            endcase
144
        else
145
            adr <= to_adr[3:0];
146
end
147
endgenerate
148
 
149
generate
150
if (adr_width > max_burst_width) begin : pass_through
151
    assign adr_o[adr_width-1:max_burst_width] = adr_i[adr_width-1:max_burst_width];
152
end
153
endgenerate
154
 
155
endmodule
156 75 unneback
`endif
157
 
158 104 unneback
`ifdef WB_B4_EOC
159
`define MODULE wb_b4_eoc
160
module `BASE`MODULE ( cyc_i, stb_i, stall_o, ack_o, busy, eoc, clk, rst);
161
`undef MODULE
162
input cyc_i, stb_i, ack_o;
163
output busy, eoc;
164
input clk, rst;
165
 
166
`define MODULE cnt_bin_ce_rew_zq_l1
167
`BASE`MODULE # ( .length(4), level1_value(1))
168
cnt0 (
169
    .cke(), .rew(), .zq(), .level1(), .rst(), clk);
170
`undef MODULE
171
 
172
endmodule
173
`endif
174
 
175 40 unneback
`ifdef WB3WB3_BRIDGE
176 12 unneback
// async wb3 - wb3 bridge
177
`timescale 1ns/1ns
178 40 unneback
`define MODULE wb3wb3_bridge
179
module `BASE`MODULE (
180
`undef MODULE
181 12 unneback
        // wishbone slave side
182
        wbs_dat_i, wbs_adr_i, wbs_sel_i, wbs_bte_i, wbs_cti_i, wbs_we_i, wbs_cyc_i, wbs_stb_i, wbs_dat_o, wbs_ack_o, wbs_clk, wbs_rst,
183
        // wishbone master side
184
        wbm_dat_o, wbm_adr_o, wbm_sel_o, wbm_bte_o, wbm_cti_o, wbm_we_o, wbm_cyc_o, wbm_stb_o, wbm_dat_i, wbm_ack_i, wbm_clk, wbm_rst);
185
 
186 94 unneback
parameter style = "FIFO"; // valid: simple, FIFO
187
parameter addr_width = 4;
188
 
189 12 unneback
input [31:0] wbs_dat_i;
190
input [31:2] wbs_adr_i;
191
input [3:0]  wbs_sel_i;
192
input [1:0]  wbs_bte_i;
193
input [2:0]  wbs_cti_i;
194
input wbs_we_i, wbs_cyc_i, wbs_stb_i;
195
output [31:0] wbs_dat_o;
196 14 unneback
output wbs_ack_o;
197 12 unneback
input wbs_clk, wbs_rst;
198
 
199
output [31:0] wbm_dat_o;
200
output reg [31:2] wbm_adr_o;
201
output [3:0]  wbm_sel_o;
202
output reg [1:0]  wbm_bte_o;
203
output reg [2:0]  wbm_cti_o;
204 14 unneback
output reg wbm_we_o;
205
output wbm_cyc_o;
206 12 unneback
output wbm_stb_o;
207
input [31:0]  wbm_dat_i;
208
input wbm_ack_i;
209
input wbm_clk, wbm_rst;
210
 
211
// bte
212
parameter linear       = 2'b00;
213
parameter wrap4        = 2'b01;
214
parameter wrap8        = 2'b10;
215
parameter wrap16       = 2'b11;
216
// cti
217
parameter classic      = 3'b000;
218
parameter incburst     = 3'b010;
219
parameter endofburst   = 3'b111;
220
 
221 94 unneback
localparam wbs_adr  = 1'b0;
222
localparam wbs_data = 1'b1;
223 12 unneback
 
224 94 unneback
localparam wbm_adr0      = 2'b00;
225
localparam wbm_adr1      = 2'b01;
226
localparam wbm_data      = 2'b10;
227
localparam wbm_data_wait = 2'b11;
228 12 unneback
 
229
reg [1:0] wbs_bte_reg;
230
reg wbs;
231
wire wbs_eoc_alert, wbm_eoc_alert;
232
reg wbs_eoc, wbm_eoc;
233
reg [1:0] wbm;
234
 
235 14 unneback
wire [1:16] wbs_count, wbm_count;
236 12 unneback
 
237
wire [35:0] a_d, a_q, b_d, b_q;
238
wire a_wr, a_rd, a_fifo_full, a_fifo_empty, b_wr, b_rd, b_fifo_full, b_fifo_empty;
239
reg a_rd_reg;
240
wire b_rd_adr, b_rd_data;
241 14 unneback
wire b_rd_data_reg;
242
wire [35:0] temp;
243 12 unneback
 
244
`define WE 5
245
`define BTE 4:3
246
`define CTI 2:0
247
 
248
assign wbs_eoc_alert = (wbs_bte_reg==wrap4 & wbs_count[3]) | (wbs_bte_reg==wrap8 & wbs_count[7]) | (wbs_bte_reg==wrap16 & wbs_count[15]);
249
always @ (posedge wbs_clk or posedge wbs_rst)
250
if (wbs_rst)
251
        wbs_eoc <= 1'b0;
252
else
253
        if (wbs==wbs_adr & wbs_stb_i & !a_fifo_full)
254 78 unneback
                wbs_eoc <= (wbs_bte_i==linear) | (wbs_cti_i==3'b111);
255 12 unneback
        else if (wbs_eoc_alert & (a_rd | a_wr))
256
                wbs_eoc <= 1'b1;
257
 
258 40 unneback
`define MODULE cnt_shreg_ce_clear
259
`BASE`MODULE # ( .length(16))
260
`undef MODULE
261 12 unneback
    cnt0 (
262
        .cke(wbs_ack_o),
263
        .clear(wbs_eoc),
264
        .q(wbs_count),
265
        .rst(wbs_rst),
266
        .clk(wbs_clk));
267
 
268
always @ (posedge wbs_clk or posedge wbs_rst)
269
if (wbs_rst)
270
        wbs <= wbs_adr;
271
else
272 75 unneback
        if ((wbs==wbs_adr) & wbs_cyc_i & wbs_stb_i & a_fifo_empty)
273 12 unneback
                wbs <= wbs_data;
274
        else if (wbs_eoc & wbs_ack_o)
275
                wbs <= wbs_adr;
276
 
277
// wbs FIFO
278 75 unneback
assign a_d = (wbs==wbs_adr) ? {wbs_adr_i[31:2],wbs_we_i,((wbs_cti_i==3'b111) ? {2'b00,3'b000} : {wbs_bte_i,wbs_cti_i})} : {wbs_dat_i,wbs_sel_i};
279
assign a_wr = (wbs==wbs_adr)  ? wbs_cyc_i & wbs_stb_i & a_fifo_empty :
280 12 unneback
              (wbs==wbs_data) ? wbs_we_i  & wbs_stb_i & !a_fifo_full :
281
              1'b0;
282
assign a_rd = !a_fifo_empty;
283
always @ (posedge wbs_clk or posedge wbs_rst)
284
if (wbs_rst)
285
        a_rd_reg <= 1'b0;
286
else
287
        a_rd_reg <= a_rd;
288
assign wbs_ack_o = a_rd_reg | (a_wr & wbs==wbs_data);
289
 
290
assign wbs_dat_o = a_q[35:4];
291
 
292
always @ (posedge wbs_clk or posedge wbs_rst)
293
if (wbs_rst)
294 13 unneback
        wbs_bte_reg <= 2'b00;
295 12 unneback
else
296 13 unneback
        wbs_bte_reg <= wbs_bte_i;
297 12 unneback
 
298
// wbm FIFO
299
assign wbm_eoc_alert = (wbm_bte_o==wrap4 & wbm_count[3]) | (wbm_bte_o==wrap8 & wbm_count[7]) | (wbm_bte_o==wrap16 & wbm_count[15]);
300
always @ (posedge wbm_clk or posedge wbm_rst)
301
if (wbm_rst)
302
        wbm_eoc <= 1'b0;
303
else
304
        if (wbm==wbm_adr0 & !b_fifo_empty)
305
                wbm_eoc <= b_q[`BTE] == linear;
306
        else if (wbm_eoc_alert & wbm_ack_i)
307
                wbm_eoc <= 1'b1;
308
 
309
always @ (posedge wbm_clk or posedge wbm_rst)
310
if (wbm_rst)
311
        wbm <= wbm_adr0;
312
else
313 33 unneback
/*
314 12 unneback
    if ((wbm==wbm_adr0 & !b_fifo_empty) |
315
        (wbm==wbm_adr1 & !b_fifo_empty & wbm_we_o) |
316
        (wbm==wbm_adr1 & !wbm_we_o) |
317
        (wbm==wbm_data & wbm_ack_i & wbm_eoc))
318
        wbm <= {wbm[0],!(wbm[1] ^ wbm[0])};  // count sequence 00,01,10
319 33 unneback
*/
320
    case (wbm)
321
    wbm_adr0:
322
        if (!b_fifo_empty)
323
            wbm <= wbm_adr1;
324
    wbm_adr1:
325
        if (!wbm_we_o | (!b_fifo_empty & wbm_we_o))
326
            wbm <= wbm_data;
327
    wbm_data:
328
        if (wbm_ack_i & wbm_eoc)
329
            wbm <= wbm_adr0;
330
        else if (b_fifo_empty & wbm_we_o & wbm_ack_i)
331
            wbm <= wbm_data_wait;
332
    wbm_data_wait:
333
        if (!b_fifo_empty)
334
            wbm <= wbm_data;
335
    endcase
336 12 unneback
 
337
assign b_d = {wbm_dat_i,4'b1111};
338
assign b_wr = !wbm_we_o & wbm_ack_i;
339
assign b_rd_adr  = (wbm==wbm_adr0 & !b_fifo_empty);
340
assign b_rd_data = (wbm==wbm_adr1 & !b_fifo_empty & wbm_we_o) ? 1'b1 : // b_q[`WE]
341
                   (wbm==wbm_data & !b_fifo_empty & wbm_we_o & wbm_ack_i & !wbm_eoc) ? 1'b1 :
342 33 unneback
                   (wbm==wbm_data_wait & !b_fifo_empty) ? 1'b1 :
343 12 unneback
                   1'b0;
344
assign b_rd = b_rd_adr | b_rd_data;
345
 
346 40 unneback
`define MODULE dff
347
`BASE`MODULE dff1 ( .d(b_rd_data), .q(b_rd_data_reg), .clk(wbm_clk), .rst(wbm_rst));
348
`undef MODULE
349
`define MODULE dff_ce
350
`BASE`MODULE # ( .width(36)) dff2 ( .d(b_q), .ce(b_rd_data_reg), .q(temp), .clk(wbm_clk), .rst(wbm_rst));
351
`undef MODULE
352 12 unneback
 
353
assign {wbm_dat_o,wbm_sel_o} = (b_rd_data_reg) ? b_q : temp;
354
 
355 40 unneback
`define MODULE cnt_shreg_ce_clear
356 42 unneback
`BASE`MODULE # ( .length(16))
357 40 unneback
`undef MODULE
358 12 unneback
    cnt1 (
359
        .cke(wbm_ack_i),
360
        .clear(wbm_eoc),
361
        .q(wbm_count),
362
        .rst(wbm_rst),
363
        .clk(wbm_clk));
364
 
365 33 unneback
assign wbm_cyc_o = (wbm==wbm_data | wbm==wbm_data_wait);
366
assign wbm_stb_o = (wbm==wbm_data);
367 12 unneback
 
368
always @ (posedge wbm_clk or posedge wbm_rst)
369
if (wbm_rst)
370
        {wbm_adr_o,wbm_we_o,wbm_bte_o,wbm_cti_o} <= {30'h0,1'b0,linear,classic};
371
else begin
372
        if (wbm==wbm_adr0 & !b_fifo_empty)
373
                {wbm_adr_o,wbm_we_o,wbm_bte_o,wbm_cti_o} <= b_q;
374
        else if (wbm_eoc_alert & wbm_ack_i)
375
                wbm_cti_o <= endofburst;
376
end
377
 
378
//async_fifo_dw_simplex_top
379 40 unneback
`define MODULE fifo_2r2w_async_simplex
380
`BASE`MODULE
381
`undef MODULE
382 12 unneback
# ( .data_width(36), .addr_width(addr_width))
383
fifo (
384
    // a side
385
    .a_d(a_d),
386
    .a_wr(a_wr),
387
    .a_fifo_full(a_fifo_full),
388
    .a_q(a_q),
389
    .a_rd(a_rd),
390
    .a_fifo_empty(a_fifo_empty),
391
    .a_clk(wbs_clk),
392
    .a_rst(wbs_rst),
393
    // b side
394
    .b_d(b_d),
395
    .b_wr(b_wr),
396
    .b_fifo_full(b_fifo_full),
397
    .b_q(b_q),
398
    .b_rd(b_rd),
399
    .b_fifo_empty(b_fifo_empty),
400
    .b_clk(wbm_clk),
401
    .b_rst(wbm_rst)
402
    );
403
 
404
endmodule
405 40 unneback
`undef WE
406
`undef BTE
407
`undef CTI
408
`endif
409 17 unneback
 
410 75 unneback
`ifdef WB3AVALON_BRIDGE
411
`define MODULE wb3avalon_bridge
412
module `BASE`MODULE (
413
`undef MODULE
414
        // wishbone slave side
415
        wbs_dat_i, wbs_adr_i, wbs_sel_i, wbs_bte_i, wbs_cti_i, wbs_we_i, wbs_cyc_i, wbs_stb_i, wbs_dat_o, wbs_ack_o, wbs_clk, wbs_rst,
416 77 unneback
        // avalon master side
417 75 unneback
        readdata, readdatavalid, address, read, be, write, burstcount, writedata, waitrequest, beginbursttransfer, clk, rst);
418
 
419 84 unneback
parameter linewrapburst = 1'b0;
420
 
421 75 unneback
input [31:0] wbs_dat_i;
422
input [31:2] wbs_adr_i;
423
input [3:0]  wbs_sel_i;
424
input [1:0]  wbs_bte_i;
425
input [2:0]  wbs_cti_i;
426 83 unneback
input wbs_we_i;
427
input wbs_cyc_i;
428
input wbs_stb_i;
429 75 unneback
output [31:0] wbs_dat_o;
430
output wbs_ack_o;
431
input wbs_clk, wbs_rst;
432
 
433
input [31:0] readdata;
434
output [31:0] writedata;
435
output [31:2] address;
436
output [3:0]  be;
437
output write;
438 81 unneback
output read;
439 75 unneback
output beginbursttransfer;
440
output [3:0] burstcount;
441
input readdatavalid;
442
input waitrequest;
443
input clk;
444
input rst;
445
 
446
wire [1:0] wbm_bte_o;
447
wire [2:0] wbm_cti_o;
448
wire wbm_we_o, wbm_cyc_o, wbm_stb_o, wbm_ack_i;
449
reg last_cyc;
450 79 unneback
reg [3:0] counter;
451 82 unneback
reg read_busy;
452 75 unneback
 
453
always @ (posedge clk or posedge rst)
454
if (rst)
455
    last_cyc <= 1'b0;
456
else
457
    last_cyc <= wbm_cyc_o;
458
 
459 79 unneback
always @ (posedge clk or posedge rst)
460
if (rst)
461 82 unneback
    read_busy <= 1'b0;
462 79 unneback
else
463 82 unneback
    if (read & !waitrequest)
464
        read_busy <= 1'b1;
465
    else if (wbm_ack_i & wbm_cti_o!=3'b010)
466
        read_busy <= 1'b0;
467
assign read = wbm_cyc_o & wbm_stb_o & !wbm_we_o & !read_busy;
468 81 unneback
 
469 75 unneback
assign beginbursttransfer = (!last_cyc & wbm_cyc_o) & wbm_cti_o==3'b010;
470
assign burstcount = (wbm_bte_o==2'b01) ? 4'd4 :
471
                    (wbm_bte_o==2'b10) ? 4'd8 :
472 78 unneback
                    (wbm_bte_o==2'b11) ? 4'd16:
473
                    4'd1;
474 82 unneback
assign wbm_ack_i = (readdatavalid) | (write & !waitrequest);
475 75 unneback
 
476 79 unneback
always @ (posedge clk or posedge rst)
477
if (rst) begin
478
    counter <= 4'd0;
479
end else
480 80 unneback
    if (wbm_we_o) begin
481
        if (!waitrequest & !last_cyc & wbm_cyc_o) begin
482 84 unneback
            counter <= burstcount -4'd1;
483 80 unneback
        end else if (waitrequest & !last_cyc & wbm_cyc_o) begin
484
            counter <= burstcount;
485
        end else if (!waitrequest & wbm_stb_o) begin
486
            counter <= counter - 4'd1;
487
        end
488 82 unneback
    end
489 81 unneback
assign write = wbm_cyc_o & wbm_stb_o & wbm_we_o & counter!=4'd0;
490 79 unneback
 
491 75 unneback
`define MODULE wb3wb3_bridge
492 77 unneback
`BASE`MODULE wbwb3inst (
493 75 unneback
`undef MODULE
494
    // wishbone slave side
495
    .wbs_dat_i(wbs_dat_i),
496
    .wbs_adr_i(wbs_adr_i),
497
    .wbs_sel_i(wbs_sel_i),
498
    .wbs_bte_i(wbs_bte_i),
499
    .wbs_cti_i(wbs_cti_i),
500
    .wbs_we_i(wbs_we_i),
501
    .wbs_cyc_i(wbs_cyc_i),
502
    .wbs_stb_i(wbs_stb_i),
503
    .wbs_dat_o(wbs_dat_o),
504
    .wbs_ack_o(wbs_ack_o),
505
    .wbs_clk(wbs_clk),
506
    .wbs_rst(wbs_rst),
507
    // wishbone master side
508
    .wbm_dat_o(writedata),
509 78 unneback
    .wbm_adr_o(address),
510 75 unneback
    .wbm_sel_o(be),
511
    .wbm_bte_o(wbm_bte_o),
512
    .wbm_cti_o(wbm_cti_o),
513
    .wbm_we_o(wbm_we_o),
514
    .wbm_cyc_o(wbm_cyc_o),
515
    .wbm_stb_o(wbm_stb_o),
516
    .wbm_dat_i(readdata),
517
    .wbm_ack_i(wbm_ack_i),
518
    .wbm_clk(clk),
519
    .wbm_rst(rst));
520
 
521
 
522
endmodule
523
`endif
524
 
525 105 unneback
`ifdef WB_ARBITER
526
`define MODULE wb_arbiter
527 42 unneback
module `BASE`MODULE (
528 40 unneback
`undef MODULE
529 39 unneback
    wbm_dat_o, wbm_adr_o, wbm_sel_o, wbm_cti_o, wbm_bte_o, wbm_we_o, wbm_stb_o, wbm_cyc_o,
530 105 unneback
    wbm_dat_i, wbm_stall_i, wbm_ack_i, wbm_err_i, wbm_rty_i,
531 39 unneback
    wbs_dat_i, wbs_adr_i, wbs_sel_i, wbs_cti_i, wbs_bte_i, wbs_we_i, wbs_stb_i, wbs_cyc_i,
532 105 unneback
    wbs_dat_o, wbs_stall_o, wbs_ack_o, wbs_err_o, wbs_rty_o,
533 39 unneback
    wb_clk, wb_rst
534
);
535
 
536
parameter nr_of_ports = 3;
537
parameter adr_size = 26;
538
parameter adr_lo   = 2;
539
parameter dat_size = 32;
540
parameter sel_size = dat_size/8;
541
 
542
localparam aw = (adr_size - adr_lo) * nr_of_ports;
543
localparam dw = dat_size * nr_of_ports;
544
localparam sw = sel_size * nr_of_ports;
545
localparam cw = 3 * nr_of_ports;
546
localparam bw = 2 * nr_of_ports;
547
 
548
input  [dw-1:0] wbm_dat_o;
549
input  [aw-1:0] wbm_adr_o;
550
input  [sw-1:0] wbm_sel_o;
551
input  [cw-1:0] wbm_cti_o;
552
input  [bw-1:0] wbm_bte_o;
553
input  [nr_of_ports-1:0] wbm_we_o, wbm_stb_o, wbm_cyc_o;
554
output [dw-1:0] wbm_dat_i;
555 105 unneback
output [nr_of_ports-1:0] wbm_stall_o, wbm_ack_i, wbm_err_i, wbm_rty_i;
556 39 unneback
 
557
output [dat_size-1:0] wbs_dat_i;
558
output [adr_size-1:adr_lo] wbs_adr_i;
559
output [sel_size-1:0] wbs_sel_i;
560
output [2:0] wbs_cti_i;
561
output [1:0] wbs_bte_i;
562
output wbs_we_i, wbs_stb_i, wbs_cyc_i;
563
input  [dat_size-1:0] wbs_dat_o;
564 105 unneback
input  wbs_stall_o, wbs_ack_o, wbs_err_o, wbs_rty_o;
565 39 unneback
 
566
input wb_clk, wb_rst;
567
 
568 44 unneback
reg  [nr_of_ports-1:0] select;
569 39 unneback
wire [nr_of_ports-1:0] state;
570
wire [nr_of_ports-1:0] eoc; // end-of-cycle
571
wire [nr_of_ports-1:0] sel;
572
wire idle;
573
 
574
genvar i;
575
 
576
assign idle = !(|state);
577
 
578
generate
579
if (nr_of_ports == 2) begin
580
 
581
    wire [2:0] wbm1_cti_o, wbm0_cti_o;
582
 
583
    assign {wbm1_cti_o,wbm0_cti_o} = wbm_cti_o;
584
 
585 44 unneback
    //assign select = (idle) ? {wbm_cyc_o[1],!wbm_cyc_o[1] & wbm_cyc_o[0]} : {nr_of_ports{1'b0}};
586
 
587
    always @ (idle or wbm_cyc_o)
588
    if (idle)
589
        casex (wbm_cyc_o)
590
        2'b1x : select = 2'b10;
591
        2'b01 : select = 2'b01;
592
        default : select = {nr_of_ports{1'b0}};
593
        endcase
594
    else
595
        select = {nr_of_ports{1'b0}};
596
 
597 39 unneback
    assign eoc[1] = (wbm_ack_i[1] & (wbm1_cti_o == 3'b000 | wbm1_cti_o == 3'b111)) | !wbm_cyc_o[1];
598
    assign eoc[0] = (wbm_ack_i[0] & (wbm0_cti_o == 3'b000 | wbm0_cti_o == 3'b111)) | !wbm_cyc_o[0];
599
 
600
end
601
endgenerate
602
 
603
generate
604
if (nr_of_ports == 3) begin
605
 
606
    wire [2:0] wbm2_cti_o, wbm1_cti_o, wbm0_cti_o;
607
 
608
    assign {wbm2_cti_o,wbm1_cti_o,wbm0_cti_o} = wbm_cti_o;
609
 
610 44 unneback
    always @ (idle or wbm_cyc_o)
611
    if (idle)
612
        casex (wbm_cyc_o)
613
        3'b1xx : select = 3'b100;
614
        3'b01x : select = 3'b010;
615
        3'b001 : select = 3'b001;
616
        default : select = {nr_of_ports{1'b0}};
617
        endcase
618
    else
619
        select = {nr_of_ports{1'b0}};
620
 
621
//    assign select = (idle) ? {wbm_cyc_o[2],!wbm_cyc_o[2] & wbm_cyc_o[1],wbm_cyc_o[2:1]==2'b00 & wbm_cyc_o[0]} : {nr_of_ports{1'b0}};
622 39 unneback
    assign eoc[2] = (wbm_ack_i[2] & (wbm2_cti_o == 3'b000 | wbm2_cti_o == 3'b111)) | !wbm_cyc_o[2];
623
    assign eoc[1] = (wbm_ack_i[1] & (wbm1_cti_o == 3'b000 | wbm1_cti_o == 3'b111)) | !wbm_cyc_o[1];
624
    assign eoc[0] = (wbm_ack_i[0] & (wbm0_cti_o == 3'b000 | wbm0_cti_o == 3'b111)) | !wbm_cyc_o[0];
625
 
626
end
627
endgenerate
628
 
629
generate
630 44 unneback
if (nr_of_ports == 4) begin
631
 
632
    wire [2:0] wbm3_cti_o, wbm2_cti_o, wbm1_cti_o, wbm0_cti_o;
633
 
634
    assign {wbm3_cti_o, wbm2_cti_o,wbm1_cti_o,wbm0_cti_o} = wbm_cti_o;
635
 
636
    //assign select = (idle) ? {wbm_cyc_o[3],!wbm_cyc_o[3] & wbm_cyc_o[2],wbm_cyc_o[3:2]==2'b00 & wbm_cyc_o[1],wbm_cyc_o[3:1]==3'b000 & wbm_cyc_o[0]} : {nr_of_ports{1'b0}};
637
 
638
    always @ (idle or wbm_cyc_o)
639
    if (idle)
640
        casex (wbm_cyc_o)
641
        4'b1xxx : select = 4'b1000;
642
        4'b01xx : select = 4'b0100;
643
        4'b001x : select = 4'b0010;
644
        4'b0001 : select = 4'b0001;
645
        default : select = {nr_of_ports{1'b0}};
646
        endcase
647
    else
648
        select = {nr_of_ports{1'b0}};
649
 
650
    assign eoc[3] = (wbm_ack_i[3] & (wbm3_cti_o == 3'b000 | wbm3_cti_o == 3'b111)) | !wbm_cyc_o[3];
651
    assign eoc[2] = (wbm_ack_i[2] & (wbm2_cti_o == 3'b000 | wbm2_cti_o == 3'b111)) | !wbm_cyc_o[2];
652
    assign eoc[1] = (wbm_ack_i[1] & (wbm1_cti_o == 3'b000 | wbm1_cti_o == 3'b111)) | !wbm_cyc_o[1];
653
    assign eoc[0] = (wbm_ack_i[0] & (wbm0_cti_o == 3'b000 | wbm0_cti_o == 3'b111)) | !wbm_cyc_o[0];
654
 
655
end
656
endgenerate
657
 
658
generate
659
if (nr_of_ports == 5) begin
660
 
661
    wire [2:0] wbm4_cti_o, wbm3_cti_o, wbm2_cti_o, wbm1_cti_o, wbm0_cti_o;
662
 
663
    assign {wbm4_cti_o, wbm3_cti_o, wbm2_cti_o,wbm1_cti_o,wbm0_cti_o} = wbm_cti_o;
664
 
665
    //assign select = (idle) ? {wbm_cyc_o[3],!wbm_cyc_o[3] & wbm_cyc_o[2],wbm_cyc_o[3:2]==2'b00 & wbm_cyc_o[1],wbm_cyc_o[3:1]==3'b000 & wbm_cyc_o[0]} : {nr_of_ports{1'b0}};
666
 
667
    always @ (idle or wbm_cyc_o)
668
    if (idle)
669
        casex (wbm_cyc_o)
670
        5'b1xxxx : select = 5'b10000;
671
        5'b01xxx : select = 5'b01000;
672
        5'b001xx : select = 5'b00100;
673
        5'b0001x : select = 5'b00010;
674
        5'b00001 : select = 5'b00001;
675
        default : select = {nr_of_ports{1'b0}};
676
        endcase
677
    else
678
        select = {nr_of_ports{1'b0}};
679
 
680
    assign eoc[4] = (wbm_ack_i[4] & (wbm4_cti_o == 3'b000 | wbm4_cti_o == 3'b111)) | !wbm_cyc_o[4];
681
    assign eoc[3] = (wbm_ack_i[3] & (wbm3_cti_o == 3'b000 | wbm3_cti_o == 3'b111)) | !wbm_cyc_o[3];
682
    assign eoc[2] = (wbm_ack_i[2] & (wbm2_cti_o == 3'b000 | wbm2_cti_o == 3'b111)) | !wbm_cyc_o[2];
683
    assign eoc[1] = (wbm_ack_i[1] & (wbm1_cti_o == 3'b000 | wbm1_cti_o == 3'b111)) | !wbm_cyc_o[1];
684
    assign eoc[0] = (wbm_ack_i[0] & (wbm0_cti_o == 3'b000 | wbm0_cti_o == 3'b111)) | !wbm_cyc_o[0];
685
 
686
end
687
endgenerate
688
 
689
generate
690 67 unneback
if (nr_of_ports == 6) begin
691
 
692
    wire [2:0] wbm5_cti_o, wbm4_cti_o, wbm3_cti_o, wbm2_cti_o, wbm1_cti_o, wbm0_cti_o;
693
 
694
    assign {wbm5_cti_o, wbm4_cti_o, wbm3_cti_o, wbm2_cti_o,wbm1_cti_o,wbm0_cti_o} = wbm_cti_o;
695
 
696
    //assign select = (idle) ? {wbm_cyc_o[3],!wbm_cyc_o[3] & wbm_cyc_o[2],wbm_cyc_o[3:2]==2'b00 & wbm_cyc_o[1],wbm_cyc_o[3:1]==3'b000 & wbm_cyc_o[0]} : {nr_of_ports{1'b0}};
697
 
698
    always @ (idle or wbm_cyc_o)
699
    if (idle)
700
        casex (wbm_cyc_o)
701
        6'b1xxxxx : select = 6'b100000;
702
        6'b01xxxx : select = 6'b010000;
703
        6'b001xxx : select = 6'b001000;
704
        6'b0001xx : select = 6'b000100;
705
        6'b00001x : select = 6'b000010;
706
        6'b000001 : select = 6'b000001;
707
        default : select = {nr_of_ports{1'b0}};
708
        endcase
709
    else
710
        select = {nr_of_ports{1'b0}};
711
 
712
    assign eoc[5] = (wbm_ack_i[5] & (wbm5_cti_o == 3'b000 | wbm5_cti_o == 3'b111)) | !wbm_cyc_o[5];
713
    assign eoc[4] = (wbm_ack_i[4] & (wbm4_cti_o == 3'b000 | wbm4_cti_o == 3'b111)) | !wbm_cyc_o[4];
714
    assign eoc[3] = (wbm_ack_i[3] & (wbm3_cti_o == 3'b000 | wbm3_cti_o == 3'b111)) | !wbm_cyc_o[3];
715
    assign eoc[2] = (wbm_ack_i[2] & (wbm2_cti_o == 3'b000 | wbm2_cti_o == 3'b111)) | !wbm_cyc_o[2];
716
    assign eoc[1] = (wbm_ack_i[1] & (wbm1_cti_o == 3'b000 | wbm1_cti_o == 3'b111)) | !wbm_cyc_o[1];
717
    assign eoc[0] = (wbm_ack_i[0] & (wbm0_cti_o == 3'b000 | wbm0_cti_o == 3'b111)) | !wbm_cyc_o[0];
718
 
719
end
720
endgenerate
721
 
722
generate
723
if (nr_of_ports == 7) begin
724
 
725
    wire [2:0] wbm6_cti_o, wbm5_cti_o, wbm4_cti_o, wbm3_cti_o, wbm2_cti_o, wbm1_cti_o, wbm0_cti_o;
726
 
727
    assign {wbm6_cti_o, wbm5_cti_o, wbm4_cti_o, wbm3_cti_o, wbm2_cti_o,wbm1_cti_o,wbm0_cti_o} = wbm_cti_o;
728
 
729
    //assign select = (idle) ? {wbm_cyc_o[3],!wbm_cyc_o[3] & wbm_cyc_o[2],wbm_cyc_o[3:2]==2'b00 & wbm_cyc_o[1],wbm_cyc_o[3:1]==3'b000 & wbm_cyc_o[0]} : {nr_of_ports{1'b0}};
730
 
731
    always @ (idle or wbm_cyc_o)
732
    if (idle)
733
        casex (wbm_cyc_o)
734
        7'b1xxxxxx : select = 7'b1000000;
735
        7'b01xxxxx : select = 7'b0100000;
736
        7'b001xxxx : select = 7'b0010000;
737
        7'b0001xxx : select = 7'b0001000;
738
        7'b00001xx : select = 7'b0000100;
739
        7'b000001x : select = 7'b0000010;
740
        7'b0000001 : select = 7'b0000001;
741
        default : select = {nr_of_ports{1'b0}};
742
        endcase
743
    else
744
        select = {nr_of_ports{1'b0}};
745
 
746
    assign eoc[6] = (wbm_ack_i[6] & (wbm6_cti_o == 3'b000 | wbm6_cti_o == 3'b111)) | !wbm_cyc_o[6];
747
    assign eoc[5] = (wbm_ack_i[5] & (wbm5_cti_o == 3'b000 | wbm5_cti_o == 3'b111)) | !wbm_cyc_o[5];
748
    assign eoc[4] = (wbm_ack_i[4] & (wbm4_cti_o == 3'b000 | wbm4_cti_o == 3'b111)) | !wbm_cyc_o[4];
749
    assign eoc[3] = (wbm_ack_i[3] & (wbm3_cti_o == 3'b000 | wbm3_cti_o == 3'b111)) | !wbm_cyc_o[3];
750
    assign eoc[2] = (wbm_ack_i[2] & (wbm2_cti_o == 3'b000 | wbm2_cti_o == 3'b111)) | !wbm_cyc_o[2];
751
    assign eoc[1] = (wbm_ack_i[1] & (wbm1_cti_o == 3'b000 | wbm1_cti_o == 3'b111)) | !wbm_cyc_o[1];
752
    assign eoc[0] = (wbm_ack_i[0] & (wbm0_cti_o == 3'b000 | wbm0_cti_o == 3'b111)) | !wbm_cyc_o[0];
753
 
754
end
755
endgenerate
756
 
757
generate
758
if (nr_of_ports == 8) begin
759
 
760
    wire [2:0] wbm7_cti_o, wbm6_cti_o, wbm5_cti_o, wbm4_cti_o, wbm3_cti_o, wbm2_cti_o, wbm1_cti_o, wbm0_cti_o;
761
 
762
    assign {wbm7_cti_o, wbm6_cti_o, wbm5_cti_o, wbm4_cti_o, wbm3_cti_o, wbm2_cti_o,wbm1_cti_o,wbm0_cti_o} = wbm_cti_o;
763
 
764
    //assign select = (idle) ? {wbm_cyc_o[3],!wbm_cyc_o[3] & wbm_cyc_o[2],wbm_cyc_o[3:2]==2'b00 & wbm_cyc_o[1],wbm_cyc_o[3:1]==3'b000 & wbm_cyc_o[0]} : {nr_of_ports{1'b0}};
765
 
766
    always @ (idle or wbm_cyc_o)
767
    if (idle)
768
        casex (wbm_cyc_o)
769
        8'b1xxxxxxx : select = 8'b10000000;
770
        8'b01xxxxxx : select = 8'b01000000;
771
        8'b001xxxxx : select = 8'b00100000;
772
        8'b0001xxxx : select = 8'b00010000;
773
        8'b00001xxx : select = 8'b00001000;
774
        8'b000001xx : select = 8'b00000100;
775
        8'b0000001x : select = 8'b00000010;
776
        8'b00000001 : select = 8'b00000001;
777
        default : select = {nr_of_ports{1'b0}};
778
        endcase
779
    else
780
        select = {nr_of_ports{1'b0}};
781
 
782
    assign eoc[7] = (wbm_ack_i[7] & (wbm7_cti_o == 3'b000 | wbm7_cti_o == 3'b111)) | !wbm_cyc_o[7];
783
    assign eoc[6] = (wbm_ack_i[6] & (wbm6_cti_o == 3'b000 | wbm6_cti_o == 3'b111)) | !wbm_cyc_o[6];
784
    assign eoc[5] = (wbm_ack_i[5] & (wbm5_cti_o == 3'b000 | wbm5_cti_o == 3'b111)) | !wbm_cyc_o[5];
785
    assign eoc[4] = (wbm_ack_i[4] & (wbm4_cti_o == 3'b000 | wbm4_cti_o == 3'b111)) | !wbm_cyc_o[4];
786
    assign eoc[3] = (wbm_ack_i[3] & (wbm3_cti_o == 3'b000 | wbm3_cti_o == 3'b111)) | !wbm_cyc_o[3];
787
    assign eoc[2] = (wbm_ack_i[2] & (wbm2_cti_o == 3'b000 | wbm2_cti_o == 3'b111)) | !wbm_cyc_o[2];
788
    assign eoc[1] = (wbm_ack_i[1] & (wbm1_cti_o == 3'b000 | wbm1_cti_o == 3'b111)) | !wbm_cyc_o[1];
789
    assign eoc[0] = (wbm_ack_i[0] & (wbm0_cti_o == 3'b000 | wbm0_cti_o == 3'b111)) | !wbm_cyc_o[0];
790
 
791
end
792
endgenerate
793
 
794
generate
795 63 unneback
for (i=0;i<nr_of_ports;i=i+1) begin : spr0
796 42 unneback
`define MODULE spr
797
    `BASE`MODULE sr0( .sp(select[i]), .r(eoc[i]), .q(state[i]), .clk(wb_clk), .rst(wb_rst));
798
`undef MODULE
799 39 unneback
end
800
endgenerate
801
 
802
    assign sel = select | state;
803
 
804 40 unneback
`define MODULE mux_andor
805
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(32)) mux0 ( .a(wbm_dat_o), .sel(sel), .dout(wbs_dat_i));
806
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(adr_size-adr_lo)) mux1 ( .a(wbm_adr_o), .sel(sel), .dout(wbs_adr_i));
807
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(sel_size)) mux2 ( .a(wbm_sel_o), .sel(sel), .dout(wbs_sel_i));
808
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(3)) mux3 ( .a(wbm_cti_o), .sel(sel), .dout(wbs_cti_i));
809
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(2)) mux4 ( .a(wbm_bte_o), .sel(sel), .dout(wbs_bte_i));
810
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(1)) mux5 ( .a(wbm_we_o), .sel(sel), .dout(wbs_we_i));
811
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(1)) mux6 ( .a(wbm_stb_o), .sel(sel), .dout(wbs_stb_i));
812
`undef MODULE
813 39 unneback
    assign wbs_cyc_i = |sel;
814
 
815
    assign wbm_dat_i = {nr_of_ports{wbs_dat_o}};
816
    assign wbm_ack_i = {nr_of_ports{wbs_ack_o}} & sel;
817
    assign wbm_err_i = {nr_of_ports{wbs_err_o}} & sel;
818
    assign wbm_rty_i = {nr_of_ports{wbs_rty_o}} & sel;
819
 
820
endmodule
821 40 unneback
`endif
822 39 unneback
 
823 101 unneback
`ifdef WB_RAM
824 49 unneback
// WB RAM with byte enable
825 101 unneback
`define MODULE wb_ram
826 59 unneback
module `BASE`MODULE (
827
`undef MODULE
828 69 unneback
    wbs_dat_i, wbs_adr_i, wbs_cti_i, wbs_bte_i, wbs_sel_i, wbs_we_i, wbs_stb_i, wbs_cyc_i,
829 101 unneback
    wbs_dat_o, wbs_ack_o, wbs_stall_o, wb_clk, wb_rst);
830 59 unneback
 
831 101 unneback
parameter adr_width = 16;
832
parameter mem_size = 1<<adr_width;
833
parameter dat_width = 32;
834
parameter max_burst_width = 4; // only used for B3
835
parameter mode = "B3"; // valid options: B3, B4
836 60 unneback
parameter memory_init = 1;
837
parameter memory_file = "vl_ram.vmem";
838 59 unneback
 
839 101 unneback
input [dat_width-1:0] wbs_dat_i;
840
input [adr_width-1:0] wbs_adr_i;
841
input [2:0] wbs_cti_i;
842
input [1:0] wbs_bte_i;
843
input [dat_width/8-1:0] wbs_sel_i;
844 70 unneback
input wbs_we_i, wbs_stb_i, wbs_cyc_i;
845 101 unneback
output [dat_width-1:0] wbs_dat_o;
846 70 unneback
output wbs_ack_o;
847 101 unneback
output wbs_stall_o;
848 71 unneback
input wb_clk, wb_rst;
849 59 unneback
 
850 101 unneback
wire [adr_width-1:0] adr;
851
wire we;
852 59 unneback
 
853 101 unneback
generate
854
if (mode=="B3") begin : B3_inst
855 83 unneback
`define MODULE wb_adr_inc
856 101 unneback
`BASE`MODULE # ( .adr_width(adr_width), .max_burst_width(max_burst_width)) adr_inc0 (
857 83 unneback
    .cyc_i(wbs_cyc_i),
858
    .stb_i(wbs_stb_i),
859
    .cti_i(wbs_cti_i),
860
    .bte_i(wbs_bte_i),
861
    .adr_i(wbs_adr_i),
862 84 unneback
    .we_i(wbs_we_i),
863 83 unneback
    .ack_o(wbs_ack_o),
864
    .adr_o(adr),
865
    .clk(wb_clk),
866
    .rst(wb_rst));
867
`undef MODULE
868 101 unneback
assign we = wbs_we_i & wbs_ack_o;
869
end else if (mode=="B4") begin : B4_inst
870
reg wbs_ack_o_reg;
871
always @ (posedge wb_clk or posedge wb_rst)
872
    if (wb_rst)
873
        wbs_ack_o_reg <= 1'b0;
874
    else
875
        wbs_ack_o_reg <= wbs_stb_i & wbs_cyc_i;
876
assign wbs_ack_o = wbs_ack_o_reg;
877
assign wbs_stall_o = 1'b0;
878
assign adr = wbs_adr_i;
879
assign we = wbs_we_i & wbs_cyc_i & wbs_stb_i;
880
end
881
endgenerate
882 60 unneback
 
883 100 unneback
`define MODULE ram_be
884
`BASE`MODULE # (
885
    .data_width(dat_width),
886
    .addr_width(adr_width),
887
    .mem_size(mem_size),
888
    .memory_init(memory_init),
889
    .memory_file(memory_file))
890
ram0(
891
`undef MODULE
892 101 unneback
    .d(wbs_dat_i),
893
    .adr(adr),
894
    .be(wbs_sel_i),
895
    .we(we),
896
    .q(wbs_dat_o),
897 100 unneback
    .clk(wb_clk)
898
);
899 49 unneback
 
900
endmodule
901
`endif
902
 
903 103 unneback
`ifdef WB_SHADOW_RAM
904
// A wishbone compliant RAM module that can be placed in front of other memory controllers
905
`define MODULE wb_shadow_ram
906
module `BASE`MODULE (
907
`undef MODULE
908
    wbs_dat_i, wbs_adr_i, wbs_cti_i, wbs_bte_i, wbs_sel_i, wbs_we_i, wbs_stb_i, wbs_cyc_i,
909
    wbs_dat_o, wbs_ack_o, wbs_stall_o,
910
    wbm_dat_o, wbm_adr_o, wbm_cti_o, wbm_bte_o, wbm_sel_o, wbm_we_o, wbm_stb_o, wbm_cyc_o,
911
    wbm_dat_i, wbm_ack_i, wbm_stall_i,
912
    wb_clk, wb_rst);
913
 
914
parameter dat_width = 32;
915
parameter mode = "B4";
916
parameter max_burst_width = 4; // only used for B3
917
 
918
parameter shadow_mem_adr_width = 10;
919
parameter shadow_mem_size = 1024;
920
parameter shadow_mem_init = 2;
921
parameter shadow_mem_file = "vl_ram.v";
922
 
923
parameter main_mem_adr_width = 24;
924
 
925
input [dat_width-1:0] wbs_dat_i;
926
input [main_mem_adr_width-1:0] wbs_adr_i;
927
input [2:0] wbs_cti_i;
928
input [1:0] wbs_bte_i;
929
input [dat_width/8-1:0] wbs_sel_i;
930
input wbs_we_i, wbs_stb_i, wbs_cyc_i;
931
output [dat_width-1:0] wbs_dat_o;
932
output wbs_ack_o;
933
output wbs_stall_o;
934
 
935
output [dat_width-1:0] wbm_dat_o;
936
output [main_mem_adr_width-1:0] wbm_adr_o;
937
output [2:0] wbm_cti_o;
938
output [1:0] wbm_bte_o;
939
output [dat_width/8-1:0] wbm_sel_o;
940
output wbm_we_o, wbm_stb_o, wbm_cyc_o;
941
input [dat_width-1:0] wbm_dat_i;
942
input wbm_ack_i, wbm_stall_i;
943
 
944
input wb_clk, wb_rst;
945
 
946
generate
947
if (shadow_mem_size>0) begin : shadow_ram_inst
948
 
949
wire cyc;
950
wire [dat_width-1:0] dat;
951
wire stall, ack;
952
 
953
assign cyc = wbs_cyc_i & (wbs_adr_i<=shadow_mem_size);
954
`define MODULE wb_ram
955
`BASE`MODULE # (
956
    .dat_width(dat_width),
957
    .adr_width(shadow_mem_adr_width),
958
    .mem_size(shadow_mem_size),
959
    .memory_init(shadow_mem_init),
960
    .mode(mode))
961
shadow_mem0 (
962
    .wbs_dat_i(wbs_dat_i),
963
    .wbs_adr_i(wbs_adr_i[shadow_mem_adr_width-1:0]),
964
    .wbs_sel_i(wbs_sel_i),
965
    .wbs_we_i (wbs_we_i),
966
    .wbs_bte_i(wbs_bte_i),
967
    .wbs_cti_i(wbs_cti_i),
968
    .wbs_stb_i(wbs_stb_i),
969
    .wbs_cyc_i(cyc),
970
    .wbs_dat_o(dat),
971
    .wbs_stall_o(stall),
972
    .wbs_ack_o(ack),
973
    .wb_clk(wb_clk),
974
    .wb_rst(wb_rst));
975
`undef MODULE
976
 
977
assign {wbm_dat_o, wbm_adr_o, wbm_cti_o, wbm_bte_o, wbm_sel_o, wbm_we_o, wbm_stb_o} =
978
       {wbs_dat_i, wbs_adr_i, wbs_cti_i, wbs_bte_i, wbs_sel_i, wbs_we_i, wbs_stb_i};
979
assign wbm_cyc_o = wbs_cyc_i & (wbs_adr_i>shadow_mem_size);
980
 
981
assign wbs_dat_o = (dat & {dat_width{cyc}}) | (wbm_dat_i & {dat_width{wbm_cyc_o}});
982
assign wbs_ack_o = (ack & cyc) | (wbm_ack_i & wbm_cyc_o);
983
assign wbs_stall_o = (stall & cyc) | (wbm_stall_i & wbm_cyc_o);
984
 
985
end else begin : no_shadow_ram_inst
986
 
987
assign {wbm_dat_o, wbm_adr_o, wbm_cti_o, wbm_bte_o, wbm_sel_o, wbm_we_o, wbm_stb_o, wbm_cyc_o} =
988
       {wbs_dat_i, wbs_adr_i, wbs_cti_i, wbs_bte_i, wbs_sel_i, wbs_we_i, wbs_stb_i, wbs_cyc_i};
989
assign {wbs_dat_o, wbs_ack_o, wbs_stall_o} = {wbm_dat_i, wbm_ack_i, wbm_stall_i};
990
 
991
end
992
endgenerate
993
 
994
endmodule
995
`endif
996
 
997 48 unneback
`ifdef WB_B4_ROM
998
// WB ROM
999
`define MODULE wb_b4_rom
1000
module `BASE`MODULE (
1001
`undef MODULE
1002
    wb_adr_i, wb_stb_i, wb_cyc_i,
1003
    wb_dat_o, stall_o, wb_ack_o, wb_clk, wb_rst);
1004
 
1005
    parameter dat_width = 32;
1006
    parameter dat_default = 32'h15000000;
1007
    parameter adr_width = 32;
1008
 
1009
/*
1010
//E2_ifndef ROM
1011
//E2_define ROM "rom.v"
1012
//E2_endif
1013
*/
1014
    input [adr_width-1:2]   wb_adr_i;
1015
    input                   wb_stb_i;
1016
    input                   wb_cyc_i;
1017
    output [dat_width-1:0]  wb_dat_o;
1018
    reg [dat_width-1:0]     wb_dat_o;
1019
    output                  wb_ack_o;
1020
    reg                     wb_ack_o;
1021
    output                  stall_o;
1022
    input                   wb_clk;
1023
    input                   wb_rst;
1024
 
1025
always @ (posedge wb_clk or posedge wb_rst)
1026
    if (wb_rst)
1027
        wb_dat_o <= {dat_width{1'b0}};
1028
    else
1029
         case (wb_adr_i[adr_width-1:2])
1030
//E2_ifdef ROM
1031
//E2_include `ROM
1032
//E2_endif
1033
           default:
1034
             wb_dat_o <= dat_default;
1035
 
1036
         endcase // case (wb_adr_i)
1037
 
1038
 
1039
always @ (posedge wb_clk or posedge wb_rst)
1040
    if (wb_rst)
1041
        wb_ack_o <= 1'b0;
1042
    else
1043
        wb_ack_o <= wb_stb_i & wb_cyc_i;
1044
 
1045
assign stall_o = 1'b0;
1046
 
1047
endmodule
1048
`endif
1049
 
1050
 
1051 40 unneback
`ifdef WB_BOOT_ROM
1052 17 unneback
// WB ROM
1053 40 unneback
`define MODULE wb_boot_rom
1054
module `BASE`MODULE (
1055
`undef MODULE
1056 17 unneback
    wb_adr_i, wb_stb_i, wb_cyc_i,
1057 18 unneback
    wb_dat_o, wb_ack_o, hit_o, wb_clk, wb_rst);
1058 17 unneback
 
1059 18 unneback
    parameter adr_hi = 31;
1060
    parameter adr_lo = 28;
1061
    parameter adr_sel = 4'hf;
1062
    parameter addr_width = 5;
1063 33 unneback
/*
1064 17 unneback
//E2_ifndef BOOT_ROM
1065
//E2_define BOOT_ROM "boot_rom.v"
1066
//E2_endif
1067 33 unneback
*/
1068 18 unneback
    input [adr_hi:2]    wb_adr_i;
1069
    input               wb_stb_i;
1070
    input               wb_cyc_i;
1071
    output [31:0]        wb_dat_o;
1072
    output              wb_ack_o;
1073
    output              hit_o;
1074
    input               wb_clk;
1075
    input               wb_rst;
1076
 
1077
    wire hit;
1078
    reg [31:0] wb_dat;
1079
    reg wb_ack;
1080
 
1081
assign hit = wb_adr_i[adr_hi:adr_lo] == adr_sel;
1082 17 unneback
 
1083
always @ (posedge wb_clk or posedge wb_rst)
1084
    if (wb_rst)
1085 18 unneback
        wb_dat <= 32'h15000000;
1086 17 unneback
    else
1087 18 unneback
         case (wb_adr_i[addr_width-1:2])
1088 33 unneback
//E2_ifdef BOOT_ROM
1089 17 unneback
//E2_include `BOOT_ROM
1090 33 unneback
//E2_endif
1091 17 unneback
           /*
1092
            // Zero r0 and jump to 0x00000100
1093 18 unneback
 
1094
            1 : wb_dat <= 32'hA8200000;
1095
            2 : wb_dat <= 32'hA8C00100;
1096
            3 : wb_dat <= 32'h44003000;
1097
            4 : wb_dat <= 32'h15000000;
1098 17 unneback
            */
1099
           default:
1100 18 unneback
             wb_dat <= 32'h00000000;
1101 17 unneback
 
1102
         endcase // case (wb_adr_i)
1103
 
1104
 
1105
always @ (posedge wb_clk or posedge wb_rst)
1106
    if (wb_rst)
1107 18 unneback
        wb_ack <= 1'b0;
1108 17 unneback
    else
1109 18 unneback
        wb_ack <= wb_stb_i & wb_cyc_i & hit & !wb_ack;
1110 17 unneback
 
1111 18 unneback
assign hit_o = hit;
1112
assign wb_dat_o = wb_dat & {32{wb_ack}};
1113
assign wb_ack_o = wb_ack;
1114
 
1115 17 unneback
endmodule
1116 40 unneback
`endif
1117 32 unneback
 
1118 106 unneback
`ifdef WB_DPRAM
1119
`define MODULE wb_dpram
1120 40 unneback
module `BASE`MODULE (
1121
`undef MODULE
1122 32 unneback
        // wishbone slave side a
1123 106 unneback
        wbsa_dat_i, wbsa_adr_i, wbsa_sel_i, wbsa_cti_i, wbsa_bte_i, wbsa_we_i, wbsa_cyc_i, wbsa_stb_i, wbsa_dat_o, wbsa_ack_o, wbsa_stall_o,
1124 32 unneback
        wbsa_clk, wbsa_rst,
1125 92 unneback
        // wishbone slave side b
1126 106 unneback
        wbsb_dat_i, wbsb_adr_i, wbsb_sel_i, wbsb_cti_i, wbsb_bte_i, wbsb_we_i, wbsb_cyc_i, wbsb_stb_i, wbsb_dat_o, wbsb_ack_o, wbsb_stall_o,
1127 32 unneback
        wbsb_clk, wbsb_rst);
1128
 
1129 92 unneback
parameter data_width_a = 32;
1130
parameter data_width_b = data_width_a;
1131
parameter addr_width_a = 8;
1132
localparam addr_width_b = data_width_a * addr_width_a / data_width_b;
1133 101 unneback
parameter mem_size = (addr_width_a>addr_width_b) ? (1<<addr_width_a) : (1<<addr_width_b);
1134 92 unneback
parameter max_burst_width_a = 4;
1135
parameter max_burst_width_b = max_burst_width_a;
1136 101 unneback
parameter mode = "B3";
1137 109 unneback
parameter memory_init = 0;
1138
parameter memory_file = "vl_ram.v";
1139 92 unneback
input [data_width_a-1:0] wbsa_dat_i;
1140
input [addr_width_a-1:0] wbsa_adr_i;
1141
input [data_width_a/8-1:0] wbsa_sel_i;
1142
input [2:0] wbsa_cti_i;
1143
input [1:0] wbsa_bte_i;
1144 32 unneback
input wbsa_we_i, wbsa_cyc_i, wbsa_stb_i;
1145 92 unneback
output [data_width_a-1:0] wbsa_dat_o;
1146 109 unneback
output wbsa_ack_o;
1147 106 unneback
output wbsa_stall_o;
1148 32 unneback
input wbsa_clk, wbsa_rst;
1149
 
1150 92 unneback
input [data_width_b-1:0] wbsb_dat_i;
1151
input [addr_width_b-1:0] wbsb_adr_i;
1152
input [data_width_b/8-1:0] wbsb_sel_i;
1153
input [2:0] wbsb_cti_i;
1154
input [1:0] wbsb_bte_i;
1155 32 unneback
input wbsb_we_i, wbsb_cyc_i, wbsb_stb_i;
1156 92 unneback
output [data_width_b-1:0] wbsb_dat_o;
1157 109 unneback
output wbsb_ack_o;
1158 106 unneback
output wbsb_stall_o;
1159 32 unneback
input wbsb_clk, wbsb_rst;
1160
 
1161 92 unneback
wire [addr_width_a-1:0] adr_a;
1162
wire [addr_width_b-1:0] adr_b;
1163 101 unneback
wire we_a, we_b;
1164
generate
1165
if (mode=="B3") begin : b3_inst
1166 92 unneback
`define MODULE wb_adr_inc
1167
`BASE`MODULE # ( .adr_width(addr_width_a), .max_burst_width(max_burst_width_a)) adr_inc0 (
1168
    .cyc_i(wbsa_cyc_i),
1169
    .stb_i(wbsa_stb_i),
1170
    .cti_i(wbsa_cti_i),
1171
    .bte_i(wbsa_bte_i),
1172
    .adr_i(wbsa_adr_i),
1173
    .we_i(wbsa_we_i),
1174
    .ack_o(wbsa_ack_o),
1175
    .adr_o(adr_a),
1176
    .clk(wbsa_clk),
1177
    .rst(wbsa_rst));
1178 101 unneback
assign we_a = wbsa_we_i & wbsa_ack_o;
1179 92 unneback
`BASE`MODULE # ( .adr_width(addr_width_b), .max_burst_width(max_burst_width_b)) adr_inc1 (
1180
    .cyc_i(wbsb_cyc_i),
1181
    .stb_i(wbsb_stb_i),
1182
    .cti_i(wbsb_cti_i),
1183
    .bte_i(wbsb_bte_i),
1184
    .adr_i(wbsb_adr_i),
1185
    .we_i(wbsb_we_i),
1186
    .ack_o(wbsb_ack_o),
1187
    .adr_o(adr_b),
1188
    .clk(wbsb_clk),
1189
    .rst(wbsb_rst));
1190 40 unneback
`undef MODULE
1191 101 unneback
assign we_b = wbsb_we_i & wbsb_ack_o;
1192
end else if (mode=="B4") begin : b4_inst
1193 109 unneback
`define MODULE dff
1194
`BASE`MODULE dffacka ( .d(wbsa_stb_i & wbsa_cyc_i), .q(wbsa_ack_o), .clk(wbsa_clk), .rst(wbsa_rst));
1195 101 unneback
assign wbsa_stall_o = 1'b0;
1196
assign we_a = wbsa_we_i & wbsa_cyc_i & wbsa_stb_i;
1197 109 unneback
`BASE`MODULE dffackb ( .d(wbsb_stb_i & wbsb_cyc_i), .q(wbsb_ack_o), .clk(wbsb_clk), .rst(wbsb_rst));
1198
`undef MODULE
1199 101 unneback
assign wbsb_stall_o = 1'b0;
1200
assign we_b = wbsb_we_i & wbsb_cyc_i & wbsb_stb_i;
1201
end
1202
endgenerate
1203 92 unneback
 
1204
`define MODULE dpram_be_2r2w
1205 109 unneback
`BASE`MODULE # ( .a_data_width(data_width_a), .a_addr_width(addr_width_a), .mem_size(mem_size),
1206 110 unneback
                 .b_data_width(data_width_b),
1207 109 unneback
                 .memory_init(memory_init), .memory_file(memory_file))
1208 92 unneback
`undef MODULE
1209
ram_i (
1210 32 unneback
    .d_a(wbsa_dat_i),
1211 92 unneback
    .q_a(wbsa_dat_o),
1212
    .adr_a(adr_a),
1213
    .be_a(wbsa_sel_i),
1214 101 unneback
    .we_a(we_a),
1215 32 unneback
    .clk_a(wbsa_clk),
1216
    .d_b(wbsb_dat_i),
1217 92 unneback
    .q_b(wbsb_dat_o),
1218
    .adr_b(adr_b),
1219
    .be_b(wbsb_sel_i),
1220 101 unneback
    .we_b(we_b),
1221 32 unneback
    .clk_b(wbsb_clk) );
1222
 
1223
endmodule
1224 40 unneback
`endif
1225 94 unneback
 
1226 101 unneback
`ifdef WB_CACHE
1227
`define MODULE wb_cache
1228 96 unneback
module `BASE`MODULE (
1229 103 unneback
    wbs_dat_i, wbs_adr_i, wbs_sel_i, wbs_cti_i, wbs_bte_i, wbs_we_i, wbs_stb_i, wbs_cyc_i, wbs_dat_o, wbs_ack_o, wbs_stall_o, wbs_clk, wbs_rst,
1230 98 unneback
    wbm_dat_o, wbm_adr_o, wbm_sel_o, wbm_cti_o, wbm_bte_o, wbm_we_o, wbm_stb_o, wbm_cyc_o, wbm_dat_i, wbm_ack_i, wbm_stall_i, wbm_clk, wbm_rst
1231 96 unneback
);
1232
`undef MODULE
1233
 
1234
parameter dw_s = 32;
1235
parameter aw_s = 24;
1236
parameter dw_m = dw_s;
1237 100 unneback
localparam aw_m = dw_s * aw_s / dw_m;
1238
parameter wbs_max_burst_width = 4;
1239 103 unneback
parameter wbs_mode = "B3";
1240 96 unneback
 
1241 97 unneback
parameter async = 1; // wbs_clk != wbm_clk
1242
 
1243 96 unneback
parameter nr_of_ways = 1;
1244 97 unneback
parameter aw_offset = 4; // 4 => 16 words per cache line
1245
parameter aw_slot = 10;
1246 100 unneback
 
1247
parameter valid_mem = 0;
1248
parameter debug = 0;
1249
 
1250
localparam aw_b_offset = aw_offset * dw_s / dw_m;
1251 98 unneback
localparam aw_tag = aw_s - aw_slot - aw_offset;
1252 97 unneback
parameter wbm_burst_size = 4; // valid options 4,8,16
1253 98 unneback
localparam bte = (wbm_burst_size==4) ? 2'b01 : (wbm_burst_size==8) ? 2'b10 : 2'b11;
1254 97 unneback
`define SIZE2WIDTH wbm_burst_size
1255
localparam wbm_burst_width `SIZE2WIDTH_EXPR
1256
`undef SIZE2WIDTH
1257
localparam nr_of_wbm_burst = ((1<<aw_offset)/wbm_burst_size) * dw_s / dw_m;
1258
`define SIZE2WIDTH nr_of_wbm_burst
1259
localparam nr_of_wbm_burst_width `SIZE2WIDTH_EXPR
1260
`undef SIZE2WIDTH
1261 100 unneback
 
1262 96 unneback
input [dw_s-1:0] wbs_dat_i;
1263
input [aw_s-1:0] wbs_adr_i; // dont include a1,a0
1264 98 unneback
input [dw_s/8-1:0] wbs_sel_i;
1265 96 unneback
input [2:0] wbs_cti_i;
1266
input [1:0] wbs_bte_i;
1267 98 unneback
input wbs_we_i, wbs_stb_i, wbs_cyc_i;
1268 96 unneback
output [dw_s-1:0] wbs_dat_o;
1269
output wbs_ack_o;
1270 103 unneback
output wbs_stall_o;
1271 96 unneback
input wbs_clk, wbs_rst;
1272
 
1273
output [dw_m-1:0] wbm_dat_o;
1274
output [aw_m-1:0] wbm_adr_o;
1275
output [dw_m/8-1:0] wbm_sel_o;
1276
output [2:0] wbm_cti_o;
1277
output [1:0] wbm_bte_o;
1278 98 unneback
output wbm_stb_o, wbm_cyc_o, wbm_we_o;
1279 96 unneback
input [dw_m-1:0] wbm_dat_i;
1280
input wbm_ack_i;
1281
input wbm_stall_i;
1282
input wbm_clk, wbm_rst;
1283
 
1284 100 unneback
wire valid, dirty, hit;
1285 97 unneback
wire [aw_tag-1:0] tag;
1286
wire tag_mem_we;
1287
wire [aw_tag-1:0] wbs_adr_tag;
1288
wire [aw_slot-1:0] wbs_adr_slot;
1289 98 unneback
wire [aw_offset-1:0] wbs_adr_word;
1290
wire [aw_s-1:0] wbs_adr;
1291 96 unneback
 
1292 97 unneback
reg [1:0] state;
1293
localparam idle = 2'h0;
1294
localparam rdwr = 2'h1;
1295
localparam push = 2'h2;
1296
localparam pull = 2'h3;
1297
wire eoc;
1298 103 unneback
wire we;
1299 97 unneback
 
1300
// cdc
1301
wire done, mem_alert, mem_done;
1302
 
1303 98 unneback
// wbm side
1304
reg [aw_m-1:0] wbm_radr;
1305
reg [aw_m-1:0] wbm_wadr;
1306 100 unneback
wire [aw_slot-1:0] wbm_adr;
1307 98 unneback
wire wbm_radr_cke, wbm_wadr_cke;
1308
 
1309 100 unneback
reg [2:0] phase;
1310
// phase = {we,stb,cyc}
1311
localparam wbm_wait     = 3'b000;
1312
localparam wbm_wr       = 3'b111;
1313
localparam wbm_wr_drain = 3'b101;
1314
localparam wbm_rd       = 3'b011;
1315
localparam wbm_rd_drain = 3'b001;
1316 98 unneback
 
1317 97 unneback
assign {wbs_adr_tag, wbs_adr_slot, wbs_adr_word} = wbs_adr_i;
1318
 
1319 100 unneback
generate
1320
if (valid_mem==0) begin : no_valid_mem
1321
assign valid = 1'b1;
1322
end else begin : valid_mem_inst
1323
`define MODULE dpram_1r1w
1324 97 unneback
`BASE`MODULE
1325 100 unneback
    # ( .data_width(1), .addr_width(aw_slot), .memory_init(2), .debug(debug))
1326
    valid_mem ( .d_a(1'b1), .adr_a(wbs_adr_slot), .we_a(mem_done), .clk_a(wbm_clk),
1327
                .q_b(valid), .adr_b(wbs_adr_slot), .clk_b(wbs_clk));
1328 97 unneback
`undef MODULE
1329 100 unneback
end
1330
endgenerate
1331 97 unneback
 
1332 100 unneback
`define MODULE dpram_1r1w
1333
`BASE`MODULE
1334
    # ( .data_width(aw_tag), .addr_width(aw_slot), .memory_init(2), .debug(debug))
1335
    tag_mem ( .d_a(wbs_adr_tag), .adr_a(wbs_adr_slot), .we_a(mem_done), .clk_a(wbm_clk),
1336
              .q_b(tag), .adr_b(wbs_adr_slot), .clk_b(wbs_clk));
1337
assign hit = wbs_adr_tag == tag;
1338
`undef MODULE
1339
 
1340
`define MODULE dpram_1r2w
1341
`BASE`MODULE
1342
    # ( .data_width(1), .addr_width(aw_slot), .memory_init(2), .debug(debug))
1343
    dirty_mem (
1344
        .d_a(1'b1), .q_a(dirty), .adr_a(wbs_adr_slot), .we_a(wbs_cyc_i & wbs_we_i & wbs_ack_o), .clk_a(wbs_clk),
1345
        .d_b(1'b0), .adr_b(wbs_adr_slot), .we_b(mem_done), .clk_b(wbm_clk));
1346
`undef MODULE
1347
 
1348 103 unneback
generate
1349
if (wbs_mode=="B3") begin : inst_b3
1350 96 unneback
`define MODULE wb_adr_inc
1351 100 unneback
`BASE`MODULE # ( .adr_width(aw_s), .max_burst_width(wbs_max_burst_width)) adr_inc0 (
1352
    .cyc_i(wbs_cyc_i & (state==rdwr) & hit & valid),
1353
    .stb_i(wbs_stb_i & (state==rdwr) & hit & valid), // throttle depending on valid
1354 96 unneback
    .cti_i(wbs_cti_i),
1355
    .bte_i(wbs_bte_i),
1356
    .adr_i(wbs_adr_i),
1357 97 unneback
    .we_i (wbs_we_i),
1358 96 unneback
    .ack_o(wbs_ack_o),
1359 97 unneback
    .adr_o(wbs_adr),
1360 100 unneback
    .clk(wbs_clk),
1361
    .rst(wbs_rst));
1362 96 unneback
`undef MODULE
1363 103 unneback
assign eoc = (wbs_cti_i==3'b000 | wbs_cti_i==3'b111) & wbs_ack_o;
1364
assign we = wbs_cyc_i &  wbs_we_i & wbs_ack_o;
1365
end else if (wbs_mode=="B4") begin : inst_b4
1366
end
1367 96 unneback
 
1368 103 unneback
endgenerate
1369
 
1370 97 unneback
`define MODULE dpram_be_2r2w
1371
`BASE`MODULE
1372 100 unneback
    # ( .a_data_width(dw_s), .a_addr_width(aw_slot+aw_offset), .b_data_width(dw_m), .debug(debug))
1373 103 unneback
    cache_mem ( .d_a(wbs_dat_i), .adr_a(wbs_adr[aw_slot+aw_offset-1:0]),   .be_a(wbs_sel_i), .we_a(we), .q_a(wbs_dat_o), .clk_a(wbs_clk),
1374 100 unneback
                .d_b(wbm_dat_i), .adr_b(wbm_adr_o[aw_slot+aw_offset-1:0]), .be_b(wbm_sel_o), .we_b(wbm_cyc_o & !wbm_we_o & wbs_ack_i), .q_b(wbm_dat_o), .clk_b(wbm_clk));
1375 97 unneback
`undef MODULE
1376
 
1377
always @ (posedge wbs_clk or posedge wbs_rst)
1378
if (wbs_rst)
1379 98 unneback
    state <= idle;
1380 97 unneback
else
1381
    case (state)
1382
    idle:
1383
        if (wbs_cyc_i)
1384
            state <= rdwr;
1385
    rdwr:
1386 100 unneback
        casex ({valid, hit, dirty, eoc})
1387
        4'b0xxx: state <= pull;
1388
        4'b11x1: state <= idle;
1389
        4'b101x: state <= push;
1390
        4'b100x: state <= pull;
1391
        endcase
1392 97 unneback
    push:
1393
        if (done)
1394
            state <= rdwr;
1395
    pull:
1396
        if (done)
1397
            state <= rdwr;
1398
    default: state <= idle;
1399
    endcase
1400
 
1401
// cdc
1402
generate
1403
if (async==1) begin : cdc0
1404
`define MODULE cdc
1405 100 unneback
`BASE`MODULE cdc0 ( .start_pl(state==rdwr & (!valid | !hit)), .take_it_pl(mem_alert), .take_it_grant_pl(mem_done), .got_it_pl(done), .clk_src(wbs_clk), .rst_src(wbs_rst), .clk_dst(wbm_clk), .rst_dst(wbm_rst));
1406 97 unneback
`undef MODULE
1407
end
1408
else begin : nocdc
1409 100 unneback
    assign mem_alert = state==rdwr & (!valid | !hit);
1410 97 unneback
    assign done = mem_done;
1411
end
1412
endgenerate
1413
 
1414
// FSM generating a number of burts 4 cycles
1415
// actual number depends on data width ratio
1416
// nr_of_wbm_burst
1417 101 unneback
reg [nr_of_wbm_burst_width+wbm_burst_width-1:0]       cnt_rw, cnt_ack;
1418 97 unneback
 
1419
always @ (posedge wbm_clk or posedge wbm_rst)
1420
if (wbm_rst)
1421 100 unneback
    cnt_rw <= {wbm_burst_width{1'b0}};
1422 97 unneback
else
1423 100 unneback
    if (wbm_cyc_o & wbm_stb_o & !wbm_stall_i)
1424
        cnt_rw <= cnt_rw + 1;
1425 97 unneback
 
1426 98 unneback
always @ (posedge wbm_clk or posedge wbm_rst)
1427
if (wbm_rst)
1428 100 unneback
    cnt_ack <= {wbm_burst_width{1'b0}};
1429 98 unneback
else
1430 100 unneback
    if (wbm_ack_i)
1431
        cnt_ack <= cnt_ack + 1;
1432 97 unneback
 
1433 100 unneback
generate
1434 101 unneback
if (nr_of_wbm_burst==1) begin : one_burst
1435 100 unneback
 
1436 98 unneback
always @ (posedge wbm_clk or posedge wbm_rst)
1437
if (wbm_rst)
1438
    phase <= wbm_wait;
1439
else
1440
    case (phase)
1441
    wbm_wait:
1442
        if (mem_alert)
1443 100 unneback
            if (state==push)
1444
                phase <= wbm_wr;
1445
            else
1446
                phase <= wbm_rd;
1447 98 unneback
    wbm_wr:
1448 100 unneback
        if (&cnt_rw)
1449
            phase <= wbm_wr_drain;
1450
    wbm_wr_drain:
1451
        if (&cnt_ack)
1452 98 unneback
            phase <= wbm_rd;
1453
    wbm_rd:
1454 100 unneback
        if (&cnt_rw)
1455
            phase <= wbm_rd_drain;
1456
    wbm_rd_drain:
1457
        if (&cnt_ack)
1458
            phase <= wbm_wait;
1459 98 unneback
    default: phase <= wbm_wait;
1460
    endcase
1461
 
1462 100 unneback
end else begin : multiple_burst
1463
 
1464 101 unneback
always @ (posedge wbm_clk or posedge wbm_rst)
1465
if (wbm_rst)
1466
    phase <= wbm_wait;
1467
else
1468
    case (phase)
1469
    wbm_wait:
1470
        if (mem_alert)
1471
            if (state==push)
1472
                phase <= wbm_wr;
1473
            else
1474
                phase <= wbm_rd;
1475
    wbm_wr:
1476
        if (&cnt_rw[wbm_burst_width-1:0])
1477
            phase <= wbm_wr_drain;
1478
    wbm_wr_drain:
1479
        if (&cnt_ack)
1480
            phase <= wbm_rd;
1481
        else if (&cnt_ack[wbm_burst_width-1:0])
1482
            phase <= wbm_wr;
1483
    wbm_rd:
1484
        if (&cnt_rw[wbm_burst_width-1:0])
1485
            phase <= wbm_rd_drain;
1486
    wbm_rd_drain:
1487
        if (&cnt_ack)
1488
            phase <= wbm_wait;
1489
        else if (&cnt_ack[wbm_burst_width-1:0])
1490
            phase <= wbm_rd;
1491
    default: phase <= wbm_wait;
1492
    endcase
1493 100 unneback
 
1494 101 unneback
 
1495 100 unneback
end
1496
endgenerate
1497
 
1498 101 unneback
assign mem_done = phase==wbm_rd_drain & (&cnt_ack) & wbm_ack_i;
1499 100 unneback
 
1500
assign wbm_adr_o = (phase[2]) ? {tag, wbs_adr_slot, cnt_rw} : {wbs_adr_tag, wbs_adr_slot, cnt_rw};
1501
assign wbm_adr   = (phase[2]) ? {wbs_adr_slot, cnt_rw} : {wbs_adr_slot, cnt_rw};
1502
assign wbm_sel_o = {dw_m/8{1'b1}};
1503
assign wbm_cti_o = (&cnt_rw | !wbm_stb_o) ? 3'b111 : 3'b010;
1504 98 unneback
assign wbm_bte_o = bte;
1505 100 unneback
assign {wbm_we_o, wbm_stb_o, wbm_cyc_o}  = phase;
1506 98 unneback
 
1507 96 unneback
endmodule
1508
`endif
1509 103 unneback
 
1510
`ifdef WB_AVALON_BRIDGE
1511
// Wishbone to avalon bridge supporting one type of burst transfer only
1512
// intended use is together with cache above
1513
// WB B4 -> pipelined avalon
1514
`define MODULE wb_avalon_bridge
1515
module `BASE`MODULE (
1516
`undef MODULE
1517
        // wishbone slave side
1518
        wbs_dat_i, wbs_adr_i, wbs_sel_i, wbs_bte_i, wbs_cti_i, wbs_we_i, wbs_cyc_i, wbs_stb_i, wbs_dat_o, wbs_ack_o, wbs_stall_o,
1519
        // avalon master side
1520
        readdata, readdatavalid, address, read, be, write, burstcount, writedata, waitrequest, beginbursttransfer,
1521
        // common
1522
        clk, rst);
1523
 
1524
parameter adr_width = 30;
1525
parameter dat_width = 32;
1526
parameter burst_size = 4;
1527
 
1528
input [dat_width-1:0] wbs_dat_i;
1529
input [adr_width-1:0] wbs_adr_i;
1530
input [dat_width/8-1:0]  wbs_sel_i;
1531
input [1:0]  wbs_bte_i;
1532
input [2:0]  wbs_cti_i;
1533
input wbs_we_i;
1534
input wbs_cyc_i;
1535
input wbs_stb_i;
1536
output [dat_width:0] wbs_dat_o;
1537
output wbs_ack_o;
1538
output wbs_stall_o;
1539
 
1540
input [dat_width-1:0] readdata;
1541
input readdatavalid;
1542
output [dat_width-1:0] writedata;
1543
output [adr_width-1:0] address;
1544
output [dat_width/8-1:0]  be;
1545
output write;
1546
output read;
1547
output beginbursttransfer;
1548
output [3:0] burstcount;
1549
input waitrequest;
1550
input clk, rst;
1551
 
1552
reg last_cyc_idle_or_eoc;
1553
 
1554
reg [3:0] cnt;
1555
always @ (posedge clk or posedge rst)
1556
if (rst)
1557
    cnt <= 4'h0;
1558
else
1559
    if (beginbursttransfer & waitrequest)
1560
        cnt <= burst_size - 1;
1561
    else if (beginbursttransfer & !waitrequest)
1562
        cnt <= burst_size - 2;
1563
    else if (wbs_ack_o)
1564
        cnt <= cnt - 1;
1565
 
1566
reg wr_ack;
1567
always @ (posedge clk or posedge rst)
1568
if (rst)
1569
    wr_ack <= 1'b0;
1570
else
1571
    wr_ack <=  (wbs_we_i & wbs_cyc_i & wbs_stb_i & !wbs_stall_o);
1572
 
1573
// to avalon
1574
assign writedata = wbs_dat_i;
1575
assign address = wbs_adr_i;
1576
assign be = wbs_sel_i;
1577
assign write = cnt==(burst_size-1) & wbs_cyc_i &  wbs_we_i;
1578
assign read  = cnt==(burst_size-1) & wbs_cyc_i & !wbs_we_i;
1579
assign beginbursttransfer = cnt==4'h0 & wbs_cyc_i;
1580
assign burstcount = burst_size;
1581
 
1582
// to wishbone
1583
assign wbs_dat_o = readdata;
1584
assign wbs_ack_o = wr_ack | readdatavalid;
1585
assign wbs_stall_o = waitrequest;
1586
 
1587
endmodule
1588
`endif
1589
 
1590
`ifdef WB_AVALON_MEM_CACHE
1591
`define MODULE wb_avalon_mem_cache
1592
module `BASE`MODULE (
1593
    wbs_dat_i, wbs_adr_i, wbs_sel_i, wbs_cti_i, wbs_bte_i, wbs_we_i, wbs_stb_i, wbs_cyc_i, wbs_dat_o, wbs_ack_o, wbs_stall_o, wbs_clk, wbs_rst,
1594
    readdata, readdatavalid, address, read, be, write, burstcount, writedata, waitrequest, beginbursttransfer, clk, rst
1595
);
1596
`undef MODULE
1597
 
1598
// wishbone
1599
parameter wb_dat_width = 32;
1600
parameter wb_adr_width = 22;
1601
parameter wb_max_burst_width = 4;
1602
parameter wb_mode = "B4";
1603
// avalon
1604
parameter avalon_dat_width = 32;
1605
localparam avalon_adr_width = wb_dat_width * wb_adr_width / avalon_dat_width;
1606
parameter avalon_burst_size = 4;
1607
// cache
1608
parameter async = 1;
1609
parameter nr_of_ways = 1;
1610
parameter aw_offset = 4;
1611
parameter aw_slot = 10;
1612
parameter valid_mem = 1;
1613
// shadow RAM
1614
parameter shadow_ram = 0;
1615
parameter shadow_ram_adr_width = 10;
1616
parameter shadow_ram_size = 1024;
1617
parameter shadow_ram_init = 2; // 0: no init, 1: from file, 2: with zero
1618
parameter shadow_ram_file = "vl_ram.v";
1619
 
1620
input [wb_dat_width-1:0] wbs_dat_i;
1621
input [wb_adr_width-1:0] wbs_adr_i; // dont include a1,a0
1622
input [wb_dat_width/8-1:0] wbs_sel_i;
1623
input [2:0] wbs_cti_i;
1624
input [1:0] wbs_bte_i;
1625
input wbs_we_i, wbs_stb_i, wbs_cyc_i;
1626
output [wb_dat_width-1:0] wbs_dat_o;
1627
output wbs_ack_o;
1628
output wbs_stall_o;
1629
input wbs_clk, wbs_rst;
1630
 
1631
input [avalon_dat_width-1:0] readdata;
1632
input readdatavalid;
1633
output [avalon_dat_width-1:0] writedata;
1634
output [avalon_adr_width-1:0] address;
1635
output [avalon_dat_width/8-1:0]  be;
1636
output write;
1637
output read;
1638
output beginbursttransfer;
1639
output [3:0] burstcount;
1640
input waitrequest;
1641
input clk, rst;
1642
 
1643
`define DAT_WIDTH wb_dat_width
1644
`define ADR_WIDTH wb_adr_width
1645
`define WB wb1
1646
`include "wb_wires.v"
1647
`define WB wb2
1648
`include "wb_wires.v"
1649
`undef DAT_WIDTH
1650
`undef ADR_WIDTH
1651
 
1652
`define MODULE wb_shadow_ram
1653
`BASE`MODULE # ( .dat_width(wb_dat_width), .mode(wb_mode), .max_burst_width(wb_max_burst_width),
1654
                 .shadow_mem_adr_width(shadow_ram_adr_width), .shadow_mem_size(shadow_ram_adr_width), .shadow_mem_init(shadow_ram_init), .shadow_mem_file(shadow_ram_file),
1655
                 .main_mem_adr_width(wb_adr_width))
1656
shadow_ram0 (
1657
    .wbs_dat_i(wbs_dat_i), .wbs_adr_i(wbs_adr_i), .wbs_cti_i(wbs_cti_i), .wbs_bte_i(wbs_bte_i), .wbs_sel_i(wbs_sel_i), .wbs_we_i(wbs_we_i), .wbs_stb_i(wbs_stb_i), .wbs_cyc_i(wbs_cyc_i),
1658
    .wbs_dat_o(wbs_dat_o), .wbs_ack_o(wbs_ack_o), .wbs_stall_o(wbs_stall_o),
1659
    .wbm_dat_o(wb1_dat_o), .wbm_adr_o(wb1_adr_o), .wbm_cti_o(wb1_cti_o), .wbm_bte_o(wb1_bte_o), .wbm_sel_o(wb1_sel_o), .wbm_we_o(wb1_we_o), .wbm_stb_o(wb1_stb_o), .wbm_cyc_o(wb1_cyc_o),
1660
    .wbm_dat_i(wb1_dat_i), .wbm_ack_i(wb1_ack_i), .wbm_stall_i(wb1_stall_i),
1661
    .wb_clk(wbs_clk), .wb_rst(wbs_rst));
1662
`undef MODULE
1663
 
1664
`define MODULE wb_cache
1665
`BASE`MODULE
1666
# ( .dw_s(wb_dat_width), .aw_s(wb_adr_width), .dw_m(avalon_dat_width), .wbs_mode(wb_mode), .wbs_max_burst_width(wb_max_burst_width), .async(async), .nr_of_ways(nr_of_ways), .aw_offset(aw_offset), .aw_slot(aw_slot), .valid_mem(valid_mem))
1667
cache0 (
1668
    .wbs_dat_i(wb1_dat_o), .wbs_adr_i(wb1_adr_o), .wbs_sel_i(wb1_sel_o), .wbs_cti_i(wb1_cti_o), .wbs_bte_i(wb1_bte_o), .wbs_we_i(wb1_we_o), .wbs_stb_i(wb1_stb_o), .wbs_cyc_i(wb1_cyc_o),
1669
    .wbs_dat_o(wb1_dat_i), .wbs_ack_o(wb1_ack_i), .wbs_stall_o(wb1_stall_i), .wbs_clk(wbs_clk), .wbs_rst(wbs_rst),
1670
    .wbm_dat_o(wb2_dat_o), .wbm_adr_o(wb2_adr_o), .wbm_sel_o(wb2_sel_o), .wbm_cti_o(wb2_cti_o), .wbm_bte_o(wb2_bte_o), .wbm_we_o(wb2_we_o), .wbm_stb_o(wb2_stb_o), .wbm_cyc_o(wb2_cyc_o),
1671
    .wbm_dat_i(wb2_dat_i), .wbm_ack_i(wb2_ack_i), .wbm_stall_i(wb2_stall_i), .wbm_clk(clk), .wbm_rst(rst));
1672
`undef MODULE
1673
 
1674
`define MODULE wb_avalon_bridge
1675
`BASE`MODULE # ( .adr_width(avalon_adr_width), .dat_width(avalon_dat_width), .burst_size(avalon_burst_size))
1676
bridge0 (
1677
        // wishbone slave side
1678
        .wbs_dat_i(wb2_dat_o), .wbs_adr_i(wb2_adr_o), .wbs_sel_i(wb2_sel_o), .wbs_bte_i(wb2_bte_o), .wbs_cti_i(wb2_cti_o), .wbs_we_i(wb2_we_o), .wbs_cyc_i(wb2_cyc_o), .wbs_stb_i(wb2_stb_o),
1679
        .wbs_dat_o(wb2_dat_i), .wbs_ack_o(wb2_ack_i), .wbs_stall_o(wb2_stall_i),
1680
        // avalon master side
1681
        .readdata(readdata), .readdatavalid(readdatavalid), .address(address), .read(read), .be(be), .write(write), .burstcount(burstcount), .writedata(writedata), .waitrequest(waitrequest), .beginbursttransfer(beginbursttransfer),
1682
        // common
1683
        .clk(clk), .rst(rst));
1684
`undef MODULE
1685
 
1686
endmodule
1687
`endif
1688 104 unneback
 
1689
`ifdef WB_SDR_SDRAM
1690
`define MODULE wb_sdr_sdram
1691
module `BASE`MODULE (
1692
`undef MODULE
1693
    // wisbone i/f
1694
    dat_i, adr_i, sel_i, we_i, cyc_i, stb_i, dat_o, ack_o, stall_o
1695
    // SDR SDRAM
1696
    ba, a, cmd, cke, cs_n, dqm, dq_i, dq_o, dq_oe,
1697
    // system
1698
    clk, rst);
1699
 
1700
    // external data bus size
1701
    parameter dat_size = 16;
1702
    // memory geometry parameters
1703
    parameter ba_size  = `SDR_BA_SIZE;
1704
    parameter row_size = `SDR_ROW_SIZE;
1705
    parameter col_size = `SDR_COL_SIZE;
1706
    parameter cl = 2;
1707
    // memory timing parameters
1708
    parameter tRFC = 9;
1709
    parameter tRP  = 2;
1710
    parameter tRCD = 2;
1711
    parameter tMRD = 2;
1712
 
1713
    // LMR
1714
    // [12:10] reserved
1715
    // [9]     WB, write burst; 0 - programmed burst length, 1 - single location
1716
    // [8:7]   OP Mode, 2'b00
1717
    // [6:4]   CAS Latency; 3'b010 - 2, 3'b011 - 3
1718
    // [3]     BT, Burst Type; 1'b0 - sequential, 1'b1 - interleaved
1719
    // [2:0]   Burst length; 3'b000 - 1, 3'b001 - 2, 3'b010 - 4, 3'b011 - 8, 3'b111 - full page
1720
    localparam init_wb = 1'b1;
1721
    localparam init_cl = (cl==2) ? 3'b010 : 3'b011;
1722
    localparam init_bt = 1'b0;
1723
    localparam init_bl = 3'b000;
1724
 
1725
    input [dat_size:0] dat_i;
1726
    input [ba_size+col_size+row_size-1:0] adr_i;
1727
    input [dat_size/8-1:0] sel_i;
1728
    input we_i, cyc_i, stb_i;
1729
    output [dat_size-1:0] dat_o;
1730
    output ack_o;
1731
    output reg stall_o;
1732
 
1733
    output [ba_size-1:0]    ba;
1734
    output reg [12:0]   a;
1735
    output reg [2:0]    cmd; // {ras,cas,we}
1736
    output cke, cs_n;
1737
    output reg [dat_size/8-1:0]    dqm;
1738
    output [dat_size-1:0]       dq_o;
1739
    output reg          dq_oe;
1740
    input  [dat_size-1:0]       dq_i;
1741
 
1742
    input clk, rst;
1743
 
1744
    wire [ba_size-1:0]   bank;
1745
    wire [row_size-1:0] row;
1746
    wire [col_size-1:0] col;
1747
    wire [0:31]  shreg;
1748
    wire                ref_cnt_zero;
1749
    reg                 refresh_req;
1750
 
1751
    wire ack_rd, rd_ack_emptyflag;
1752
    wire ack_wr;
1753
 
1754
    // to keep track of open rows per bank
1755
    reg [row_size-1:0]   open_row[0:3];
1756
    reg [0:3]            open_ba;
1757
    reg                 current_bank_closed, current_row_open;
1758
 
1759
    parameter rfr_length = 10;
1760
    parameter rfr_wrap_value = 1010;
1761
 
1762
    parameter [2:0] cmd_nop = 3'b111,
1763
                    cmd_act = 3'b011,
1764
                    cmd_rd  = 3'b101,
1765
                    cmd_wr  = 3'b100,
1766
                    cmd_pch = 3'b010,
1767
                    cmd_rfr = 3'b001,
1768
                    cmd_lmr = 3'b000;
1769
 
1770
// ctrl FSM
1771
`define FSM_INIT 3'b000
1772
`define FSM_IDLE 3'b001
1773
`define FSM_RFR  3'b010
1774
`define FSM_ADR  3'b011
1775
`define FSM_PCH  3'b100
1776
`define FSM_ACT  3'b101
1777
`define FSM_RW   3'b111
1778
 
1779
    assign cke = 1'b1;
1780
    assign cs_n = 1'b0;
1781
 
1782
    reg [2:0] state, next;
1783
 
1784
    function [12:0] a10_fix;
1785
        input [col_size-1:0] a;
1786
        integer i;
1787
    begin
1788
        for (i=0;i<13;i=i+1) begin
1789
            if (i<10)
1790
              if (i<col_size)
1791
                a10_fix[i] = a[i];
1792
              else
1793
                a10_fix[i] = 1'b0;
1794
            else if (i==10)
1795
              a10_fix[i] = 1'b0;
1796
            else
1797
              if (i<col_size)
1798
                a10_fix[i] = a[i-1];
1799
              else
1800
                a10_fix[i] = 1'b0;
1801
        end
1802
    end
1803
    endfunction
1804
 
1805
    assign {bank,row,col} = adr_i;
1806
 
1807
    always @ (posedge clk or posedge rst)
1808
    if (rst)
1809
       state <= `FSM_INIT;
1810
    else
1811
       state <= next;
1812
 
1813
    always @*
1814
    begin
1815
        next = state;
1816
        case (state)
1817
        `FSM_INIT:
1818
            if (shreg[3+tRP+tRFC+tRFC+tMRD]) next = `FSM_IDLE;
1819
        `FSM_IDLE:
1820
            if (refresh_req) next = `FSM_RFR;
1821
            else if (cyc_i & stb_i & rd_ack_emptyflag) next = `FSM_ADR;
1822
        `FSM_RFR:
1823
            if (shreg[tRP+tRFC-2]) next = `FSM_IDLE; // take away two cycles because no cmd will be issued in idle and adr
1824
        `FSM_ADR:
1825
            if (current_bank_closed) next = `FSM_ACT;
1826
            else if (current_row_open) next = `FSM_RW;
1827
            else next = `FSM_PCH;
1828
        `FSM_PCH:
1829
            if (shreg[tRP]) next = `FSM_ACT;
1830
        `FSM_ACT:
1831
            if (shreg[tRCD]) next = `FSM_RW;
1832
        `FSM_RW:
1833
            if (!stb_i) next = `FSM_IDLE;
1834
        endcase
1835
    end
1836
 
1837
    // counter
1838
`define MODULE cnt_shreg_ce_clear
1839
    `VLBASE`MODULE # ( .length(32))
1840
`undef MODULE
1841
        cnt0 (
1842
            .clear(state!=next),
1843
            .q(shreg),
1844
            .rst(rst),
1845
            .clk(clk));
1846
 
1847
    // ba, a, cmd
1848
    // outputs dependent on state vector
1849
    always @ (*)
1850
        begin
1851
            {a,cmd} = {13'd0,cmd_nop};
1852
            dqm = 2'b11;
1853
            dq_oe = 1'b0;
1854
            stall_o = 1'b1;
1855
            case (state)
1856
            `FSM_INIT:
1857
                if (shreg[3]) begin
1858
                    {a,cmd} = {13'b0010000000000, cmd_pch};
1859
                end else if (shreg[3+tRP] | shreg[3+tRP+tRFC])
1860
                    {a,cmd} = {13'd0, cmd_rfr};
1861
                else if (shreg[3+tRP+tRFC+tRFC])
1862
                    {a,cmd} = {3'b000,init_wb,2'b00,init_cl,init_bt,init_bl,cmd_lmr};
1863
            `FSM_RFR:
1864
                if (shreg[0])
1865
                    {a,cmd} = {13'b0010000000000, cmd_pch};
1866
                else if (shreg[tRP])
1867
                    {a,cmd} = {13'd0, cmd_rfr};
1868
            `FSM_PCH:
1869
                if (shreg[0])
1870
                    {a,cmd} = {13'd0,cmd_pch};
1871
            `FSM_ACT:
1872
                if (shreg[0])
1873
                    {a[row_size-1:0],cmd} = {row,cmd_act};
1874
            `FSM_RW:
1875
                begin
1876
                    if (we_i)
1877
                        cmd = cmd_wr;
1878
                    else
1879
                        cmd = cmd_rd;
1880
                    if (we_i)
1881
                        dqm = ~sel_i;
1882
                    else
1883
                        dqm = 2'b00;
1884
                    if (we_i)
1885
                        dq_oe = 1'b1;
1886
                    a = a10_fix(col);
1887
                    stall_o = 1'b1;
1888
                end
1889
            endcase
1890
        end
1891
 
1892
    assign ba = bank;
1893
 
1894
    // precharge individual bank A10=0
1895
    // precharge all bank A10=1
1896
    genvar i;
1897
    generate
1898
    for (i=0;i<2<<ba_size-1;i=i+1) begin
1899
 
1900
        always @ (posedge clk or posedge rst)
1901
        if (rst)
1902
            {open_ba[i],open_row[i]} <= {1'b0,{row_size{1'b0}}};
1903
        else
1904
            if (cmd==cmd_pch & (a[10] | bank==i))
1905
                open_ba[i] <= 1'b0;
1906
            else if (cmd==cmd_act & bank==i)
1907
                {open_ba[i],open_row[i]} <= {1'b1,row};
1908
 
1909
    end
1910
    endgenerate
1911
 
1912
    // bank and row open ?
1913
    always @ (posedge clk or posedge rst)
1914
    if (rst)
1915
       {current_bank_closed, current_row_open} <= {1'b1, 1'b0};
1916
    else
1917
       {current_bank_closed, current_row_open} <= {!(open_ba[bank]), open_row[bank]==row};
1918
 
1919
    // refresh counter
1920
`define MODULE cnt_lfsr_zq
1921
    `VLBASE`MODULE # ( .length(rfr_length), .wrap_value (rfr_wrap_value)) ref_counter0( .zq(ref_cnt_zero), .rst(rst), .clk(clk));
1922
`undef MODULE
1923
 
1924
    always @ (posedge clk or posedge rst)
1925
    if (rst)
1926
        refresh_req <= 1'b0;
1927
    else
1928
        if (ref_cnt_zero)
1929
            refresh_req <= 1'b1;
1930
        else if (state==`FSM_RFR)
1931
            refresh_req <= 1'b0;
1932
 
1933
    assign dat_o = dq_i;
1934
 
1935
    assign ack_wr = (state==`FSM_RW & count0 & we_i);
1936
`define MODULE delay_emptyflag
1937
    `VLBASE`MODULE # ( .depth(cl+2)) delay0 ( .d(state==`FSM_RW & stb_i & !we_i), .q(ack_rd), .emptyflag(rd_ack_emptyflag), .clk(clk), .rst(rst));
1938
`undef MODULE
1939
    assign ack_o = ack_rd | ack_wr;
1940
 
1941
    assign dq_o = dat_i;
1942
 
1943
endmodule
1944
`endif

powered by: WebSVN 2.1.0

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