OpenCores
URL https://opencores.org/ocsvn/amber/amber/trunk

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [system/] [wishbone_arbiter.v] - Diff between revs 2 and 35

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 2 Rev 35
Line 38... Line 38...
// Public License along with this source; if not, download it   //
// Public License along with this source; if not, download it   //
// from http://www.opencores.org/lgpl.shtml                     //
// from http://www.opencores.org/lgpl.shtml                     //
//                                                              //
//                                                              //
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
 
 
 
// TODO add module to switch endianess of ethmac i/f
 
 
 
module wishbone_arbiter #(
 
parameter WB_DWIDTH  = 32,
 
parameter WB_SWIDTH  = 4
 
)(
 
 
module wishbone_arbiter (
 
input                   i_wb_clk,     // WISHBONE clock
input                   i_wb_clk,     // WISHBONE clock
 
 
// WISHBONE master 0 - Amber
// WISHBONE master 0 - Amber
input       [31:0]      i_m0_wb_adr,
input       [31:0]      i_m0_wb_adr,
input       [3:0]       i_m0_wb_sel,
input       [WB_SWIDTH-1:0] i_m0_wb_sel,
input                   i_m0_wb_we,
input                   i_m0_wb_we,
output      [31:0]      o_m0_wb_dat,
output      [WB_DWIDTH-1:0] o_m0_wb_dat,
input       [31:0]      i_m0_wb_dat,
input       [WB_DWIDTH-1:0] i_m0_wb_dat,
input                   i_m0_wb_cyc,
input                   i_m0_wb_cyc,
input                   i_m0_wb_stb,
input                   i_m0_wb_stb,
output                  o_m0_wb_ack,
output                  o_m0_wb_ack,
output                  o_m0_wb_err,
output                  o_m0_wb_err,
 
 
 
 
// WISHBONE master 1 - Ethmac
// WISHBONE master 1 - Ethmac
input       [31:0]      i_m1_wb_adr,
input       [31:0]      i_m1_wb_adr,
input       [3:0]       i_m1_wb_sel,
input       [WB_SWIDTH-1:0] i_m1_wb_sel,
input                   i_m1_wb_we,
input                   i_m1_wb_we,
output      [31:0]      o_m1_wb_dat,
output      [WB_DWIDTH-1:0] o_m1_wb_dat,
input       [31:0]      i_m1_wb_dat,
input       [WB_DWIDTH-1:0] i_m1_wb_dat,
input                   i_m1_wb_cyc,
input                   i_m1_wb_cyc,
input                   i_m1_wb_stb,
input                   i_m1_wb_stb,
output                  o_m1_wb_ack,
output                  o_m1_wb_ack,
output                  o_m1_wb_err,
output                  o_m1_wb_err,
 
 
 
 
// WISHBONE slave 0 - Ethmac
// WISHBONE slave 0 - Ethmac
output      [31:0]      o_s0_wb_adr,
output      [31:0]      o_s0_wb_adr,
output      [3:0]       o_s0_wb_sel,
output      [WB_SWIDTH-1:0] o_s0_wb_sel,
output                  o_s0_wb_we,
output                  o_s0_wb_we,
input       [31:0]      i_s0_wb_dat,
input       [WB_DWIDTH-1:0] i_s0_wb_dat,
output      [31:0]      o_s0_wb_dat,
output      [WB_DWIDTH-1:0] o_s0_wb_dat,
output                  o_s0_wb_cyc,
output                  o_s0_wb_cyc,
output                  o_s0_wb_stb,
output                  o_s0_wb_stb,
input                   i_s0_wb_ack,
input                   i_s0_wb_ack,
input                   i_s0_wb_err,
input                   i_s0_wb_err,
 
 
 
 
// WISHBONE slave 1 - Boot Memory
// WISHBONE slave 1 - Boot Memory
output      [31:0]      o_s1_wb_adr,
output      [31:0]      o_s1_wb_adr,
output      [3:0]       o_s1_wb_sel,
output      [WB_SWIDTH-1:0] o_s1_wb_sel,
output                  o_s1_wb_we,
output                  o_s1_wb_we,
input       [31:0]      i_s1_wb_dat,
input       [WB_DWIDTH-1:0] i_s1_wb_dat,
output      [31:0]      o_s1_wb_dat,
output      [WB_DWIDTH-1:0] o_s1_wb_dat,
output                  o_s1_wb_cyc,
output                  o_s1_wb_cyc,
output                  o_s1_wb_stb,
output                  o_s1_wb_stb,
input                   i_s1_wb_ack,
input                   i_s1_wb_ack,
input                   i_s1_wb_err,
input                   i_s1_wb_err,
 
 
 
 
// WISHBONE slave 2 - Main Memory
// WISHBONE slave 2 - Main Memory
output      [31:0]      o_s2_wb_adr,
output      [31:0]      o_s2_wb_adr,
output      [3:0]       o_s2_wb_sel,
output      [WB_SWIDTH-1:0] o_s2_wb_sel,
output                  o_s2_wb_we,
output                  o_s2_wb_we,
input       [31:0]      i_s2_wb_dat,
input       [WB_DWIDTH-1:0] i_s2_wb_dat,
output      [31:0]      o_s2_wb_dat,
output      [WB_DWIDTH-1:0] o_s2_wb_dat,
output                  o_s2_wb_cyc,
output                  o_s2_wb_cyc,
output                  o_s2_wb_stb,
output                  o_s2_wb_stb,
input                   i_s2_wb_ack,
input                   i_s2_wb_ack,
input                   i_s2_wb_err,
input                   i_s2_wb_err,
 
 
 
 
// WISHBONE slave 3 - UART 0
// WISHBONE slave 3 - UART 0
output      [31:0]      o_s3_wb_adr,
output      [31:0]      o_s3_wb_adr,
output      [3:0]       o_s3_wb_sel,
output      [WB_SWIDTH-1:0] o_s3_wb_sel,
output                  o_s3_wb_we,
output                  o_s3_wb_we,
input       [31:0]      i_s3_wb_dat,
input       [WB_DWIDTH-1:0] i_s3_wb_dat,
output      [31:0]      o_s3_wb_dat,
output      [WB_DWIDTH-1:0] o_s3_wb_dat,
output                  o_s3_wb_cyc,
output                  o_s3_wb_cyc,
output                  o_s3_wb_stb,
output                  o_s3_wb_stb,
input                   i_s3_wb_ack,
input                   i_s3_wb_ack,
input                   i_s3_wb_err,
input                   i_s3_wb_err,
 
 
 
 
// WISHBONE slave 4 - UART 1
// WISHBONE slave 4 - UART 1
output      [31:0]      o_s4_wb_adr,
output      [31:0]      o_s4_wb_adr,
output      [3:0]       o_s4_wb_sel,
output      [WB_SWIDTH-1:0] o_s4_wb_sel,
output                  o_s4_wb_we,
output                  o_s4_wb_we,
input       [31:0]      i_s4_wb_dat,
input       [WB_DWIDTH-1:0] i_s4_wb_dat,
output      [31:0]      o_s4_wb_dat,
output      [WB_DWIDTH-1:0] o_s4_wb_dat,
output                  o_s4_wb_cyc,
output                  o_s4_wb_cyc,
output                  o_s4_wb_stb,
output                  o_s4_wb_stb,
input                   i_s4_wb_ack,
input                   i_s4_wb_ack,
input                   i_s4_wb_err,
input                   i_s4_wb_err,
 
 
 
 
// WISHBONE slave 5 - Test Module
// WISHBONE slave 5 - Test Module
output      [31:0]      o_s5_wb_adr,
output      [31:0]      o_s5_wb_adr,
output      [3:0]       o_s5_wb_sel,
output      [WB_SWIDTH-1:0] o_s5_wb_sel,
output                  o_s5_wb_we,
output                  o_s5_wb_we,
input       [31:0]      i_s5_wb_dat,
input       [WB_DWIDTH-1:0] i_s5_wb_dat,
output      [31:0]      o_s5_wb_dat,
output      [WB_DWIDTH-1:0] o_s5_wb_dat,
output                  o_s5_wb_cyc,
output                  o_s5_wb_cyc,
output                  o_s5_wb_stb,
output                  o_s5_wb_stb,
input                   i_s5_wb_ack,
input                   i_s5_wb_ack,
input                   i_s5_wb_err,
input                   i_s5_wb_err,
 
 
 
 
// WISHBONE slave 6 - Timer Module
// WISHBONE slave 6 - Timer Module
output      [31:0]      o_s6_wb_adr,
output      [31:0]      o_s6_wb_adr,
output      [3:0]       o_s6_wb_sel,
output      [WB_SWIDTH-1:0] o_s6_wb_sel,
output                  o_s6_wb_we,
output                  o_s6_wb_we,
input       [31:0]      i_s6_wb_dat,
input       [WB_DWIDTH-1:0] i_s6_wb_dat,
output      [31:0]      o_s6_wb_dat,
output      [WB_DWIDTH-1:0] o_s6_wb_dat,
output                  o_s6_wb_cyc,
output                  o_s6_wb_cyc,
output                  o_s6_wb_stb,
output                  o_s6_wb_stb,
input                   i_s6_wb_ack,
input                   i_s6_wb_ack,
input                   i_s6_wb_err,
input                   i_s6_wb_err,
 
 
 
 
 // WISHBONE slave 7 - Interrupt Controller
 // WISHBONE slave 7 - Interrupt Controller
output      [31:0]      o_s7_wb_adr,
output      [31:0]      o_s7_wb_adr,
output      [3:0]       o_s7_wb_sel,
output      [WB_SWIDTH-1:0] o_s7_wb_sel,
output                  o_s7_wb_we,
output                  o_s7_wb_we,
input       [31:0]      i_s7_wb_dat,
input       [WB_DWIDTH-1:0] i_s7_wb_dat,
output      [31:0]      o_s7_wb_dat,
output      [WB_DWIDTH-1:0] o_s7_wb_dat,
output                  o_s7_wb_cyc,
output                  o_s7_wb_cyc,
output                  o_s7_wb_stb,
output                  o_s7_wb_stb,
input                   i_s7_wb_ack,
input                   i_s7_wb_ack,
input                   i_s7_wb_err
input                   i_s7_wb_err
);
);
 
 
`include "memory_configuration.v"
`include "memory_configuration.v"
reg         m0_wb_cyc_r = 'd0;
reg         m0_wb_hold_r = 'd0;
reg         m1_wb_cyc_r = 'd0;
reg         m1_wb_hold_r = 'd0;
wire        m0_in_cycle;
// wire        m0_in_cycle;
wire        m1_in_cycle;
// wire        m1_in_cycle;
wire        current_master;
wire        current_master;
reg         current_master_r = 'd0;
reg         current_master_r = 'd0;
wire        next_master;
wire        next_master;
wire        select_master;
wire        select_master;
wire [3:0]  current_slave;
wire [3:0]  current_slave;
 
 
wire [31:0] master_adr;
wire [31:0] master_adr;
wire [3:0]  master_sel;
wire [WB_SWIDTH-1:0]    master_sel;
wire        master_we;
wire        master_we;
wire [31:0] master_wdat;
wire [WB_DWIDTH-1:0]    master_wdat;
wire        master_cyc;
wire        master_cyc;
wire        master_stb;
wire        master_stb;
wire [31:0] master_rdat;
wire [WB_DWIDTH-1:0]    master_rdat;
wire        master_ack;
wire        master_ack;
wire        master_err;
wire        master_err;
 
 
 
 
// Arbitrate between m0 and m1. Ethmac (m0) always gets priority
// Arbitrate between m0 and m1. Ethmac (m0) always gets priority
assign next_master    = i_m0_wb_cyc ? 1'd0 : 1'd1;
assign next_master    = i_m0_wb_cyc ? 1'd0 : 1'd1;
 
 
// Use cyc signal for arbitration so block accesses are not split up
// Use cyc signal for arbitration so block accesses are not split up
assign m0_in_cycle    = m0_wb_cyc_r && i_m0_wb_cyc;
// assign m0_in_cycle    = m0_wb_hold_r && !master_ack;
assign m1_in_cycle    = m1_wb_cyc_r && i_m1_wb_cyc;
// assign m1_in_cycle    = m1_wb_hold_r && !master_ack;
 
 
// only select a new bus master when the current bus master
// only select a new bus master when the current bus master
// de-asserts the cyc signal
// daccess ends
assign select_master  = current_master_r ? !m1_in_cycle : !m0_in_cycle;
assign select_master  = current_master_r ? !m1_wb_hold_r : !m0_wb_hold_r;
assign current_master = select_master ? next_master : current_master_r;
assign current_master = select_master ? next_master : current_master_r;
 
 
 
 
always @( posedge i_wb_clk )
always @( posedge i_wb_clk )
    begin
    begin
    current_master_r    <= current_master;
    current_master_r    <= current_master;
    m0_wb_cyc_r         <= i_m0_wb_cyc;
    m0_wb_hold_r        <= i_m0_wb_stb && !o_m0_wb_ack;
    m1_wb_cyc_r         <= i_m1_wb_cyc;
    m1_wb_hold_r        <= i_m1_wb_stb && !o_m1_wb_ack;
    end
    end
 
 
 
 
// Arbitrate between slaves
// Arbitrate between slaves
assign current_slave = in_ethmac   ( master_adr ) ? 4'd0  :  // Ethmac
assign current_slave = in_ethmac   ( master_adr ) ? 4'd0  :  // Ethmac
Line 217... Line 223...
                       in_ic       ( master_adr ) ? 4'd7  :  // Interrupt Controller
                       in_ic       ( master_adr ) ? 4'd7  :  // Interrupt Controller
                                                    4'd2  ;  // default to main memory
                                                    4'd2  ;  // default to main memory
 
 
 
 
assign master_adr   = current_master ? i_m1_wb_adr : i_m0_wb_adr ;
assign master_adr   = current_master ? i_m1_wb_adr : i_m0_wb_adr ;
// Switch endianess of ethmac Master
assign master_sel   = current_master ? i_m1_wb_sel : i_m0_wb_sel ;
assign master_sel   = current_master ? i_m1_wb_sel : {i_m0_wb_sel[0], i_m0_wb_sel[1],
assign master_wdat  = current_master ? i_m1_wb_dat : i_m0_wb_dat ;
                                                      i_m0_wb_sel[2], i_m0_wb_sel[3]};
 
assign master_wdat  = current_master ? i_m1_wb_dat : {i_m0_wb_dat[7:0],  i_m0_wb_dat[15:8],
 
                                                      i_m0_wb_dat[23:16],i_m0_wb_dat[31:24]} ;
 
assign master_we    = current_master ? i_m1_wb_we  : i_m0_wb_we  ;
assign master_we    = current_master ? i_m1_wb_we  : i_m0_wb_we  ;
assign master_cyc   = current_master ? i_m1_wb_cyc : i_m0_wb_cyc ;
assign master_cyc   = current_master ? i_m1_wb_cyc : i_m0_wb_cyc ;
assign master_stb   = current_master ? i_m1_wb_stb : i_m0_wb_stb ;
assign master_stb   = current_master ? i_m1_wb_stb : i_m0_wb_stb ;
 
 
 
 
Line 327... Line 330...
                      current_slave == 4'd7  ? i_s7_wb_err  :
                      current_slave == 4'd7  ? i_s7_wb_err  :
                                               i_s2_wb_err  ;
                                               i_s2_wb_err  ;
 
 
 
 
// Ethmac Master Outputs
// Ethmac Master Outputs
// Switch endianess of ethmac Master
assign o_m0_wb_dat  = master_rdat;
assign o_m0_wb_dat  = {master_rdat[7:0], master_rdat[15:8],
 
                       master_rdat[23:16],master_rdat[31:24]};
 
assign o_m0_wb_ack  = current_master  ? 1'd0 : master_ack ;
assign o_m0_wb_ack  = current_master  ? 1'd0 : master_ack ;
assign o_m0_wb_err  = current_master  ? 1'd0 : master_err ;
assign o_m0_wb_err  = current_master  ? 1'd0 : master_err ;
 
 
// Amber Master Outputs
// Amber Master Outputs
assign o_m1_wb_dat  = master_rdat;
assign o_m1_wb_dat  = master_rdat;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.