//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// Copyright (C) 2017 Authors and OPENCORES.ORG ////
|
//// Copyright (C) 2017 Authors and OPENCORES.ORG ////
|
//// ////
|
//// ////
|
//// This source file may be used and distributed without ////
|
//// This source file may be used and distributed without ////
|
//// restriction provided that this copyright statement is not ////
|
//// restriction provided that this copyright statement is not ////
|
//// removed from the file and that any derivative work contains ////
|
//// removed from the file and that any derivative work contains ////
|
//// the original copyright notice and the associated disclaimer. ////
|
//// the original copyright notice and the associated disclaimer. ////
|
//// ////
|
//// ////
|
//// This source file is free software; you can redistribute it ////
|
//// This source file is free software; you can redistribute it ////
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
//// Public License as published by the Free Software Foundation; ////
|
//// Public License as published by the Free Software Foundation; ////
|
//// either version 2.1 of the License, or (at your option) any ////
|
//// either version 2.1 of the License, or (at your option) any ////
|
//// later version. ////
|
//// later version. ////
|
//// ////
|
//// ////
|
//// This source is distributed in the hope that it will be ////
|
//// This source is distributed in the hope that it will be ////
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
//// details. ////
|
//// details. ////
|
//// ////
|
//// ////
|
//// You should have received a copy of the GNU Lesser General ////
|
//// You should have received a copy of the GNU Lesser General ////
|
//// 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 ////
|
//// ////
|
//// ////
|
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
module
|
module
|
axis_switch_allocator
|
axis_switch_allocator
|
#(
|
#(
|
N, // data bus width in bytes
|
N, // data bus width in bytes
|
I = 1, // TID width
|
I = 1, // TID width
|
D = 1, // TDEST width
|
D = 1, // TDEST width
|
U = 1, // TUSER width
|
U = 1, // TUSER width
|
U_IS_EOP = -1, // set to -1 for tlast, else set to index of tuser
|
U_IS_EOP = -1, // set to -1 for tlast, else set to index of tuser
|
SA, // select width
|
SA, // select width
|
SD = 2 ** SA
|
SD = 2 ** SA
|
)
|
)
|
(
|
(
|
axis_if axis_in,
|
axis_if axis_in,
|
axis_if axis_out[SD-1:0],
|
axis_if axis_out[SD-1:0],
|
input aclk,
|
input aclk,
|
input aresetn
|
input aresetn
|
);
|
);
|
|
|
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
//
|
//
|
wire eop_in;
|
|
|
|
axis_eop_set #(U_IS_EOP)
|
|
axis_eop_set_i
|
|
(
|
|
.axis_in(axis_in),
|
|
.tready(axis_switch_in.tready),
|
|
.tvalid(axis_in.tvalid),
|
|
.axis_eop(eop_in),
|
|
.*
|
|
);
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
//
|
|
wire eop_out_mux;
|
wire eop_out_mux;
|
reg [SA-1:0] select;
|
reg [SA-1:0] select;
|
|
|
axis_eop_mux #(.U_IS_EOP(U_IS_EOP), .MA(SA))
|
axis_eop_mux #(.U_IS_EOP(U_IS_EOP), .MA(SA))
|
axis_eop_mux_i
|
axis_eop_mux_i
|
(
|
(
|
.axis_in(axis_out),
|
.axis_in(axis_out),
|
.axis_eop(eop_out_mux),
|
.axis_eop(eop_out_mux),
|
.*
|
.*
|
);
|
);
|
|
|
|
|
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
//
|
//
|
axis_if #(.N(N), .I(I), .D(D), .U(U)) axis_switch_in(.*);
|
axis_if #(.N(N), .I(I), .D(D), .U(U)) axis_switch_in(.*);
|
|
|
axis_alias #(.CONNECT_TREADY(0), .CONNECT_TVALID(0))
|
axis_alias #(.CONNECT_TREADY(0), .CONNECT_TVALID(0))
|
axis_alias_i(.axis_out(axis_switch_in), .*);
|
axis_alias_i(.axis_out(axis_switch_in), .*);
|
|
|
|
|
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
|
//
|
|
wire eop_in;
|
|
|
|
axis_eop_set #(U_IS_EOP)
|
|
axis_eop_set_i
|
|
(
|
|
.axis_in(axis_in),
|
|
.tready(axis_switch_in.tready),
|
|
.tvalid(axis_in.tvalid),
|
|
.axis_eop(eop_in),
|
|
.*
|
|
);
|
|
|
|
|
|
// --------------------------------------------------------------------
|
// state machine binary definitions
|
// state machine binary definitions
|
enum reg [3:0]
|
enum reg [3:0]
|
{
|
{
|
ALLOT = 4'b0001,
|
ALLOT = 4'b0001,
|
FLUSH = 4'b0010,
|
FLUSH = 4'b0010,
|
SWITCH = 4'b0100,
|
SWITCH = 4'b0100,
|
SETTLE = 4'b1000
|
SETTLE = 4'b1000
|
} state, next_state;
|
} state, next_state;
|
|
|
|
|
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
// state machine flop
|
// state machine flop
|
always_ff @(posedge aclk)
|
always_ff @(posedge aclk)
|
if(~aresetn)
|
if(~aresetn)
|
state <= ALLOT;
|
state <= ALLOT;
|
else
|
else
|
state <= next_state;
|
state <= next_state;
|
|
|
|
|
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
// state machine
|
// state machine
|
always_comb
|
always_comb
|
case(state)
|
case(state)
|
ALLOT: if(eop_in)
|
ALLOT: if(eop_in)
|
next_state <= FLUSH;
|
next_state <= FLUSH;
|
else
|
else
|
next_state <= ALLOT;
|
next_state <= ALLOT;
|
|
|
FLUSH: if(eop_out_mux)
|
FLUSH: if(eop_out_mux)
|
next_state <= SWITCH;
|
next_state <= SWITCH;
|
else
|
else
|
next_state <= FLUSH;
|
next_state <= FLUSH;
|
|
|
SWITCH: next_state <= SETTLE;
|
SWITCH: next_state <= SETTLE;
|
|
|
SETTLE: next_state <= ALLOT; // let select propagate to the switches
|
SETTLE: next_state <= ALLOT; // let select propagate to the switches
|
|
|
default: next_state <= ALLOT;
|
default: next_state <= ALLOT;
|
endcase
|
endcase
|
|
|
|
|
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
//
|
//
|
always_ff @(posedge aclk)
|
always_ff @(posedge aclk)
|
if(~aresetn)
|
if(~aresetn)
|
select <= 0;
|
select <= 0;
|
else if(state == SWITCH)
|
else if(state == SWITCH)
|
select <= select + 1;
|
select <= select + 1;
|
|
|
|
|
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
//
|
//
|
recursive_axis_switch #(.N(N), .I(I), .D(D), .U(U), .SA(SA))
|
recursive_axis_switch #(.N(N), .I(I), .D(D), .U(U), .SA(SA))
|
recursive_axis_switch_i(.axis_in(axis_switch_in), .*);
|
recursive_axis_switch_i(.axis_in(axis_switch_in), .*);
|
|
|
|
|
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
//
|
//
|
assign axis_in.tready = (state == ALLOT) & axis_switch_in.tready;
|
assign axis_in.tready = (state == ALLOT) & axis_switch_in.tready;
|
assign axis_switch_in.tvalid = (state == ALLOT) & axis_in.tvalid;
|
assign axis_switch_in.tvalid = (state == ALLOT) & axis_in.tvalid;
|
|
|
|
|
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
//
|
//
|
endmodule
|
endmodule
|
|
|
|
|