Skip to content

Commit 3cd4cc8

Browse files
feat(usb_host): Apply review comments, add dconn test
1 parent 025f3a1 commit 3cd4cc8

File tree

13 files changed

+120
-32
lines changed

13 files changed

+120
-32
lines changed

host/usb/include/usb/usb_host.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ typedef enum {
5353
} usb_host_client_event_t;
5454

5555
/**
56-
* @brief USB Host lib power management
56+
* @brief USB Host lib power management timer type
5757
*/
5858
typedef enum {
5959
USB_HOST_LIB_PM_SUSPEND_ONE_SHOT, /**< USB Host lib power management -> Auto suspend one-shot timer */
@@ -292,25 +292,26 @@ esp_err_t usb_host_lib_root_port_suspend(void);
292292
esp_err_t usb_host_lib_root_port_resume(void);
293293

294294
/**
295-
* @brief Set auto power management timer (auto suspend/resume)
295+
* @brief Set auto power management timer
296296
*
297-
* - The function sets the auto suspend (resume) timer, used for global suspend (resume) of the root port
298-
* - The timer is a one-shot timer which expires after the set period, only if there is no activity on the USB Bus
297+
* - The function sets the auto suspend timer, used for global suspend of the root port
298+
* - The timer is either one-shot or periodic
299+
* - The timerexpires after the set period, only if there is no activity on the USB Bus
299300
* - The timer resets (if enabled) every time, the usb_host_client_handle_events() handles any client events,
300-
* or the usb_host_lib_handle_events() handles any host lib events, thus checking any activity
301-
* on all the registered clients or inside the host lib
301+
* or the usb_host_lib_handle_events() handles any host lib events, thus checking any activity on all the
302+
* registered clients or inside the host lib
302303
* - Once the timer expires, an auto_pm_timer_cb() is called, which delivers USB Host lib event flags
303304
*
304-
* @note set the timer interval to 0, to disable the timer (in case NO auto suspend (resume) functionality is required)
305+
* @note set the timer interval to 0, to disable the timer (in case NO auto suspend functionality is required anymore)
305306
* @note this function is not ISR safe
306-
* @param[in] pm_action Power management action (Suspend/Resume)
307-
* @param[in] auto_pm_interval_ms Interval after which the automatic suspend (resume) occurs (0 to disable)
307+
* @param[in] timer_type Power management timer type (periodic/one-shot)
308+
* @param[in] timer_interval_ms Interval after which a usb_host lib event flag is delivered (0 to disable running timer)
308309
* @return
309310
* - ESP_OK: Timer set or stopped
310311
* - ESP_ERR_INVALID_STATE: USB Host lib is not installed
311312
* - ESP_FAIL: Timer was not configured correctly
312313
*/
313-
esp_err_t usb_host_lib_set_auto_pm(usb_host_lib_pm_t pm_action, size_t auto_pm_interval_ms);
314+
esp_err_t usb_host_lib_set_auto_pm(usb_host_lib_pm_t timer_type, size_t timer_interval_ms);
314315

315316
// ------------------------------------------------ Client Functions ---------------------------------------------------
316317

host/usb/private_include/hub.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ esp_err_t hub_uninstall(void);
112112
* @note This function should only be called from the Host Library task
113113
*
114114
* @return
115-
* - ESP_OK: Hub driver started successfully
115+
* - ESP_OK: Root port has been powered on
116116
* - ESP_ERR_INVALID_STATE: Hub driver is not installed, or root port is in other state than not powered
117117
*/
118118
esp_err_t hub_root_start(void);
@@ -123,7 +123,7 @@ esp_err_t hub_root_start(void);
123123
* This will power OFF the root port
124124
*
125125
* @return
126-
* - ESP_OK: Hub driver stopped successfully
126+
* - ESP_OK: Root port has been powered off
127127
* - ESP_ERR_INVALID_STATE: Hub driver is not installed, or root port is in not powered state
128128
*/
129129
esp_err_t hub_root_stop(void);

host/usb/src/hcd_dwc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,13 +1337,15 @@ static esp_err_t _port_cmd_bus_suspend(port_t *port)
13371337
HCD_ENTER_CRITICAL();
13381338

13391339
if (port->state != HCD_PORT_STATE_SUSPENDING) {
1340+
// Port state unexpectedly changed
13401341
ret = ESP_ERR_INVALID_RESPONSE;
13411342
goto exit;
13421343
}
13431344

13441345
// Here we are calling ll directly instead of hal, to allow the suspend/resume feature to be used as a managed usb
13451346
// component in all active IDF releases (Currently IDF 5.4.x, IDF 5.5.x and IDF 6.0) and all it's minor releases
13461347
// because the hal function usb_dwc_hal_port_check_if_suspended(port->hal) starts to be supported in IDF 5.5.2, (and IDF 5.4.2)
1348+
// TODO: use usb_dwc_hal_hprt_get_port_suspend() instead of usb_dwc_ll_hprt_get_port_suspend() when IDF 5.5 is EOL
13471349

13481350
// Sanity check, the root port should have entered the suspended state after the SUSPEND_ENTRY_MS delay
13491351
if (!usb_dwc_ll_hprt_get_port_suspend(port->hal->dev)) {

host/usb/src/usb_host.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ typedef struct {
159159
struct {
160160
SemaphoreHandle_t event_sem;
161161
SemaphoreHandle_t mux_lock;
162-
TimerHandle_t auto_pm_timer; // Freertos timer used for automatic suspend/resume
162+
TimerHandle_t auto_pm_timer; // Freertos timer used for automatic power management
163163
usb_phy_handle_t phy_handle; // Will be NULL if host library is installed with skip_phy_setup
164164
void *enum_client; // Pointer to Enum driver (acting as a client). Used to reroute completed USBH control transfers
165165
void *hub_client; // Pointer to External Hub driver (acting as a client). Used to reroute completed USBH control transfers. NULL, when External Hub Driver not available.
@@ -928,7 +928,7 @@ esp_err_t usb_host_lib_root_port_resume(void)
928928
return ret;
929929
}
930930

931-
esp_err_t usb_host_lib_set_auto_pm(usb_host_lib_pm_t pm_action, size_t auto_pm_interval_ms)
931+
esp_err_t usb_host_lib_set_auto_pm(usb_host_lib_pm_t timer_type, size_t timer_interval_ms)
932932
{
933933
HOST_ENTER_CRITICAL();
934934
HOST_CHECK_FROM_CRIT(p_host_lib_obj != NULL, ESP_ERR_INVALID_STATE);
@@ -937,7 +937,7 @@ esp_err_t usb_host_lib_set_auto_pm(usb_host_lib_pm_t pm_action, size_t auto_pm_i
937937
TimerHandle_t suspend_tmr = p_host_lib_obj->constant.auto_pm_timer;
938938

939939
// Interval is 0, stop the timer
940-
if (auto_pm_interval_ms == 0) {
940+
if (timer_interval_ms == 0) {
941941
if (xTimerIsTimerActive(suspend_tmr) == pdTRUE) {
942942
ESP_RETURN_ON_FALSE(xTimerStop(suspend_tmr, portMAX_DELAY), ESP_FAIL, USB_HOST_TAG, "Timer could not be stopped");
943943
}
@@ -946,7 +946,7 @@ esp_err_t usb_host_lib_set_auto_pm(usb_host_lib_pm_t pm_action, size_t auto_pm_i
946946
}
947947

948948
// Set timer reload mode: One-Shot or periodic
949-
switch (pm_action) {
949+
switch (timer_type) {
950950
case USB_HOST_LIB_PM_SUSPEND_ONE_SHOT:
951951
vTimerSetReloadMode(suspend_tmr, pdFALSE);
952952
break;
@@ -958,11 +958,11 @@ esp_err_t usb_host_lib_set_auto_pm(usb_host_lib_pm_t pm_action, size_t auto_pm_i
958958
}
959959

960960
// Change the timer period, this also starts the timer if stopped
961-
ESP_RETURN_ON_FALSE(xTimerChangePeriod(suspend_tmr, pdMS_TO_TICKS(auto_pm_interval_ms), portMAX_DELAY),
961+
ESP_RETURN_ON_FALSE(xTimerChangePeriod(suspend_tmr, pdMS_TO_TICKS(timer_interval_ms), portMAX_DELAY),
962962
ESP_FAIL, USB_HOST_TAG, "Timer period could not be changed");
963963

964964
ESP_LOGD(USB_HOST_TAG, "Auto suspend timer set to %d ms, %s mode and started",
965-
auto_pm_interval_ms, ((pm_action == USB_HOST_LIB_PM_SUSPEND_ONE_SHOT) ? ("One-Shot") : ("Periodic")));
965+
timer_interval_ms, ((timer_type == USB_HOST_LIB_PM_SUSPEND_ONE_SHOT) ? ("One-Shot") : ("Periodic")));
966966

967967
return ESP_OK;
968968
}

host/usb/src/usbh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ static inline void handle_prop_resume_event(device_t *dev_obj)
633633

634634
static inline void handle_prop_all_idle_event(void)
635635
{
636-
ESP_LOGD(USBH_TAG, "ALl devices idle");
636+
ESP_LOGD(USBH_TAG, "All devices idle");
637637
usbh_event_data_t event_data = {
638638
.event = USBH_EVENT_ALL_IDLE,
639639
};

host/usb/test/target_test/common/dev_msc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -99,7 +99,7 @@ static const dev_msc_info_t dev_info = {
9999
.bInterfaceNumber = 0x00,
100100
.bAlternateSetting = 0x00,
101101
.in_ep_addr = 0x81,
102-
.out_up_addr = 0x02,
102+
.out_ep_addr = 0x02,
103103
.scsi_sector_size = 512,
104104
};
105105

host/usb/test/target_test/common/dev_msc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -34,7 +34,7 @@ typedef struct {
3434
uint8_t bInterfaceNumber;
3535
uint8_t bAlternateSetting;
3636
uint8_t in_ep_addr;
37-
uint8_t out_up_addr;
37+
uint8_t out_ep_addr;
3838
unsigned int scsi_sector_size;
3939
} dev_msc_info_t;
4040

host/usb/test/target_test/usb_host/main/msc_client_async_dconn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void msc_client_async_dconn_task(void *arg)
234234
msc_obj.dev_info->scsi_sector_size,
235235
msc_obj.test_param.msc_scsi_xfer_tag);
236236
xfer_out->num_bytes = sizeof(mock_msc_bulk_cbw_t);
237-
xfer_out->bEndpointAddress = msc_obj.dev_info->out_up_addr;
237+
xfer_out->bEndpointAddress = msc_obj.dev_info->out_ep_addr;
238238
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_submit(xfer_out));
239239
// Next stage set from transfer callback
240240
break;

host/usb/test/target_test/usb_host/main/msc_client_async_seq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void msc_client_async_seq_task(void *arg)
236236
msc_obj.dev_info->scsi_sector_size,
237237
msc_obj.test_param.msc_scsi_xfer_tag);
238238
xfer_out->num_bytes = sizeof(mock_msc_bulk_cbw_t);
239-
xfer_out->bEndpointAddress = msc_obj.dev_info->out_up_addr;
239+
xfer_out->bEndpointAddress = msc_obj.dev_info->out_ep_addr;
240240
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_submit(xfer_out));
241241
// Test that an inflight transfer cannot be resubmitted
242242
TEST_ASSERT_EQUAL(ESP_ERR_NOT_FINISHED, usb_host_transfer_submit(xfer_out));

host/usb/test/target_test/usb_host/main/msc_client_suspend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void msc_client_async_suspend_resume_task(void *arg)
318318
msc_obj.dev_info->scsi_sector_size,
319319
msc_obj.test_param.msc_scsi_xfer_tag);
320320
xfer_out->num_bytes = sizeof(mock_msc_bulk_cbw_t);
321-
xfer_out->bEndpointAddress = msc_obj.dev_info->out_up_addr;
321+
xfer_out->bEndpointAddress = msc_obj.dev_info->out_ep_addr;
322322
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_submit(xfer_out));
323323
// Next stage set from transfer callback
324324
break;

0 commit comments

Comments
 (0)