//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// hostSlaveMuxBI.v ////
|
//// hostSlaveMuxBI.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> ////
|
//// ////
|
//// ////
|
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//
|
//
|
`timescale 1ns / 1ps
|
`include "timescale.v"
|
|
|
`include "usbHostSlave_h.v"
|
`include "usbHostSlave_h.v"
|
|
|
module hostSlaveMuxBI (dataIn, dataOut, address, writeEn, strobe_i, busClk, usbClk,
|
module hostSlaveMuxBI (dataIn, dataOut, address, writeEn, strobe_i, busClk, usbClk,
|
hostMode, hostSlaveMuxSel, rstFromWire, rstSyncToBusClkOut, rstSyncToUsbClkOut);
|
hostMode, hostSlaveMuxSel, rstFromWire, rstSyncToBusClkOut, rstSyncToUsbClkOut);
|
|
|
input [7:0] dataIn;
|
input [7:0] dataIn;
|
input address;
|
input address;
|
input writeEn;
|
input writeEn;
|
input strobe_i;
|
input strobe_i;
|
input busClk;
|
input busClk;
|
input usbClk;
|
input usbClk;
|
output [7:0] dataOut;
|
output [7:0] dataOut;
|
input hostSlaveMuxSel;
|
input hostSlaveMuxSel;
|
output hostMode;
|
output hostMode;
|
input rstFromWire;
|
input rstFromWire;
|
output rstSyncToBusClkOut;
|
output rstSyncToBusClkOut;
|
output rstSyncToUsbClkOut;
|
output rstSyncToUsbClkOut;
|
|
|
wire [7:0] dataIn;
|
wire [7:0] dataIn;
|
wire address;
|
wire address;
|
wire writeEn;
|
wire writeEn;
|
wire strobe_i;
|
wire strobe_i;
|
wire busClk;
|
wire busClk;
|
wire usbClk;
|
wire usbClk;
|
reg [7:0] dataOut;
|
reg [7:0] dataOut;
|
wire hostSlaveMuxSel;
|
wire hostSlaveMuxSel;
|
reg hostMode;
|
reg hostMode;
|
wire rstFromWire;
|
wire rstFromWire;
|
reg rstSyncToBusClkOut;
|
reg rstSyncToBusClkOut;
|
reg rstSyncToUsbClkOut;
|
reg rstSyncToUsbClkOut;
|
|
|
//internal wire and regs
|
//internal wire and regs
|
reg [5:0] rstShift;
|
reg [5:0] rstShift;
|
reg rstFromBus;
|
reg rstFromBus;
|
reg rstSyncToUsbClkFirst;
|
reg rstSyncToUsbClkFirst;
|
|
|
//sync write demux
|
//sync write demux
|
always @(posedge busClk)
|
always @(posedge busClk)
|
begin
|
begin
|
if (rstSyncToBusClkOut == 1'b1)
|
if (rstSyncToBusClkOut == 1'b1)
|
hostMode <= 1'b0;
|
hostMode <= 1'b0;
|
else begin
|
else begin
|
if (writeEn == 1'b1 && hostSlaveMuxSel == 1'b1 && strobe_i == 1'b1 && address == `HOST_SLAVE_CONTROL_REG )
|
if (writeEn == 1'b1 && hostSlaveMuxSel == 1'b1 && strobe_i == 1'b1 && address == `HOST_SLAVE_CONTROL_REG )
|
hostMode <= dataIn[0];
|
hostMode <= dataIn[0];
|
end
|
end
|
if (writeEn == 1'b1 && hostSlaveMuxSel == 1'b1 && strobe_i == 1'b1 && address == `HOST_SLAVE_CONTROL_REG && dataIn[1] == 1'b1 )
|
if (writeEn == 1'b1 && hostSlaveMuxSel == 1'b1 && strobe_i == 1'b1 && address == `HOST_SLAVE_CONTROL_REG && dataIn[1] == 1'b1 )
|
rstFromBus <= 1'b1;
|
rstFromBus <= 1'b1;
|
else
|
else
|
rstFromBus <= 1'b0;
|
rstFromBus <= 1'b0;
|
end
|
end
|
|
|
// async read mux
|
// async read mux
|
always @(address or hostMode)
|
always @(address or hostMode)
|
begin
|
begin
|
case (address)
|
case (address)
|
`HOST_SLAVE_CONTROL_REG: dataOut <= {7'h0, hostMode};
|
`HOST_SLAVE_CONTROL_REG: dataOut <= {7'h0, hostMode};
|
`HOST_SLAVE_VERSION_REG: dataOut <= `USBHOSTSLAVE_VERSION_NUM;
|
`HOST_SLAVE_VERSION_REG: dataOut <= `USBHOSTSLAVE_VERSION_NUM;
|
endcase
|
endcase
|
end
|
end
|
|
|
// reset control
|
// reset control
|
//generate 'rstSyncToBusClk'
|
//generate 'rstSyncToBusClk'
|
//assuming that 'busClk' < 5 * 'usbClk'. ie 'busClk' < 240MHz
|
//assuming that 'busClk' < 5 * 'usbClk'. ie 'busClk' < 240MHz
|
always @(posedge busClk) begin
|
always @(posedge busClk) begin
|
if (rstFromWire == 1'b1 || rstFromBus == 1'b1)
|
if (rstFromWire == 1'b1 || rstFromBus == 1'b1)
|
rstShift <= 6'b111111;
|
rstShift <= 6'b111111;
|
else
|
else
|
rstShift <= {1'b0, rstShift[5:1]};
|
rstShift <= {1'b0, rstShift[5:1]};
|
end
|
end
|
|
|
always @(rstShift)
|
always @(rstShift)
|
rstSyncToBusClkOut <= rstShift[0];
|
rstSyncToBusClkOut <= rstShift[0];
|
|
|
// double sync across clock domains to generate 'forceEmptySyncToWrClk'
|
// double sync across clock domains to generate 'forceEmptySyncToWrClk'
|
always @(posedge usbClk) begin
|
always @(posedge usbClk) begin
|
rstSyncToUsbClkFirst <= rstSyncToBusClkOut;
|
rstSyncToUsbClkFirst <= rstSyncToBusClkOut;
|
rstSyncToUsbClkOut <= rstSyncToUsbClkFirst;
|
rstSyncToUsbClkOut <= rstSyncToUsbClkFirst;
|
end
|
end
|
|
|
endmodule
|
endmodule
|
|
|