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 31

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
// async wb3 - wb3 bridge
44
`timescale 1ns/1ns
45 18 unneback
module vl_wb3wb3_bridge (
46 12 unneback
        // wishbone slave side
47
        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,
48
        // wishbone master side
49
        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);
50
 
51
input [31:0] wbs_dat_i;
52
input [31:2] wbs_adr_i;
53
input [3:0]  wbs_sel_i;
54
input [1:0]  wbs_bte_i;
55
input [2:0]  wbs_cti_i;
56
input wbs_we_i, wbs_cyc_i, wbs_stb_i;
57
output [31:0] wbs_dat_o;
58 14 unneback
output wbs_ack_o;
59 12 unneback
input wbs_clk, wbs_rst;
60
 
61
output [31:0] wbm_dat_o;
62
output reg [31:2] wbm_adr_o;
63
output [3:0]  wbm_sel_o;
64
output reg [1:0]  wbm_bte_o;
65
output reg [2:0]  wbm_cti_o;
66 14 unneback
output reg wbm_we_o;
67
output wbm_cyc_o;
68 12 unneback
output wbm_stb_o;
69
input [31:0]  wbm_dat_i;
70
input wbm_ack_i;
71
input wbm_clk, wbm_rst;
72
 
73
parameter addr_width = 4;
74
 
75
// bte
76
parameter linear       = 2'b00;
77
parameter wrap4        = 2'b01;
78
parameter wrap8        = 2'b10;
79
parameter wrap16       = 2'b11;
80
// cti
81
parameter classic      = 3'b000;
82
parameter incburst     = 3'b010;
83
parameter endofburst   = 3'b111;
84
 
85
parameter wbs_adr  = 1'b0;
86
parameter wbs_data = 1'b1;
87
 
88
parameter wbm_adr0 = 2'b00;
89
parameter wbm_adr1 = 2'b01;
90
parameter wbm_data = 2'b10;
91
 
92
reg [1:0] wbs_bte_reg;
93
reg wbs;
94
wire wbs_eoc_alert, wbm_eoc_alert;
95
reg wbs_eoc, wbm_eoc;
96
reg [1:0] wbm;
97
 
98 14 unneback
wire [1:16] wbs_count, wbm_count;
99 12 unneback
 
100
wire [35:0] a_d, a_q, b_d, b_q;
101
wire a_wr, a_rd, a_fifo_full, a_fifo_empty, b_wr, b_rd, b_fifo_full, b_fifo_empty;
102
reg a_rd_reg;
103
wire b_rd_adr, b_rd_data;
104 14 unneback
wire b_rd_data_reg;
105
wire [35:0] temp;
106 12 unneback
 
107
`define WE 5
108
`define BTE 4:3
109
`define CTI 2:0
110
 
111
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]);
112
always @ (posedge wbs_clk or posedge wbs_rst)
113
if (wbs_rst)
114
        wbs_eoc <= 1'b0;
115
else
116
        if (wbs==wbs_adr & wbs_stb_i & !a_fifo_full)
117
                wbs_eoc <= wbs_bte_i==linear;
118
        else if (wbs_eoc_alert & (a_rd | a_wr))
119
                wbs_eoc <= 1'b1;
120
 
121 18 unneback
vl_cnt_shreg_ce_clear # ( .length(16))
122 12 unneback
    cnt0 (
123
        .cke(wbs_ack_o),
124
        .clear(wbs_eoc),
125
        .q(wbs_count),
126
        .rst(wbs_rst),
127
        .clk(wbs_clk));
128
 
129
always @ (posedge wbs_clk or posedge wbs_rst)
130
if (wbs_rst)
131
        wbs <= wbs_adr;
132
else
133
        if ((wbs==wbs_adr) & wbs_cyc_i & wbs_stb_i & !a_fifo_full)
134
                wbs <= wbs_data;
135
        else if (wbs_eoc & wbs_ack_o)
136
                wbs <= wbs_adr;
137
 
138
// wbs FIFO
139
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};
140
assign a_wr = (wbs==wbs_adr)  ? wbs_cyc_i & wbs_stb_i & !a_fifo_full :
141
              (wbs==wbs_data) ? wbs_we_i  & wbs_stb_i & !a_fifo_full :
142
              1'b0;
143
assign a_rd = !a_fifo_empty;
144
always @ (posedge wbs_clk or posedge wbs_rst)
145
if (wbs_rst)
146
        a_rd_reg <= 1'b0;
147
else
148
        a_rd_reg <= a_rd;
149
assign wbs_ack_o = a_rd_reg | (a_wr & wbs==wbs_data);
150
 
151
assign wbs_dat_o = a_q[35:4];
152
 
153
always @ (posedge wbs_clk or posedge wbs_rst)
154
if (wbs_rst)
155 13 unneback
        wbs_bte_reg <= 2'b00;
156 12 unneback
else
157 13 unneback
        wbs_bte_reg <= wbs_bte_i;
158 12 unneback
 
159
// wbm FIFO
160
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]);
161
always @ (posedge wbm_clk or posedge wbm_rst)
162
if (wbm_rst)
163
        wbm_eoc <= 1'b0;
164
else
165
        if (wbm==wbm_adr0 & !b_fifo_empty)
166
                wbm_eoc <= b_q[`BTE] == linear;
167
        else if (wbm_eoc_alert & wbm_ack_i)
168
                wbm_eoc <= 1'b1;
169
 
170
always @ (posedge wbm_clk or posedge wbm_rst)
171
if (wbm_rst)
172
        wbm <= wbm_adr0;
173
else
174
    if ((wbm==wbm_adr0 & !b_fifo_empty) |
175
        (wbm==wbm_adr1 & !b_fifo_empty & wbm_we_o) |
176
        (wbm==wbm_adr1 & !wbm_we_o) |
177
        (wbm==wbm_data & wbm_ack_i & wbm_eoc))
178
        wbm <= {wbm[0],!(wbm[1] ^ wbm[0])};  // count sequence 00,01,10
179
 
180
assign b_d = {wbm_dat_i,4'b1111};
181
assign b_wr = !wbm_we_o & wbm_ack_i;
182
assign b_rd_adr  = (wbm==wbm_adr0 & !b_fifo_empty);
183
assign b_rd_data = (wbm==wbm_adr1 & !b_fifo_empty & wbm_we_o) ? 1'b1 : // b_q[`WE]
184
                   (wbm==wbm_data & !b_fifo_empty & wbm_we_o & wbm_ack_i & !wbm_eoc) ? 1'b1 :
185
                   1'b0;
186
assign b_rd = b_rd_adr | b_rd_data;
187
 
188 18 unneback
vl_dff dff1 ( .d(b_rd_data), .q(b_rd_data_reg), .clk(wbm_clk), .rst(wbm_rst));
189
vl_dff_ce # ( .width(36)) dff2 ( .d(b_q), .ce(b_rd_data_reg), .q(temp), .clk(wbm_clk), .rst(wbm_rst));
190 12 unneback
 
191
assign {wbm_dat_o,wbm_sel_o} = (b_rd_data_reg) ? b_q : temp;
192
 
193 18 unneback
vl_cnt_shreg_ce_clear # ( .length(16))
194 12 unneback
    cnt1 (
195
        .cke(wbm_ack_i),
196
        .clear(wbm_eoc),
197
        .q(wbm_count),
198
        .rst(wbm_rst),
199
        .clk(wbm_clk));
200
 
201
assign wbm_cyc_o = wbm==wbm_data;
202
assign wbm_stb_o = (wbm==wbm_data & wbm_we_o) ? !b_fifo_empty :
203
                   (wbm==wbm_data) ? 1'b1 :
204
                   1'b0;
205
 
206
always @ (posedge wbm_clk or posedge wbm_rst)
207
if (wbm_rst)
208
        {wbm_adr_o,wbm_we_o,wbm_bte_o,wbm_cti_o} <= {30'h0,1'b0,linear,classic};
209
else begin
210
        if (wbm==wbm_adr0 & !b_fifo_empty)
211
                {wbm_adr_o,wbm_we_o,wbm_bte_o,wbm_cti_o} <= b_q;
212
        else if (wbm_eoc_alert & wbm_ack_i)
213
                wbm_cti_o <= endofburst;
214
end
215
 
216
//async_fifo_dw_simplex_top
217
vl_fifo_2r2w_async_simplex
218
# ( .data_width(36), .addr_width(addr_width))
219
fifo (
220
    // a side
221
    .a_d(a_d),
222
    .a_wr(a_wr),
223
    .a_fifo_full(a_fifo_full),
224
    .a_q(a_q),
225
    .a_rd(a_rd),
226
    .a_fifo_empty(a_fifo_empty),
227
    .a_clk(wbs_clk),
228
    .a_rst(wbs_rst),
229
    // b side
230
    .b_d(b_d),
231
    .b_wr(b_wr),
232
    .b_fifo_full(b_fifo_full),
233
    .b_q(b_q),
234
    .b_rd(b_rd),
235
    .b_fifo_empty(b_fifo_empty),
236
    .b_clk(wbm_clk),
237
    .b_rst(wbm_rst)
238
    );
239
 
240
endmodule
241 17 unneback
 
242
// WB ROM
243 18 unneback
module vl_wb_boot_rom (
244 17 unneback
    wb_adr_i, wb_stb_i, wb_cyc_i,
245 18 unneback
    wb_dat_o, wb_ack_o, hit_o, wb_clk, wb_rst);
246 17 unneback
 
247 18 unneback
    parameter adr_hi = 31;
248
    parameter adr_lo = 28;
249
    parameter adr_sel = 4'hf;
250
    parameter addr_width = 5;
251
 
252 17 unneback
//E2_ifndef BOOT_ROM
253
//E2_define BOOT_ROM "boot_rom.v"
254
//E2_endif
255
 
256 18 unneback
    input [adr_hi:2]    wb_adr_i;
257
    input               wb_stb_i;
258
    input               wb_cyc_i;
259
    output [31:0]        wb_dat_o;
260
    output              wb_ack_o;
261
    output              hit_o;
262
    input               wb_clk;
263
    input               wb_rst;
264
 
265
    wire hit;
266
    reg [31:0] wb_dat;
267
    reg wb_ack;
268
 
269
assign hit = wb_adr_i[adr_hi:adr_lo] == adr_sel;
270 17 unneback
 
271
always @ (posedge wb_clk or posedge wb_rst)
272
    if (wb_rst)
273 18 unneback
        wb_dat <= 32'h15000000;
274 17 unneback
    else
275 18 unneback
         case (wb_adr_i[addr_width-1:2])
276 17 unneback
//E2_include `BOOT_ROM
277
           /*
278
            // Zero r0 and jump to 0x00000100
279 18 unneback
 
280
            1 : wb_dat <= 32'hA8200000;
281
            2 : wb_dat <= 32'hA8C00100;
282
            3 : wb_dat <= 32'h44003000;
283
            4 : wb_dat <= 32'h15000000;
284 17 unneback
            */
285
           default:
286 18 unneback
             wb_dat <= 32'h00000000;
287 17 unneback
 
288
         endcase // case (wb_adr_i)
289
 
290
 
291
always @ (posedge wb_clk or posedge wb_rst)
292
    if (wb_rst)
293 18 unneback
        wb_ack <= 1'b0;
294 17 unneback
    else
295 18 unneback
        wb_ack <= wb_stb_i & wb_cyc_i & hit & !wb_ack;
296 17 unneback
 
297 18 unneback
assign hit_o = hit;
298
assign wb_dat_o = wb_dat & {32{wb_ack}};
299
assign wb_ack_o = wb_ack;
300
 
301 17 unneback
endmodule

powered by: WebSVN 2.1.0

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