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 17

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
module wb3wb3_bridge (
46
        // 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
cnt_shreg_ce_clear # ( .length(16))
122
    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
dff dff1 ( .d(b_rd_data), .q(b_rd_data_reg), .clk(wbm_clk), .rst(wbm_rst));
189
dff_ce # ( .width(36)) dff2 ( .d(b_q), .ce(b_rd_data_reg), .q(temp), .clk(wbm_clk), .rst(wbm_rst));
190
 
191
assign {wbm_dat_o,wbm_sel_o} = (b_rd_data_reg) ? b_q : temp;
192
 
193
cnt_shreg_ce_clear # ( .length(16))
194
    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
module wb_boot_rom (
244
    wb_adr_i, wb_stb_i, wb_cyc_i,
245
    wb_dat_o, wb_ack_o, wb_clk, wb_rst);
246
 
247
//E2_ifndef BOOT_ROM
248
//E2_define BOOT_ROM "boot_rom.v"
249
//E2_endif
250
    parameter addr_width = 5;
251
 
252
   input [(addr_width+2)-1:2]       wb_adr_i;
253
   input                            wb_stb_i;
254
   input                            wb_cyc_i;
255
   output reg [31:0]                 wb_dat_o;
256
   output reg                       wb_ack_o;
257
   input                            wb_clk;
258
   input                            wb_rst;
259
 
260
always @ (posedge wb_clk or posedge wb_rst)
261
    if (wb_rst)
262
        wb_dat_o <= 32'h15000000;
263
    else
264
         case (wb_adr_i)
265
//E2_include `BOOT_ROM
266
           /*
267
            // Zero r0 and jump to 0x00000100
268
 
269
            1 : wb_dat_o <= 32'hA8200000;
270
            2 : wb_dat_o <= 32'hA8C00100;
271
            3 : wb_dat_o <= 32'h44003000;
272
            4 : wb_dat_o <= 32'h15000000;
273
            */
274
           default:
275
             wb_dat_o <= 32'h00000000;
276
 
277
         endcase // case (wb_adr_i)
278
 
279
 
280
always @ (posedge wb_clk or posedge wb_rst)
281
    if (wb_rst)
282
        wb_ack_o <= 1'b0;
283
    else
284
        wb_ack_o <= wb_stb_i & wb_cyc_i & !wb_ack_o;
285
 
286
endmodule

powered by: WebSVN 2.1.0

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