forked from espressif/esp-idf
refactor(emac): use heap component API to allocate cached aligned DMA buffer
This commit is contained in:
@@ -33,7 +33,6 @@
|
|||||||
#include "esp_memory_utils.h"
|
#include "esp_memory_utils.h"
|
||||||
#include "esp_clk_tree.h"
|
#include "esp_clk_tree.h"
|
||||||
#include "esp_attr.h"
|
#include "esp_attr.h"
|
||||||
#include "esp_dma_utils.h"
|
|
||||||
#include "esp_private/gdma.h"
|
#include "esp_private/gdma.h"
|
||||||
#include "esp_cache.h"
|
#include "esp_cache.h"
|
||||||
|
|
||||||
|
@@ -23,7 +23,6 @@
|
|||||||
#include "soc/i2s_periph.h"
|
#include "soc/i2s_periph.h"
|
||||||
#include "soc/spi_periph.h"
|
#include "soc/spi_periph.h"
|
||||||
#include "soc/parlio_periph.h"
|
#include "soc/parlio_periph.h"
|
||||||
#include "esp_dma_utils.h"
|
|
||||||
#include "esp_attr.h"
|
#include "esp_attr.h"
|
||||||
#include "test_board.h"
|
#include "test_board.h"
|
||||||
|
|
||||||
|
@@ -68,8 +68,5 @@ if(CONFIG_ETH_ENABLED)
|
|||||||
if(CONFIG_ETH_USE_SPI_ETHERNET)
|
if(CONFIG_ETH_USE_SPI_ETHERNET)
|
||||||
idf_component_optional_requires(PUBLIC esp_driver_spi)
|
idf_component_optional_requires(PUBLIC esp_driver_spi)
|
||||||
endif()
|
endif()
|
||||||
idf_component_optional_requires(PRIVATE esp_netif esp_pm)
|
idf_component_optional_requires(PRIVATE esp_netif esp_pm esp_mm)
|
||||||
if(CONFIG_SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE)
|
|
||||||
idf_component_optional_requires(PRIVATE esp_mm)
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
@@ -5,13 +5,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "esp_check.h"
|
#include "esp_check.h"
|
||||||
#include "esp_dma_utils.h"
|
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "soc/soc_caps.h"
|
#include "soc/soc_caps.h"
|
||||||
#if SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE
|
|
||||||
#include "esp_cache.h"
|
#include "esp_cache.h"
|
||||||
#endif
|
|
||||||
#include "hal/emac_hal.h"
|
#include "hal/emac_hal.h"
|
||||||
|
#include "esp_heap_caps.h"
|
||||||
#include "esp_private/eth_mac_esp_dma.h"
|
#include "esp_private/eth_mac_esp_dma.h"
|
||||||
|
|
||||||
#define ETH_CRC_LENGTH (4)
|
#define ETH_CRC_LENGTH (4)
|
||||||
@@ -41,8 +39,7 @@
|
|||||||
|
|
||||||
static const char *TAG = "esp.emac.dma";
|
static const char *TAG = "esp.emac.dma";
|
||||||
|
|
||||||
struct emac_esp_dma_t
|
struct emac_esp_dma_t {
|
||||||
{
|
|
||||||
emac_hal_context_t hal;
|
emac_hal_context_t hal;
|
||||||
uint32_t tx_desc_flags;
|
uint32_t tx_desc_flags;
|
||||||
uint32_t rx_desc_flags;
|
uint32_t rx_desc_flags;
|
||||||
@@ -459,20 +456,15 @@ esp_err_t emac_esp_new_dma(const emac_esp_dma_config_t* config, emac_esp_dma_han
|
|||||||
/* alloc memory for ethernet dma descriptor */
|
/* alloc memory for ethernet dma descriptor */
|
||||||
uint32_t desc_size = CONFIG_ETH_DMA_RX_BUFFER_NUM * sizeof(eth_dma_rx_descriptor_t) +
|
uint32_t desc_size = CONFIG_ETH_DMA_RX_BUFFER_NUM * sizeof(eth_dma_rx_descriptor_t) +
|
||||||
CONFIG_ETH_DMA_TX_BUFFER_NUM * sizeof(eth_dma_tx_descriptor_t);
|
CONFIG_ETH_DMA_TX_BUFFER_NUM * sizeof(eth_dma_tx_descriptor_t);
|
||||||
esp_dma_mem_info_t dma_mem_info = {
|
emac_esp_dma->descriptors = heap_caps_aligned_calloc(4, 1, desc_size, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||||
.extra_heap_caps = MALLOC_CAP_INTERNAL,
|
|
||||||
.dma_alignment_bytes = 4,
|
|
||||||
};
|
|
||||||
esp_dma_capable_calloc(1, desc_size, &dma_mem_info, (void*)&emac_esp_dma->descriptors, NULL);
|
|
||||||
|
|
||||||
ESP_GOTO_ON_FALSE(emac_esp_dma->descriptors, ESP_ERR_NO_MEM, err, TAG, "no mem for descriptors");
|
ESP_GOTO_ON_FALSE(emac_esp_dma->descriptors, ESP_ERR_NO_MEM, err, TAG, "no mem for descriptors");
|
||||||
/* alloc memory for ethernet dma buffer */
|
/* alloc memory for ethernet dma buffer */
|
||||||
for (int i = 0; i < CONFIG_ETH_DMA_RX_BUFFER_NUM; i++) {
|
for (int i = 0; i < CONFIG_ETH_DMA_RX_BUFFER_NUM; i++) {
|
||||||
esp_dma_capable_calloc(1, CONFIG_ETH_DMA_BUFFER_SIZE, &dma_mem_info, (void*)&emac_esp_dma->rx_buf[i], NULL);
|
emac_esp_dma->rx_buf[i] = heap_caps_aligned_calloc(4, 1, CONFIG_ETH_DMA_BUFFER_SIZE, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||||
ESP_GOTO_ON_FALSE(emac_esp_dma->rx_buf[i], ESP_ERR_NO_MEM, err, TAG, "no mem for RX DMA buffers");
|
ESP_GOTO_ON_FALSE(emac_esp_dma->rx_buf[i], ESP_ERR_NO_MEM, err, TAG, "no mem for RX DMA buffers");
|
||||||
}
|
}
|
||||||
for (int i = 0; i < CONFIG_ETH_DMA_TX_BUFFER_NUM; i++) {
|
for (int i = 0; i < CONFIG_ETH_DMA_TX_BUFFER_NUM; i++) {
|
||||||
esp_dma_capable_calloc(1, CONFIG_ETH_DMA_BUFFER_SIZE, &dma_mem_info, (void*)&emac_esp_dma->tx_buf[i], NULL);
|
emac_esp_dma->tx_buf[i] = heap_caps_aligned_calloc(4, 1, CONFIG_ETH_DMA_BUFFER_SIZE, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||||
ESP_GOTO_ON_FALSE(emac_esp_dma->tx_buf[i], ESP_ERR_NO_MEM, err, TAG, "no mem for TX DMA buffers");
|
ESP_GOTO_ON_FALSE(emac_esp_dma->tx_buf[i], ESP_ERR_NO_MEM, err, TAG, "no mem for TX DMA buffers");
|
||||||
}
|
}
|
||||||
emac_hal_init(&emac_esp_dma->hal);
|
emac_hal_init(&emac_esp_dma->hal);
|
||||||
|
Reference in New Issue
Block a user