1 |
35 |
csantifort |
//////////////////////////////////////////////////////////////////
|
2 |
|
|
// //
|
3 |
|
|
// Ethmac module Wishbone bus width and endian switch //
|
4 |
|
|
// //
|
5 |
|
|
// This file is part of the Amber project //
|
6 |
|
|
// http://www.opencores.org/project,amber //
|
7 |
|
|
// //
|
8 |
|
|
// Description //
|
9 |
|
|
// Arbitrates between two wishbone masters and 13 wishbone //
|
10 |
|
|
// slave modules. The ethernet MAC wishbone master is given //
|
11 |
|
|
// priority over the Amber core. //
|
12 |
|
|
// //
|
13 |
|
|
// Author(s): //
|
14 |
|
|
// - Conor Santifort, csantifort.amber@gmail.com //
|
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 |
|
|
|
44 |
|
|
module ethmac_wb #(
|
45 |
|
|
parameter WB_DWIDTH = 32,
|
46 |
|
|
parameter WB_SWIDTH = 4
|
47 |
|
|
)(
|
48 |
|
|
|
49 |
|
|
// Ethmac side
|
50 |
|
|
input [31:0] i_m_wb_adr,
|
51 |
|
|
input [3:0] i_m_wb_sel,
|
52 |
|
|
input i_m_wb_we,
|
53 |
|
|
output [31:0] o_m_wb_rdat,
|
54 |
|
|
input [31:0] i_m_wb_wdat,
|
55 |
|
|
input i_m_wb_cyc,
|
56 |
|
|
input i_m_wb_stb,
|
57 |
|
|
output o_m_wb_ack,
|
58 |
|
|
output o_m_wb_err,
|
59 |
|
|
|
60 |
|
|
// Wishbone arbiter side
|
61 |
|
|
output [31:0] o_m_wb_adr,
|
62 |
|
|
output [WB_SWIDTH-1:0] o_m_wb_sel,
|
63 |
|
|
output o_m_wb_we,
|
64 |
|
|
input [WB_DWIDTH-1:0] i_m_wb_rdat,
|
65 |
|
|
output [WB_DWIDTH-1:0] o_m_wb_wdat,
|
66 |
|
|
output o_m_wb_cyc,
|
67 |
|
|
output o_m_wb_stb,
|
68 |
|
|
input i_m_wb_ack,
|
69 |
|
|
input i_m_wb_err,
|
70 |
|
|
|
71 |
|
|
// Wishbone arbiter side
|
72 |
|
|
input [31:0] i_s_wb_adr,
|
73 |
|
|
input [WB_SWIDTH-1:0] i_s_wb_sel,
|
74 |
|
|
input i_s_wb_we,
|
75 |
|
|
output [WB_DWIDTH-1:0] o_s_wb_rdat,
|
76 |
|
|
input [WB_DWIDTH-1:0] i_s_wb_wdat,
|
77 |
|
|
input i_s_wb_cyc,
|
78 |
|
|
input i_s_wb_stb,
|
79 |
|
|
output o_s_wb_ack,
|
80 |
|
|
output o_s_wb_err,
|
81 |
|
|
|
82 |
|
|
// Ethmac side
|
83 |
|
|
output [31:0] o_s_wb_adr,
|
84 |
|
|
output [3:0] o_s_wb_sel,
|
85 |
|
|
output o_s_wb_we,
|
86 |
|
|
input [31:0] i_s_wb_rdat,
|
87 |
|
|
output [31:0] o_s_wb_wdat,
|
88 |
|
|
output o_s_wb_cyc,
|
89 |
|
|
output o_s_wb_stb,
|
90 |
|
|
input i_s_wb_ack,
|
91 |
|
|
input i_s_wb_err
|
92 |
|
|
|
93 |
|
|
);
|
94 |
|
|
|
95 |
|
|
`include "system_functions.v"
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
// =========================
|
99 |
|
|
// Master interface - with endian conversion
|
100 |
|
|
// =========================
|
101 |
|
|
generate
|
102 |
|
|
if (WB_DWIDTH == 128)
|
103 |
|
|
begin : wbm128
|
104 |
|
|
assign o_m_wb_rdat = i_m_wb_adr[3:2] == 2'd3 ? endian_x32(i_m_wb_rdat[127:96]) :
|
105 |
|
|
i_m_wb_adr[3:2] == 2'd2 ? endian_x32(i_m_wb_rdat[ 95:64]) :
|
106 |
|
|
i_m_wb_adr[3:2] == 2'd1 ? endian_x32(i_m_wb_rdat[ 63:32]) :
|
107 |
|
|
endian_x32(i_m_wb_rdat[ 31: 0]) ;
|
108 |
|
|
|
109 |
|
|
assign o_m_wb_sel = i_m_wb_adr[3:2] == 2'd3 ? { endian_x4(i_m_wb_sel), 12'd0} :
|
110 |
|
|
i_m_wb_adr[3:2] == 2'd2 ? { 4'd0, endian_x4(i_m_wb_sel), 8'd0} :
|
111 |
|
|
i_m_wb_adr[3:2] == 2'd1 ? { 8'd0, endian_x4(i_m_wb_sel), 4'd0} :
|
112 |
|
|
{12'd0, endian_x4(i_m_wb_sel) } ;
|
113 |
|
|
|
114 |
|
|
assign o_m_wb_wdat = i_m_wb_adr[3:2] == 2'd3 ? { endian_x32(i_m_wb_wdat), 96'd0} :
|
115 |
|
|
i_m_wb_adr[3:2] == 2'd2 ? {32'd0, endian_x32(i_m_wb_wdat), 64'd0} :
|
116 |
|
|
i_m_wb_adr[3:2] == 2'd1 ? {64'd0, endian_x32(i_m_wb_wdat), 32'd0} :
|
117 |
|
|
{96'd0, endian_x32(i_m_wb_wdat) } ;
|
118 |
|
|
end
|
119 |
|
|
else
|
120 |
|
|
begin : wbm32
|
121 |
|
|
assign o_m_wb_rdat = endian_x32(i_m_wb_rdat);
|
122 |
|
|
assign o_m_wb_sel = endian_x4 (i_m_wb_sel);
|
123 |
|
|
assign o_m_wb_wdat = endian_x32(i_m_wb_wdat);
|
124 |
|
|
end
|
125 |
|
|
endgenerate
|
126 |
|
|
|
127 |
|
|
assign o_m_wb_ack = i_m_wb_ack;
|
128 |
|
|
assign o_m_wb_err = i_m_wb_err;
|
129 |
|
|
assign o_m_wb_adr = i_m_wb_adr;
|
130 |
|
|
assign o_m_wb_we = i_m_wb_we ;
|
131 |
|
|
assign o_m_wb_cyc = i_m_wb_cyc;
|
132 |
|
|
assign o_m_wb_stb = i_m_wb_stb;
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
// =========================
|
136 |
|
|
// Slave interface - no endian conversion
|
137 |
|
|
// =========================
|
138 |
|
|
generate
|
139 |
|
|
if (WB_DWIDTH == 128)
|
140 |
|
|
begin : wbs128
|
141 |
|
|
assign o_s_wb_wdat = i_s_wb_adr[3:2] == 2'd3 ? i_s_wb_wdat[127:96] :
|
142 |
|
|
i_s_wb_adr[3:2] == 2'd2 ? i_s_wb_wdat[ 95:64] :
|
143 |
|
|
i_s_wb_adr[3:2] == 2'd1 ? i_s_wb_wdat[ 63:32] :
|
144 |
|
|
i_s_wb_wdat[ 31: 0] ;
|
145 |
|
|
|
146 |
|
|
assign o_s_wb_sel = i_s_wb_adr[3:2] == 2'd3 ? i_s_wb_sel[15:12] :
|
147 |
|
|
i_s_wb_adr[3:2] == 2'd2 ? i_s_wb_sel[11: 8] :
|
148 |
|
|
i_s_wb_adr[3:2] == 2'd1 ? i_s_wb_sel[ 7: 4] :
|
149 |
|
|
i_s_wb_sel[ 3: 0] ;
|
150 |
|
|
|
151 |
|
|
assign o_s_wb_rdat = i_s_wb_adr[3:2] == 2'd3 ? { i_s_wb_rdat, 96'd0} :
|
152 |
|
|
i_s_wb_adr[3:2] == 2'd2 ? {32'd0, i_s_wb_rdat, 64'd0} :
|
153 |
|
|
i_s_wb_adr[3:2] == 2'd1 ? {64'd0, i_s_wb_rdat, 32'd0} :
|
154 |
|
|
{96'd0, i_s_wb_rdat } ;
|
155 |
|
|
end
|
156 |
|
|
else
|
157 |
|
|
begin : wbs32
|
158 |
|
|
assign o_s_wb_wdat = i_s_wb_wdat;
|
159 |
|
|
assign o_s_wb_sel = i_s_wb_sel;
|
160 |
|
|
assign o_s_wb_rdat = i_s_wb_rdat;
|
161 |
|
|
end
|
162 |
|
|
endgenerate
|
163 |
|
|
|
164 |
|
|
assign o_s_wb_ack = i_s_wb_ack;
|
165 |
|
|
assign o_s_wb_err = i_s_wb_err;
|
166 |
|
|
assign o_s_wb_adr = i_s_wb_adr;
|
167 |
|
|
assign o_s_wb_we = i_s_wb_we ;
|
168 |
|
|
assign o_s_wb_cyc = i_s_wb_cyc;
|
169 |
|
|
assign o_s_wb_stb = i_s_wb_stb;
|
170 |
|
|
|
171 |
|
|
endmodule
|
172 |
|
|
|