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 48

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 48 unneback
`ifdef WB_B4_ROM
471
// WB ROM
472
`define MODULE wb_b4_rom
473
module `BASE`MODULE (
474
`undef MODULE
475
    wb_adr_i, wb_stb_i, wb_cyc_i,
476
    wb_dat_o, stall_o, wb_ack_o, wb_clk, wb_rst);
477
 
478
    parameter dat_width = 32;
479
    parameter dat_default = 32'h15000000;
480
    parameter adr_width = 32;
481
 
482
/*
483
//E2_ifndef ROM
484
//E2_define ROM "rom.v"
485
//E2_endif
486
*/
487
    input [adr_width-1:2]   wb_adr_i;
488
    input                   wb_stb_i;
489
    input                   wb_cyc_i;
490
    output [dat_width-1:0]  wb_dat_o;
491
    reg [dat_width-1:0]     wb_dat_o;
492
    output                  wb_ack_o;
493
    reg                     wb_ack_o;
494
    output                  stall_o;
495
    input                   wb_clk;
496
    input                   wb_rst;
497
 
498
always @ (posedge wb_clk or posedge wb_rst)
499
    if (wb_rst)
500
        wb_dat_o <= {dat_width{1'b0}};
501
    else
502
         case (wb_adr_i[adr_width-1:2])
503
//E2_ifdef ROM
504
//E2_include `ROM
505
//E2_endif
506
           default:
507
             wb_dat_o <= dat_default;
508
 
509
         endcase // case (wb_adr_i)
510
 
511
 
512
always @ (posedge wb_clk or posedge wb_rst)
513
    if (wb_rst)
514
        wb_ack_o <= 1'b0;
515
    else
516
        wb_ack_o <= wb_stb_i & wb_cyc_i;
517
 
518
assign stall_o = 1'b0;
519
 
520
endmodule
521
`endif
522
 
523
 
524 40 unneback
`ifdef WB_BOOT_ROM
525 17 unneback
// WB ROM
526 40 unneback
`define MODULE wb_boot_rom
527
module `BASE`MODULE (
528
`undef MODULE
529 17 unneback
    wb_adr_i, wb_stb_i, wb_cyc_i,
530 18 unneback
    wb_dat_o, wb_ack_o, hit_o, wb_clk, wb_rst);
531 17 unneback
 
532 18 unneback
    parameter adr_hi = 31;
533
    parameter adr_lo = 28;
534
    parameter adr_sel = 4'hf;
535
    parameter addr_width = 5;
536 33 unneback
/*
537 17 unneback
//E2_ifndef BOOT_ROM
538
//E2_define BOOT_ROM "boot_rom.v"
539
//E2_endif
540 33 unneback
*/
541 18 unneback
    input [adr_hi:2]    wb_adr_i;
542
    input               wb_stb_i;
543
    input               wb_cyc_i;
544
    output [31:0]        wb_dat_o;
545
    output              wb_ack_o;
546
    output              hit_o;
547
    input               wb_clk;
548
    input               wb_rst;
549
 
550
    wire hit;
551
    reg [31:0] wb_dat;
552
    reg wb_ack;
553
 
554
assign hit = wb_adr_i[adr_hi:adr_lo] == adr_sel;
555 17 unneback
 
556
always @ (posedge wb_clk or posedge wb_rst)
557
    if (wb_rst)
558 18 unneback
        wb_dat <= 32'h15000000;
559 17 unneback
    else
560 18 unneback
         case (wb_adr_i[addr_width-1:2])
561 33 unneback
//E2_ifdef BOOT_ROM
562 17 unneback
//E2_include `BOOT_ROM
563 33 unneback
//E2_endif
564 17 unneback
           /*
565
            // Zero r0 and jump to 0x00000100
566 18 unneback
 
567
            1 : wb_dat <= 32'hA8200000;
568
            2 : wb_dat <= 32'hA8C00100;
569
            3 : wb_dat <= 32'h44003000;
570
            4 : wb_dat <= 32'h15000000;
571 17 unneback
            */
572
           default:
573 18 unneback
             wb_dat <= 32'h00000000;
574 17 unneback
 
575
         endcase // case (wb_adr_i)
576
 
577
 
578
always @ (posedge wb_clk or posedge wb_rst)
579
    if (wb_rst)
580 18 unneback
        wb_ack <= 1'b0;
581 17 unneback
    else
582 18 unneback
        wb_ack <= wb_stb_i & wb_cyc_i & hit & !wb_ack;
583 17 unneback
 
584 18 unneback
assign hit_o = hit;
585
assign wb_dat_o = wb_dat & {32{wb_ack}};
586
assign wb_ack_o = wb_ack;
587
 
588 17 unneback
endmodule
589 40 unneback
`endif
590 32 unneback
 
591 40 unneback
`ifdef WB_DPRAM
592
`define MODULE wb_dpram
593
module `BASE`MODULE (
594
`undef MODULE
595 32 unneback
        // wishbone slave side a
596
        wbsa_dat_i, wbsa_adr_i, wbsa_we_i, wbsa_cyc_i, wbsa_stb_i, wbsa_dat_o, wbsa_ack_o,
597
        wbsa_clk, wbsa_rst,
598
        // wishbone slave side a
599
        wbsb_dat_i, wbsb_adr_i, wbsb_we_i, wbsb_cyc_i, wbsb_stb_i, wbsb_dat_o, wbsb_ack_o,
600
        wbsb_clk, wbsb_rst);
601
 
602
parameter data_width = 32;
603
parameter addr_width = 8;
604
 
605
parameter dat_o_mask_a = 1;
606
parameter dat_o_mask_b = 1;
607
 
608
input [31:0] wbsa_dat_i;
609
input [addr_width-1:2] wbsa_adr_i;
610
input wbsa_we_i, wbsa_cyc_i, wbsa_stb_i;
611
output [31:0] wbsa_dat_o;
612
output wbsa_ack_o;
613
input wbsa_clk, wbsa_rst;
614
 
615
input [31:0] wbsb_dat_i;
616
input [addr_width-1:2] wbsb_adr_i;
617
input wbsb_we_i, wbsb_cyc_i, wbsb_stb_i;
618
output [31:0] wbsb_dat_o;
619
output wbsb_ack_o;
620
input wbsb_clk, wbsb_rst;
621
 
622
wire wbsa_dat_tmp, wbsb_dat_tmp;
623
 
624 40 unneback
`define MODULE dpram_2r2w
625
`BASE`MODULE # (
626
`undef MODULE
627 33 unneback
    .data_width(data_width), .addr_width(addr_width) )
628 32 unneback
dpram0(
629
    .d_a(wbsa_dat_i),
630
    .q_a(wbsa_dat_tmp),
631
    .adr_a(wbsa_adr_i),
632
    .we_a(wbsa_we_i),
633
    .clk_a(wbsa_clk),
634
    .d_b(wbsb_dat_i),
635
    .q_b(wbsb_dat_tmp),
636
    .adr_b(wbsb_adr_i),
637
    .we_b(wbsb_we_i),
638
    .clk_b(wbsb_clk) );
639
 
640 33 unneback
generate if (dat_o_mask_a==1)
641 32 unneback
    assign wbsa_dat_o = wbsa_dat_tmp & {data_width{wbsa_ack_o}};
642
endgenerate
643 33 unneback
generate if (dat_o_mask_a==0)
644 32 unneback
    assign wbsa_dat_o = wbsa_dat_tmp;
645
endgenerate
646
 
647 33 unneback
generate if (dat_o_mask_b==1)
648 32 unneback
    assign wbsb_dat_o = wbsb_dat_tmp & {data_width{wbsb_ack_o}};
649
endgenerate
650 33 unneback
generate if (dat_o_mask_b==0)
651 32 unneback
    assign wbsb_dat_o = wbsb_dat_tmp;
652
endgenerate
653
 
654 40 unneback
`define MODULE spr
655
`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));
656
`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));
657
`undef MODULE
658 32 unneback
 
659
endmodule
660 40 unneback
`endif

powered by: WebSVN 2.1.0

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