change(usb/host): Remove data buffer headers from URBs

This commit removes the ability to reserve a header in the data buffer of an
allocated URB. The header was required for a now defunct implementation of a
synchronous USB Host library API. Thus, headers are no longer required in
URB data buffers.
pull/12702/head
Darian Leung 2023-11-22 00:47:38 +08:00
rodzic 76011fc8f7
commit 16c37f9db1
4 zmienionych plików z 11 dodań i 15 usunięć

Wyświetl plik

@ -938,7 +938,7 @@ esp_err_t hub_install(hub_config_t *hub_config)
HUB_DRIVER_EXIT_CRITICAL();
// Allocate Hub driver object
hub_driver_t *hub_driver_obj = heap_caps_calloc(1, sizeof(hub_driver_t), MALLOC_CAP_DEFAULT);
urb_t *enum_urb = urb_alloc(sizeof(usb_setup_packet_t) + ENUM_CTRL_TRANSFER_MAX_DATA_LEN, 0, 0);
urb_t *enum_urb = urb_alloc(sizeof(usb_setup_packet_t) + ENUM_CTRL_TRANSFER_MAX_DATA_LEN, 0);
if (hub_driver_obj == NULL || enum_urb == NULL) {
return ESP_ERR_NO_MEM;
}

Wyświetl plik

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -43,7 +43,6 @@ struct urb_s {
uint32_t hcd_var;
// Host Lib Layer:
void *usb_host_client; // Currently only used when submitted to shared pipes (i.e., Device default pipes)
size_t usb_host_header_size; // USB Host may need the data buffer to have a transparent header
bool usb_host_inflight; // Debugging variable, used to prevent re-submitting URBs already inflight
// Public transfer structure. Must be last due to variable length array
usb_transfer_t transfer;
@ -76,15 +75,13 @@ typedef bool (*usb_proc_req_cb_t)(usb_proc_req_source_t source, bool in_isr, voi
*
* - Data buffer is allocated in DMA capable memory
* - The constant fields of the URB are also set
* - The data_buffer field of the URB is set to point to start of the allocated data buffer AFTER the header. To access
* the header, users need a negative offset from data_buffer.
* - The data_buffer field of the URB is set to point to start of the allocated data buffer.
*
* @param data_buffer_size Size of the URB's data buffer
* @param header_size Size of header to put in front of URB's data buffer
* @param num_isoc_packets Number of isochronous packet descriptors
* @return urb_t* URB object
*/
urb_t *urb_alloc(size_t data_buffer_size, size_t header_size, int num_isoc_packets);
urb_t *urb_alloc(size_t data_buffer_size, int num_isoc_packets);
/**
* @brief Free a URB

Wyświetl plik

@ -1245,7 +1245,7 @@ exit:
esp_err_t usb_host_transfer_alloc(size_t data_buffer_size, int num_isoc_packets, usb_transfer_t **transfer)
{
urb_t *urb = urb_alloc(data_buffer_size, 0, num_isoc_packets);
urb_t *urb = urb_alloc(data_buffer_size, num_isoc_packets);
if (urb == NULL) {
return ESP_ERR_NO_MEM;
}

Wyświetl plik

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -8,17 +8,16 @@
#include "usb_private.h"
#include "usb/usb_types_ch9.h"
urb_t *urb_alloc(size_t data_buffer_size, size_t header_size, int num_isoc_packets)
urb_t *urb_alloc(size_t data_buffer_size, int num_isoc_packets)
{
urb_t *urb = heap_caps_calloc(1, sizeof(urb_t) + (sizeof(usb_isoc_packet_desc_t) * num_isoc_packets), MALLOC_CAP_DEFAULT);
uint8_t *data_buffer = heap_caps_malloc(data_buffer_size + header_size, MALLOC_CAP_DMA);
uint8_t *data_buffer = heap_caps_malloc(data_buffer_size, MALLOC_CAP_DMA);
if (urb == NULL || data_buffer == NULL) {
goto err;
}
urb->usb_host_header_size = header_size; // Indicate that this URB's data_buffer has a header in front of it.
// Case as dummy transfer to write to initialize const fields
// Cast as dummy transfer so that we can assign to const fields
usb_transfer_dummy_t *dummy_transfer = (usb_transfer_dummy_t *)&urb->transfer;
dummy_transfer->data_buffer = (uint8_t *)(data_buffer + header_size);
dummy_transfer->data_buffer = data_buffer;
dummy_transfer->data_buffer_size = data_buffer_size;
dummy_transfer->num_isoc_packets = num_isoc_packets;
return urb;
@ -33,6 +32,6 @@ void urb_free(urb_t *urb)
if (urb == NULL) {
return;
}
heap_caps_free((uint8_t *)(urb->transfer.data_buffer - urb->usb_host_header_size));
heap_caps_free(urb->transfer.data_buffer);
heap_caps_free(urb);
}