Skip to content

Commit 10c3138

Browse files
Merge pull request #333 from espressif/refactor/usb_host_auto_suspend_timer_api_rename
Refactor(usb_host): Rename auto suspend timer public API
2 parents b621ba3 + 3670dbd commit 10c3138

File tree

7 files changed

+227
-227
lines changed

7 files changed

+227
-227
lines changed

host/class/cdc/usb_host_cdc_acm/test_app/main/test_cdc_acm_host.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -906,14 +906,14 @@ TEST_CASE("suspend_resume_multiple_devs", "[cdc_acm]")
906906
vTaskDelay(20); // Short delay to allow task to be cleaned up
907907
}
908908

909-
#define TEST_CDC_ACM_PM_TIMER_INTERVAL_MS 1000
910-
#define TEST_CDC_ACM_PM_TIMER_MARGIN_MS 50
909+
#define TEST_CDC_ACM_SUSPEND_TIMER_INTERVAL_MS 1000
910+
#define TEST_CDC_ACM_SUSPEND_TIMER_MARGIN_MS 50
911911
/**
912912
* @brief Test: Automatic suspend timer
913913
*
914-
* #. open the device, set One-Shot PM timer, expect one USB_HOST_CLIENT_EVENT_DEV_SUSPENDED event
915-
* #. Set Periodic PM timer, expect multiple USB_HOST_CLIENT_EVENT_DEV_SUSPENDED events
916-
* #. Disable Periodic PM timer, expect no event
914+
* #. open the device, set One-Shot auto suspend timer, expect one USB_HOST_CLIENT_EVENT_DEV_SUSPENDED event
915+
* #. Set Periodic auto suspend timer, expect multiple USB_HOST_CLIENT_EVENT_DEV_SUSPENDED events
916+
* #. Disable Periodic auto suspend timer, expect no event
917917
* #. disconnect the device
918918
* #. cleanup
919919
*/
@@ -932,23 +932,23 @@ TEST_CASE("automatic_suspend_timer", "[cdc_acm]")
932932
TEST_ASSERT_NOT_NULL(cdc_dev);
933933
vTaskDelay(10);
934934

935-
// Set One-Shot PM timer
936-
TEST_ASSERT_EQUAL(ESP_OK, usb_host_lib_set_auto_pm(USB_HOST_LIB_PM_SUSPEND_ONE_SHOT, TEST_CDC_ACM_PM_TIMER_INTERVAL_MS));
937-
wait_for_app_event(CDC_ACM_HOST_DEVICE_SUSPENDED, pdMS_TO_TICKS(TEST_CDC_ACM_PM_TIMER_INTERVAL_MS + TEST_CDC_ACM_PM_TIMER_MARGIN_MS));
935+
// Set One-Shot auto suspend timer
936+
TEST_ASSERT_EQUAL(ESP_OK, usb_host_lib_set_auto_suspend(USB_HOST_LIB_AUTO_SUSPEND_ONE_SHOT, TEST_CDC_ACM_SUSPEND_TIMER_INTERVAL_MS));
937+
wait_for_app_event(CDC_ACM_HOST_DEVICE_SUSPENDED, pdMS_TO_TICKS(TEST_CDC_ACM_SUSPEND_TIMER_INTERVAL_MS + TEST_CDC_ACM_SUSPEND_TIMER_MARGIN_MS));
938938

939939
// Manually resume the root port and expect the resumed event
940940
TEST_ASSERT_EQUAL(ESP_OK, usb_host_lib_root_port_resume());
941941
wait_for_app_event(CDC_ACM_HOST_DEVICE_RESUMED, 20);
942942

943943
// Make sure no event is delivered, since the timer is a One-Shot timer
944-
wait_for_no_app_event(pdMS_TO_TICKS(TEST_CDC_ACM_PM_TIMER_INTERVAL_MS * 2));
944+
wait_for_no_app_event(pdMS_TO_TICKS(TEST_CDC_ACM_SUSPEND_TIMER_INTERVAL_MS * 2));
945945

946-
// Set Periodic PM suspend timer
947-
TEST_ASSERT_EQUAL(ESP_OK, usb_host_lib_set_auto_pm(USB_HOST_LIB_PM_SUSPEND_PERIODIC, TEST_CDC_ACM_PM_TIMER_INTERVAL_MS));
946+
// Set Periodic auto suspend timer
947+
TEST_ASSERT_EQUAL(ESP_OK, usb_host_lib_set_auto_suspend(USB_HOST_LIB_AUTO_SUSPEND_PERIODIC, TEST_CDC_ACM_SUSPEND_TIMER_INTERVAL_MS));
948948

949949
for (int i = 0; i < 3; i++) {
950950
// Expect suspended event from auto suspend timer
951-
wait_for_app_event(CDC_ACM_HOST_DEVICE_SUSPENDED, pdMS_TO_TICKS(TEST_CDC_ACM_PM_TIMER_INTERVAL_MS + TEST_CDC_ACM_PM_TIMER_MARGIN_MS));
951+
wait_for_app_event(CDC_ACM_HOST_DEVICE_SUSPENDED, pdMS_TO_TICKS(TEST_CDC_ACM_SUSPEND_TIMER_INTERVAL_MS + TEST_CDC_ACM_SUSPEND_TIMER_MARGIN_MS));
952952

953953
// Resume the root port manually and expect the resume event
954954
TEST_ASSERT_EQUAL(ESP_OK, usb_host_lib_root_port_resume());
@@ -958,10 +958,10 @@ TEST_CASE("automatic_suspend_timer", "[cdc_acm]")
958958
TEST_ASSERT_EQUAL(ESP_OK, cdc_acm_host_data_tx_blocking(cdc_dev, tx_buf, sizeof(tx_buf), 1000));
959959
}
960960

961-
// Disable the Periodic PM timer
962-
TEST_ASSERT_EQUAL(ESP_OK, usb_host_lib_set_auto_pm(USB_HOST_LIB_PM_SUSPEND_PERIODIC, 0));
961+
// Disable the Periodic auto suspend timer
962+
TEST_ASSERT_EQUAL(ESP_OK, usb_host_lib_set_auto_suspend(USB_HOST_LIB_AUTO_SUSPEND_PERIODIC, 0));
963963
// Make sure no event is delivered
964-
wait_for_no_app_event(pdMS_TO_TICKS(TEST_CDC_ACM_PM_TIMER_INTERVAL_MS * 2));
964+
wait_for_no_app_event(pdMS_TO_TICKS(TEST_CDC_ACM_SUSPEND_TIMER_INTERVAL_MS * 2));
965965

966966
// Clean-up
967967
TEST_ASSERT_EQUAL(ESP_OK, cdc_acm_host_close(cdc_dev));

host/class/msc/usb_host_msc/test_app/main/test_msc.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -646,71 +646,71 @@ TEST_CASE("suspend_resume", "[usb_msc]")
646646
msc_teardown();
647647
}
648648

649-
#define MSC_TEST_PM_TIMER_INTERVAL_MS 1000
650-
#define MSC_TEST_PM_TIMER_MARGIN_MS 50
649+
#define MSC_TEST_SUSPEND_TIMER_INTERVAL_MS 1000
650+
#define MSC_TEST_SUSPEND_TIMER_MARGIN_MS 50
651651
/**
652-
* @brief USB MSC driver with the Power Management timer
652+
* @brief USB MSC driver with the automatic suspend timer timer
653653
*
654654
* Purpose:
655-
* - Test One-Shot and Periodic PM timer for global Suspend of the root port with MSC Driver
655+
* - Test One-Shot and Periodic auto suspend timer for global Suspend of the root port with MSC Driver
656656
*
657657
* Procedure:
658658
* - Install USB Host lib, Install MSC driver, open a device, register VFS
659-
* - Set One-Shot PM timer to 1000ms
659+
* - Set One-Shot auto suspend timer to 1000ms
660660
* - Simulate some USB traffic by reading/writing a file multiple times and regularly check that no USB_HOST_LIB event is delivered
661661
* - Once all the traffic is idle, verify the MSC_DEVICE_SUSPENDED event is delivered
662662
* - Measure time from issuing automatic suspend until the suspend event delivery
663-
- Set Periodic PM timer and periodically check for MSC_DEVICE_SUSPENDED event, manually resume the device and verify device functionality
664-
* - Disable the Periodic PM timer it and make sure no other event is delivered
663+
- Set Periodic auto suspend timer and periodically check for MSC_DEVICE_SUSPENDED event, manually resume the device and verify device functionality
664+
* - Disable the Periodic auto suspend timer and make sure no other event is delivered
665665
* - Teardown
666666
*/
667667
TEST_CASE("auto_suspend_timer", "[usb_msc]")
668668
{
669669
msc_setup();
670670

671-
// Set One-Shot PM suspend timer and start measuring ticks
672-
ESP_OK_ASSERT(usb_host_lib_set_auto_pm(USB_HOST_LIB_PM_SUSPEND_ONE_SHOT, MSC_TEST_PM_TIMER_INTERVAL_MS));
673-
TickType_t auto_pm_suspend_tick_start = xTaskGetTickCount();
671+
// Set One-Shot auto suspend timer and start measuring ticks
672+
ESP_OK_ASSERT(usb_host_lib_set_auto_suspend(USB_HOST_LIB_AUTO_SUSPEND_ONE_SHOT, MSC_TEST_SUSPEND_TIMER_INTERVAL_MS));
673+
TickType_t auto_suspend_tick_start = xTaskGetTickCount();
674674
msc_host_event_t peek_event, expected_event;
675675

676-
// Simulate some traffic, so the root port would not suspend after MSC_TEST_PM_TIMER_INTERVAL_MS from now,
677-
// but after MSC_TEST_PM_TIMER_INTERVAL_MS, once there is no traffic
676+
// Simulate some traffic, so the root port would not suspend after MSC_TEST_SUSPEND_TIMER_INTERVAL_MS from now,
677+
// but after MSC_TEST_SUSPEND_TIMER_INTERVAL_MS, once there is no traffic
678678
// Regularly check, that there is no item in queue (check that the timer did not expire)
679679
for (int i = 0; i < 5; i++) {
680680
write_read_file(FILE_NAME);
681681
TEST_ASSERT_EQUAL(pdFALSE, xQueuePeek(app_queue, &peek_event, 0));
682682
}
683683

684-
// Expect MSC device to be suspended, expect app queue and block for MSC_TEST_PM_TIMER_INTERVAL_MS + some margin
684+
// Expect MSC device to be suspended, expect app queue and block for MSC_TEST_SUSPEND_TIMER_INTERVAL_MS + some margin
685685
expected_event.event = MSC_DEVICE_SUSPENDED;
686-
wait_for_app_event(&expected_event, pdMS_TO_TICKS(MSC_TEST_PM_TIMER_INTERVAL_MS + MSC_TEST_PM_TIMER_MARGIN_MS));
686+
wait_for_app_event(&expected_event, pdMS_TO_TICKS(MSC_TEST_SUSPEND_TIMER_INTERVAL_MS + MSC_TEST_SUSPEND_TIMER_MARGIN_MS));
687687

688-
TickType_t auto_pm_suspend_tick_end = xTaskGetTickCount(); // App event received, stop measuring ticks
689-
const uint32_t elapsed_ms = (auto_pm_suspend_tick_end - auto_pm_suspend_tick_start) * portTICK_PERIOD_MS;
688+
TickType_t auto_suspend_tick_end = xTaskGetTickCount(); // App event received, stop measuring ticks
689+
const uint32_t elapsed_ms = (auto_suspend_tick_end - auto_suspend_tick_start) * portTICK_PERIOD_MS;
690690

691691
// Check that, the time elapsed between setting the auto suspend timer and MSC_DEVICE_SUSPENDED event
692-
// is more than MSC_TEST_PM_TIMER_INTERVAL_MS + some margin
692+
// is more than MSC_TEST_SUSPEND_TIMER_INTERVAL_MS + some margin
693693
TEST_ASSERT_GREATER_THAN_UINT32_MESSAGE(
694-
MSC_TEST_PM_TIMER_INTERVAL_MS + MSC_TEST_PM_TIMER_MARGIN_MS, elapsed_ms,
694+
MSC_TEST_SUSPEND_TIMER_INTERVAL_MS + MSC_TEST_SUSPEND_TIMER_MARGIN_MS, elapsed_ms,
695695
"Auto suspend timer did not expire on time"
696696
);
697697

698698
// Make sure that no event is delivered, since we set the timer to be One-Shot
699-
wait_for_app_event(NULL, pdMS_TO_TICKS(MSC_TEST_PM_TIMER_INTERVAL_MS * 2));
699+
wait_for_app_event(NULL, pdMS_TO_TICKS(MSC_TEST_SUSPEND_TIMER_INTERVAL_MS * 2));
700700

701701
// Resume the root port manually and expect the resume event
702702
ESP_OK_ASSERT(usb_host_lib_root_port_resume());
703703
expected_event.event = MSC_DEVICE_RESUMED;
704704
wait_for_app_event(&expected_event, 20);
705705

706-
// Set Periodic PM suspend timer
707-
ESP_OK_ASSERT(usb_host_lib_set_auto_pm(USB_HOST_LIB_PM_SUSPEND_PERIODIC, MSC_TEST_PM_TIMER_INTERVAL_MS));
706+
// Set Periodic auto suspend timer
707+
ESP_OK_ASSERT(usb_host_lib_set_auto_suspend(USB_HOST_LIB_AUTO_SUSPEND_PERIODIC, MSC_TEST_SUSPEND_TIMER_INTERVAL_MS));
708708

709709
for (int i = 0; i < 3; i++) {
710710

711711
// Expect suspended event from auto suspend timer
712712
expected_event.event = MSC_DEVICE_SUSPENDED;
713-
wait_for_app_event(&expected_event, pdMS_TO_TICKS(MSC_TEST_PM_TIMER_INTERVAL_MS + MSC_TEST_PM_TIMER_MARGIN_MS));
713+
wait_for_app_event(&expected_event, pdMS_TO_TICKS(MSC_TEST_SUSPEND_TIMER_INTERVAL_MS + MSC_TEST_SUSPEND_TIMER_MARGIN_MS));
714714

715715
// Resume the root port manually and expect the resume event
716716
ESP_OK_ASSERT(usb_host_lib_root_port_resume());
@@ -721,10 +721,10 @@ TEST_CASE("auto_suspend_timer", "[usb_msc]")
721721
write_read_file(FILE_NAME);
722722
}
723723

724-
// Disable Periodic PM timer
725-
ESP_OK_ASSERT(usb_host_lib_set_auto_pm(USB_HOST_LIB_PM_SUSPEND_PERIODIC, 0));
726-
// Test that the Periodic PM timer can be disabled and no other event is delivered
727-
TEST_ASSERT_EQUAL(pdFALSE, xQueuePeek(app_queue, &peek_event, pdMS_TO_TICKS(MSC_TEST_PM_TIMER_INTERVAL_MS * 2)));
724+
// Disable Periodic auto suspend timer
725+
ESP_OK_ASSERT(usb_host_lib_set_auto_suspend(USB_HOST_LIB_AUTO_SUSPEND_PERIODIC, 0));
726+
// Test that the Periodic auto suspend timer can be disabled and no other event is delivered
727+
TEST_ASSERT_EQUAL(pdFALSE, xQueuePeek(app_queue, &peek_event, pdMS_TO_TICKS(MSC_TEST_SUSPEND_TIMER_INTERVAL_MS * 2)));
728728
msc_teardown();
729729
}
730730

host/usb/include/usb/usb_host.h

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

5555
/**
56-
* @brief USB Host lib power management timer type
56+
* @brief USB Host lib automatic suspend timer
5757
*/
5858
typedef enum {
59-
USB_HOST_LIB_PM_SUSPEND_ONE_SHOT, /**< USB Host lib power management -> Auto suspend one-shot timer */
60-
USB_HOST_LIB_PM_SUSPEND_PERIODIC, /**< USB Host lib power management -> Auto suspend periodic timer */
61-
} usb_host_lib_pm_t;
59+
USB_HOST_LIB_AUTO_SUSPEND_ONE_SHOT, /**< Automatic suspend one-shot timer */
60+
USB_HOST_LIB_AUTO_SUSPEND_PERIODIC, /**< Automatic suspend periodic timer */
61+
} usb_host_lib_auto_suspend_tmr_t;
6262

6363
/**
6464
* @brief Client event message
@@ -292,15 +292,15 @@ 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
295+
* @brief Set automatic suspend timer
296296
*
297-
* - The function sets the auto suspend timer, used for global suspend of the root port
297+
* - The function sets the automatic suspend timer, used for global suspend of the root port
298298
* - 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
299+
* - The timer expires after the set period, only if there is no activity on the USB Bus
300300
* - The timer resets (if enabled) every time, the usb_host_client_handle_events() handles any client events,
301301
* or the usb_host_lib_handle_events() handles any host lib events, thus checking any activity on all the
302302
* registered clients or inside the host lib
303-
* - Once the timer expires, an auto_pm_timer_cb() is called, which delivers USB Host lib event flags
303+
* - Once the timer expires, an auto_suspend_timer_cb() is called, which delivers USB Host lib event flags
304304
*
305305
* @note set the timer interval to 0, to disable the timer (in case NO auto suspend functionality is required anymore)
306306
* @note this function is not ISR safe
@@ -311,7 +311,7 @@ esp_err_t usb_host_lib_root_port_resume(void);
311311
* - ESP_ERR_INVALID_STATE: USB Host lib is not installed
312312
* - ESP_FAIL: Timer was not configured correctly
313313
*/
314-
esp_err_t usb_host_lib_set_auto_pm(usb_host_lib_pm_t timer_type, size_t timer_interval_ms);
314+
esp_err_t usb_host_lib_set_auto_suspend(usb_host_lib_auto_suspend_tmr_t timer_type, size_t timer_interval_ms);
315315

316316
// ------------------------------------------------ Client Functions ---------------------------------------------------
317317

0 commit comments

Comments
 (0)