agorararmard | 6c766a8 | 2020-12-10 18:13:12 +0200 | [diff] [blame] | 1 | // SPDX-FileCopyrightText: 2020 Efabless Corporation |
agorararmard | e5780bf | 2020-12-09 21:27:56 +0000 | [diff] [blame] | 2 | // |
| 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. |
agorararmard | afa96ea | 2020-12-09 23:37:31 +0200 | [diff] [blame] | 14 | // SPDX-License-Identifier: Apache-2.0 |
agorararmard | e5780bf | 2020-12-09 21:27:56 +0000 | [diff] [blame] | 15 | |
Matt Venn | 08cd6eb | 2020-11-16 12:01:14 +0100 | [diff] [blame] | 16 | `default_nettype none |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 17 | module 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 Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 43 | { 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 |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 49 | }; |
| 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 Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 73 | endmodule |
Tim Edwards | 581068f | 2020-11-19 12:45:25 -0500 | [diff] [blame] | 74 | `default_nettype wire |