2021-08-24 11:20:50 -04:00
|
|
|
/*
|
2024-01-08 03:31:39 -05:00
|
|
|
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
2021-08-24 11:20:50 -04: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 11:47:38 -05:00
|
|
|
urb_t *urb_alloc(size_t data_buffer_size, int num_isoc_packets)
|
2021-08-24 11:20:50 -04:00
|
|
|
{
|
|
|
|
urb_t *urb = heap_caps_calloc(1, sizeof(urb_t) + (sizeof(usb_isoc_packet_desc_t) * num_isoc_packets), MALLOC_CAP_DEFAULT);
|
2024-08-16 02:59:02 -04:00
|
|
|
void *data_buffer = heap_caps_malloc(data_buffer_size, MALLOC_CAP_DMA | MALLOC_CAP_CACHE_ALIGNED);
|
2021-08-24 11:20:50 -04:00
|
|
|
if (urb == NULL || data_buffer == NULL) {
|
|
|
|
goto err;
|
|
|
|
}
|
2023-11-21 11:47:38 -05:00
|
|
|
// Cast as dummy transfer so that we can assign to const fields
|
2021-08-24 11:20:50 -04:00
|
|
|
usb_transfer_dummy_t *dummy_transfer = (usb_transfer_dummy_t *)&urb->transfer;
|
2023-11-21 11:47:38 -05:00
|
|
|
dummy_transfer->data_buffer = data_buffer;
|
2024-08-16 02:59:02 -04:00
|
|
|
dummy_transfer->data_buffer_size = heap_caps_get_allocated_size(data_buffer);
|
2021-08-24 11:20:50 -04: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 11:47:38 -05:00
|
|
|
heap_caps_free(urb->transfer.data_buffer);
|
2021-08-24 11:20:50 -04:00
|
|
|
heap_caps_free(urb);
|
|
|
|
}
|