34 #include "sw/device/lib/testing/pinmux_testutils.h"
35 #include "sw/device/lib/testing/test_framework/check.h"
37 #include "sw/device/lib/testing/usb_testutils.h"
38 #include "sw/device/lib/testing/usb_testutils_controlep.h"
39 #include "sw/device/lib/testing/usb_testutils_diags.h"
40 #include "sw/device/lib/testing/usb_testutils_streams.h"
46 #define NUM_STREAMS USBUTILS_STREAMS_MAX
49 #define TRANSFER_BYTES_SILICON (4U << 20)
50 #define TRANSFER_BYTES_FPGA (8U << 16)
53 #define TRANSFER_BYTES_VERILATOR 0x2400U
56 #define TRANSFER_BYTES_DVSIM 0x800U
61 static const char *xfr_name[] = {
73 static const usb_testutils_transfer_type_t xfr_types[USBUTILS_STREAMS_MAX] = {
74 kUsbTransferTypeIsochronous, kUsbTransferTypeBulk,
75 kUsbTransferTypeBulk, kUsbTransferTypeBulk,
77 kUsbTransferTypeIsochronous, kUsbTransferTypeInterrupt,
78 kUsbTransferTypeBulk, kUsbTransferTypeBulk,
80 kUsbTransferTypeInterrupt, kUsbTransferTypeBulk,
85 #define CFG_DSCR_TOTAL_LEN \
87 NUM_STREAMS * (USB_INTERFACE_DSCR_LEN + 2 * USB_EP_DSCR_LEN))
92 static uint8_t config_descriptors[CFG_DSCR_TOTAL_LEN] = {
93 USB_CFG_DSCR_HEAD(CFG_DSCR_TOTAL_LEN, NUM_STREAMS)
100 static usbdev_stream_flags_t test_flags;
105 static uint8_t test_descriptor[USB_TESTUTILS_TEST_DSCR_LEN];
116 static dif_pinmux_t pinmux;
128 static const bool kVerbose =
false;
136 static const bool kSending =
true;
141 static const bool kGenerating =
true;
147 static const bool kRetrying =
true;
152 static const bool kRecving =
true;
159 static const bool kMaxPackets =
false;
164 static const unsigned nstreams = NUM_STREAMS;
166 OTTF_DEFINE_TEST_CONFIG();
172 LOG_INFO(
"Running USBDEV MIXED Test");
178 uint32_t transfer_bytes = TRANSFER_BYTES_FPGA;
181 transfer_bytes = TRANSFER_BYTES_VERILATOR;
184 transfer_bytes = TRANSFER_BYTES_DVSIM;
187 transfer_bytes = TRANSFER_BYTES_SILICON;
195 transfer_bytes = (transfer_bytes + nstreams - 1) / nstreams;
196 LOG_INFO(
" - %u stream(s), 0x%x bytes each", nstreams, transfer_bytes);
198 CHECK_DIF_OK(dif_pinmux_init(
200 pinmux_testutils_init(&pinmux);
206 test_flags = (kSending ? kUsbdevStreamFlagRetrieve : 0U) |
207 (kGenerating ? kUsbdevStreamFlagCheck : 0U) |
208 (kRetrying ? kUsbdevStreamFlagRetry : 0U) |
209 (kRecving ? kUsbdevStreamFlagSend : 0U) |
211 (kMaxPackets ? kUsbdevStreamFlagMaxPackets : 0U);
219 CHECK_STATUS_OK(usb_testutils_init(ctx->
usbdev,
false,
227 uint32_t mixed_types = 0U;
228 uint8_t *cfg = &config_descriptors[USB_CFG_DSCR_LEN];
229 for (uint8_t s = 0U; s < nstreams; s++) {
230 usb_testutils_transfer_type_t xfr_type = xfr_types[s];
233 mixed_types |= xfr_type << (s * 2U);
239 uint8_t ep_in = (uint8_t)(s + 1U);
240 uint8_t ep_out = (uint8_t)(s + 1U);
243 uint8_t bInterval = (xfr_type == kUsbTransferTypeIsochronous ||
244 xfr_type == kUsbTransferTypeInterrupt);
247 uint8_t int_dscr[USB_INTERFACE_DSCR_LEN + 2 * USB_EP_DSCR_LEN] = {
248 VEND_INTERFACE_DSCR(s, 2, 0x50, 1),
249 USB_EP_DSCR(0, ep_out, (uint8_t)xfr_type, USBDEV_MAX_PACKET_SIZE,
251 USB_EP_DSCR(1, ep_in, (uint8_t)xfr_type, USBDEV_MAX_PACKET_SIZE,
255 memcpy(cfg, int_dscr,
sizeof(int_dscr));
256 cfg +=
sizeof(int_dscr);
258 CHECK_STATUS_OK(usb_testutils_stream_init(
259 ctx, s, xfr_type, ep_in, ep_out, transfer_bytes, test_flags, kVerbose));
260 LOG_INFO(
"S%u: IN %u:OUT %u : %s - 0x%x bytes flags 0x%x", s, ep_in, ep_out,
261 xfr_name[xfr_type], transfer_bytes, test_flags);
265 CHECK(usb_testutils_streams_count_set(ctx, nstreams));
269 const uint8_t desc[] = {USB_TESTUTILS_TEST_DSCR(
270 kUsbTestNumberMixed, NUM_STREAMS | (uint8_t)test_flags,
271 (uint8_t)mixed_types, (uint8_t)(mixed_types >> 8),
272 (uint8_t)(mixed_types >> 16))};
273 memcpy(test_descriptor, desc,
sizeof(test_descriptor));
277 CHECK_STATUS_OK(usb_testutils_controlep_init(
278 &usbdev_control, ctx->
usbdev, 0, config_descriptors,
279 sizeof(config_descriptors), test_descriptor,
sizeof(test_descriptor)));
284 usb_testutils_controlep_config_wait(&usbdev_control, &usbdev));
286 USBUTILS_USER_PROMPT(
"Start host-side streaming software");
292 CHECK_STATUS_OK(usb_testutils_streams_service(ctx));
295 done = usb_testutils_streams_completed(ctx);
299 uint32_t tx_bytes = 0U;
300 uint32_t rx_bytes = 0U;
301 for (uint8_t s = 0U; s < nstreams; s++) {
303 CHECK_STATUS_OK(usb_testutils_stream_status(ctx, s, NULL, &tx, &rx));
308 LOG_INFO(
"USB sent 0x%x byte(s), received and checked 0x%x byte(s)", tx_bytes,
314 CHECK(tx_bytes >= nstreams * transfer_bytes,
315 "Unexpected count of byte(s) sent to USB host");
318 CHECK(rx_bytes >= nstreams * transfer_bytes,
319 "Unexpected count of byte(s) received from USB host");