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 13

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
output reg wbs_ack_o;
59
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
output reg wbm_we_o, wbm_cyc_o;
67
output wbm_stb_o;
68
input [31:0]  wbm_dat_i;
69
input wbm_ack_i;
70
input wbm_clk, wbm_rst;
71
 
72
parameter addr_width = 4;
73
 
74
// bte
75
parameter linear       = 2'b00;
76
parameter wrap4        = 2'b01;
77
parameter wrap8        = 2'b10;
78
parameter wrap16       = 2'b11;
79
// cti
80
parameter classic      = 3'b000;
81
parameter incburst     = 3'b010;
82
parameter endofburst   = 3'b111;
83
 
84
parameter wbs_adr  = 1'b0;
85
parameter wbs_data = 1'b1;
86
 
87
parameter wbm_adr0 = 2'b00;
88
parameter wbm_adr1 = 2'b01;
89
parameter wbm_data = 2'b10;
90
 
91
reg [1:0] wbs_bte_reg;
92
reg wbs;
93
wire wbs_eoc_alert, wbm_eoc_alert;
94
reg wbs_eoc, wbm_eoc;
95
reg [1:0] wbm;
96
 
97
reg [1:16] wbs_count, wbm_count;
98
 
99
wire [35:0] a_d, a_q, b_d, b_q;
100
wire a_wr, a_rd, a_fifo_full, a_fifo_empty, b_wr, b_rd, b_fifo_full, b_fifo_empty;
101
reg a_rd_reg;
102
wire b_rd_adr, b_rd_data;
103
reg b_rd_data_reg;
104
reg [35:0] temp;
105
 
106
`define WE 5
107
`define BTE 4:3
108
`define CTI 2:0
109
 
110
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]);
111
always @ (posedge wbs_clk or posedge wbs_rst)
112
if (wbs_rst)
113
        wbs_eoc <= 1'b0;
114
else
115
        if (wbs==wbs_adr & wbs_stb_i & !a_fifo_full)
116
                wbs_eoc <= wbs_bte_i==linear;
117
        else if (wbs_eoc_alert & (a_rd | a_wr))
118
                wbs_eoc <= 1'b1;
119
 
120
cnt_shreg_ce_clear # ( .length(16))
121
    cnt0 (
122
        .cke(wbs_ack_o),
123
        .clear(wbs_eoc),
124
        .q(wbs_count),
125
        .rst(wbs_rst),
126
        .clk(wbs_clk));
127
 
128
always @ (posedge wbs_clk or posedge wbs_rst)
129
if (wbs_rst)
130
        wbs <= wbs_adr;
131
else
132
        if ((wbs==wbs_adr) & wbs_cyc_i & wbs_stb_i & !a_fifo_full)
133
                wbs <= wbs_data;
134
        else if (wbs_eoc & wbs_ack_o)
135
                wbs <= wbs_adr;
136
 
137
// wbs FIFO
138
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};
139
assign a_wr = (wbs==wbs_adr)  ? wbs_cyc_i & wbs_stb_i & !a_fifo_full :
140
              (wbs==wbs_data) ? wbs_we_i  & wbs_stb_i & !a_fifo_full :
141
              1'b0;
142
assign a_rd = !a_fifo_empty;
143
always @ (posedge wbs_clk or posedge wbs_rst)
144
if (wbs_rst)
145
        a_rd_reg <= 1'b0;
146
else
147
        a_rd_reg <= a_rd;
148
assign wbs_ack_o = a_rd_reg | (a_wr & wbs==wbs_data);
149
 
150
assign wbs_dat_o = a_q[35:4];
151
 
152
always @ (posedge wbs_clk or posedge wbs_rst)
153
if (wbs_rst)
154 13 unneback
        wbs_bte_reg <= 2'b00;
155 12 unneback
else
156 13 unneback
        wbs_bte_reg <= wbs_bte_i;
157 12 unneback
 
158
// wbm FIFO
159
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]);
160
always @ (posedge wbm_clk or posedge wbm_rst)
161
if (wbm_rst)
162
        wbm_eoc <= 1'b0;
163
else
164
        if (wbm==wbm_adr0 & !b_fifo_empty)
165
                wbm_eoc <= b_q[`BTE] == linear;
166
        else if (wbm_eoc_alert & wbm_ack_i)
167
                wbm_eoc <= 1'b1;
168
 
169
always @ (posedge wbm_clk or posedge wbm_rst)
170
if (wbm_rst)
171
        wbm <= wbm_adr0;
172
else
173
    if ((wbm==wbm_adr0 & !b_fifo_empty) |
174
        (wbm==wbm_adr1 & !b_fifo_empty & wbm_we_o) |
175
        (wbm==wbm_adr1 & !wbm_we_o) |
176
        (wbm==wbm_data & wbm_ack_i & wbm_eoc))
177
        wbm <= {wbm[0],!(wbm[1] ^ wbm[0])};  // count sequence 00,01,10
178
 
179
assign b_d = {wbm_dat_i,4'b1111};
180
assign b_wr = !wbm_we_o & wbm_ack_i;
181
assign b_rd_adr  = (wbm==wbm_adr0 & !b_fifo_empty);
182
assign b_rd_data = (wbm==wbm_adr1 & !b_fifo_empty & wbm_we_o) ? 1'b1 : // b_q[`WE]
183
                   (wbm==wbm_data & !b_fifo_empty & wbm_we_o & wbm_ack_i & !wbm_eoc) ? 1'b1 :
184
                   1'b0;
185
assign b_rd = b_rd_adr | b_rd_data;
186
 
187
dff dff1 ( .d(b_rd_data), .q(b_rd_data_reg), .clk(wbm_clk), .rst(wbm_rst));
188
dff_ce # ( .width(36)) dff2 ( .d(b_q), .ce(b_rd_data_reg), .q(temp), .clk(wbm_clk), .rst(wbm_rst));
189
 
190
assign {wbm_dat_o,wbm_sel_o} = (b_rd_data_reg) ? b_q : temp;
191
 
192
cnt_shreg_ce_clear # ( .length(16))
193
    cnt1 (
194
        .cke(wbm_ack_i),
195
        .clear(wbm_eoc),
196
        .q(wbm_count),
197
        .rst(wbm_rst),
198
        .clk(wbm_clk));
199
 
200
assign wbm_cyc_o = wbm==wbm_data;
201
assign wbm_stb_o = (wbm==wbm_data & wbm_we_o) ? !b_fifo_empty :
202
                   (wbm==wbm_data) ? 1'b1 :
203
                   1'b0;
204
 
205
always @ (posedge wbm_clk or posedge wbm_rst)
206
if (wbm_rst)
207
        {wbm_adr_o,wbm_we_o,wbm_bte_o,wbm_cti_o} <= {30'h0,1'b0,linear,classic};
208
else begin
209
        if (wbm==wbm_adr0 & !b_fifo_empty)
210
                {wbm_adr_o,wbm_we_o,wbm_bte_o,wbm_cti_o} <= b_q;
211
        else if (wbm_eoc_alert & wbm_ack_i)
212
                wbm_cti_o <= endofburst;
213
end
214
 
215
//async_fifo_dw_simplex_top
216
vl_fifo_2r2w_async_simplex
217
# ( .data_width(36), .addr_width(addr_width))
218
fifo (
219
    // a side
220
    .a_d(a_d),
221
    .a_wr(a_wr),
222
    .a_fifo_full(a_fifo_full),
223
    .a_q(a_q),
224
    .a_rd(a_rd),
225
    .a_fifo_empty(a_fifo_empty),
226
    .a_clk(wbs_clk),
227
    .a_rst(wbs_rst),
228
    // b side
229
    .b_d(b_d),
230
    .b_wr(b_wr),
231
    .b_fifo_full(b_fifo_full),
232
    .b_q(b_q),
233
    .b_rd(b_rd),
234
    .b_fifo_empty(b_fifo_empty),
235
    .b_clk(wbm_clk),
236
    .b_rst(wbm_rst)
237
    );
238
 
239
endmodule

powered by: WebSVN 2.1.0

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