blob: 7ebce83f5a6e6ec6f7aa4d09be8b95a2610fc964 [file] [log] [blame]
agorararmard6c766a82020-12-10 18:13:12 +02001// SPDX-FileCopyrightText: 2020 Efabless Corporation
agorararmarde5780bf2020-12-09 21:27:56 +00002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
agorararmardafa96ea2020-12-09 23:37:31 +020014// SPDX-License-Identifier: Apache-2.0
agorararmarde5780bf2020-12-09 21:27:56 +000015
Matt Venn08cd6eb2020-11-16 12:01:14 +010016`default_nettype none
shalanfd13eb52020-08-21 16:48:07 +020017module wb_intercon #(
18 parameter DW = 32, // Data Width
19 parameter AW = 32, // Address Width
20 parameter NS = 6 // Number of Slaves
21) (
22 // Master Interface
23 input [AW-1:0] wbm_adr_i,
24 input wbm_stb_i,
25
26 output reg [DW-1:0] wbm_dat_o,
27 output wbm_ack_o,
28
29 // Slave Interface
30 input [NS*DW-1:0] wbs_dat_i,
31 input [NS-1:0] wbs_ack_i,
32 output [NS-1:0] wbs_stb_o
33);
34 parameter [NS*AW-1:0] ADR_MASK = { // Page & Sub-page bits
35 {8'hFF, {24{1'b0}} },
36 {8'hFF, {24{1'b0}} },
37 {8'hFF, {24{1'b0}} },
38 {8'hFF, {24{1'b0}} },
39 {8'hFF, {24{1'b0}} },
40 {8'hFF, {24{1'b0}} }
41 };
42 parameter [NS*AW-1:0] SLAVE_ADR = {
Tim Edwards04ba17f2020-10-02 22:27:50 -040043 { 32'h2800_0000 }, // Flash Configuration Register
44 { 32'h2200_0000 }, // System Control
45 { 32'h2100_0000 }, // GPIOs
46 { 32'h2000_0000 }, // UART
47 { 32'h1000_0000 }, // Flash
48 { 32'h0000_0000 } // RAM
shalanfd13eb52020-08-21 16:48:07 +020049 };
50
51 wire [NS-1: 0] slave_sel;
52
53 // Address decoder
54 genvar iS;
55 generate
56 for (iS = 0; iS < NS; iS = iS + 1) begin
57 assign slave_sel[iS] =
58 ((wbm_adr_i & ADR_MASK[(iS+1)*AW-1:iS*AW]) == SLAVE_ADR[(iS+1)*AW-1:iS*AW]);
59 end
60 endgenerate
61
62 // Data-out Assignment
63 assign wbm_ack_o = |(wbs_ack_i & slave_sel);
64 assign wbs_stb_o = {NS{wbm_stb_i}} & slave_sel;
65
66 integer i;
67 always @(*) begin
68 wbm_dat_o = {DW{1'b0}};
69 for (i=0; i<(NS*DW); i=i+1)
70 wbm_dat_o[i%DW] = wbm_dat_o[i%DW] | (slave_sel[i/DW] & wbs_dat_i[i]);
71 end
72
Tim Edwards04ba17f2020-10-02 22:27:50 -040073endmodule
Tim Edwards581068f2020-11-19 12:45:25 -050074`default_nettype wire