Skip to content

Commit 8aa9a42

Browse files
Dazza0espressif-bot
authored andcommitted
refactor(usb/usbh): Rename device pool functions and ref_count
This commit renames the following APIs and variables in the USBH: - Rename the prefix of device pool functions from 'usbh_dev_...' to 'usbh_devs_...'. - Rename 'ref_count' to 'open_count'. This variable tracks the number of times a device has been opened.
1 parent c14eae9 commit 8aa9a42

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

components/usb/private_include/usbh.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,13 @@ esp_err_t usbh_process(void);
178178
* @param[out] num_devs_ret Current number of devices
179179
* @return esp_err_t
180180
*/
181-
esp_err_t usbh_num_devs(int *num_devs_ret);
181+
esp_err_t usbh_devs_num(int *num_devs_ret);
182182

183183
/**
184184
* @brief Fill list with address of currently connected devices
185185
*
186186
* - This function fills the provided list with the address of current connected devices
187-
* - Device address can then be used in usbh_dev_open()
187+
* - Device address can then be used in usbh_devs_open()
188188
* - If there are more devices than the list_len, this function will only fill
189189
* up to list_len number of devices.
190190
*
@@ -193,18 +193,18 @@ esp_err_t usbh_num_devs(int *num_devs_ret);
193193
* @param[out] num_dev_ret Number of devices filled into list
194194
* @return esp_err_t
195195
*/
196-
esp_err_t usbh_dev_addr_list_fill(int list_len, uint8_t *dev_addr_list, int *num_dev_ret);
196+
esp_err_t usbh_devs_addr_list_fill(int list_len, uint8_t *dev_addr_list, int *num_dev_ret);
197197

198198
/**
199199
* @brief Mark that all devices should be freed at the next possible opportunity
200200
*
201-
* A device marked as free will not be freed until the last client using the device has called usbh_dev_close()
201+
* A device marked as free will not be freed until the last client using the device has called usbh_devs_close()
202202
*
203203
* @return
204204
* - ESP_OK: There were no devices to free to begin with. Current state is all free
205205
* - ESP_ERR_NOT_FINISHED: One or more devices still need to be freed (but have been marked "to be freed")
206206
*/
207-
esp_err_t usbh_dev_mark_all_free(void);
207+
esp_err_t usbh_devs_mark_all_free(void);
208208

209209
/**
210210
* @brief Open a device by address
@@ -215,17 +215,17 @@ esp_err_t usbh_dev_mark_all_free(void);
215215
* @param[out] dev_hdl Device handle
216216
* @return esp_err_t
217217
*/
218-
esp_err_t usbh_dev_open(uint8_t dev_addr, usb_device_handle_t *dev_hdl);
218+
esp_err_t usbh_devs_open(uint8_t dev_addr, usb_device_handle_t *dev_hdl);
219219

220220
/**
221221
* @brief CLose a device
222222
*
223-
* Device can be opened by calling usbh_dev_open()
223+
* Device can be opened by calling usbh_devs_open()
224224
*
225225
* @param[in] dev_hdl Device handle
226226
* @return esp_err_t
227227
*/
228-
esp_err_t usbh_dev_close(usb_device_handle_t dev_hdl);
228+
esp_err_t usbh_devs_close(usb_device_handle_t dev_hdl);
229229

230230
// ------------------------------------------------ Device Functions ---------------------------------------------------
231231

@@ -282,7 +282,7 @@ esp_err_t usbh_dev_get_config_desc(usb_device_handle_t dev_hdl, const usb_config
282282
*
283283
* This function allows clients to allocate a non-default endpoint (i.e., not EP0) on a connected device
284284
*
285-
* - A client must have opened the device using usbh_dev_open() before attempting to allocate an endpoint on the device
285+
* - A client must have opened the device using usbh_devs_open() before attempting to allocate an endpoint on the device
286286
* - A client should call this function to allocate all endpoints in an interface that the client has claimed.
287287
* - A client must allocate an endpoint using this function before attempting to communicate with it
288288
* - Once the client allocates an endpoint, the client is now owns/manages the endpoint. No other client should use or

components/usb/usb_host.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ esp_err_t usb_host_lib_info(usb_host_lib_info_t *info_ret)
574574
HOST_CHECK_FROM_CRIT(p_host_lib_obj != NULL, ESP_ERR_INVALID_STATE);
575575
num_clients_temp = p_host_lib_obj->dynamic.flags.num_clients;
576576
HOST_EXIT_CRITICAL();
577-
usbh_num_devs(&num_devs_temp);
577+
usbh_devs_num(&num_devs_temp);
578578

579579
// Write back return values
580580
info_ret->num_devices = num_devs_temp;
@@ -820,7 +820,7 @@ esp_err_t usb_host_device_open(usb_host_client_handle_t client_hdl, uint8_t dev_
820820

821821
esp_err_t ret;
822822
usb_device_handle_t dev_hdl;
823-
ret = usbh_dev_open(dev_addr, &dev_hdl);
823+
ret = usbh_devs_open(dev_addr, &dev_hdl);
824824
if (ret != ESP_OK) {
825825
goto exit;
826826
}
@@ -841,7 +841,7 @@ esp_err_t usb_host_device_open(usb_host_client_handle_t client_hdl, uint8_t dev_
841841
return ret;
842842

843843
already_opened:
844-
ESP_ERROR_CHECK(usbh_dev_close(dev_hdl));
844+
ESP_ERROR_CHECK(usbh_devs_close(dev_hdl));
845845
exit:
846846
return ret;
847847
}
@@ -883,7 +883,7 @@ esp_err_t usb_host_device_close(usb_host_client_handle_t client_hdl, usb_device_
883883
_clear_client_opened_device(client_obj, dev_addr);
884884
HOST_EXIT_CRITICAL();
885885

886-
ESP_ERROR_CHECK(usbh_dev_close(dev_hdl));
886+
ESP_ERROR_CHECK(usbh_devs_close(dev_hdl));
887887
ret = ESP_OK;
888888
exit:
889889
xSemaphoreGive(p_host_lib_obj->constant.mux_lock);
@@ -896,15 +896,15 @@ esp_err_t usb_host_device_free_all(void)
896896
HOST_CHECK_FROM_CRIT(p_host_lib_obj->dynamic.flags.num_clients == 0, ESP_ERR_INVALID_STATE); // All clients must have been deregistered
897897
HOST_EXIT_CRITICAL();
898898
esp_err_t ret;
899-
ret = usbh_dev_mark_all_free();
899+
ret = usbh_devs_mark_all_free();
900900
// If ESP_ERR_NOT_FINISHED is returned, caller must wait for USB_HOST_LIB_EVENT_FLAGS_ALL_FREE to confirm all devices are free
901901
return ret;
902902
}
903903

904904
esp_err_t usb_host_device_addr_list_fill(int list_len, uint8_t *dev_addr_list, int *num_dev_ret)
905905
{
906906
HOST_CHECK(dev_addr_list != NULL && num_dev_ret != NULL, ESP_ERR_INVALID_ARG);
907-
return usbh_dev_addr_list_fill(list_len, dev_addr_list, num_dev_ret);
907+
return usbh_devs_addr_list_fill(list_len, dev_addr_list, num_dev_ret);
908908
}
909909

910910
// ------------------------------------------------- Device Requests ---------------------------------------------------

components/usb/usbh.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct device_s {
6464
uint32_t action_flags;
6565
int num_ctrl_xfers_inflight;
6666
usb_device_state_t state;
67-
uint32_t ref_count;
67+
uint32_t open_count;
6868
} dynamic;
6969
// Mux protected members must be protected by the USBH mux_lock when accessed
7070
struct {
@@ -702,7 +702,7 @@ esp_err_t usbh_process(void)
702702

703703
// ---------------------------------------------- Device Pool Functions ------------------------------------------------
704704

705-
esp_err_t usbh_num_devs(int *num_devs_ret)
705+
esp_err_t usbh_devs_num(int *num_devs_ret)
706706
{
707707
USBH_CHECK(num_devs_ret != NULL, ESP_ERR_INVALID_ARG);
708708
xSemaphoreTake(p_usbh_obj->constant.mux_lock, portMAX_DELAY);
@@ -711,7 +711,7 @@ esp_err_t usbh_num_devs(int *num_devs_ret)
711711
return ESP_OK;
712712
}
713713

714-
esp_err_t usbh_dev_addr_list_fill(int list_len, uint8_t *dev_addr_list, int *num_dev_ret)
714+
esp_err_t usbh_devs_addr_list_fill(int list_len, uint8_t *dev_addr_list, int *num_dev_ret)
715715
{
716716
USBH_CHECK(dev_addr_list != NULL && num_dev_ret != NULL, ESP_ERR_INVALID_ARG);
717717
USBH_ENTER_CRITICAL();
@@ -741,7 +741,7 @@ esp_err_t usbh_dev_addr_list_fill(int list_len, uint8_t *dev_addr_list, int *num
741741
return ESP_OK;
742742
}
743743

744-
esp_err_t usbh_dev_mark_all_free(void)
744+
esp_err_t usbh_devs_mark_all_free(void)
745745
{
746746
USBH_ENTER_CRITICAL();
747747
/*
@@ -763,11 +763,11 @@ esp_err_t usbh_dev_mark_all_free(void)
763763
while (dev_obj_cur != NULL) {
764764
// Keep a copy of the next item first in case we remove the current item
765765
dev_obj_next = TAILQ_NEXT(dev_obj_cur, dynamic.tailq_entry);
766-
if (dev_obj_cur->dynamic.ref_count == 0) {
767-
// Device is not referenced. Can free immediately.
766+
if (dev_obj_cur->dynamic.open_count == 0) {
767+
// Device is not opened. Can free immediately.
768768
call_proc_req_cb |= _dev_set_actions(dev_obj_cur, DEV_ACTION_FREE);
769769
} else {
770-
// Device is still referenced. Just mark it as waiting to be freed
770+
// Device is still opened. Just mark it as waiting to be freed
771771
dev_obj_cur->dynamic.flags.waiting_free = 1;
772772
}
773773
// At least one device needs to be freed. User needs to wait for USBH_EVENT_ALL_FREE event
@@ -783,7 +783,7 @@ esp_err_t usbh_dev_mark_all_free(void)
783783
return (wait_for_free) ? ESP_ERR_NOT_FINISHED : ESP_OK;
784784
}
785785

786-
esp_err_t usbh_dev_open(uint8_t dev_addr, usb_device_handle_t *dev_hdl)
786+
esp_err_t usbh_devs_open(uint8_t dev_addr, usb_device_handle_t *dev_hdl)
787787
{
788788
USBH_CHECK(dev_hdl != NULL, ESP_ERR_INVALID_ARG);
789789
esp_err_t ret;
@@ -806,11 +806,11 @@ esp_err_t usbh_dev_open(uint8_t dev_addr, usb_device_handle_t *dev_hdl)
806806
}
807807
exit:
808808
if (found_dev_obj != NULL) {
809-
// The device is not in a state to be referenced
809+
// The device is not in a state to be opened
810810
if (dev_obj->dynamic.flags.is_gone || dev_obj->dynamic.flags.waiting_free) {
811811
ret = ESP_ERR_INVALID_STATE;
812812
} else {
813-
dev_obj->dynamic.ref_count++;
813+
dev_obj->dynamic.open_count++;
814814
*dev_hdl = (usb_device_handle_t)found_dev_obj;
815815
ret = ESP_OK;
816816
}
@@ -822,18 +822,18 @@ esp_err_t usbh_dev_open(uint8_t dev_addr, usb_device_handle_t *dev_hdl)
822822
return ret;
823823
}
824824

825-
esp_err_t usbh_dev_close(usb_device_handle_t dev_hdl)
825+
esp_err_t usbh_devs_close(usb_device_handle_t dev_hdl)
826826
{
827827
USBH_CHECK(dev_hdl != NULL, ESP_ERR_INVALID_ARG);
828828
device_t *dev_obj = (device_t *)dev_hdl;
829829

830830
USBH_ENTER_CRITICAL();
831-
dev_obj->dynamic.ref_count--;
831+
dev_obj->dynamic.open_count--;
832832
bool call_proc_req_cb = false;
833-
if (dev_obj->dynamic.ref_count == 0) {
833+
if (dev_obj->dynamic.open_count == 0) {
834834
// Sanity check.
835835
assert(dev_obj->dynamic.num_ctrl_xfers_inflight == 0); // There cannot be any control transfer in-flight
836-
assert(!dev_obj->dynamic.flags.waiting_free); // This can only be set when ref count reaches 0
836+
assert(!dev_obj->dynamic.flags.waiting_free); // This can only be set when open_count reaches 0
837837
if (dev_obj->dynamic.flags.is_gone || dev_obj->dynamic.flags.waiting_free) {
838838
// Device is already gone or is awaiting to be freed. Trigger the USBH process to free the device
839839
call_proc_req_cb = _dev_set_actions(dev_obj, DEV_ACTION_FREE);
@@ -1152,11 +1152,11 @@ esp_err_t usbh_hub_dev_gone(usb_device_handle_t dev_hdl)
11521152
USBH_ENTER_CRITICAL();
11531153
dev_obj->dynamic.flags.is_gone = 1;
11541154
// Check if the device can be freed immediately
1155-
if (dev_obj->dynamic.ref_count == 0) {
1156-
// Device is not currently referenced at all. Can free immediately.
1155+
if (dev_obj->dynamic.open_count == 0) {
1156+
// Device is not currently opened at all. Can free immediately.
11571157
call_proc_req_cb = _dev_set_actions(dev_obj, DEV_ACTION_FREE);
11581158
} else {
1159-
// Device is still being referenced. Flush endpoints and propagate device gone event
1159+
// Device is still opened. Flush endpoints and propagate device gone event
11601160
call_proc_req_cb = _dev_set_actions(dev_obj,
11611161
DEV_ACTION_EPn_HALT_FLUSH |
11621162
DEV_ACTION_EP0_FLUSH |

0 commit comments

Comments
 (0)