2021-08-24 15:20:50 +00:00
|
|
|
/*
|
2024-01-08 08:31:39 +00:00
|
|
|
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
2021-08-24 15:20:50 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "esp_heap_caps.h"
|
2024-01-08 08:31:39 +00:00
|
|
|
#include "esp_dma_utils.h"
|
2021-08-24 15:20:50 +00:00
|
|
|
#include "usb_private.h"
|
|
|
|
#include "usb/usb_types_ch9.h"
|
|
|
|
|
2023-11-21 16:47:38 +00:00
|
|
|
urb_t *urb_alloc(size_t data_buffer_size, int num_isoc_packets)
|
2021-08-24 15:20:50 +00:00
|
|
|
{
|
|
|
|
urb_t *urb = heap_caps_calloc(1, sizeof(urb_t) + (sizeof(usb_isoc_packet_desc_t) * num_isoc_packets), MALLOC_CAP_DEFAULT);
|
2024-01-08 08:31:39 +00:00
|
|
|
void *data_buffer;
|
|
|
|
size_t real_size;
|
|
|
|
esp_dma_malloc(data_buffer_size, 0, &data_buffer, &real_size);
|
2021-08-24 15:20:50 +00:00
|
|
|
if (urb == NULL || data_buffer == NULL) {
|
|
|
|
goto err;
|
|
|
|
}
|
2023-11-21 16:47:38 +00:00
|
|
|
// Cast as dummy transfer so that we can assign to const fields
|
2021-08-24 15:20:50 +00:00
|
|
|
usb_transfer_dummy_t *dummy_transfer = (usb_transfer_dummy_t *)&urb->transfer;
|
2023-11-21 16:47:38 +00:00
|
|
|
dummy_transfer->data_buffer = data_buffer;
|
2024-01-08 08:31:39 +00:00
|
|
|
dummy_transfer->data_buffer_size = real_size;
|
2021-08-24 15:20:50 +00:00
|
|
|
dummy_transfer->num_isoc_packets = num_isoc_packets;
|
|
|
|
return urb;
|
|
|
|
err:
|
|
|
|
heap_caps_free(urb);
|
|
|
|
heap_caps_free(data_buffer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void urb_free(urb_t *urb)
|
|
|
|
{
|
|
|
|
if (urb == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2023-11-21 16:47:38 +00:00
|
|
|
heap_caps_free(urb->transfer.data_buffer);
|
2021-08-24 15:20:50 +00:00
|
|
|
heap_caps_free(urb);
|
|
|
|
}
|