/* * e1_wb.v * * vim: ts=4 sw=4 * * E1 wishbone top-level * * Copyright (C) 2019-2020 Sylvain Munaut * SPDX-License-Identifier: CERN-OHL-W-2.0 */ `default_nettype none module e1_wb #( parameter integer N = 1, // Number of units parameter UNIT_HAS_RX = 1'b1, // 1 bit per unit parameter UNIT_HAS_TX = 1'b1, // 1 bit per unit parameter integer LIU = 0, parameter integer MFW = 7 )( // IO pads // Raw PHY input wire [N-1:0] pad_rx_hi_p, input wire [N-1:0] pad_rx_hi_n, input wire [N-1:0] pad_rx_lo_p, input wire [N-1:0] pad_rx_lo_n, output wire [N-1:0] pad_tx_hi, output wire [N-1:0] pad_tx_lo, // LIU input wire [N-1:0] pad_rx_data, input wire [N-1:0] pad_rx_clk, output wire [N-1:0] pad_tx_data, output wire [N-1:0] pad_tx_clk, // Buffer interface // E1 RX (write) output wire [(N*8) -1:0] buf_rx_data, output wire [(N*5) -1:0] buf_rx_ts, output wire [(N*4) -1:0] buf_rx_frame, output wire [(N*MFW)-1:0] buf_rx_mf, output wire [ N -1:0] buf_rx_we, input wire [ N -1:0] buf_rx_rdy, // E1 TX (read) input wire [(N*8) -1:0] buf_tx_data, output wire [(N*5) -1:0] buf_tx_ts, output wire [(N*4) -1:0] buf_tx_frame, output wire [(N*MFW)-1:0] buf_tx_mf, output wire [ N -1:0] buf_tx_re, input wire [ N -1:0] buf_tx_rdy, // Wishbone slave input wire [ 7:0] wb_addr, output reg [15:0] wb_rdata, input wire [15:0] wb_wdata, input wire wb_we, input wire wb_cyc, output reg wb_ack, // External strobes output reg irq, output wire [4*N-1:0] mon_tick, // Common input wire clk, input wire rst ); // -------------------------------------------------------------------------- // Common part // -------------------------------------------------------------------------- localparam integer MB = $clog2(2*N); // Signals // ------- // Bus access wire bus_clr; wire [ 0:0] bus_addr_lsb; wire [15:0] bus_rdata_rx[0:N-1]; wire [15:0] bus_rdata_tx[0:N-1]; reg [15:0] bus_rdata; wire [15:0] bus_wdata; wire bus_we; // Loopback paths wire [N-1:0] lb_bit; wire [N-1:0] lb_valid; // IRQs wire [N-1:0] irq_rx; wire [N-1:0] irq_tx; // Bus access // ---------- // Ack is always 1 cycle after access always @(posedge clk) wb_ack <= wb_cyc & ~wb_ack; assign bus_clr = ~wb_cyc | wb_ack; // Direct map of some signals to custom local bus assign bus_addr_lsb = wb_addr[0]; assign bus_wdata = wb_wdata; assign bus_we = wb_we; // Read MUX always @(*) begin : rdata_or integer j; bus_rdata = 0; for (j=0; j