-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chip_tb] Integrate usbdpi into chip tb
Initial integration of usbdpi model into chip dvsim/tb; usbdev_test is up and running Simple chip_sw_usbdev_dpi_vseq created but incomplete. Include workaround for mmio32 routines reading X from usbdev. Added pull up resistors in diff receiver; driven by usbdev_aon_wake module in pinmux. Signed-off-by: Adrian Lees <[email protected]>
- Loading branch information
Showing
17 changed files
with
314 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
CAPI=2: | ||
# Copyright lowRISC contributors. | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
name: "lowrisc:dv:usb20_usbdpi:0.1" | ||
description: "USB20-USBDPI" | ||
|
||
filesets: | ||
files_rtl: | ||
files: | ||
- usb20_usbdpi.sv: { file_type: systemVerilogSource } | ||
|
||
targets: | ||
default: | ||
filesets: | ||
- files_rtl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
// Copyright lowRISC contributors. | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
module usb20_usbdpi ( | ||
input clk_i, | ||
input rst_ni, | ||
|
||
// VBUS/SENSE is driven high to activate/power the device. | ||
output usb_sense_o, | ||
|
||
// Bidirectional, differential bus. | ||
inout usb_p, | ||
inout usb_n | ||
); | ||
|
||
// Functioning sketch of integration of USBDPI model into dv top-level tb | ||
// as a connectivity and function test for ASIC | ||
|
||
// This module integrates the existing `usbdpi` module into the DV chip test | ||
// bench, reconstructing the two unidirectional buses and driver enables that | ||
// the DPI model requires for its operation, using just the bare bidirectional | ||
// USB signals. | ||
// | ||
// Nomenclature notes: | ||
// dp (or p) and dn (or n) are the two signals of the differential USB | ||
// d2p means device to DPI | ||
// p2d means DPI to device | ||
|
||
// VBUS/SENSE output from DPI | ||
wire usb_sense_p2d; | ||
// DPI driver enables | ||
wire usb_dp_en_p2d; | ||
wire usb_dn_en_p2d; | ||
// DPI driver outputs | ||
wire usb_dp_p2d; | ||
wire usb_dn_p2d; | ||
|
||
assign usb_sense_o = usb_sense_p2d; | ||
|
||
// Weak pull downs so that we can detect the presence of the device, and we | ||
// also prevent Z triggering 'X assertions' in usbdev | ||
assign (weak0, weak1) usb_p = 1'b0; | ||
assign (weak0, weak1) usb_n = 1'b0; | ||
// Tri-stated output drivers | ||
assign (strong0, strong1) usb_p = usb_dp_en_p2d ? usb_dp_p2d : 1'bZ; | ||
assign (strong0, strong1) usb_n = usb_dn_en_p2d ? usb_dn_p2d : 1'bZ; | ||
|
||
/////////////////////////////////////////////////////////////////////////// | ||
// Simple detection of pull up assertion indicating device presence; | ||
// we simply respond to the first line to be pulled high by the device after | ||
// VSENSE assertion, without regard for proper USB 2.0 timing | ||
/////////////////////////////////////////////////////////////////////////// | ||
logic usb_pullupdp_d2p; | ||
logic usb_pullupdn_d2p; | ||
|
||
// Has either pull up been asserted by the device? | ||
wire usb_pullup_detect = usb_pullupdp_d2p | usb_pullupdn_d2p; | ||
|
||
always_ff @(posedge clk_i or negedge rst_ni) begin | ||
if (!rst_ni) begin | ||
usb_pullupdp_d2p <= 1'b0; | ||
usb_pullupdn_d2p <= 1'b0; | ||
end else if (usb_sense_p2d && !usb_pullup_detect) begin | ||
// Is the FS device pulling DP high? | ||
if (usb_p === 1'b1) begin | ||
usb_pullupdp_d2p <= 1'b1; | ||
end | ||
// Is the FS device pulling DN high, implying that it has been configured | ||
// to perform pin-flipping? | ||
if (usb_n === 1'b1) begin | ||
usb_pullupdn_d2p <= 1'b1; | ||
end | ||
end | ||
end | ||
|
||
/////////////////////////////////////////////////////////////////////////// | ||
// Basic activity detection; DPI model indicates whether it is driving, | ||
// but for the device we must detect a departure from the bus Idle state | ||
/////////////////////////////////////////////////////////////////////////// | ||
logic usb_dp_en_d2p_last; | ||
logic usb_dn_en_d2p_last; | ||
logic usb_dp_en_d2p; | ||
logic usb_dn_en_d2p; | ||
|
||
always_comb begin | ||
usb_dp_en_d2p = usb_dp_en_d2p_last; | ||
usb_dn_en_d2p = usb_dn_en_d2p_last; | ||
// Detect transmission start of DPI or device | ||
if (usb_dp_en_p2d || (!usb_dp_en_d2p && usb_p != 1'b1)) begin | ||
usb_dp_en_d2p = !usb_dp_en_p2d; | ||
end | ||
if (usb_dn_en_p2d || (!usb_dn_en_d2p && usb_n != 1'b0)) begin | ||
usb_dn_en_d2p = !usb_dn_en_p2d; | ||
end | ||
end | ||
|
||
// Count of SE0 cycles (1/4 bit intervals). This is just an approximate | ||
// detection of EOP for the purpose of ascertaining when the device is | ||
// relinquishing the bus; it will also count during bus resets. | ||
logic [2:0] se0_cnt; | ||
always @(posedge clk_i or negedge rst_ni) begin | ||
if (!rst_ni) begin | ||
se0_cnt <= 'b0; | ||
end else if (usb_p === 1'b0 && usb_n === 1'b0) begin | ||
se0_cnt <= se0_cnt + 1'b1; | ||
end else begin | ||
se0_cnt <= 'b0; | ||
end | ||
end | ||
|
||
// Assume that the device is driving if the DPI model is not | ||
always_ff @(posedge clk_i or negedge rst_ni) begin | ||
if (!rst_ni) begin | ||
usb_dp_en_d2p_last <= 1'b0; | ||
usb_dn_en_d2p_last <= 1'b0; | ||
end else if (usb_sense_p2d & usb_pullup_detect) begin | ||
// Detect the end of EOP when the device has been transmitting | ||
if (&{usb_dp_en_d2p_last, se0_cnt}) begin | ||
usb_dp_en_d2p_last <= 1'b0; | ||
end else begin | ||
usb_dp_en_d2p_last <= usb_dp_en_d2p; | ||
end | ||
// Detect the end of EOP when the device has been transmitting | ||
if ({usb_dn_en_d2p_last, se0_cnt}) begin | ||
usb_dn_en_d2p_last <= 1'b0; | ||
end else begin | ||
usb_dn_en_d2p_last <= usb_dn_en_d2p; | ||
end | ||
end | ||
end | ||
|
||
// USB DPI | ||
usbdpi u_usbdpi ( | ||
.clk_i (clk_i), | ||
.rst_ni (rst_ni), | ||
.clk_48MHz_i (clk_i), | ||
|
||
.sense_p2d (usb_sense_p2d), | ||
.pullupdp_d2p (usb_pullupdp_d2p), | ||
.pullupdn_d2p (usb_pullupdn_d2p), | ||
|
||
.dp_en_p2d (usb_dp_en_p2d), | ||
.dp_p2d (usb_dp_p2d), | ||
.dp_d2p (usb_p), | ||
.dp_en_d2p (usb_dp_en_d2p), | ||
|
||
.dn_en_p2d (usb_dn_en_p2d), | ||
.dn_p2d (usb_dn_p2d), | ||
.dn_d2p (usb_n), | ||
.dn_en_d2p (usb_dn_en_d2p), | ||
|
||
// ASIC communicates via true differential signaling | ||
.d_p2d (), | ||
.d_d2p (1'b0), // not used | ||
.d_en_d2p (1'b0), | ||
.se0_d2p (1'b0), // not used | ||
.rx_enable_d2p (1'b0), | ||
.tx_use_d_se0_d2p(1'b0) | ||
); | ||
|
||
endmodule |
Oops, something went wrong.