22 #include "sw/device/lib/base/status.h"
29 #include "sw/device/lib/testing/pinmux_testutils.h"
30 #include "sw/device/lib/testing/test_framework/check.h"
33 #define USBDEV_BASE_ADDR TOP_EARLGREY_USBDEV_BASE_ADDR
38 static dif_usbdev_t usbdev;
44 static dif_pinmux_t pinmux;
48 static status_t config_set(
bool pinflip) {
63 static status_t vbus_wait(
bool expected, uint32_t timeout_micros) {
69 if (vbus == expected) {
74 return DEADLINE_EXCEEDED();
79 static status_t line_wait(
bool dp,
bool expected, uint32_t timeout_micros) {
86 if ((dp &&
status.rx_dp == expected) || (!dp &&
status.rx_dn == expected)) {
91 return DEADLINE_EXCEEDED();
111 return DEADLINE_EXCEEDED();
116 static status_t delay(
bool prompt, uint32_t timeout_micros) {
125 OTTF_DEFINE_TEST_CONFIG();
131 uint32_t timeout_micros = 1500u;
132 uint32_t delay_micros = 1u;
137 timeout_micros = 30 * 1000 * 1000u;
140 delay_micros = 2 * 1000 * 1000u;
143 LOG_INFO(
"Running USBDEV_SETUPRX test");
147 CHECK_DIF_OK(dif_pinmux_init(
149 pinmux_testutils_init(&pinmux);
157 CHECK_STATUS_OK(config_set(
false));
167 LOG_INFO(
"Connect or power up the USB");
172 CHECK_STATUS_OK(vbus_wait(
true, timeout_micros));
176 CHECK_STATUS_OK(delay(prompt, delay_micros));
184 const uint8_t endpoint = 0u;
193 ep_id.
direction = USBDEV_ENDPOINT_DIR_OUT;
200 CHECK_STATUS_OK(line_wait(
true,
true, 1000u));
209 CHECK_STATUS_OK(packet_wait(&info, &buffer, timeout_micros));
215 "Received packet does not have the expected properties; expecting the "
216 "start of a Control Transfer from the host.");
218 uint8_t packet[USBDEV_MAX_PACKET_SIZE];
221 sizeof(packet), &written));
222 CHECK(written == info.
length,
"Packet data is not of the expected length.");
223 CHECK(packet[0] == 0x80u,
"bmRequestType field not as expected");
242 CHECK_STATUS_OK(line_wait(
true,
false, 1000u));