1 //////////////////////////////////////////////////////////////////////
5 //// This file is part of the Ethernet IP core project ////
6 //// http://www.opencores.org/projects/ethmac/ ////
9 //// - Igor Mohor (igorM@opencores.org) ////
11 //// All additional information is avaliable in the Readme.txt ////
14 //////////////////////////////////////////////////////////////////////
16 //// Copyright (C) 2001, 2002 Authors ////
18 //// This source file may be used and distributed without ////
19 //// restriction provided that this copyright statement is not ////
20 //// removed from the file and that any derivative work contains ////
21 //// the original copyright notice and the associated disclaimer. ////
23 //// This source file is free software; you can redistribute it ////
24 //// and/or modify it under the terms of the GNU Lesser General ////
25 //// Public License as published by the Free Software Foundation; ////
26 //// either version 2.1 of the License, or (at your option) any ////
27 //// later version. ////
29 //// This source is distributed in the hope that it will be ////
30 //// useful, but WITHOUT ANY WARRANTY; without even the implied ////
31 //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
32 //// PURPOSE. See the GNU Lesser General Public License for more ////
35 //// You should have received a copy of the GNU Lesser General ////
36 //// Public License along with this source; if not, download it ////
37 //// from http://www.opencores.org/lgpl.shtml ////
39 //////////////////////////////////////////////////////////////////////
41 // CVS Revision History
43 // $Log: eth_cop.v,v $
44 // Revision 1.4 2003/06/13 11:55:37 mohor
45 // Define file in eth_cop.v is changed to eth_defines.v. Some defines were
46 // moved from tb_eth_defines.v to eth_defines.v.
48 // Revision 1.3 2002/10/10 16:43:59 mohor
49 // Minor $display change.
51 // Revision 1.2 2002/09/09 12:54:13 mohor
52 // error acknowledge cycle termination added to display.
54 // Revision 1.1 2002/08/14 17:16:07 mohor
55 // Traffic cop with 2 wishbone master interfaces and 2 wishbona slave
57 // - Host connects to the master interface
58 // - Ethernet master (DMA) connects to the second master interface
59 // - Memory interface connects to the slave interface
60 // - Ethernet slave interface (access to registers and BDs) connects to second
68 `include "eth_defines.v"
69 `include "timescale.v"
77 m1_wb_adr_i
, m1_wb_sel_i
, m1_wb_we_i
, m1_wb_dat_o
,
78 m1_wb_dat_i
, m1_wb_cyc_i
, m1_wb_stb_i
, m1_wb_ack_o
,
82 m2_wb_adr_i
, m2_wb_sel_i
, m2_wb_we_i
, m2_wb_dat_o
,
83 m2_wb_dat_i
, m2_wb_cyc_i
, m2_wb_stb_i
, m2_wb_ack_o
,
87 s1_wb_adr_o
, s1_wb_sel_o
, s1_wb_we_o
, s1_wb_cyc_o
,
88 s1_wb_stb_o
, s1_wb_ack_i
, s1_wb_err_i
, s1_wb_dat_i
,
92 s2_wb_adr_o
, s2_wb_sel_o
, s2_wb_we_o
, s2_wb_cyc_o
,
93 s2_wb_stb_o
, s2_wb_ack_i
, s2_wb_err_i
, s2_wb_dat_i
,
100 input wb_clk_i
, wb_rst_i
;
103 input [31:0] m1_wb_adr_i
, m1_wb_dat_i
;
104 input [3:0] m1_wb_sel_i
;
105 input m1_wb_cyc_i
, m1_wb_stb_i
, m1_wb_we_i
;
106 output [31:0] m1_wb_dat_o
;
107 output m1_wb_ack_o
, m1_wb_err_o
;
110 input [31:0] m2_wb_adr_i
, m2_wb_dat_i
;
111 input [3:0] m2_wb_sel_i
;
112 input m2_wb_cyc_i
, m2_wb_stb_i
, m2_wb_we_i
;
113 output [31:0] m2_wb_dat_o
;
114 output m2_wb_ack_o
, m2_wb_err_o
;
117 input [31:0] s1_wb_dat_i
;
118 input s1_wb_ack_i
, s1_wb_err_i
;
119 output [31:0] s1_wb_adr_o
, s1_wb_dat_o
;
120 output [3:0] s1_wb_sel_o
;
121 output s1_wb_we_o
, s1_wb_cyc_o
, s1_wb_stb_o
;
124 input [31:0] s2_wb_dat_i
;
125 input s2_wb_ack_i
, s2_wb_err_i
;
126 output [31:0] s2_wb_adr_o
, s2_wb_dat_o
;
127 output [3:0] s2_wb_sel_o
;
128 output s2_wb_we_o
, s2_wb_cyc_o
, s2_wb_stb_o
;
132 reg [31:0] s1_wb_adr_o
;
133 reg [3:0] s1_wb_sel_o
;
135 reg [31:0] s1_wb_dat_o
;
138 reg [31:0] s2_wb_adr_o
;
139 reg [3:0] s2_wb_sel_o
;
141 reg [31:0] s2_wb_dat_o
;
146 reg [31:0] m1_wb_dat_o
;
148 reg [31:0] m2_wb_dat_o
;
153 wire m_wb_access_finished
;
154 wire m1_req
= m1_wb_cyc_i
& m1_wb_stb_i
& (`M1_ADDRESSED_S1 | `M1_ADDRESSED_S2);
155 wire m2_req
= m2_wb_cyc_i
& m2_wb_stb_i
& (`M2_ADDRESSED_S1 | `M2_ADDRESSED_S2);
157 always @ (posedge wb_clk_i
or posedge wb_rst_i
)
161 m1_in_progress
<=#Tp
0;
162 m2_in_progress
<=#Tp
0;
178 case({m1_in_progress
, m2_in_progress
, m1_req
, m2_req
, m_wb_access_finished
}) // synopsys_full_case synopsys_paralel_case
179 5'b00_10_0, 5'b00_11_0 :
181 m1_in_progress
<=#Tp
1'b1; // idle: m1 or (m1 & m2) want access: m1 -> m
184 s1_wb_adr_o
<=#Tp m1_wb_adr_i
;
185 s1_wb_sel_o
<=#Tp m1_wb_sel_i
;
186 s1_wb_we_o
<=#Tp m1_wb_we_i
;
187 s1_wb_dat_o
<=#Tp m1_wb_dat_i
;
188 s1_wb_cyc_o
<=#Tp
1'b1;
189 s1_wb_stb_o
<=#Tp
1'b1;
191 else if(`M1_ADDRESSED_S2)
193 s2_wb_adr_o
<=#Tp m1_wb_adr_i
;
194 s2_wb_sel_o
<=#Tp m1_wb_sel_i
;
195 s2_wb_we_o
<=#Tp m1_wb_we_i
;
196 s2_wb_dat_o
<=#Tp m1_wb_dat_i
;
197 s2_wb_cyc_o
<=#Tp
1'b1;
198 s2_wb_stb_o
<=#Tp
1'b1;
201 $display("(%t)(%m)WISHBONE ERROR: Unspecified address space accessed", $time);
205 m2_in_progress
<=#Tp
1'b1; // idle: m2 wants access: m2 -> m
208 s1_wb_adr_o
<=#Tp m2_wb_adr_i
;
209 s1_wb_sel_o
<=#Tp m2_wb_sel_i
;
210 s1_wb_we_o
<=#Tp m2_wb_we_i
;
211 s1_wb_dat_o
<=#Tp m2_wb_dat_i
;
212 s1_wb_cyc_o
<=#Tp
1'b1;
213 s1_wb_stb_o
<=#Tp
1'b1;
215 else if(`M2_ADDRESSED_S2)
217 s2_wb_adr_o
<=#Tp m2_wb_adr_i
;
218 s2_wb_sel_o
<=#Tp m2_wb_sel_i
;
219 s2_wb_we_o
<=#Tp m2_wb_we_i
;
220 s2_wb_dat_o
<=#Tp m2_wb_dat_i
;
221 s2_wb_cyc_o
<=#Tp
1'b1;
222 s2_wb_stb_o
<=#Tp
1'b1;
225 $display("(%t)(%m)WISHBONE ERROR: Unspecified address space accessed", $time);
227 5'b10_10_1, 5'b10_11_1 :
229 m1_in_progress
<=#Tp
1'b0; // m1 in progress. Cycle is finished. Send ack or err to m1.
232 s1_wb_cyc_o
<=#Tp
1'b0;
233 s1_wb_stb_o
<=#Tp
1'b0;
235 else if(`M1_ADDRESSED_S2)
237 s2_wb_cyc_o
<=#Tp
1'b0;
238 s2_wb_stb_o
<=#Tp
1'b0;
241 5'b01_01_1, 5'b01_11_1 :
243 m2_in_progress
<=#Tp
1'b0; // m2 in progress. Cycle is finished. Send ack or err to m2.
246 s1_wb_cyc_o
<=#Tp
1'b0;
247 s1_wb_stb_o
<=#Tp
1'b0;
249 else if(`M2_ADDRESSED_S2)
251 s2_wb_cyc_o
<=#Tp
1'b0;
252 s2_wb_stb_o
<=#Tp
1'b0;
259 // Generating Ack for master 1
260 always @ (m1_in_progress
or m1_wb_adr_i
or s1_wb_ack_i
or s2_wb_ack_i
or s1_wb_dat_i
or s2_wb_dat_i
or `M1_ADDRESSED_S1 or `M1_ADDRESSED_S2)
264 if(`M1_ADDRESSED_S1) begin
265 m1_wb_ack_o
<= s1_wb_ack_i
;
266 m1_wb_dat_o
<= s1_wb_dat_i
;
268 else if(`M1_ADDRESSED_S2) begin
269 m1_wb_ack_o
<= s2_wb_ack_i
;
270 m1_wb_dat_o
<= s2_wb_dat_i
;
278 // Generating Ack for master 2
279 always @ (m2_in_progress
or m2_wb_adr_i
or s1_wb_ack_i
or s2_wb_ack_i
or s1_wb_dat_i
or s2_wb_dat_i
or `M2_ADDRESSED_S1 or `M2_ADDRESSED_S2)
283 if(`M2_ADDRESSED_S1) begin
284 m2_wb_ack_o
<= s1_wb_ack_i
;
285 m2_wb_dat_o
<= s1_wb_dat_i
;
287 else if(`M2_ADDRESSED_S2) begin
288 m2_wb_ack_o
<= s2_wb_ack_i
;
289 m2_wb_dat_o
<= s2_wb_dat_i
;
297 // Generating Err for master 1
298 always @ (m1_in_progress
or m1_wb_adr_i
or s1_wb_err_i
or s2_wb_err_i
or `M2_ADDRESSED_S1 or `M2_ADDRESSED_S2 or
299 m1_wb_cyc_i
or m1_wb_stb_i
)
301 if(m1_in_progress
) begin
303 m1_wb_err_o
<= s1_wb_err_i
;
304 else if(`M1_ADDRESSED_S2)
305 m1_wb_err_o
<= s2_wb_err_i
;
307 else if(m1_wb_cyc_i
& m1_wb_stb_i
& ~`M1_ADDRESSED_S1 & ~`M1_ADDRESSED_S2)
314 // Generating Err for master 2
315 always @ (m2_in_progress
or m2_wb_adr_i
or s1_wb_err_i
or s2_wb_err_i
or `M2_ADDRESSED_S1 or `M2_ADDRESSED_S2 or
316 m2_wb_cyc_i
or m2_wb_stb_i
)
318 if(m2_in_progress
) begin
320 m2_wb_err_o
<= s1_wb_err_i
;
321 else if(`M2_ADDRESSED_S2)
322 m2_wb_err_o
<= s2_wb_err_i
;
324 else if(m2_wb_cyc_i
& m2_wb_stb_i
& ~`M2_ADDRESSED_S1 & ~`M2_ADDRESSED_S2)
331 assign m_wb_access_finished
= m1_wb_ack_o | m1_wb_err_o | m2_wb_ack_o | m2_wb_err_o
;
336 always @ (posedge wb_clk_i
or posedge wb_rst_i
)
341 if(s1_wb_ack_i | s1_wb_err_i | s2_wb_ack_i | s2_wb_err_i
)
344 if(s1_wb_cyc_o | s2_wb_cyc_o
)
348 always @ (posedge wb_clk_i
)
351 $display("(%0t)(%m) ERROR: WB activity ??? ", $time);
352 if(s1_wb_cyc_o
) begin
353 $display("s1_wb_dat_o = 0x%0x", s1_wb_dat_o
);
354 $display("s1_wb_adr_o = 0x%0x", s1_wb_adr_o
);
355 $display("s1_wb_sel_o = 0x%0x", s1_wb_sel_o
);
356 $display("s1_wb_we_o = 0x%0x", s1_wb_we_o
);
358 else if(s2_wb_cyc_o
) begin
359 $display("s2_wb_dat_o = 0x%0x", s2_wb_dat_o
);
360 $display("s2_wb_adr_o = 0x%0x", s2_wb_adr_o
);
361 $display("s2_wb_sel_o = 0x%0x", s2_wb_sel_o
);
362 $display("s2_wb_we_o = 0x%0x", s2_wb_we_o
);
370 always @ (posedge wb_clk_i
)
372 if(s1_wb_err_i
& s1_wb_cyc_o
) begin
373 $display("(%0t) ERROR: WB cycle finished with error acknowledge ", $time);
374 $display("s1_wb_dat_o = 0x%0x", s1_wb_dat_o
);
375 $display("s1_wb_adr_o = 0x%0x", s1_wb_adr_o
);
376 $display("s1_wb_sel_o = 0x%0x", s1_wb_sel_o
);
377 $display("s1_wb_we_o = 0x%0x", s1_wb_we_o
);
380 if(s2_wb_err_i
& s2_wb_cyc_o
) begin
381 $display("(%0t) ERROR: WB cycle finished with error acknowledge ", $time);
382 $display("s2_wb_dat_o = 0x%0x", s2_wb_dat_o
);
383 $display("s2_wb_adr_o = 0x%0x", s2_wb_adr_o
);
384 $display("s2_wb_sel_o = 0x%0x", s2_wb_sel_o
);
385 $display("s2_wb_we_o = 0x%0x", s2_wb_we_o
);