2021-08-24 11:20:50 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2021-03-11 07:50:05 -05:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/semphr.h"
|
|
|
|
#include "unity.h"
|
2024-05-06 17:17:16 -04:00
|
|
|
#include "mock_msc.h"
|
|
|
|
#include "mock_hid.h"
|
2021-03-11 07:50:05 -05:00
|
|
|
#include "test_hcd_common.h"
|
|
|
|
|
|
|
|
// --------------------------------------------------- Test Cases ------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
2021-06-09 09:49:08 -04:00
|
|
|
Test HCD interrupt pipe URBs
|
2021-03-11 07:50:05 -05:00
|
|
|
Purpose:
|
|
|
|
- Test that an interrupt pipe can be created
|
2021-06-09 09:49:08 -04:00
|
|
|
- URBs can be created and enqueued to the interrupt pipe
|
|
|
|
- Interrupt pipe returns HCD_PIPE_EVENT_URB_DONE
|
|
|
|
- Test that URBs can be aborted when enqueued
|
2021-03-11 07:50:05 -05:00
|
|
|
|
|
|
|
Procedure:
|
|
|
|
- Setup HCD and wait for connection
|
|
|
|
- Allocate default pipe and enumerate the device
|
2021-06-09 09:49:08 -04:00
|
|
|
- Setup interrupt pipe and allocate URBs
|
|
|
|
- Enqueue URBs, expect HCD_PIPE_EVENT_URB_DONE, and requeue
|
2021-03-11 07:50:05 -05:00
|
|
|
- Stop after fixed number of iterations
|
2021-06-09 09:49:08 -04:00
|
|
|
- Deallocate URBs
|
2021-03-11 07:50:05 -05:00
|
|
|
- Teardown
|
|
|
|
|
|
|
|
Note: Some mice will NAK until it is moved, so try moving the mouse around if this test case gets stuck.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define TEST_HID_DEV_SPEED USB_SPEED_LOW
|
2021-06-09 09:49:08 -04:00
|
|
|
#define NUM_URBS 3
|
2022-10-06 17:16:54 -04:00
|
|
|
#define URB_DATA_BUFF_SIZE MOCK_HID_MOUSE_INTR_IN_MPS
|
2021-06-09 09:49:08 -04:00
|
|
|
#define NUM_URB_ITERS (NUM_URBS * 100)
|
2021-03-11 07:50:05 -05:00
|
|
|
|
2022-10-06 17:16:54 -04:00
|
|
|
TEST_CASE("Test HCD interrupt pipe URBs", "[intr][low_speed]")
|
2021-03-11 07:50:05 -05:00
|
|
|
{
|
2024-05-06 17:17:16 -04:00
|
|
|
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); // Trigger a connection
|
2022-10-06 17:16:54 -04:00
|
|
|
TEST_ASSERT_EQUAL_MESSAGE(TEST_HID_DEV_SPEED, port_speed, "Connected device is not Low Speed!");
|
2024-05-06 17:17:16 -04:00
|
|
|
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)
|
2021-03-11 07:50:05 -05:00
|
|
|
|
2024-05-06 17:17:16 -04:00
|
|
|
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, 0, port_speed); // Create a default pipe (using a NULL EP descriptor)
|
2021-06-09 09:49:08 -04:00
|
|
|
uint8_t dev_addr = test_hcd_enum_device(default_pipe);
|
2021-03-11 07:50:05 -05:00
|
|
|
|
2024-05-06 17:17:16 -04:00
|
|
|
// Allocate interrupt pipe and URBS
|
2021-06-28 00:39:39 -04:00
|
|
|
hcd_pipe_handle_t intr_pipe = test_hcd_pipe_alloc(port_hdl, &mock_hid_mouse_in_ep_desc, dev_addr, port_speed);
|
2021-06-09 09:49:08 -04:00
|
|
|
urb_t *urb_list[NUM_URBS];
|
|
|
|
for (int i = 0; i < NUM_URBS; i++) {
|
|
|
|
urb_list[i] = test_hcd_alloc_urb(0, URB_DATA_BUFF_SIZE);
|
|
|
|
urb_list[i]->transfer.num_bytes = URB_DATA_BUFF_SIZE;
|
|
|
|
urb_list[i]->transfer.context = URB_CONTEXT_VAL;
|
2021-03-11 07:50:05 -05:00
|
|
|
}
|
|
|
|
|
2024-05-06 17:17:16 -04:00
|
|
|
// Enqueue URBs
|
2021-06-09 09:49:08 -04:00
|
|
|
for (int i = 0; i < NUM_URBS; i++) {
|
|
|
|
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(intr_pipe, urb_list[i]));
|
2021-03-11 07:50:05 -05:00
|
|
|
}
|
2021-06-09 09:49:08 -04:00
|
|
|
int iter_count = NUM_URB_ITERS;
|
|
|
|
for (iter_count = NUM_URB_ITERS; iter_count > 0; iter_count--) {
|
2024-05-06 17:17:16 -04:00
|
|
|
// Wait for an URB to be done
|
2021-06-09 09:49:08 -04:00
|
|
|
test_hcd_expect_pipe_event(intr_pipe, HCD_PIPE_EVENT_URB_DONE);
|
2024-05-06 17:17:16 -04:00
|
|
|
// Dequeue the URB and check results
|
2021-06-09 09:49:08 -04:00
|
|
|
urb_t *urb = hcd_urb_dequeue(intr_pipe);
|
2022-10-06 17:16:54 -04:00
|
|
|
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, urb->transfer.status, "Transfer NOT completed");
|
2021-06-09 09:49:08 -04:00
|
|
|
TEST_ASSERT_EQUAL(URB_CONTEXT_VAL, urb->transfer.context);
|
|
|
|
mock_hid_process_report((mock_hid_mouse_report_t *)urb->transfer.data_buffer, iter_count);
|
2024-05-06 17:17:16 -04:00
|
|
|
// Requeue URB
|
2021-06-09 09:49:08 -04:00
|
|
|
if (iter_count > NUM_URBS) {
|
|
|
|
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(intr_pipe, urb));
|
2021-03-11 07:50:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-06 17:17:16 -04:00
|
|
|
// Free URB list and pipe
|
2021-06-09 09:49:08 -04:00
|
|
|
for (int i = 0; i < NUM_URBS; i++) {
|
|
|
|
test_hcd_free_urb(urb_list[i]);
|
2021-03-11 07:50:05 -05:00
|
|
|
}
|
|
|
|
test_hcd_pipe_free(intr_pipe);
|
|
|
|
test_hcd_pipe_free(default_pipe);
|
2024-05-06 17:17:16 -04:00
|
|
|
// Clearnup
|
2021-03-11 07:50:05 -05:00
|
|
|
test_hcd_wait_for_disconn(port_hdl, false);
|
|
|
|
}
|