2021-08-24 15:20:50 +00:00
|
|
|
/*
|
2023-11-21 16:47:38 +00:00
|
|
|
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
2021-08-24 15:20:50 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "esp_heap_caps.h"
|
|
|
|
#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);
|
2023-11-21 16:47:38 +00:00
|
|
|
uint8_t *data_buffer = heap_caps_malloc(data_buffer_size, MALLOC_CAP_DMA);
|
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;
|
2021-08-24 15:20:50 +00:00
|
|
|
dummy_transfer->data_buffer_size = data_buffer_size;
|
|
|
|
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);
|
|
|
|
}
|