mirror of
https://github.com/espressif/esp-idf.git
synced 2026-08-18 06:35:35 +03:00
feat(dma): refactor dma calloc function
This commit is contained in:
@@ -1040,18 +1040,18 @@ static void port_obj_free(port_t *port)
|
||||
|
||||
void *frame_list_alloc(size_t frame_list_len)
|
||||
{
|
||||
esp_err_t ret = ESP_FAIL;
|
||||
esp_err_t ret;
|
||||
void *frame_list = NULL;
|
||||
size_t actual_size = 0;
|
||||
esp_dma_mem_info_t dma_mem_info = {
|
||||
.heap_caps = MALLOC_CAP_DMA,
|
||||
.custom_alignment = USB_DWC_FRAME_LIST_MEM_ALIGN,
|
||||
.dma_alignment_bytes = USB_DWC_FRAME_LIST_MEM_ALIGN,
|
||||
};
|
||||
ret = esp_dma_capable_calloc(frame_list_len, sizeof(uint32_t), &dma_mem_info, &frame_list, NULL);
|
||||
assert(ret != ESP_ERR_INVALID_ARG);
|
||||
ret = esp_dma_capable_calloc(frame_list_len, sizeof(uint32_t), &dma_mem_info, &frame_list, &actual_size);
|
||||
assert(ret == ESP_OK);
|
||||
|
||||
// Both Frame List start address and size should be already cache aligned so this is only a sanity check
|
||||
if (frame_list) {
|
||||
if (!esp_dma_is_buffer_alignment_satisfied(frame_list, frame_list_len * sizeof(uint32_t), &dma_mem_info)) {
|
||||
if (!esp_dma_is_buffer_alignment_satisfied(frame_list, actual_size, dma_mem_info)) {
|
||||
// This should never happen
|
||||
heap_caps_free(frame_list);
|
||||
frame_list = NULL;
|
||||
@@ -1072,17 +1072,17 @@ void *transfer_descriptor_list_alloc(size_t list_len, size_t *list_len_bytes_out
|
||||
*list_len_bytes_out = list_len * sizeof(usb_dwc_ll_dma_qtd_t);
|
||||
#endif // SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE
|
||||
|
||||
esp_err_t ret = ESP_FAIL;
|
||||
esp_err_t ret;
|
||||
void *qtd_list = NULL;
|
||||
size_t actual_size = 0;
|
||||
esp_dma_mem_info_t dma_mem_info = {
|
||||
.heap_caps = MALLOC_CAP_DMA,
|
||||
.custom_alignment = USB_DWC_QTD_LIST_MEM_ALIGN,
|
||||
.dma_alignment_bytes = USB_DWC_QTD_LIST_MEM_ALIGN,
|
||||
};
|
||||
ret = esp_dma_capable_calloc(*list_len_bytes_out, 1, &dma_mem_info, &qtd_list, NULL);
|
||||
assert(ret != ESP_ERR_INVALID_ARG);
|
||||
ret = esp_dma_capable_calloc(*list_len_bytes_out, 1, &dma_mem_info, &qtd_list, &actual_size);
|
||||
assert(ret == ESP_OK);
|
||||
|
||||
if (qtd_list) {
|
||||
if (!esp_dma_is_buffer_alignment_satisfied(qtd_list, *list_len_bytes_out * sizeof(usb_dwc_ll_dma_qtd_t), &dma_mem_info)) {
|
||||
if (!esp_dma_is_buffer_alignment_satisfied(qtd_list, actual_size, dma_mem_info)) {
|
||||
// This should never happen
|
||||
heap_caps_free(qtd_list);
|
||||
qtd_list = NULL;
|
||||
|
||||
@@ -267,11 +267,7 @@ urb_t *test_hcd_alloc_urb(int num_isoc_packets, size_t data_buffer_size)
|
||||
void *data_buffer;
|
||||
size_t real_size;
|
||||
esp_dma_mem_info_t dma_mem_info = {
|
||||
.dma_type = ESP_DMA_OTHERS,
|
||||
.mem_flags = {
|
||||
.dir = ESP_DMA_MEM_DIR_DONT_CARE,
|
||||
},
|
||||
.custom_alignment = 4,
|
||||
.dma_alignment_bytes = 4,
|
||||
};
|
||||
esp_dma_capable_malloc(data_buffer_size, &dma_mem_info, &data_buffer, &real_size);
|
||||
TEST_ASSERT_NOT_NULL_MESSAGE(urb, "Failed to allocate URB");
|
||||
|
||||
@@ -15,12 +15,9 @@ urb_t *urb_alloc(size_t data_buffer_size, int num_isoc_packets)
|
||||
void *data_buffer;
|
||||
size_t real_size;
|
||||
esp_dma_mem_info_t dma_mem_info = {
|
||||
.dma_type = ESP_DMA_OTHERS,
|
||||
.mem_flags = {
|
||||
.dir = ESP_DMA_MEM_DIR_DONT_CARE,
|
||||
},
|
||||
.custom_alignment = 4,
|
||||
.dma_alignment_bytes = 4,
|
||||
};
|
||||
//TODO: IDF-9639
|
||||
esp_dma_capable_malloc(data_buffer_size, &dma_mem_info, &data_buffer, &real_size);
|
||||
if (urb == NULL || data_buffer == NULL) {
|
||||
goto err;
|
||||
|
||||
Reference in New Issue
Block a user