Line 42... |
Line 42... |
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//
|
//
|
`timescale 1ns / 1ps
|
`timescale 1ns / 1ps
|
`include "usbSerialInterfaceEngine_h.v"
|
`include "usbSerialInterfaceEngine_h.v"
|
|
|
module readUSBWireData (RxBitsIn, RxDataInTick, RxBitsOut, SIERxRdyIn, SIERxWEn, fullSpeedRate, TxWireActiveDrive, clk, rst, noActivityTimeOut);
|
module readUSBWireData (RxBitsIn, RxDataInTick, RxBitsOut, SIERxRdyIn, SIERxWEn, fullSpeedRate, TxWireActiveDrive, clk, rst, noActivityTimeOut, RxWireActive);
|
input [1:0] RxBitsIn;
|
input [1:0] RxBitsIn;
|
output RxDataInTick;
|
output RxDataInTick;
|
input SIERxRdyIn;
|
input SIERxRdyIn;
|
input clk;
|
input clk;
|
input fullSpeedRate;
|
input fullSpeedRate;
|
input rst;
|
input rst;
|
input TxWireActiveDrive;
|
input TxWireActiveDrive;
|
output [1:0] RxBitsOut;
|
output [1:0] RxBitsOut;
|
output SIERxWEn;
|
output SIERxWEn;
|
output noActivityTimeOut;
|
output noActivityTimeOut;
|
|
output RxWireActive;
|
|
|
wire [1:0] RxBitsIn;
|
wire [1:0] RxBitsIn;
|
reg RxDataInTick;
|
reg RxDataInTick;
|
wire SIERxRdyIn;
|
wire SIERxRdyIn;
|
wire clk;
|
wire clk;
|
wire fullSpeedRate;
|
wire fullSpeedRate;
|
wire rst;
|
wire rst;
|
reg [1:0] RxBitsOut;
|
reg [1:0] RxBitsOut;
|
reg SIERxWEn;
|
reg SIERxWEn;
|
reg noActivityTimeOut;
|
reg noActivityTimeOut;
|
|
reg RxWireActive;
|
|
|
// local registers
|
// local registers
|
reg [1:0]buffer0;
|
reg [2:0]buffer0;
|
reg [1:0]buffer1;
|
reg [2:0]buffer1;
|
reg [1:0]buffer2;
|
reg [2:0]buffer2;
|
reg [1:0]buffer3;
|
reg [2:0]buffer3;
|
reg [2:0]bufferCnt;
|
reg [2:0]bufferCnt;
|
reg [1:0]bufferInIndex;
|
reg [1:0]bufferInIndex;
|
reg [1:0]bufferOutIndex;
|
reg [1:0]bufferOutIndex;
|
reg decBufferCnt;
|
reg decBufferCnt;
|
reg [4:0]i;
|
reg [4:0]i;
|
reg incBufferCnt;
|
reg incBufferCnt;
|
reg [1:0]oldRxBitsIn;
|
reg [1:0]oldRxBitsIn;
|
reg [1:0] RxBitsInReg;
|
reg [1:0] RxBitsInReg;
|
reg [15:0] timeOutCnt;
|
reg [15:0] timeOutCnt;
|
reg RxWireActive;
|
reg RxWireEdgeDetect;
|
|
reg RxWireActiveReg1;
|
|
reg RxWireActiveReg2;
|
|
|
// buffer output state machine state codes:
|
// buffer output state machine state codes:
|
`define WAIT_BUFFER_NOT_EMPTY 2'b00
|
`define WAIT_BUFFER_NOT_EMPTY 2'b00
|
`define WAIT_SIE_RX_READY 2'b01
|
`define WAIT_SIE_RX_READY 2'b01
|
`define SIE_RX_WRITE 2'b10
|
`define SIE_RX_WRITE 2'b10
|
Line 111... |
Line 115... |
if (rst == 1'b1)
|
if (rst == 1'b1)
|
begin
|
begin
|
i <= 5'b00000;
|
i <= 5'b00000;
|
incBufferCnt <= 1'b0;
|
incBufferCnt <= 1'b0;
|
bufferInIndex <= 2'b00;
|
bufferInIndex <= 2'b00;
|
buffer0 <= 2'b00;
|
buffer0 <= 3'b000;
|
buffer1 <= 2'b00;
|
buffer1 <= 3'b000;
|
buffer2 <= 2'b00;
|
buffer2 <= 3'b000;
|
buffer3 <= 2'b00;
|
buffer3 <= 3'b000;
|
RxDataInTick <= 1'b0;
|
RxDataInTick <= 1'b0;
|
RxWireActive <= 1'b0;
|
RxWireEdgeDetect <= 1'b0;
|
|
RxWireActiveReg1 <= 1'b0;
|
|
RxWireActiveReg2 <= 1'b0;
|
end
|
end
|
else begin
|
else begin
|
RxBitsInReg <= RxBitsIn; //sync to local clock to avoid metastability issues
|
RxWireActiveReg2 <= RxWireActiveReg1; //Delay RxWireActiveReg1 until after i has been reset
|
|
RxBitsInReg <= RxBitsIn; //sync incoming data to local clock to avoid metastability issues
|
incBufferCnt <= 1'b0; //default value
|
incBufferCnt <= 1'b0; //default value
|
oldRxBitsIn <= RxBitsInReg;
|
oldRxBitsIn <= RxBitsInReg;
|
if (oldRxBitsIn != RxBitsInReg) begin //if edge detected then
|
if ( (TxWireActiveDrive == 1'b0) && (oldRxBitsIn != RxBitsInReg)) begin //if edge detected then
|
i <= 5'b00000; //reset the counter
|
i <= 5'b00000; //reset the counter
|
RxWireActive <= 1'b1; // flag receive activity
|
RxWireEdgeDetect <= 1'b1; // flag receive activity
|
|
RxWireActiveReg1 <= 1'b1;
|
end
|
end
|
else begin
|
else begin
|
i <= i + 1'b1;
|
i <= i + 1'b1;
|
RxWireActive <= 1'b0;
|
RxWireEdgeDetect <= 1'b0;
|
end
|
end
|
|
if (noActivityTimeOut == 1'b1)
|
|
RxWireActiveReg1 <= 1'b0;
|
if ( (fullSpeedRate == 1'b1 && i[1:0] == 2'b01) || (fullSpeedRate == 1'b0 && i == 5'b10000) )
|
if ( (fullSpeedRate == 1'b1 && i[1:0] == 2'b01) || (fullSpeedRate == 1'b0 && i == 5'b10000) )
|
begin
|
begin
|
RxDataInTick <= !RxDataInTick;
|
RxDataInTick <= !RxDataInTick;
|
if (TxWireActiveDrive != 1'b1) //do not read wire data when transmitter is active
|
if (TxWireActiveDrive != 1'b1) //do not read wire data when transmitter is active
|
begin
|
begin
|
incBufferCnt <= 1'b1;
|
incBufferCnt <= 1'b1;
|
bufferInIndex <= bufferInIndex + 1'b1;
|
bufferInIndex <= bufferInIndex + 1'b1;
|
case (bufferInIndex)
|
case (bufferInIndex)
|
2'b00 : buffer0 <= RxBitsInReg;
|
2'b00 : buffer0 <= {RxWireActiveReg2, RxBitsInReg};
|
2'b01 : buffer1 <= RxBitsInReg;
|
2'b01 : buffer1 <= {RxWireActiveReg2, RxBitsInReg};
|
2'b10 : buffer2 <= RxBitsInReg;
|
2'b10 : buffer2 <= {RxWireActiveReg2, RxBitsInReg};
|
2'b11 : buffer3 <= RxBitsInReg;
|
2'b11 : buffer3 <= {RxWireActiveReg2, RxBitsInReg};
|
endcase
|
endcase
|
end
|
end
|
end
|
end
|
end
|
end
|
end
|
end
|
Line 176... |
Line 186... |
SIERxWEn <= 1'b1;
|
SIERxWEn <= 1'b1;
|
bufferOutStMachCurrState <= `SIE_RX_WRITE;
|
bufferOutStMachCurrState <= `SIE_RX_WRITE;
|
decBufferCnt <= 1'b1;
|
decBufferCnt <= 1'b1;
|
bufferOutIndex <= bufferOutIndex + 1'b1;
|
bufferOutIndex <= bufferOutIndex + 1'b1;
|
case (bufferOutIndex)
|
case (bufferOutIndex)
|
2'b00 : RxBitsOut <= buffer0;
|
2'b00 : begin RxBitsOut <= buffer0[1:0]; RxWireActive <= buffer0[2]; end
|
2'b01 : RxBitsOut <= buffer1;
|
2'b01 : begin RxBitsOut <= buffer1[1:0]; RxWireActive <= buffer1[2]; end
|
2'b10 : RxBitsOut <= buffer2;
|
2'b10 : begin RxBitsOut <= buffer2[1:0]; RxWireActive <= buffer2[2]; end
|
2'b11 : RxBitsOut <= buffer3;
|
2'b11 : begin RxBitsOut <= buffer3[1:0]; RxWireActive <= buffer3[2]; end
|
endcase
|
endcase
|
end
|
end
|
end
|
end
|
`SIE_RX_WRITE:
|
`SIE_RX_WRITE:
|
begin
|
begin
|
Line 200... |
Line 210... |
if (rst) begin
|
if (rst) begin
|
timeOutCnt <= 16'h0000;
|
timeOutCnt <= 16'h0000;
|
noActivityTimeOut <= 1'b0;
|
noActivityTimeOut <= 1'b0;
|
end
|
end
|
else begin
|
else begin
|
if (TxWireActiveDrive == 1'b1 || RxWireActive == 1'b1)
|
if (TxWireActiveDrive == 1'b1 || RxWireEdgeDetect == 1'b1)
|
timeOutCnt <= 16'h0000;
|
timeOutCnt <= 16'h0000;
|
else
|
else
|
timeOutCnt <= timeOutCnt + 1'b1;
|
timeOutCnt <= timeOutCnt + 1'b1;
|
//if (timeOutCnt == `RX_PACKET_TOUT * `OVER_SAMPLE_RATE)
|
|
if ( (fullSpeedRate == 1'b1 && timeOutCnt == `RX_PACKET_TOUT * `FS_OVER_SAMPLE_RATE)
|
if ( (fullSpeedRate == 1'b1 && timeOutCnt == `RX_PACKET_TOUT * `FS_OVER_SAMPLE_RATE)
|
|| (fullSpeedRate == 1'b0 && timeOutCnt == `RX_PACKET_TOUT * `LS_OVER_SAMPLE_RATE) )
|
|| (fullSpeedRate == 1'b0 && timeOutCnt == `RX_PACKET_TOUT * `LS_OVER_SAMPLE_RATE) )
|
//if (timeOutCnt == 16'h200) //temporary hack
|
|
noActivityTimeOut <= 1'b1;
|
noActivityTimeOut <= 1'b1;
|
else
|
else
|
noActivityTimeOut <= 1'b0;
|
noActivityTimeOut <= 1'b0;
|
end
|
end
|
end
|
end
|
|
|
|
|
|
|
|
|
endmodule
|
endmodule
|
No newline at end of file
|
No newline at end of file
|