Line 1... |
Line 1... |
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
// ULPI (Link) Wrapper
|
// ULPI (Link) Wrapper
|
// V1.0
|
// V1.1
|
// Ultra-Embedded.com
|
// Ultra-Embedded.com
|
// Copyright 2015-2018
|
// Copyright 2015-2018
|
//
|
//
|
// Email: admin@ultra-embedded.com
|
// Email: admin@ultra-embedded.com
|
//
|
//
|
Line 90... |
Line 90... |
reg mode_update_q;
|
reg mode_update_q;
|
reg [1:0] xcvrselect_q;
|
reg [1:0] xcvrselect_q;
|
reg termselect_q;
|
reg termselect_q;
|
reg [1:0] opmode_q;
|
reg [1:0] opmode_q;
|
reg phy_reset_q;
|
reg phy_reset_q;
|
|
reg mode_write_q;
|
|
|
|
// Detect register write completion
|
|
wire mode_complete_w = (state_q == STATE_REG &&
|
|
mode_write_q &&
|
|
ulpi_nxt_i &&
|
|
!ulpi_dir_i); // Not interrupted by a Rx
|
|
|
always @ (posedge ulpi_clk60_i or posedge ulpi_rst_i)
|
always @ (posedge ulpi_clk60_i or posedge ulpi_rst_i)
|
if (ulpi_rst_i)
|
if (ulpi_rst_i)
|
begin
|
begin
|
mode_update_q <= 1'b0;
|
mode_update_q <= 1'b0;
|
Line 106... |
Line 113... |
begin
|
begin
|
xcvrselect_q <= utmi_xcvrselect_i;
|
xcvrselect_q <= utmi_xcvrselect_i;
|
termselect_q <= utmi_termselect_i;
|
termselect_q <= utmi_termselect_i;
|
opmode_q <= utmi_op_mode_i;
|
opmode_q <= utmi_op_mode_i;
|
|
|
if (mode_update_q && (state_q == STATE_CMD) && (ulpi_data_in_o == REG_FUNC_CTRL))
|
if (mode_update_q && mode_complete_w)
|
begin
|
begin
|
mode_update_q <= 1'b0;
|
mode_update_q <= 1'b0;
|
phy_reset_q <= 1'b0;
|
phy_reset_q <= 1'b0;
|
end
|
end
|
else if (opmode_q != utmi_op_mode_i ||
|
else if (opmode_q != utmi_op_mode_i ||
|
Line 123... |
Line 130... |
// UTMI OTG Control
|
// UTMI OTG Control
|
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
reg otg_update_q;
|
reg otg_update_q;
|
reg dppulldown_q;
|
reg dppulldown_q;
|
reg dmpulldown_q;
|
reg dmpulldown_q;
|
|
reg otg_write_q;
|
|
|
|
// Detect register write completion
|
|
wire otg_complete_w = (state_q == STATE_REG &&
|
|
otg_write_q &&
|
|
ulpi_nxt_i &&
|
|
!ulpi_dir_i); // Not interrupted by a Rx
|
|
|
always @ (posedge ulpi_clk60_i or posedge ulpi_rst_i)
|
always @ (posedge ulpi_clk60_i or posedge ulpi_rst_i)
|
if (ulpi_rst_i)
|
if (ulpi_rst_i)
|
begin
|
begin
|
otg_update_q <= 1'b0;
|
otg_update_q <= 1'b0;
|
Line 136... |
Line 150... |
else
|
else
|
begin
|
begin
|
dppulldown_q <= utmi_dppulldown_i;
|
dppulldown_q <= utmi_dppulldown_i;
|
dmpulldown_q <= utmi_dmpulldown_i;
|
dmpulldown_q <= utmi_dmpulldown_i;
|
|
|
if (otg_update_q && (state_q == STATE_CMD) && (ulpi_data_in_o == REG_OTG_CTRL))
|
if (otg_update_q && otg_complete_w)
|
otg_update_q <= 1'b0;
|
otg_update_q <= 1'b0;
|
else if (dppulldown_q != utmi_dppulldown_i ||
|
else if (dppulldown_q != utmi_dppulldown_i ||
|
dmpulldown_q != utmi_dmpulldown_i)
|
dmpulldown_q != utmi_dmpulldown_i)
|
otg_update_q <= 1'b1;
|
otg_update_q <= 1'b1;
|
end
|
end
|
Line 252... |
Line 266... |
utmi_rxvalid_q <= 1'b0;
|
utmi_rxvalid_q <= 1'b0;
|
utmi_rxerror_q <= 1'b0;
|
utmi_rxerror_q <= 1'b0;
|
utmi_rxactive_q <= 1'b0;
|
utmi_rxactive_q <= 1'b0;
|
utmi_linestate_q <= 2'b0;
|
utmi_linestate_q <= 2'b0;
|
utmi_data_q <= 8'b0;
|
utmi_data_q <= 8'b0;
|
|
|
|
mode_write_q <= 1'b0;
|
|
otg_write_q <= 1'b0;
|
end
|
end
|
else
|
else
|
begin
|
begin
|
ulpi_stp_q <= 1'b0;
|
ulpi_stp_q <= 1'b0;
|
utmi_rxvalid_q <= 1'b0;
|
utmi_rxvalid_q <= 1'b0;
|
|
|
// Turnaround: Input + NXT - set RX_ACTIVE
|
// Turnaround: Input + NXT - set RX_ACTIVE
|
if (turnaround_w && ulpi_dir_i && ulpi_nxt_i)
|
if (turnaround_w && ulpi_dir_i && ulpi_nxt_i)
|
begin
|
begin
|
utmi_rxactive_q <= 1'b1;
|
utmi_rxactive_q <= 1'b1;
|
|
|
|
// Register write - abort
|
|
if (state_q == STATE_REG)
|
|
begin
|
|
state_q <= STATE_IDLE;
|
|
ulpi_data_q <= 8'b0; // IDLE
|
|
end
|
end
|
end
|
// Turnaround: Input -> Output - reset RX_ACTIVE
|
// Turnaround: Input -> Output - reset RX_ACTIVE
|
else if (turnaround_w && !ulpi_dir_i)
|
else if (turnaround_w && !ulpi_dir_i)
|
begin
|
begin
|
utmi_rxactive_q <= 1'b0;
|
utmi_rxactive_q <= 1'b0;
|
|
|
|
// Register write - abort
|
|
if (state_q == STATE_REG)
|
|
begin
|
|
state_q <= STATE_IDLE;
|
|
ulpi_data_q <= 8'b0; // IDLE
|
|
end
|
end
|
end
|
// Non-turnaround cycle
|
// Non-turnaround cycle
|
else if (!turnaround_w)
|
else if (!turnaround_w)
|
begin
|
begin
|
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
Line 318... |
Line 349... |
if ((state_q == STATE_IDLE) && mode_update_q)
|
if ((state_q == STATE_IDLE) && mode_update_q)
|
begin
|
begin
|
data_q <= {1'b0, 1'b1, phy_reset_q, opmode_q, termselect_q, xcvrselect_q};
|
data_q <= {1'b0, 1'b1, phy_reset_q, opmode_q, termselect_q, xcvrselect_q};
|
ulpi_data_q <= REG_FUNC_CTRL;
|
ulpi_data_q <= REG_FUNC_CTRL;
|
|
|
|
otg_write_q <= 1'b0;
|
|
mode_write_q <= 1'b1;
|
|
|
state_q <= STATE_CMD;
|
state_q <= STATE_CMD;
|
end
|
end
|
// IDLE: Pending OTG control update
|
// IDLE: Pending OTG control update
|
else if ((state_q == STATE_IDLE) && otg_update_q)
|
else if ((state_q == STATE_IDLE) && otg_update_q)
|
begin
|
begin
|
data_q <= {5'b0, dmpulldown_q, dppulldown_q, 1'b0};
|
data_q <= {5'b0, dmpulldown_q, dppulldown_q, 1'b0};
|
ulpi_data_q <= REG_OTG_CTRL;
|
ulpi_data_q <= REG_OTG_CTRL;
|
|
|
|
otg_write_q <= 1'b1;
|
|
mode_write_q <= 1'b0;
|
|
|
state_q <= STATE_CMD;
|
state_q <= STATE_CMD;
|
end
|
end
|
// IDLE: Pending transmit
|
// IDLE: Pending transmit
|
else if ((state_q == STATE_IDLE) && utmi_tx_ready_w)
|
else if ((state_q == STATE_IDLE) && utmi_tx_ready_w)
|
begin
|
begin
|
Line 347... |
Line 384... |
else if (state_q == STATE_REG && ulpi_nxt_i)
|
else if (state_q == STATE_REG && ulpi_nxt_i)
|
begin
|
begin
|
state_q <= STATE_IDLE;
|
state_q <= STATE_IDLE;
|
ulpi_data_q <= 8'b0; // IDLE
|
ulpi_data_q <= 8'b0; // IDLE
|
ulpi_stp_q <= 1'b1;
|
ulpi_stp_q <= 1'b1;
|
|
|
|
otg_write_q <= 1'b0;
|
|
mode_write_q <= 1'b0;
|
end
|
end
|
// Data
|
// Data
|
else if (state_q == STATE_DATA && ulpi_nxt_i)
|
else if (state_q == STATE_DATA && ulpi_nxt_i)
|
begin
|
begin
|
// End of packet
|
// End of packet
|
Line 389... |
Line 429... |
assign utmi_rxvalid_o = utmi_rxvalid_q;
|
assign utmi_rxvalid_o = utmi_rxvalid_q;
|
|
|
|
|
|
|
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
|