1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-01-17 20:02:53 +08:00
oh/elink/hdl/etx_arbiter.v

158 lines
5.2 KiB
Coq
Raw Normal View History

/*
########################################################################
EPIPHANY eMesh Arbiter
########################################################################
This block takes three FIFO inputs (write, read request, read response)
and the DMA channel, arbitrates between the active channels, and forwards
the result to the transmit output pins.
Arbitration Priority:
1) host writes (highest)
2) read requests from host
3) read responses
4) DMA (lowest)
*/
module etx_arbiter (/*AUTOARG*/
// Outputs
txwr_fifo_read, txrd_fifo_read, txrr_fifo_read, edma_wait,
etx_access, etx_packet, etx_rr,
// Inputs
clk, reset, txwr_fifo_empty, txwr_fifo_packet, txrd_fifo_empty,
txrd_fifo_packet, txrr_fifo_empty, txrr_fifo_packet, edma_access,
edma_packet, ctrlmode_bypass, ctrlmode, etx_rd_wait, etx_wr_wait,
etx_io_wait, etx_cfg_wait
);
2015-04-23 17:57:24 -04:00
parameter PW = 104;
parameter ID = 0;
2015-04-23 17:57:24 -04:00
//tx clock and reset
input clk;
input reset;
2015-04-23 17:57:24 -04:00
//Write Request (from slave)
2015-04-23 17:57:24 -04:00
input txwr_fifo_empty;
input [PW-1:0] txwr_fifo_packet;
output txwr_fifo_read;
//Read Request (from slave)
2015-04-23 17:57:24 -04:00
input txrd_fifo_empty;
input [PW-1:0] txrd_fifo_packet;
output txrd_fifo_read;
//Read Response (from master)
2015-04-23 17:57:24 -04:00
input txrr_fifo_empty;
input [PW-1:0] txrr_fifo_packet;
output txrr_fifo_read;
//DMA Master
input edma_access;
input [PW-1:0] edma_packet;
output edma_wait;
//ctrlmode for rd/wr transactions
input ctrlmode_bypass;
input [3:0] ctrlmode;
//Transaction for IO protocol
2015-04-23 17:57:24 -04:00
output etx_access;
output [PW-1:0] etx_packet;
output etx_rr; //bypass translation on read response
//Wait signals
2015-04-23 17:57:24 -04:00
input etx_rd_wait;
input etx_wr_wait;
input etx_io_wait;
input etx_cfg_wait;
//regs
2015-04-23 17:57:24 -04:00
reg etx_access;
reg [PW-1:0] etx_packet;
reg etx_rr; //bypass translation on read response
//wires
2015-04-23 17:57:24 -04:00
wire rr_ready;
wire rd_ready;
wire wr_ready;
wire [3:0] txrd_ctrlmode;
wire [3:0] txwr_ctrlmode;
//##########################################################################
//# Arbitrate & forward
//##########################################################################
2015-04-23 17:57:24 -04:00
//TODO: Add weighted round robin arbiter
//Host-slave should always be able to get "1" read or write in there.
//Current implementation can deadlock!! (move rd below rr)
// priority-based ready signals
assign wr_ready = ~txwr_fifo_empty & ~etx_wr_wait; //highest
assign rd_ready = ~txrd_fifo_empty & ~etx_rd_wait & ~wr_ready;
assign rr_ready = ~txrr_fifo_empty & ~etx_wr_wait & ~wr_ready & ~rd_ready;//lowest
2015-04-23 17:57:24 -04:00
// FIFO read enables (one hot)
// Hold until transaction has been accepted by IO
assign txrr_fifo_read = rr_ready & (~etx_access | etx_io_wait);
assign txrd_fifo_read = rd_ready & (~etx_access | etx_io_wait);
assign txwr_fifo_read = wr_ready & (~etx_access | etx_io_wait);
2015-04-23 17:57:24 -04:00
//Selecting control mode on slave transcations
assign txrd_ctrlmode[3:0] = ctrlmode_bypass ? ctrlmode[3:0] :
txrd_fifo_packet[7:4];
2015-04-23 17:57:24 -04:00
assign txwr_ctrlmode[3:0] = ctrlmode_bypass ? ctrlmode[3:0] :
txwr_fifo_packet[7:4];
//##########################################################################
//# Generate Access Signalf For IO
//##########################################################################
always @ (posedge clk)
if( reset )
begin
2015-04-23 17:57:24 -04:00
etx_access <= 1'b0;
etx_rr <= 1'b0;//only way to diff between 'rr' and 'wr'
2015-04-23 17:57:24 -04:00
etx_packet[PW-1:0] <= 'd0;
end
2015-04-23 17:57:24 -04:00
else if (txrr_fifo_read | txrd_fifo_read | txwr_fifo_read )
begin
etx_rr <= txrr_fifo_read;
etx_access <= 1'b1;
2015-04-23 17:57:24 -04:00
etx_packet[PW-1:0] <= txrr_fifo_read ? txrr_fifo_packet[PW-1:0] :
txrd_fifo_read ? {txrd_fifo_packet[PW-1:8],
txrd_ctrlmode[3:0],
txrd_fifo_packet[3:0]} :
{txwr_fifo_packet[PW-1:8],
txwr_ctrlmode[3:0],
txwr_fifo_packet[3:0]};
end
else if (~etx_io_wait)
begin
2015-04-23 17:57:24 -04:00
etx_access <= 1'b0;
end
endmodule // etx_arbiter
/*
File: etx_arbiter.v
This file is part of the Parallella Project.
Copyright (C) 2014 Adapteva, Inc.
Contributed by Fred Huettig <fred@adapteva.com>
Contributed by Andreas Olofsson <andreas@adapteva.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program (see the file COPYING). If not, see
<http://www.gnu.org/licenses/>.
*/