26 #include "sw/device/lib/base/status.h"
32 #include "sw/device/lib/testing/pinmux_testutils.h"
33 #include "sw/device/lib/testing/test_framework/check.h"
36 #define USBDEV_BASE_ADDR TOP_EARLGREY_USBDEV_BASE_ADDR
42 static const bool kCheckLowFirst =
false;
47 static dif_usbdev_t usbdev;
53 static dif_pinmux_t pinmux;
57 static status_t config_set(
bool pinflip) {
72 static status_t vbus_wait(
bool expected, uint32_t timeout_micros) {
78 if (vbus == expected) {
88 static status_t line_wait(
bool dp,
bool expected, uint32_t timeout_micros) {
95 if ((dp &&
status.rx_dp == expected) || (!dp &&
status.rx_dn == expected)) {
100 return UNAVAILABLE();
105 static status_t delay(
bool prompt, uint32_t timeout_micros) {
114 OTTF_DEFINE_TEST_CONFIG();
119 uint32_t timeout_micros = 1000u;
120 uint32_t delay_micros = 1u;
121 bool can_flip =
true;
126 timeout_micros = 30 * 1000 * 1000u;
129 delay_micros = 2 * 1000 * 1000u;
138 CHECK_DIF_OK(dif_pinmux_init(
140 pinmux_testutils_init(&pinmux);
152 CHECK_STATUS_OK(config_set(!dp));
156 if (kCheckLowFirst) {
161 LOG_INFO(
"Disconnect or power down the USB");
165 CHECK_STATUS_OK(vbus_wait(
false, timeout_micros));
168 LOG_INFO(
"Connect or power up the USB");
173 CHECK_STATUS_OK(vbus_wait(
true, timeout_micros));
176 CHECK_STATUS_OK(line_wait(dp,
false, 1000u));
180 CHECK_STATUS_OK(delay(prompt, delay_micros));
186 CHECK_STATUS_OK(line_wait(dp,
true, 1000u));
191 CHECK_STATUS_OK(delay(prompt, delay_micros));
197 CHECK_STATUS_OK(line_wait(dp,
false, 1000u));
201 }
while (can_flip && !dp);