//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// endpMux.v ////
|
//// endpMux.v ////
|
//// ////
|
//// ////
|
//// This file is part of the usbhostslave opencores effort.
|
//// This file is part of the usbhostslave opencores effort.
|
//// <http://www.opencores.org/cores//> ////
|
//// <http://www.opencores.org/cores//> ////
|
//// ////
|
//// ////
|
//// Module Description: ////
|
//// Module Description: ////
|
////
|
////
|
//// ////
|
//// ////
|
//// To Do: ////
|
//// To Do: ////
|
////
|
////
|
//// ////
|
//// ////
|
//// Author(s): ////
|
//// Author(s): ////
|
//// - Steve Fielding, sfielding@base2designs.com ////
|
//// - Steve Fielding, sfielding@base2designs.com ////
|
//// ////
|
//// ////
|
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// Copyright (C) 2004 Steve Fielding and OPENCORES.ORG ////
|
//// Copyright (C) 2004 Steve Fielding 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> ////
|
//// ////
|
//// ////
|
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//
|
//
|
`include "timescale.v"
|
`include "timescale.v"
|
`include "usbSlaveControl_h.v"
|
`include "usbSlaveControl_h.v"
|
|
|
module endpMux (
|
module endpMux (
|
clk,
|
clk,
|
rst,
|
rst,
|
currEndP,
|
currEndP,
|
NAKSent,
|
NAKSent,
|
stallSent,
|
stallSent,
|
CRCError,
|
CRCError,
|
bitStuffError,
|
bitStuffError,
|
RxOverflow,
|
RxOverflow,
|
RxTimeOut,
|
RxTimeOut,
|
dataSequence,
|
dataSequence,
|
ACKRxed,
|
ACKRxed,
|
transType,
|
transType,
|
transTypeNAK,
|
transTypeNAK,
|
endPControlReg,
|
endPControlReg,
|
clrEPRdy,
|
clrEPRdy,
|
endPMuxErrorsWEn,
|
endPMuxErrorsWEn,
|
endP0ControlReg,
|
endP0ControlReg,
|
endP1ControlReg,
|
endP1ControlReg,
|
endP2ControlReg,
|
endP2ControlReg,
|
endP3ControlReg,
|
endP3ControlReg,
|
endP0StatusReg,
|
endP0StatusReg,
|
endP1StatusReg,
|
endP1StatusReg,
|
endP2StatusReg,
|
endP2StatusReg,
|
endP3StatusReg,
|
endP3StatusReg,
|
endP0TransTypeReg,
|
endP0TransTypeReg,
|
endP1TransTypeReg,
|
endP1TransTypeReg,
|
endP2TransTypeReg,
|
endP2TransTypeReg,
|
endP3TransTypeReg,
|
endP3TransTypeReg,
|
endP0NAKTransTypeReg,
|
endP0NAKTransTypeReg,
|
endP1NAKTransTypeReg,
|
endP1NAKTransTypeReg,
|
endP2NAKTransTypeReg,
|
endP2NAKTransTypeReg,
|
endP3NAKTransTypeReg,
|
endP3NAKTransTypeReg,
|
clrEP0Rdy,
|
clrEP0Rdy,
|
clrEP1Rdy,
|
clrEP1Rdy,
|
clrEP2Rdy,
|
clrEP2Rdy,
|
clrEP3Rdy);
|
clrEP3Rdy);
|
|
|
|
|
input clk;
|
input clk;
|
input rst;
|
input rst;
|
input [3:0] currEndP;
|
input [3:0] currEndP;
|
input NAKSent;
|
input NAKSent;
|
input stallSent;
|
input stallSent;
|
input CRCError;
|
input CRCError;
|
input bitStuffError;
|
input bitStuffError;
|
input RxOverflow;
|
input RxOverflow;
|
input RxTimeOut;
|
input RxTimeOut;
|
input dataSequence;
|
input dataSequence;
|
input ACKRxed;
|
input ACKRxed;
|
input [1:0] transType;
|
input [1:0] transType;
|
input [1:0] transTypeNAK;
|
input [1:0] transTypeNAK;
|
output [4:0] endPControlReg;
|
output [4:0] endPControlReg;
|
input clrEPRdy;
|
input clrEPRdy;
|
input endPMuxErrorsWEn;
|
input endPMuxErrorsWEn;
|
input [4:0] endP0ControlReg;
|
input [4:0] endP0ControlReg;
|
input [4:0] endP1ControlReg;
|
input [4:0] endP1ControlReg;
|
input [4:0] endP2ControlReg;
|
input [4:0] endP2ControlReg;
|
input [4:0] endP3ControlReg;
|
input [4:0] endP3ControlReg;
|
output [7:0] endP0StatusReg;
|
output [7:0] endP0StatusReg;
|
output [7:0] endP1StatusReg;
|
output [7:0] endP1StatusReg;
|
output [7:0] endP2StatusReg;
|
output [7:0] endP2StatusReg;
|
output [7:0] endP3StatusReg;
|
output [7:0] endP3StatusReg;
|
output [1:0] endP0TransTypeReg;
|
output [1:0] endP0TransTypeReg;
|
output [1:0] endP1TransTypeReg;
|
output [1:0] endP1TransTypeReg;
|
output [1:0] endP2TransTypeReg;
|
output [1:0] endP2TransTypeReg;
|
output [1:0] endP3TransTypeReg;
|
output [1:0] endP3TransTypeReg;
|
output [1:0] endP0NAKTransTypeReg;
|
output [1:0] endP0NAKTransTypeReg;
|
output [1:0] endP1NAKTransTypeReg;
|
output [1:0] endP1NAKTransTypeReg;
|
output [1:0] endP2NAKTransTypeReg;
|
output [1:0] endP2NAKTransTypeReg;
|
output [1:0] endP3NAKTransTypeReg;
|
output [1:0] endP3NAKTransTypeReg;
|
output clrEP0Rdy;
|
output clrEP0Rdy;
|
output clrEP1Rdy;
|
output clrEP1Rdy;
|
output clrEP2Rdy;
|
output clrEP2Rdy;
|
output clrEP3Rdy;
|
output clrEP3Rdy;
|
|
|
wire clk;
|
wire clk;
|
wire rst;
|
wire rst;
|
wire [3:0] currEndP;
|
wire [3:0] currEndP;
|
wire NAKSent;
|
wire NAKSent;
|
wire stallSent;
|
wire stallSent;
|
wire CRCError;
|
wire CRCError;
|
wire bitStuffError;
|
wire bitStuffError;
|
wire RxOverflow;
|
wire RxOverflow;
|
wire RxTimeOut;
|
wire RxTimeOut;
|
wire dataSequence;
|
wire dataSequence;
|
wire ACKRxed;
|
wire ACKRxed;
|
wire [1:0] transType;
|
wire [1:0] transType;
|
wire [1:0] transTypeNAK;
|
wire [1:0] transTypeNAK;
|
reg [4:0] endPControlReg;
|
reg [4:0] endPControlReg;
|
wire clrEPRdy;
|
wire clrEPRdy;
|
wire endPMuxErrorsWEn;
|
wire endPMuxErrorsWEn;
|
wire [4:0] endP0ControlReg;
|
wire [4:0] endP0ControlReg;
|
wire [4:0] endP1ControlReg;
|
wire [4:0] endP1ControlReg;
|
wire [4:0] endP2ControlReg;
|
wire [4:0] endP2ControlReg;
|
wire [4:0] endP3ControlReg;
|
wire [4:0] endP3ControlReg;
|
reg [7:0] endP0StatusReg;
|
reg [7:0] endP0StatusReg;
|
reg [7:0] endP1StatusReg;
|
reg [7:0] endP1StatusReg;
|
reg [7:0] endP2StatusReg;
|
reg [7:0] endP2StatusReg;
|
reg [7:0] endP3StatusReg;
|
reg [7:0] endP3StatusReg;
|
reg [1:0] endP0TransTypeReg;
|
reg [1:0] endP0TransTypeReg;
|
reg [1:0] endP1TransTypeReg;
|
reg [1:0] endP1TransTypeReg;
|
reg [1:0] endP2TransTypeReg;
|
reg [1:0] endP2TransTypeReg;
|
reg [1:0] endP3TransTypeReg;
|
reg [1:0] endP3TransTypeReg;
|
reg [1:0] endP0NAKTransTypeReg;
|
reg [1:0] endP0NAKTransTypeReg;
|
reg [1:0] endP1NAKTransTypeReg;
|
reg [1:0] endP1NAKTransTypeReg;
|
reg [1:0] endP2NAKTransTypeReg;
|
reg [1:0] endP2NAKTransTypeReg;
|
reg [1:0] endP3NAKTransTypeReg;
|
reg [1:0] endP3NAKTransTypeReg;
|
reg clrEP0Rdy;
|
reg clrEP0Rdy;
|
reg clrEP1Rdy;
|
reg clrEP1Rdy;
|
reg clrEP2Rdy;
|
reg clrEP2Rdy;
|
reg clrEP3Rdy;
|
reg clrEP3Rdy;
|
|
|
//internal wires and regs
|
//internal wires and regs
|
reg [7:0] endPStatusCombine;
|
reg [7:0] endPStatusCombine;
|
|
|
//mux endPControlReg and clrEPRdy
|
//mux endPControlReg and clrEPRdy
|
always @(posedge clk)
|
always @(posedge clk)
|
begin
|
begin
|
case (currEndP[1:0])
|
case (currEndP[1:0])
|
2'b00: begin
|
2'b00: begin
|
endPControlReg <= endP0ControlReg;
|
endPControlReg <= endP0ControlReg;
|
clrEP0Rdy <= clrEPRdy;
|
clrEP0Rdy <= clrEPRdy;
|
end
|
end
|
2'b01: begin
|
2'b01: begin
|
endPControlReg <= endP1ControlReg;
|
endPControlReg <= endP1ControlReg;
|
clrEP1Rdy <= clrEPRdy;
|
clrEP1Rdy <= clrEPRdy;
|
end
|
end
|
2'b10: begin
|
2'b10: begin
|
endPControlReg <= endP2ControlReg;
|
endPControlReg <= endP2ControlReg;
|
clrEP2Rdy <= clrEPRdy;
|
clrEP2Rdy <= clrEPRdy;
|
end
|
end
|
2'b11: begin
|
2'b11: begin
|
endPControlReg <= endP3ControlReg;
|
endPControlReg <= endP3ControlReg;
|
clrEP3Rdy <= clrEPRdy;
|
clrEP3Rdy <= clrEPRdy;
|
end
|
end
|
endcase
|
endcase
|
end
|
end
|
|
|
//mux endPNAKTransType, endPTransType, endPStatusReg
|
//mux endPNAKTransType, endPTransType, endPStatusReg
|
//If there was a NAK sent then set the NAKSent bit, and leave the other status reg bits untouched.
|
//If there was a NAK sent then set the NAKSent bit, and leave the other status reg bits untouched.
|
//else update the entire status reg
|
//else update the entire status reg
|
always @(posedge clk)
|
always @(posedge clk)
|
begin
|
begin
|
if (rst) begin
|
if (rst) begin
|
endP0NAKTransTypeReg <= 2'b00;
|
endP0NAKTransTypeReg <= 2'b00;
|
endP1NAKTransTypeReg <= 2'b00;
|
endP1NAKTransTypeReg <= 2'b00;
|
endP2NAKTransTypeReg <= 2'b00;
|
endP2NAKTransTypeReg <= 2'b00;
|
endP3NAKTransTypeReg <= 2'b00;
|
endP3NAKTransTypeReg <= 2'b00;
|
endP0TransTypeReg <= 2'b00;
|
endP0TransTypeReg <= 2'b00;
|
endP1TransTypeReg <= 2'b00;
|
endP1TransTypeReg <= 2'b00;
|
endP2TransTypeReg <= 2'b00;
|
endP2TransTypeReg <= 2'b00;
|
endP3TransTypeReg <= 2'b00;
|
endP3TransTypeReg <= 2'b00;
|
endP0StatusReg <= 4'h0;
|
endP0StatusReg <= 4'h0;
|
endP1StatusReg <= 4'h0;
|
endP1StatusReg <= 4'h0;
|
endP2StatusReg <= 4'h0;
|
endP2StatusReg <= 4'h0;
|
endP3StatusReg <= 4'h0;
|
endP3StatusReg <= 4'h0;
|
end
|
end
|
else begin
|
else begin
|
if (endPMuxErrorsWEn == 1'b1) begin
|
if (endPMuxErrorsWEn == 1'b1) begin
|
if (NAKSent == 1'b1) begin
|
if (NAKSent == 1'b1) begin
|
case (currEndP[1:0])
|
case (currEndP[1:0])
|
2'b00: begin
|
2'b00: begin
|
endP0NAKTransTypeReg <= transTypeNAK;
|
endP0NAKTransTypeReg <= transTypeNAK;
|
endP0StatusReg <= endP0StatusReg | `NAK_SET_MASK;
|
endP0StatusReg <= endP0StatusReg | `NAK_SET_MASK;
|
end
|
end
|
2'b01: begin
|
2'b01: begin
|
endP1NAKTransTypeReg <= transTypeNAK;
|
endP1NAKTransTypeReg <= transTypeNAK;
|
endP1StatusReg <= endP1StatusReg | `NAK_SET_MASK;
|
endP1StatusReg <= endP1StatusReg | `NAK_SET_MASK;
|
end
|
end
|
2'b10: begin
|
2'b10: begin
|
endP2NAKTransTypeReg <= transTypeNAK;
|
endP2NAKTransTypeReg <= transTypeNAK;
|
endP2StatusReg <= endP2StatusReg | `NAK_SET_MASK;
|
endP2StatusReg <= endP2StatusReg | `NAK_SET_MASK;
|
end
|
end
|
2'b11: begin
|
2'b11: begin
|
endP3NAKTransTypeReg <= transTypeNAK;
|
endP3NAKTransTypeReg <= transTypeNAK;
|
endP3StatusReg <= endP3StatusReg | `NAK_SET_MASK;
|
endP3StatusReg <= endP3StatusReg | `NAK_SET_MASK;
|
end
|
end
|
endcase
|
endcase
|
end
|
end
|
else begin
|
else begin
|
case (currEndP[1:0])
|
case (currEndP[1:0])
|
2'b00: begin
|
2'b00: begin
|
endP0TransTypeReg <= transType;
|
endP0TransTypeReg <= transType;
|
endP0StatusReg <= endPStatusCombine;
|
endP0StatusReg <= endPStatusCombine;
|
end
|
end
|
2'b01: begin
|
2'b01: begin
|
endP1TransTypeReg <= transType;
|
endP1TransTypeReg <= transType;
|
endP1StatusReg <= endPStatusCombine;
|
endP1StatusReg <= endPStatusCombine;
|
end
|
end
|
2'b10: begin
|
2'b10: begin
|
endP2TransTypeReg <= transType;
|
endP2TransTypeReg <= transType;
|
endP2StatusReg <= endPStatusCombine;
|
endP2StatusReg <= endPStatusCombine;
|
end
|
end
|
2'b11: begin
|
2'b11: begin
|
endP3TransTypeReg <= transType;
|
endP3TransTypeReg <= transType;
|
endP3StatusReg <= endPStatusCombine;
|
endP3StatusReg <= endPStatusCombine;
|
end
|
end
|
endcase
|
endcase
|
end
|
end
|
end
|
end
|
end
|
end
|
end
|
end
|
|
|
|
|
//combine status bits into a single word
|
//combine status bits into a single word
|
always @(dataSequence or ACKRxed or stallSent or RxTimeOut or RxOverflow or bitStuffError or CRCError)
|
always @(dataSequence or ACKRxed or stallSent or RxTimeOut or RxOverflow or bitStuffError or CRCError)
|
begin
|
begin
|
endPStatusCombine <= {dataSequence, ACKRxed, stallSent, 1'b0, RxTimeOut, RxOverflow, bitStuffError, CRCError};
|
endPStatusCombine <= {dataSequence, ACKRxed, stallSent, 1'b0, RxTimeOut, RxOverflow, bitStuffError, CRCError};
|
end
|
end
|
|
|
|
|
endmodule
|
endmodule
|
|
|