Skip to content

Commit eb36bd2

Browse files
feat(usb_host): Mutex acquire early bail
1 parent dee8594 commit eb36bd2

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

host/usb/private_include/usbh.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ void usbh_devs_set_pm_actions_all(usbh_dev_ctrl_t device_ctrl);
328328
* - ESP_OK: All devices flush/halt successful
329329
* - ESP_ERR_INVALID_STATE: USBH driver is not installed
330330
* - ESP_ERR_INVALID_SIZE: Too many devices connected for synchronous handling
331+
* - ESP_ERR_NOT_FINISHED: usb host lib busy, mutex to process the EPs can't be acquired. We bail the auto-suspend
332+
* operation in favor of a low latency to enter light sleep.
331333
*/
332334
esp_err_t usbh_devs_halt_flush_all_sync(void);
333335
#endif // AUTO_PM_LIGHT_SLEEP

host/usb/src/usbh.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,11 @@ esp_err_t usbh_devs_halt_flush_all_sync(void)
11201120
{
11211121
esp_err_t ret;
11221122
USBH_CHECK(p_usbh_obj != NULL, ESP_ERR_INVALID_STATE);
1123-
xSemaphoreTake(p_usbh_obj->constant.mux_lock, portMAX_DELAY);
1123+
1124+
// Try to acquire mutex, if busy, bail the auto supend in favour of low latency to enter the light sleep
1125+
if (xSemaphoreTake(p_usbh_obj->constant.mux_lock, 0) != pdTRUE) {
1126+
return ESP_ERR_NOT_FINISHED;
1127+
}
11241128

11251129
ESP_GOTO_ON_FALSE(p_usbh_obj->mux_protected.num_device <= USBH_MAX_SYNC_DEVS_HANDLED, ESP_ERR_INVALID_SIZE,
11261130
unlock, USBH_TAG, "Too many devices for synchronous handling");

0 commit comments

Comments
 (0)