Skip to content

Commit

Permalink
zephyr: Use shared multi heap in wifi adapter
Browse files Browse the repository at this point in the history
Allow to use the shared multi heap in the wifi
related heap allocations.

Signed-off-by: Marek Matej <marek.matej@espressif.com>
  • Loading branch information
Marek Matej committed Aug 16, 2024
1 parent 83f145a commit c7d27c6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions zephyr/esp32/src/wifi/esp_wifi_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ LOG_MODULE_REGISTER(esp32_wifi_adapter, CONFIG_WIFI_LOG_LEVEL);
#include "wifi/wifi_event.h"
#include "esp_private/adc_share_hw_ctrl.h"

#include <zephyr/multi_heap/shared_multi_heap.h>


ESP_EVENT_DEFINE_BASE(WIFI_EVENT);

static void *wifi_msgq_buffer;
Expand Down Expand Up @@ -74,7 +77,11 @@ static void IRAM_ATTR s_esp_dport_access_stall_other_cpu_end(void)

IRAM_ATTR void *wifi_malloc(size_t size)
{
#ifdef CONFIG_ESP32_WIFI_NET_ALLOC_SPIRAM
void *ptr = shared_multi_heap_aligned_alloc(SMH_REG_ATTR_EXTERNAL, 32, size);
#else
void *ptr = k_malloc(size);
#endif

if (ptr == NULL) {
LOG_ERR("memory allocation failed");
Expand All @@ -91,7 +98,14 @@ IRAM_ATTR void *wifi_realloc(void *ptr, size_t size)

IRAM_ATTR void *wifi_calloc(size_t n, size_t size)
{
#ifndef CONFIG_ESP32_WIFI_NET_ALLOC_SPIRAM
void *ptr = shared_multi_heap_aligned_alloc(SMH_REG_ATTR_EXTERNAL, 32, size);
if (ptr) {
(void)memset(ptr, 0, size);
}
#else
void *ptr = k_calloc(n, size);
#endif

if (ptr == NULL) {
LOG_ERR("memory allocation failed");
Expand Down

0 comments on commit c7d27c6

Please sign in to comment.