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 59

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 40 unneback
`ifdef WB3WB3_BRIDGE
44 12 unneback
// async wb3 - wb3 bridge
45
`timescale 1ns/1ns
46 40 unneback
`define MODULE wb3wb3_bridge
47
module `BASE`MODULE (
48
`undef MODULE
49 12 unneback
        // wishbone slave side
50
        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,
51
        // wishbone master side
52
        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);
53
 
54
input [31:0] wbs_dat_i;
55
input [31:2] wbs_adr_i;
56
input [3:0]  wbs_sel_i;
57
input [1:0]  wbs_bte_i;
58
input [2:0]  wbs_cti_i;
59
input wbs_we_i, wbs_cyc_i, wbs_stb_i;
60
output [31:0] wbs_dat_o;
61 14 unneback
output wbs_ack_o;
62 12 unneback
input wbs_clk, wbs_rst;
63
 
64
output [31:0] wbm_dat_o;
65
output reg [31:2] wbm_adr_o;
66
output [3:0]  wbm_sel_o;
67
output reg [1:0]  wbm_bte_o;
68
output reg [2:0]  wbm_cti_o;
69 14 unneback
output reg wbm_we_o;
70
output wbm_cyc_o;
71 12 unneback
output wbm_stb_o;
72
input [31:0]  wbm_dat_i;
73
input wbm_ack_i;
74
input wbm_clk, wbm_rst;
75
 
76
parameter addr_width = 4;
77
 
78
// bte
79
parameter linear       = 2'b00;
80
parameter wrap4        = 2'b01;
81
parameter wrap8        = 2'b10;
82
parameter wrap16       = 2'b11;
83
// cti
84
parameter classic      = 3'b000;
85
parameter incburst     = 3'b010;
86
parameter endofburst   = 3'b111;
87
 
88
parameter wbs_adr  = 1'b0;
89
parameter wbs_data = 1'b1;
90
 
91 33 unneback
parameter wbm_adr0      = 2'b00;
92
parameter wbm_adr1      = 2'b01;
93
parameter wbm_data      = 2'b10;
94
parameter wbm_data_wait = 2'b11;
95 12 unneback
 
96
reg [1:0] wbs_bte_reg;
97
reg wbs;
98
wire wbs_eoc_alert, wbm_eoc_alert;
99
reg wbs_eoc, wbm_eoc;
100
reg [1:0] wbm;
101
 
102 14 unneback
wire [1:16] wbs_count, wbm_count;
103 12 unneback
 
104
wire [35:0] a_d, a_q, b_d, b_q;
105
wire a_wr, a_rd, a_fifo_full, a_fifo_empty, b_wr, b_rd, b_fifo_full, b_fifo_empty;
106
reg a_rd_reg;
107
wire b_rd_adr, b_rd_data;
108 14 unneback
wire b_rd_data_reg;
109
wire [35:0] temp;
110 12 unneback
 
111
`define WE 5
112
`define BTE 4:3
113
`define CTI 2:0
114
 
115
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]);
116
always @ (posedge wbs_clk or posedge wbs_rst)
117
if (wbs_rst)
118
        wbs_eoc <= 1'b0;
119
else
120
        if (wbs==wbs_adr & wbs_stb_i & !a_fifo_full)
121
                wbs_eoc <= wbs_bte_i==linear;
122
        else if (wbs_eoc_alert & (a_rd | a_wr))
123
                wbs_eoc <= 1'b1;
124
 
125 40 unneback
`define MODULE cnt_shreg_ce_clear
126
`BASE`MODULE # ( .length(16))
127
`undef MODULE
128 12 unneback
    cnt0 (
129
        .cke(wbs_ack_o),
130
        .clear(wbs_eoc),
131
        .q(wbs_count),
132
        .rst(wbs_rst),
133
        .clk(wbs_clk));
134
 
135
always @ (posedge wbs_clk or posedge wbs_rst)
136
if (wbs_rst)
137
        wbs <= wbs_adr;
138
else
139
        if ((wbs==wbs_adr) & wbs_cyc_i & wbs_stb_i & !a_fifo_full)
140
                wbs <= wbs_data;
141
        else if (wbs_eoc & wbs_ack_o)
142
                wbs <= wbs_adr;
143
 
144
// wbs FIFO
145
assign a_d = (wbs==wbs_adr) ? {wbs_adr_i[31:2],wbs_we_i,wbs_bte_i,wbs_cti_i} : {wbs_dat_i,wbs_sel_i};
146
assign a_wr = (wbs==wbs_adr)  ? wbs_cyc_i & wbs_stb_i & !a_fifo_full :
147
              (wbs==wbs_data) ? wbs_we_i  & wbs_stb_i & !a_fifo_full :
148
              1'b0;
149
assign a_rd = !a_fifo_empty;
150
always @ (posedge wbs_clk or posedge wbs_rst)
151
if (wbs_rst)
152
        a_rd_reg <= 1'b0;
153
else
154
        a_rd_reg <= a_rd;
155
assign wbs_ack_o = a_rd_reg | (a_wr & wbs==wbs_data);
156
 
157
assign wbs_dat_o = a_q[35:4];
158
 
159
always @ (posedge wbs_clk or posedge wbs_rst)
160
if (wbs_rst)
161 13 unneback
        wbs_bte_reg <= 2'b00;
162 12 unneback
else
163 13 unneback
        wbs_bte_reg <= wbs_bte_i;
164 12 unneback
 
165
// wbm FIFO
166
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]);
167
always @ (posedge wbm_clk or posedge wbm_rst)
168
if (wbm_rst)
169
        wbm_eoc <= 1'b0;
170
else
171
        if (wbm==wbm_adr0 & !b_fifo_empty)
172
                wbm_eoc <= b_q[`BTE] == linear;
173
        else if (wbm_eoc_alert & wbm_ack_i)
174
                wbm_eoc <= 1'b1;
175
 
176
always @ (posedge wbm_clk or posedge wbm_rst)
177
if (wbm_rst)
178
        wbm <= wbm_adr0;
179
else
180 33 unneback
/*
181 12 unneback
    if ((wbm==wbm_adr0 & !b_fifo_empty) |
182
        (wbm==wbm_adr1 & !b_fifo_empty & wbm_we_o) |
183
        (wbm==wbm_adr1 & !wbm_we_o) |
184
        (wbm==wbm_data & wbm_ack_i & wbm_eoc))
185
        wbm <= {wbm[0],!(wbm[1] ^ wbm[0])};  // count sequence 00,01,10
186 33 unneback
*/
187
    case (wbm)
188
    wbm_adr0:
189
        if (!b_fifo_empty)
190
            wbm <= wbm_adr1;
191
    wbm_adr1:
192
        if (!wbm_we_o | (!b_fifo_empty & wbm_we_o))
193
            wbm <= wbm_data;
194
    wbm_data:
195
        if (wbm_ack_i & wbm_eoc)
196
            wbm <= wbm_adr0;
197
        else if (b_fifo_empty & wbm_we_o & wbm_ack_i)
198
            wbm <= wbm_data_wait;
199
    wbm_data_wait:
200
        if (!b_fifo_empty)
201
            wbm <= wbm_data;
202
    endcase
203 12 unneback
 
204
assign b_d = {wbm_dat_i,4'b1111};
205
assign b_wr = !wbm_we_o & wbm_ack_i;
206
assign b_rd_adr  = (wbm==wbm_adr0 & !b_fifo_empty);
207
assign b_rd_data = (wbm==wbm_adr1 & !b_fifo_empty & wbm_we_o) ? 1'b1 : // b_q[`WE]
208
                   (wbm==wbm_data & !b_fifo_empty & wbm_we_o & wbm_ack_i & !wbm_eoc) ? 1'b1 :
209 33 unneback
                   (wbm==wbm_data_wait & !b_fifo_empty) ? 1'b1 :
210 12 unneback
                   1'b0;
211
assign b_rd = b_rd_adr | b_rd_data;
212
 
213 40 unneback
`define MODULE dff
214
`BASE`MODULE dff1 ( .d(b_rd_data), .q(b_rd_data_reg), .clk(wbm_clk), .rst(wbm_rst));
215
`undef MODULE
216
`define MODULE dff_ce
217
`BASE`MODULE # ( .width(36)) dff2 ( .d(b_q), .ce(b_rd_data_reg), .q(temp), .clk(wbm_clk), .rst(wbm_rst));
218
`undef MODULE
219 12 unneback
 
220
assign {wbm_dat_o,wbm_sel_o} = (b_rd_data_reg) ? b_q : temp;
221
 
222 40 unneback
`define MODULE cnt_shreg_ce_clear
223 42 unneback
`BASE`MODULE # ( .length(16))
224 40 unneback
`undef MODULE
225 12 unneback
    cnt1 (
226
        .cke(wbm_ack_i),
227
        .clear(wbm_eoc),
228
        .q(wbm_count),
229
        .rst(wbm_rst),
230
        .clk(wbm_clk));
231
 
232 33 unneback
assign wbm_cyc_o = (wbm==wbm_data | wbm==wbm_data_wait);
233
assign wbm_stb_o = (wbm==wbm_data);
234 12 unneback
 
235
always @ (posedge wbm_clk or posedge wbm_rst)
236
if (wbm_rst)
237
        {wbm_adr_o,wbm_we_o,wbm_bte_o,wbm_cti_o} <= {30'h0,1'b0,linear,classic};
238
else begin
239
        if (wbm==wbm_adr0 & !b_fifo_empty)
240
                {wbm_adr_o,wbm_we_o,wbm_bte_o,wbm_cti_o} <= b_q;
241
        else if (wbm_eoc_alert & wbm_ack_i)
242
                wbm_cti_o <= endofburst;
243
end
244
 
245
//async_fifo_dw_simplex_top
246 40 unneback
`define MODULE fifo_2r2w_async_simplex
247
`BASE`MODULE
248
`undef MODULE
249 12 unneback
# ( .data_width(36), .addr_width(addr_width))
250
fifo (
251
    // a side
252
    .a_d(a_d),
253
    .a_wr(a_wr),
254
    .a_fifo_full(a_fifo_full),
255
    .a_q(a_q),
256
    .a_rd(a_rd),
257
    .a_fifo_empty(a_fifo_empty),
258
    .a_clk(wbs_clk),
259
    .a_rst(wbs_rst),
260
    // b side
261
    .b_d(b_d),
262
    .b_wr(b_wr),
263
    .b_fifo_full(b_fifo_full),
264
    .b_q(b_q),
265
    .b_rd(b_rd),
266
    .b_fifo_empty(b_fifo_empty),
267
    .b_clk(wbm_clk),
268
    .b_rst(wbm_rst)
269
    );
270
 
271
endmodule
272 40 unneback
`undef WE
273
`undef BTE
274
`undef CTI
275
`endif
276 17 unneback
 
277 40 unneback
`ifdef WB3_ARBITER_TYPE1
278
`define MODULE wb3_arbiter_type1
279 42 unneback
module `BASE`MODULE (
280 40 unneback
`undef MODULE
281 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,
282
    wbm_dat_i, wbm_ack_i, wbm_err_i, wbm_rty_i,
283
    wbs_dat_i, wbs_adr_i, wbs_sel_i, wbs_cti_i, wbs_bte_i, wbs_we_i, wbs_stb_i, wbs_cyc_i,
284
    wbs_dat_o, wbs_ack_o, wbs_err_o, wbs_rty_o,
285
    wb_clk, wb_rst
286
);
287
 
288
parameter nr_of_ports = 3;
289
parameter adr_size = 26;
290
parameter adr_lo   = 2;
291
parameter dat_size = 32;
292
parameter sel_size = dat_size/8;
293
 
294
localparam aw = (adr_size - adr_lo) * nr_of_ports;
295
localparam dw = dat_size * nr_of_ports;
296
localparam sw = sel_size * nr_of_ports;
297
localparam cw = 3 * nr_of_ports;
298
localparam bw = 2 * nr_of_ports;
299
 
300
input  [dw-1:0] wbm_dat_o;
301
input  [aw-1:0] wbm_adr_o;
302
input  [sw-1:0] wbm_sel_o;
303
input  [cw-1:0] wbm_cti_o;
304
input  [bw-1:0] wbm_bte_o;
305
input  [nr_of_ports-1:0] wbm_we_o, wbm_stb_o, wbm_cyc_o;
306
output [dw-1:0] wbm_dat_i;
307
output [nr_of_ports-1:0] wbm_ack_i, wbm_err_i, wbm_rty_i;
308
 
309
output [dat_size-1:0] wbs_dat_i;
310
output [adr_size-1:adr_lo] wbs_adr_i;
311
output [sel_size-1:0] wbs_sel_i;
312
output [2:0] wbs_cti_i;
313
output [1:0] wbs_bte_i;
314
output wbs_we_i, wbs_stb_i, wbs_cyc_i;
315
input  [dat_size-1:0] wbs_dat_o;
316
input  wbs_ack_o, wbs_err_o, wbs_rty_o;
317
 
318
input wb_clk, wb_rst;
319
 
320 44 unneback
reg  [nr_of_ports-1:0] select;
321 39 unneback
wire [nr_of_ports-1:0] state;
322
wire [nr_of_ports-1:0] eoc; // end-of-cycle
323
wire [nr_of_ports-1:0] sel;
324
wire idle;
325
 
326
genvar i;
327
 
328
assign idle = !(|state);
329
 
330
generate
331
if (nr_of_ports == 2) begin
332
 
333
    wire [2:0] wbm1_cti_o, wbm0_cti_o;
334
 
335
    assign {wbm1_cti_o,wbm0_cti_o} = wbm_cti_o;
336
 
337 44 unneback
    //assign select = (idle) ? {wbm_cyc_o[1],!wbm_cyc_o[1] & wbm_cyc_o[0]} : {nr_of_ports{1'b0}};
338
 
339
    always @ (idle or wbm_cyc_o)
340
    if (idle)
341
        casex (wbm_cyc_o)
342
        2'b1x : select = 2'b10;
343
        2'b01 : select = 2'b01;
344
        default : select = {nr_of_ports{1'b0}};
345
        endcase
346
    else
347
        select = {nr_of_ports{1'b0}};
348
 
349 39 unneback
    assign eoc[1] = (wbm_ack_i[1] & (wbm1_cti_o == 3'b000 | wbm1_cti_o == 3'b111)) | !wbm_cyc_o[1];
350
    assign eoc[0] = (wbm_ack_i[0] & (wbm0_cti_o == 3'b000 | wbm0_cti_o == 3'b111)) | !wbm_cyc_o[0];
351
 
352
end
353
endgenerate
354
 
355
generate
356
if (nr_of_ports == 3) begin
357
 
358
    wire [2:0] wbm2_cti_o, wbm1_cti_o, wbm0_cti_o;
359
 
360
    assign {wbm2_cti_o,wbm1_cti_o,wbm0_cti_o} = wbm_cti_o;
361
 
362 44 unneback
    always @ (idle or wbm_cyc_o)
363
    if (idle)
364
        casex (wbm_cyc_o)
365
        3'b1xx : select = 3'b100;
366
        3'b01x : select = 3'b010;
367
        3'b001 : select = 3'b001;
368
        default : select = {nr_of_ports{1'b0}};
369
        endcase
370
    else
371
        select = {nr_of_ports{1'b0}};
372
 
373
//    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}};
374 39 unneback
    assign eoc[2] = (wbm_ack_i[2] & (wbm2_cti_o == 3'b000 | wbm2_cti_o == 3'b111)) | !wbm_cyc_o[2];
375
    assign eoc[1] = (wbm_ack_i[1] & (wbm1_cti_o == 3'b000 | wbm1_cti_o == 3'b111)) | !wbm_cyc_o[1];
376
    assign eoc[0] = (wbm_ack_i[0] & (wbm0_cti_o == 3'b000 | wbm0_cti_o == 3'b111)) | !wbm_cyc_o[0];
377
 
378
end
379
endgenerate
380
 
381
generate
382 44 unneback
if (nr_of_ports == 4) begin
383
 
384
    wire [2:0] wbm3_cti_o, wbm2_cti_o, wbm1_cti_o, wbm0_cti_o;
385
 
386
    assign {wbm3_cti_o, wbm2_cti_o,wbm1_cti_o,wbm0_cti_o} = wbm_cti_o;
387
 
388
    //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}};
389
 
390
    always @ (idle or wbm_cyc_o)
391
    if (idle)
392
        casex (wbm_cyc_o)
393
        4'b1xxx : select = 4'b1000;
394
        4'b01xx : select = 4'b0100;
395
        4'b001x : select = 4'b0010;
396
        4'b0001 : select = 4'b0001;
397
        default : select = {nr_of_ports{1'b0}};
398
        endcase
399
    else
400
        select = {nr_of_ports{1'b0}};
401
 
402
    assign eoc[3] = (wbm_ack_i[3] & (wbm3_cti_o == 3'b000 | wbm3_cti_o == 3'b111)) | !wbm_cyc_o[3];
403
    assign eoc[2] = (wbm_ack_i[2] & (wbm2_cti_o == 3'b000 | wbm2_cti_o == 3'b111)) | !wbm_cyc_o[2];
404
    assign eoc[1] = (wbm_ack_i[1] & (wbm1_cti_o == 3'b000 | wbm1_cti_o == 3'b111)) | !wbm_cyc_o[1];
405
    assign eoc[0] = (wbm_ack_i[0] & (wbm0_cti_o == 3'b000 | wbm0_cti_o == 3'b111)) | !wbm_cyc_o[0];
406
 
407
end
408
endgenerate
409
 
410
generate
411
if (nr_of_ports == 5) begin
412
 
413
    wire [2:0] wbm4_cti_o, wbm3_cti_o, wbm2_cti_o, wbm1_cti_o, wbm0_cti_o;
414
 
415
    assign {wbm4_cti_o, wbm3_cti_o, wbm2_cti_o,wbm1_cti_o,wbm0_cti_o} = wbm_cti_o;
416
 
417
    //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}};
418
 
419
    always @ (idle or wbm_cyc_o)
420
    if (idle)
421
        casex (wbm_cyc_o)
422
        5'b1xxxx : select = 5'b10000;
423
        5'b01xxx : select = 5'b01000;
424
        5'b001xx : select = 5'b00100;
425
        5'b0001x : select = 5'b00010;
426
        5'b00001 : select = 5'b00001;
427
        default : select = {nr_of_ports{1'b0}};
428
        endcase
429
    else
430
        select = {nr_of_ports{1'b0}};
431
 
432
    assign eoc[4] = (wbm_ack_i[4] & (wbm4_cti_o == 3'b000 | wbm4_cti_o == 3'b111)) | !wbm_cyc_o[4];
433
    assign eoc[3] = (wbm_ack_i[3] & (wbm3_cti_o == 3'b000 | wbm3_cti_o == 3'b111)) | !wbm_cyc_o[3];
434
    assign eoc[2] = (wbm_ack_i[2] & (wbm2_cti_o == 3'b000 | wbm2_cti_o == 3'b111)) | !wbm_cyc_o[2];
435
    assign eoc[1] = (wbm_ack_i[1] & (wbm1_cti_o == 3'b000 | wbm1_cti_o == 3'b111)) | !wbm_cyc_o[1];
436
    assign eoc[0] = (wbm_ack_i[0] & (wbm0_cti_o == 3'b000 | wbm0_cti_o == 3'b111)) | !wbm_cyc_o[0];
437
 
438
end
439
endgenerate
440
 
441
generate
442 39 unneback
for (i=0;i<nr_of_ports;i=i+1) begin
443 42 unneback
`define MODULE spr
444
    `BASE`MODULE sr0( .sp(select[i]), .r(eoc[i]), .q(state[i]), .clk(wb_clk), .rst(wb_rst));
445
`undef MODULE
446 39 unneback
end
447
endgenerate
448
 
449
    assign sel = select | state;
450
 
451 40 unneback
`define MODULE mux_andor
452
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(32)) mux0 ( .a(wbm_dat_o), .sel(sel), .dout(wbs_dat_i));
453
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(adr_size-adr_lo)) mux1 ( .a(wbm_adr_o), .sel(sel), .dout(wbs_adr_i));
454
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(sel_size)) mux2 ( .a(wbm_sel_o), .sel(sel), .dout(wbs_sel_i));
455
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(3)) mux3 ( .a(wbm_cti_o), .sel(sel), .dout(wbs_cti_i));
456
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(2)) mux4 ( .a(wbm_bte_o), .sel(sel), .dout(wbs_bte_i));
457
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(1)) mux5 ( .a(wbm_we_o), .sel(sel), .dout(wbs_we_i));
458
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(1)) mux6 ( .a(wbm_stb_o), .sel(sel), .dout(wbs_stb_i));
459
`undef MODULE
460 39 unneback
    assign wbs_cyc_i = |sel;
461
 
462
    assign wbm_dat_i = {nr_of_ports{wbs_dat_o}};
463
    assign wbm_ack_i = {nr_of_ports{wbs_ack_o}} & sel;
464
    assign wbm_err_i = {nr_of_ports{wbs_err_o}} & sel;
465
    assign wbm_rty_i = {nr_of_ports{wbs_rty_o}} & sel;
466
 
467
endmodule
468 40 unneback
`endif
469 39 unneback
 
470 49 unneback
`ifdef WB_B4_RAM_BE
471
// WB RAM with byte enable
472 59 unneback
`define MODULE wb_b3_ram_be
473
module `BASE`MODULE (
474
`undef MODULE
475
    wb_dat_i, wb_adr_i, wb_cti_i, wb_sel_i, wb_we_i, wb_stb_i, wb_cyc_i,
476
    wb_dat_o, wb_ack_o, wb_clk, wb_rst);
477
 
478
    parameter dat_width = 32;
479
    parameter adr_width = 8;
480
 
481
input [dat_width-1:0] wb_dat_i;
482
input [adr_width-1:0] wb_adr_i;
483
input [2:0] wb_cti_i;
484
input [dat_width/8-1:0] wb_sel_i;
485
input wb_we_i, wb_stb_i, wb_cyc_i;
486
output [dat_width-1:0] wb_dat_o;
487
reg [dat_width-1:0] wb_dat_o;
488
output wb_stall_o;
489
output wb_ack_o;
490
reg wb_ack_o;
491
input wb_clk, wb_rst;
492
 
493
wire [dat_width/8-1:0] cke;
494
 
495
generate
496
if (dat_width==32) begin
497
reg [7:0] ram3 [1<<(adr_width-2)-1:0];
498
reg [7:0] ram2 [1<<(adr_width-2)-1:0];
499
reg [7:0] ram1 [1<<(adr_width-2)-1:0];
500
reg [7:0] ram0 [1<<(adr_width-2)-1:0];
501
assign cke = wb_sel_i & {(dat_width/8){wb_we_i}};
502
    always @ (posedge wb_clk)
503
    begin
504
        if (cke[3]) ram3[wb_adr_i[adr_width-1:2]] <= wb_dat_i[31:24];
505
        if (cke[2]) ram2[wb_adr_i[adr_width-1:2]] <= wb_dat_i[23:16];
506
        if (cke[1]) ram1[wb_adr_i[adr_width-1:2]] <= wb_dat_i[15:8];
507
        if (cke[0]) ram0[wb_adr_i[adr_width-1:2]] <= wb_dat_i[7:0];
508
    end
509
    always @ (posedge wb_clk or posedge wb_rst)
510
    begin
511
        if (wb_rst)
512
            wb_dat_o <= 32'h0;
513
        else
514
            wb_dat_o <= {ram3[wb_adr_i[adr_width-1:2]],ram2[wb_adr_i[adr_width-1:2]],ram1[wb_adr_i[adr_width-1:2]],ram0[wb_adr_i[adr_width-1:2]]};
515
    end
516
end
517
endgenerate
518
 
519
always @ (posedge wb_clk or posedge wb_rst)
520
if (wb_rst)
521
    wb_ack_o <= 1'b0;
522
else
523
    if (wb_cti_i=3'b000 | wb_cti_i=3'b111)
524
        wb_ack_o <= wb_stb_i & wb_cyc_i & !wb_ack_o;
525
    else
526
        wb_ack_o <= wb_stb_i & wb_cyc_i;
527
endmodule
528
`endif
529
 
530
`ifdef WB_B4_RAM_BE
531
// WB RAM with byte enable
532 49 unneback
`define MODULE wb_b4_ram_be
533
module `BASE`MODULE (
534
`undef MODULE
535
    wb_dat_i, wb_adr_i, wb_sel_i, wb_we_i, wb_stb_i, wb_cyc_i,
536 52 unneback
    wb_dat_o, wb_stall_o, wb_ack_o, wb_clk, wb_rst);
537 49 unneback
 
538
    parameter dat_width = 32;
539
    parameter adr_width = 8;
540
 
541
input [dat_width-1:0] wb_dat_i;
542
input [adr_width-1:0] wb_adr_i;
543
input [dat_width/8-1:0] wb_sel_i;
544
input wb_we_i, wb_stb_i, wb_cyc_i;
545
output [dat_width-1:0] wb_dat_o;
546 51 unneback
reg [dat_width-1:0] wb_dat_o;
547 52 unneback
output wb_stall_o;
548 49 unneback
output wb_ack_o;
549
reg wb_ack_o;
550
input wb_clk, wb_rst;
551
 
552 56 unneback
wire [dat_width/8-1:0] cke;
553
 
554 49 unneback
generate
555
if (dat_width==32) begin
556 51 unneback
reg [7:0] ram3 [1<<(adr_width-2)-1:0];
557
reg [7:0] ram2 [1<<(adr_width-2)-1:0];
558
reg [7:0] ram1 [1<<(adr_width-2)-1:0];
559
reg [7:0] ram0 [1<<(adr_width-2)-1:0];
560 56 unneback
assign cke = wb_sel_i & {(dat_width/8){wb_we_i}};
561 49 unneback
    always @ (posedge wb_clk)
562
    begin
563 56 unneback
        if (cke[3]) ram3[wb_adr_i[adr_width-1:2]] <= wb_dat_i[31:24];
564
        if (cke[2]) ram2[wb_adr_i[adr_width-1:2]] <= wb_dat_i[23:16];
565
        if (cke[1]) ram1[wb_adr_i[adr_width-1:2]] <= wb_dat_i[15:8];
566
        if (cke[0]) ram0[wb_adr_i[adr_width-1:2]] <= wb_dat_i[7:0];
567 49 unneback
    end
568 59 unneback
    always @ (posedge wb_clk or posedge wb_rst)
569
    begin
570
        if (wb_rst)
571
            wb_dat_o <= 32'h0;
572
        else
573
            wb_dat_o <= {ram3[wb_adr_i[adr_width-1:2]],ram2[wb_adr_i[adr_width-1:2]],ram1[wb_adr_i[adr_width-1:2]],ram0[wb_adr_i[adr_width-1:2]]};
574
    end
575 49 unneback
end
576
endgenerate
577
 
578 52 unneback
always @ (posedge wb_clk or posedge wb_rst)
579 55 unneback
if (wb_rst)
580 52 unneback
    wb_ack_o <= 1'b0;
581
else
582 54 unneback
    wb_ack_o <= wb_stb_i & wb_cyc_i;
583 52 unneback
 
584
assign wb_stall_o = 1'b0;
585
 
586 49 unneback
endmodule
587
`endif
588
 
589 48 unneback
`ifdef WB_B4_ROM
590
// WB ROM
591
`define MODULE wb_b4_rom
592
module `BASE`MODULE (
593
`undef MODULE
594
    wb_adr_i, wb_stb_i, wb_cyc_i,
595
    wb_dat_o, stall_o, wb_ack_o, wb_clk, wb_rst);
596
 
597
    parameter dat_width = 32;
598
    parameter dat_default = 32'h15000000;
599
    parameter adr_width = 32;
600
 
601
/*
602
//E2_ifndef ROM
603
//E2_define ROM "rom.v"
604
//E2_endif
605
*/
606
    input [adr_width-1:2]   wb_adr_i;
607
    input                   wb_stb_i;
608
    input                   wb_cyc_i;
609
    output [dat_width-1:0]  wb_dat_o;
610
    reg [dat_width-1:0]     wb_dat_o;
611
    output                  wb_ack_o;
612
    reg                     wb_ack_o;
613
    output                  stall_o;
614
    input                   wb_clk;
615
    input                   wb_rst;
616
 
617
always @ (posedge wb_clk or posedge wb_rst)
618
    if (wb_rst)
619
        wb_dat_o <= {dat_width{1'b0}};
620
    else
621
         case (wb_adr_i[adr_width-1:2])
622
//E2_ifdef ROM
623
//E2_include `ROM
624
//E2_endif
625
           default:
626
             wb_dat_o <= dat_default;
627
 
628
         endcase // case (wb_adr_i)
629
 
630
 
631
always @ (posedge wb_clk or posedge wb_rst)
632
    if (wb_rst)
633
        wb_ack_o <= 1'b0;
634
    else
635
        wb_ack_o <= wb_stb_i & wb_cyc_i;
636
 
637
assign stall_o = 1'b0;
638
 
639
endmodule
640
`endif
641
 
642
 
643 40 unneback
`ifdef WB_BOOT_ROM
644 17 unneback
// WB ROM
645 40 unneback
`define MODULE wb_boot_rom
646
module `BASE`MODULE (
647
`undef MODULE
648 17 unneback
    wb_adr_i, wb_stb_i, wb_cyc_i,
649 18 unneback
    wb_dat_o, wb_ack_o, hit_o, wb_clk, wb_rst);
650 17 unneback
 
651 18 unneback
    parameter adr_hi = 31;
652
    parameter adr_lo = 28;
653
    parameter adr_sel = 4'hf;
654
    parameter addr_width = 5;
655 33 unneback
/*
656 17 unneback
//E2_ifndef BOOT_ROM
657
//E2_define BOOT_ROM "boot_rom.v"
658
//E2_endif
659 33 unneback
*/
660 18 unneback
    input [adr_hi:2]    wb_adr_i;
661
    input               wb_stb_i;
662
    input               wb_cyc_i;
663
    output [31:0]        wb_dat_o;
664
    output              wb_ack_o;
665
    output              hit_o;
666
    input               wb_clk;
667
    input               wb_rst;
668
 
669
    wire hit;
670
    reg [31:0] wb_dat;
671
    reg wb_ack;
672
 
673
assign hit = wb_adr_i[adr_hi:adr_lo] == adr_sel;
674 17 unneback
 
675
always @ (posedge wb_clk or posedge wb_rst)
676
    if (wb_rst)
677 18 unneback
        wb_dat <= 32'h15000000;
678 17 unneback
    else
679 18 unneback
         case (wb_adr_i[addr_width-1:2])
680 33 unneback
//E2_ifdef BOOT_ROM
681 17 unneback
//E2_include `BOOT_ROM
682 33 unneback
//E2_endif
683 17 unneback
           /*
684
            // Zero r0 and jump to 0x00000100
685 18 unneback
 
686
            1 : wb_dat <= 32'hA8200000;
687
            2 : wb_dat <= 32'hA8C00100;
688
            3 : wb_dat <= 32'h44003000;
689
            4 : wb_dat <= 32'h15000000;
690 17 unneback
            */
691
           default:
692 18 unneback
             wb_dat <= 32'h00000000;
693 17 unneback
 
694
         endcase // case (wb_adr_i)
695
 
696
 
697
always @ (posedge wb_clk or posedge wb_rst)
698
    if (wb_rst)
699 18 unneback
        wb_ack <= 1'b0;
700 17 unneback
    else
701 18 unneback
        wb_ack <= wb_stb_i & wb_cyc_i & hit & !wb_ack;
702 17 unneback
 
703 18 unneback
assign hit_o = hit;
704
assign wb_dat_o = wb_dat & {32{wb_ack}};
705
assign wb_ack_o = wb_ack;
706
 
707 17 unneback
endmodule
708 40 unneback
`endif
709 32 unneback
 
710 40 unneback
`ifdef WB_DPRAM
711
`define MODULE wb_dpram
712
module `BASE`MODULE (
713
`undef MODULE
714 32 unneback
        // wishbone slave side a
715
        wbsa_dat_i, wbsa_adr_i, wbsa_we_i, wbsa_cyc_i, wbsa_stb_i, wbsa_dat_o, wbsa_ack_o,
716
        wbsa_clk, wbsa_rst,
717
        // wishbone slave side a
718
        wbsb_dat_i, wbsb_adr_i, wbsb_we_i, wbsb_cyc_i, wbsb_stb_i, wbsb_dat_o, wbsb_ack_o,
719
        wbsb_clk, wbsb_rst);
720
 
721
parameter data_width = 32;
722
parameter addr_width = 8;
723
 
724
parameter dat_o_mask_a = 1;
725
parameter dat_o_mask_b = 1;
726
 
727
input [31:0] wbsa_dat_i;
728
input [addr_width-1:2] wbsa_adr_i;
729
input wbsa_we_i, wbsa_cyc_i, wbsa_stb_i;
730
output [31:0] wbsa_dat_o;
731
output wbsa_ack_o;
732
input wbsa_clk, wbsa_rst;
733
 
734
input [31:0] wbsb_dat_i;
735
input [addr_width-1:2] wbsb_adr_i;
736
input wbsb_we_i, wbsb_cyc_i, wbsb_stb_i;
737
output [31:0] wbsb_dat_o;
738
output wbsb_ack_o;
739
input wbsb_clk, wbsb_rst;
740
 
741
wire wbsa_dat_tmp, wbsb_dat_tmp;
742
 
743 40 unneback
`define MODULE dpram_2r2w
744
`BASE`MODULE # (
745
`undef MODULE
746 33 unneback
    .data_width(data_width), .addr_width(addr_width) )
747 32 unneback
dpram0(
748
    .d_a(wbsa_dat_i),
749
    .q_a(wbsa_dat_tmp),
750
    .adr_a(wbsa_adr_i),
751
    .we_a(wbsa_we_i),
752
    .clk_a(wbsa_clk),
753
    .d_b(wbsb_dat_i),
754
    .q_b(wbsb_dat_tmp),
755
    .adr_b(wbsb_adr_i),
756
    .we_b(wbsb_we_i),
757
    .clk_b(wbsb_clk) );
758
 
759 33 unneback
generate if (dat_o_mask_a==1)
760 32 unneback
    assign wbsa_dat_o = wbsa_dat_tmp & {data_width{wbsa_ack_o}};
761
endgenerate
762 33 unneback
generate if (dat_o_mask_a==0)
763 32 unneback
    assign wbsa_dat_o = wbsa_dat_tmp;
764
endgenerate
765
 
766 33 unneback
generate if (dat_o_mask_b==1)
767 32 unneback
    assign wbsb_dat_o = wbsb_dat_tmp & {data_width{wbsb_ack_o}};
768
endgenerate
769 33 unneback
generate if (dat_o_mask_b==0)
770 32 unneback
    assign wbsb_dat_o = wbsb_dat_tmp;
771
endgenerate
772
 
773 40 unneback
`define MODULE spr
774
`BASE`MODULE ack_a( .sp(wbsa_cyc_i & wbsa_stb_i & !wbsa_ack_o), .r(1'b1), .q(wbsa_ack_o), .clk(wbsa_clk), .rst(wbsa_rst));
775
`BASE`MODULE ack_b( .sp(wbsb_cyc_i & wbsb_stb_i & !wbsb_ack_o), .r(1'b1), .q(wbsb_ack_o), .clk(wbsb_clk), .rst(wbsb_rst));
776
`undef MODULE
777 32 unneback
 
778
endmodule
779 40 unneback
`endif

powered by: WebSVN 2.1.0

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