Line 46... |
Line 46... |
|
|
`include "usbSlaveControl_h.v"
|
`include "usbSlaveControl_h.v"
|
|
|
module USBSlaveControlBI (address, dataIn, dataOut, writeEn,
|
module USBSlaveControlBI (address, dataIn, dataOut, writeEn,
|
strobe_i,
|
strobe_i,
|
clk, rst,
|
busClk,
|
|
rstSyncToBusClk,
|
|
usbClk,
|
|
rstSyncToUsbClk,
|
SOFRxedIntOut, resetEventIntOut, resumeIntOut, transDoneIntOut, NAKSentIntOut,
|
SOFRxedIntOut, resetEventIntOut, resumeIntOut, transDoneIntOut, NAKSentIntOut,
|
endP0TransTypeReg, endP0NAKTransTypeReg,
|
endP0TransTypeReg, endP0NAKTransTypeReg,
|
endP1TransTypeReg, endP1NAKTransTypeReg,
|
endP1TransTypeReg, endP1NAKTransTypeReg,
|
endP2TransTypeReg, endP2NAKTransTypeReg,
|
endP2TransTypeReg, endP2NAKTransTypeReg,
|
endP3TransTypeReg, endP3NAKTransTypeReg,
|
endP3TransTypeReg, endP3NAKTransTypeReg,
|
Line 75... |
Line 78... |
);
|
);
|
input [4:0] address;
|
input [4:0] address;
|
input [7:0] dataIn;
|
input [7:0] dataIn;
|
input writeEn;
|
input writeEn;
|
input strobe_i;
|
input strobe_i;
|
input clk;
|
input busClk;
|
input rst;
|
input rstSyncToBusClk;
|
|
input usbClk;
|
|
input rstSyncToUsbClk;
|
output [7:0] dataOut;
|
output [7:0] dataOut;
|
output SOFRxedIntOut;
|
output SOFRxedIntOut;
|
output resetEventIntOut;
|
output resetEventIntOut;
|
output resumeIntOut;
|
output resumeIntOut;
|
output transDoneIntOut;
|
output transDoneIntOut;
|
Line 123... |
Line 128... |
|
|
wire [4:0] address;
|
wire [4:0] address;
|
wire [7:0] dataIn;
|
wire [7:0] dataIn;
|
wire writeEn;
|
wire writeEn;
|
wire strobe_i;
|
wire strobe_i;
|
wire clk;
|
wire busClk;
|
wire rst;
|
wire rstSyncToBusClk;
|
|
wire usbClk;
|
|
wire rstSyncToUsbClk;
|
reg [7:0] dataOut;
|
reg [7:0] dataOut;
|
|
|
reg SOFRxedIntOut;
|
reg SOFRxedIntOut;
|
reg resetEventIntOut;
|
reg resetEventIntOut;
|
reg resumeIntOut;
|
reg resumeIntOut;
|
Line 208... |
Line 215... |
reg EP0Ready;
|
reg EP0Ready;
|
reg EP1Ready;
|
reg EP1Ready;
|
reg EP2Ready;
|
reg EP2Ready;
|
reg EP3Ready;
|
reg EP3Ready;
|
|
|
|
//clock domain crossing sync registers
|
|
//STB = Sync To Busclk
|
|
reg [4:0] endP0ControlRegSTB;
|
|
reg [4:0] endP1ControlRegSTB;
|
|
reg [4:0] endP2ControlRegSTB;
|
|
reg [4:0] endP3ControlRegSTB;
|
|
reg NAKSentInSTB;
|
|
reg SOFRxedInSTB;
|
|
reg resetEventInSTB;
|
|
reg resumeIntInSTB;
|
|
reg transDoneInSTB;
|
|
reg clrEP0ReadySTB;
|
|
reg clrEP1ReadySTB;
|
|
reg clrEP2ReadySTB;
|
|
reg clrEP3ReadySTB;
|
|
reg SCGlobalEnSTB;
|
|
reg [1:0] TxLineStateSTB;
|
|
reg LineDirectControlEnSTB;
|
|
reg fullSpeedPolSTB;
|
|
reg fullSpeedRateSTB;
|
|
reg [7:0] EP0StatusRegSTB;
|
|
reg [7:0] EP1StatusRegSTB;
|
|
reg [7:0] EP2StatusRegSTB;
|
|
reg [7:0] EP3StatusRegSTB;
|
|
reg [1:0] endP0TransTypeRegSTB;
|
|
reg [1:0] endP0NAKTransTypeRegSTB;
|
|
reg [1:0] endP1TransTypeRegSTB;
|
|
reg [1:0] endP1NAKTransTypeRegSTB;
|
|
reg [1:0] endP2TransTypeRegSTB;
|
|
reg [1:0] endP2NAKTransTypeRegSTB;
|
|
reg [1:0] endP3TransTypeRegSTB;
|
|
reg [1:0] endP3NAKTransTypeRegSTB;
|
|
reg [10:0] frameNumSTB;
|
|
|
|
|
//sync write demux
|
//sync write demux
|
always @(posedge clk)
|
always @(posedge busClk)
|
begin
|
begin
|
if (rst == 1'b1) begin
|
if (rstSyncToBusClk == 1'b1) begin
|
EP0IsoEn <= 1'b0;
|
EP0IsoEn <= 1'b0;
|
EP0SendStall <= 1'b0;
|
EP0SendStall <= 1'b0;
|
EP0DataSequence <= 1'b0;
|
EP0DataSequence <= 1'b0;
|
EP0Enable <= 1'b0;
|
EP0Enable <= 1'b0;
|
EP1IsoEn <= 1'b0;
|
EP1IsoEn <= 1'b0;
|
Line 290... |
Line 331... |
end
|
end
|
end
|
end
|
end
|
end
|
|
|
//interrupt control
|
//interrupt control
|
always @(posedge clk)
|
always @(posedge busClk)
|
begin
|
begin
|
if (rst == 1'b1) begin
|
if (rstSyncToBusClk == 1'b1) begin
|
NAKSentInt <= 1'b0;
|
NAKSentInt <= 1'b0;
|
SOFRxedInt <= 1'b0;
|
SOFRxedInt <= 1'b0;
|
resetEventInt <= 1'b0;
|
resetEventInt <= 1'b0;
|
resumeInt <= 1'b0;
|
resumeInt <= 1'b0;
|
transDoneInt <= 1'b0;
|
transDoneInt <= 1'b0;
|
end
|
end
|
else begin
|
else begin
|
if (NAKSentIn == 1'b1)
|
if (NAKSentInSTB == 1'b1)
|
NAKSentInt <= 1'b1;
|
NAKSentInt <= 1'b1;
|
else if (clrNAKReq == 1'b1)
|
else if (clrNAKReq == 1'b1)
|
NAKSentInt <= 1'b0;
|
NAKSentInt <= 1'b0;
|
|
|
if (SOFRxedIn == 1'b1)
|
if (SOFRxedInSTB == 1'b1)
|
SOFRxedInt <= 1'b1;
|
SOFRxedInt <= 1'b1;
|
else if (clrSOFReq == 1'b1)
|
else if (clrSOFReq == 1'b1)
|
SOFRxedInt <= 1'b0;
|
SOFRxedInt <= 1'b0;
|
|
|
if (resetEventIn == 1'b1)
|
if (resetEventInSTB == 1'b1)
|
resetEventInt <= 1'b1;
|
resetEventInt <= 1'b1;
|
else if (clrResetReq == 1'b1)
|
else if (clrResetReq == 1'b1)
|
resetEventInt <= 1'b0;
|
resetEventInt <= 1'b0;
|
|
|
if (resumeIntIn == 1'b1)
|
if (resumeIntInSTB == 1'b1)
|
resumeInt <= 1'b1;
|
resumeInt <= 1'b1;
|
else if (clrResInReq == 1'b1)
|
else if (clrResInReq == 1'b1)
|
resumeInt <= 1'b0;
|
resumeInt <= 1'b0;
|
|
|
if (transDoneIn == 1'b1)
|
if (transDoneInSTB == 1'b1)
|
transDoneInt <= 1'b1;
|
transDoneInt <= 1'b1;
|
else if (clrTransDoneReq == 1'b1)
|
else if (clrTransDoneReq == 1'b1)
|
transDoneInt <= 1'b0;
|
transDoneInt <= 1'b0;
|
end
|
end
|
end
|
end
|
Line 337... |
Line 378... |
SOFRxedIntOut <= SOFRxedInt & interruptMaskReg[`SOF_RECEIVED_BIT];
|
SOFRxedIntOut <= SOFRxedInt & interruptMaskReg[`SOF_RECEIVED_BIT];
|
NAKSentIntOut <= NAKSentInt & interruptMaskReg[`NAK_SENT_INT_BIT];
|
NAKSentIntOut <= NAKSentInt & interruptMaskReg[`NAK_SENT_INT_BIT];
|
end
|
end
|
|
|
//end point ready, set/clear
|
//end point ready, set/clear
|
always @(posedge clk)
|
//Since 'busClk' can be a higher freq than 'usbClk',
|
|
//'EP0SetReady' etc must be delayed with respect to other control signals, thus
|
|
//ensuring that control signals have been clocked through to 'usbClk' clock
|
|
//domain before the ready is asserted.
|
|
//Not sure this is required because there is at least two 'usbClk' ticks between
|
|
//detection of 'EP0Ready' and sampling of related control signals.always @(posedge busClk)
|
|
always @(posedge busClk)
|
begin
|
begin
|
if (rst == 1'b1) begin
|
if (rstSyncToBusClk == 1'b1) begin
|
EP0Ready <= 1'b0;
|
EP0Ready <= 1'b0;
|
EP1Ready <= 1'b0;
|
EP1Ready <= 1'b0;
|
EP2Ready <= 1'b0;
|
EP2Ready <= 1'b0;
|
EP3Ready <= 1'b0;
|
EP3Ready <= 1'b0;
|
end
|
end
|
else begin
|
else begin
|
if (EP0SetReady == 1'b1)
|
if (EP0SetReady == 1'b1)
|
EP0Ready <= 1'b1;
|
EP0Ready <= 1'b1;
|
else if (clrEP0Ready == 1'b1)
|
else if (clrEP0ReadySTB == 1'b1)
|
EP0Ready <= 1'b0;
|
EP0Ready <= 1'b0;
|
|
|
if (EP1SetReady == 1'b1)
|
if (EP1SetReady == 1'b1)
|
EP1Ready <= 1'b1;
|
EP1Ready <= 1'b1;
|
else if (clrEP1Ready == 1'b1)
|
else if (clrEP1ReadySTB == 1'b1)
|
EP1Ready <= 1'b0;
|
EP1Ready <= 1'b0;
|
|
|
if (EP2SetReady == 1'b1)
|
if (EP2SetReady == 1'b1)
|
EP2Ready <= 1'b1;
|
EP2Ready <= 1'b1;
|
else if (clrEP2Ready == 1'b1)
|
else if (clrEP2ReadySTB == 1'b1)
|
EP2Ready <= 1'b0;
|
EP2Ready <= 1'b0;
|
|
|
if (EP3SetReady == 1'b1)
|
if (EP3SetReady == 1'b1)
|
EP3Ready <= 1'b1;
|
EP3Ready <= 1'b1;
|
else if (clrEP3Ready == 1'b1)
|
else if (clrEP3ReadySTB == 1'b1)
|
EP3Ready <= 1'b0;
|
EP3Ready <= 1'b0;
|
end
|
end
|
end
|
end
|
|
|
//break out control signals
|
//break out control signals
|
always @(SCControlReg) begin
|
always @(SCControlReg) begin
|
SCGlobalEn <= SCControlReg[`SC_GLOBAL_ENABLE_BIT];
|
SCGlobalEnSTB <= SCControlReg[`SC_GLOBAL_ENABLE_BIT];
|
TxLineState <= SCControlReg[`SC_TX_LINE_STATE_MSBIT:`SC_TX_LINE_STATE_LSBIT];
|
TxLineStateSTB <= SCControlReg[`SC_TX_LINE_STATE_MSBIT:`SC_TX_LINE_STATE_LSBIT];
|
LineDirectControlEn <= SCControlReg[`SC_DIRECT_CONTROL_BIT];
|
LineDirectControlEnSTB <= SCControlReg[`SC_DIRECT_CONTROL_BIT];
|
fullSpeedPol <= SCControlReg[`SC_FULL_SPEED_LINE_POLARITY_BIT];
|
fullSpeedPolSTB <= SCControlReg[`SC_FULL_SPEED_LINE_POLARITY_BIT];
|
fullSpeedRate <= SCControlReg[`SC_FULL_SPEED_LINE_RATE_BIT];
|
fullSpeedRateSTB <= SCControlReg[`SC_FULL_SPEED_LINE_RATE_BIT];
|
end
|
end
|
|
|
//combine endpoint control signals
|
//combine endpoint control signals
|
always @(EP0IsoEn or EP0SendStall or EP0Ready or EP0DataSequence or EP0Enable or
|
always @(EP0IsoEn or EP0SendStall or EP0Ready or EP0DataSequence or EP0Enable or
|
EP1IsoEn or EP1SendStall or EP1Ready or EP1DataSequence or EP1Enable or
|
EP1IsoEn or EP1SendStall or EP1Ready or EP1DataSequence or EP1Enable or
|
EP2IsoEn or EP2SendStall or EP2Ready or EP2DataSequence or EP2Enable or
|
EP2IsoEn or EP2SendStall or EP2Ready or EP2DataSequence or EP2Enable or
|
EP3IsoEn or EP3SendStall or EP3Ready or EP3DataSequence or EP3Enable)
|
EP3IsoEn or EP3SendStall or EP3Ready or EP3DataSequence or EP3Enable)
|
begin
|
begin
|
endP0ControlReg <= {EP0IsoEn, EP0SendStall, EP0DataSequence, EP0Ready, EP0Enable};
|
endP0ControlRegSTB <= {EP0IsoEn, EP0SendStall, EP0DataSequence, EP0Ready, EP0Enable};
|
endP1ControlReg <= {EP1IsoEn, EP1SendStall, EP1DataSequence, EP1Ready, EP1Enable};
|
endP1ControlRegSTB <= {EP1IsoEn, EP1SendStall, EP1DataSequence, EP1Ready, EP1Enable};
|
endP2ControlReg <= {EP2IsoEn, EP2SendStall, EP2DataSequence, EP2Ready, EP2Enable};
|
endP2ControlRegSTB <= {EP2IsoEn, EP2SendStall, EP2DataSequence, EP2Ready, EP2Enable};
|
endP3ControlReg <= {EP3IsoEn, EP3SendStall, EP3DataSequence, EP3Ready, EP3Enable};
|
endP3ControlRegSTB <= {EP3IsoEn, EP3SendStall, EP3DataSequence, EP3Ready, EP3Enable};
|
end
|
end
|
|
|
|
|
// async read mux
|
// async read mux
|
|
// FIX ME
|
|
// Not sure why 'EP0SendStall' etc are in sensitivity list. May be related to
|
|
// some translation bug
|
always @(address or
|
always @(address or
|
EP0SendStall or EP0Ready or EP0DataSequence or EP0Enable or
|
EP0SendStall or EP0Ready or EP0DataSequence or EP0Enable or
|
EP1SendStall or EP1Ready or EP1DataSequence or EP1Enable or
|
EP1SendStall or EP1Ready or EP1DataSequence or EP1Enable or
|
EP2SendStall or EP2Ready or EP2DataSequence or EP2Enable or
|
EP2SendStall or EP2Ready or EP2DataSequence or EP2Enable or
|
EP3SendStall or EP3Ready or EP3DataSequence or EP3Enable or
|
EP3SendStall or EP3Ready or EP3DataSequence or EP3Enable or
|
EP0StatusReg or EP1StatusReg or EP2StatusReg or EP3StatusReg or
|
EP0StatusRegSTB or EP1StatusRegSTB or EP2StatusRegSTB or EP3StatusRegSTB or
|
endP0ControlReg or endP1ControlReg or endP2ControlReg or endP3ControlReg or
|
endP0ControlRegSTB or endP1ControlRegSTB or endP2ControlRegSTB or endP3ControlRegSTB or
|
endP0NAKTransTypeReg or endP1NAKTransTypeReg or endP2NAKTransTypeReg or endP3NAKTransTypeReg or
|
endP0NAKTransTypeRegSTB or endP1NAKTransTypeRegSTB or endP2NAKTransTypeRegSTB or endP3NAKTransTypeRegSTB or
|
endP0TransTypeReg or endP1TransTypeReg or endP2TransTypeReg or endP3TransTypeReg or
|
endP0TransTypeRegSTB or endP1TransTypeRegSTB or endP2TransTypeRegSTB or endP3TransTypeRegSTB or
|
SCControlReg or connectStateIn or
|
SCControlReg or connectStateIn or
|
NAKSentInt or SOFRxedInt or resetEventInt or resumeInt or transDoneInt or
|
NAKSentInt or SOFRxedInt or resetEventInt or resumeInt or transDoneInt or
|
interruptMaskReg or SCAddrReg or frameNum)
|
interruptMaskReg or SCAddrReg or frameNumSTB)
|
begin
|
begin
|
case (address)
|
case (address)
|
`EP0_CTRL_REG : dataOut <= endP0ControlReg;
|
`EP0_CTRL_REG : dataOut <= endP0ControlRegSTB;
|
`EP0_STS_REG : dataOut <= EP0StatusReg;
|
`EP0_STS_REG : dataOut <= EP0StatusRegSTB;
|
`EP0_TRAN_TYPE_STS_REG : dataOut <= endP0TransTypeReg;
|
`EP0_TRAN_TYPE_STS_REG : dataOut <= endP0TransTypeRegSTB;
|
`EP0_NAK_TRAN_TYPE_STS_REG : dataOut <= endP0NAKTransTypeReg;
|
`EP0_NAK_TRAN_TYPE_STS_REG : dataOut <= endP0NAKTransTypeRegSTB;
|
`EP1_CTRL_REG : dataOut <= endP1ControlReg;
|
`EP1_CTRL_REG : dataOut <= endP1ControlRegSTB;
|
`EP1_STS_REG : dataOut <= EP1StatusReg;
|
`EP1_STS_REG : dataOut <= EP1StatusRegSTB;
|
`EP1_TRAN_TYPE_STS_REG : dataOut <= endP1TransTypeReg;
|
`EP1_TRAN_TYPE_STS_REG : dataOut <= endP1TransTypeRegSTB;
|
`EP1_NAK_TRAN_TYPE_STS_REG : dataOut <= endP1NAKTransTypeReg;
|
`EP1_NAK_TRAN_TYPE_STS_REG : dataOut <= endP1NAKTransTypeRegSTB;
|
`EP2_CTRL_REG : dataOut <= endP2ControlReg;
|
`EP2_CTRL_REG : dataOut <= endP2ControlRegSTB;
|
`EP2_STS_REG : dataOut <= EP2StatusReg;
|
`EP2_STS_REG : dataOut <= EP2StatusRegSTB;
|
`EP2_TRAN_TYPE_STS_REG : dataOut <= endP2TransTypeReg;
|
`EP2_TRAN_TYPE_STS_REG : dataOut <= endP2TransTypeRegSTB;
|
`EP2_NAK_TRAN_TYPE_STS_REG : dataOut <= endP2NAKTransTypeReg;
|
`EP2_NAK_TRAN_TYPE_STS_REG : dataOut <= endP2NAKTransTypeRegSTB;
|
`EP3_CTRL_REG : dataOut <= endP3ControlReg;
|
`EP3_CTRL_REG : dataOut <= endP3ControlRegSTB;
|
`EP3_STS_REG : dataOut <= EP3StatusReg;
|
`EP3_STS_REG : dataOut <= EP3StatusRegSTB;
|
`EP3_TRAN_TYPE_STS_REG : dataOut <= endP3TransTypeReg;
|
`EP3_TRAN_TYPE_STS_REG : dataOut <= endP3TransTypeRegSTB;
|
`EP3_NAK_TRAN_TYPE_STS_REG : dataOut <= endP3NAKTransTypeReg;
|
`EP3_NAK_TRAN_TYPE_STS_REG : dataOut <= endP3NAKTransTypeRegSTB;
|
`SC_CONTROL_REG : dataOut <= SCControlReg;
|
`SC_CONTROL_REG : dataOut <= SCControlReg;
|
`SC_LINE_STATUS_REG : dataOut <= {6'b000000, connectStateIn};
|
`SC_LINE_STATUS_REG : dataOut <= {6'b000000, connectStateIn};
|
`SC_INTERRUPT_STATUS_REG : dataOut <= {3'b000, NAKSentInt, SOFRxedInt, resetEventInt, resumeInt, transDoneInt};
|
`SC_INTERRUPT_STATUS_REG : dataOut <= {3'b000, NAKSentInt, SOFRxedInt, resetEventInt, resumeInt, transDoneInt};
|
`SC_INTERRUPT_MASK_REG : dataOut <= {3'b000, interruptMaskReg};
|
`SC_INTERRUPT_MASK_REG : dataOut <= {3'b000, interruptMaskReg};
|
`SC_ADDRESS : dataOut <= {1'b0, SCAddrReg};
|
`SC_ADDRESS : dataOut <= {1'b0, SCAddrReg};
|
`SC_FRAME_NUM_MSP : dataOut <= {5'b00000, frameNum[10:8]};
|
`SC_FRAME_NUM_MSP : dataOut <= {5'b00000, frameNumSTB[10:8]};
|
`SC_FRAME_NUM_LSP : dataOut <= frameNum[7:0];
|
`SC_FRAME_NUM_LSP : dataOut <= frameNumSTB[7:0];
|
default: dataOut <= 8'h00;
|
default: dataOut <= 8'h00;
|
endcase
|
endcase
|
end
|
end
|
|
|
|
//re-sync from busClk to usbClk.
|
|
always @(posedge usbClk) begin
|
|
endP0ControlReg <= endP0ControlRegSTB;
|
|
endP1ControlReg <= endP1ControlRegSTB;
|
|
endP2ControlReg <= endP2ControlRegSTB;
|
|
endP3ControlReg <= endP3ControlRegSTB;
|
|
SCGlobalEn <= SCGlobalEnSTB;
|
|
TxLineState <= TxLineStateSTB;
|
|
LineDirectControlEn <= LineDirectControlEnSTB;
|
|
fullSpeedPol <= fullSpeedPolSTB;
|
|
fullSpeedRate <= fullSpeedRateSTB;
|
|
end
|
|
|
|
//re-sync from usbClk to busClk. Since 'NAKSentIn', 'SOFRxedIn' etc are only asserted
|
|
//for one 'usbClk' tick, busClk freq must be greater than or equal to usbClk freq
|
|
always @(posedge busClk) begin
|
|
NAKSentInSTB <= NAKSentIn;
|
|
SOFRxedInSTB <= SOFRxedIn;
|
|
resetEventInSTB <= resetEventIn;
|
|
resumeIntInSTB <= resumeIntIn;
|
|
transDoneInSTB <= transDoneIn;
|
|
clrEP0ReadySTB <= clrEP0Ready;
|
|
clrEP1ReadySTB <= clrEP1Ready;
|
|
clrEP2ReadySTB <= clrEP2Ready;
|
|
clrEP3ReadySTB <= clrEP3Ready;
|
|
EP0StatusRegSTB <= EP0StatusReg;
|
|
EP1StatusRegSTB <= EP1StatusReg;
|
|
EP2StatusRegSTB <= EP2StatusReg;
|
|
EP3StatusRegSTB <= EP3StatusReg;
|
|
endP0TransTypeRegSTB <= endP0TransTypeReg;
|
|
endP1TransTypeRegSTB <= endP1TransTypeReg;
|
|
endP2TransTypeRegSTB <= endP2TransTypeReg;
|
|
endP3TransTypeRegSTB <= endP3TransTypeReg;
|
|
endP0NAKTransTypeRegSTB <= endP0NAKTransTypeReg;
|
|
endP1NAKTransTypeRegSTB <= endP1NAKTransTypeReg;
|
|
endP2NAKTransTypeRegSTB <= endP2NAKTransTypeReg;
|
|
endP3NAKTransTypeRegSTB <= endP3NAKTransTypeReg;
|
|
frameNumSTB <= frameNum;
|
|
end
|
|
|
endmodule
|
endmodule
|
No newline at end of file
|
No newline at end of file
|
|
|
No newline at end of file
|
No newline at end of file
|