diff --git a/arch/xtensa/src/esp32/Make.defs b/arch/xtensa/src/esp32/Make.defs index 6516cfd05bd..7c31b94cdaa 100644 --- a/arch/xtensa/src/esp32/Make.defs +++ b/arch/xtensa/src/esp32/Make.defs @@ -185,6 +185,7 @@ endif endif ifeq ($(CONFIG_ARCH_USE_TEXT_HEAP),y) +CHIP_CSRCS += esp32_iramheap.c CHIP_CSRCS += esp32_textheap.c CMN_ASRCS += xtensa_loadstore.S endif diff --git a/arch/xtensa/src/esp32/esp32_iramheap.c b/arch/xtensa/src/esp32/esp32_iramheap.c new file mode 100644 index 00000000000..56d854cccbb --- /dev/null +++ b/arch/xtensa/src/esp32/esp32_iramheap.c @@ -0,0 +1,191 @@ +/**************************************************************************** + * arch/xtensa/src/esp32/esp32_iramheap.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include "esp32_iramheap.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct mm_heap_s g_iramheap; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32_iramheap_initialize + * + * Description: + * Initialize the IRAM heap. + * + ****************************************************************************/ + +void esp32_iramheap_initialize(void) +{ + void *start; + size_t size; + + /* These values come from the linker scripts. Check boards/xtensa/esp32. */ + + extern uint8_t *_siramheap; + extern uint8_t *_eiramheap; + + start = (void *)&_siramheap; + size = (size_t)((uintptr_t)&_eiramheap - (uintptr_t)&_siramheap); + mm_initialize(&g_iramheap, start, size); + +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) + static struct procfs_meminfo_entry_s g_iram_procfs; + + g_iram_procfs.name = "iramheap"; + g_iram_procfs.mallinfo = (void *)mm_mallinfo; + g_iram_procfs.user_data = &g_iramheap; + procfs_register_meminfo(&g_iram_procfs); +#endif +} + +/**************************************************************************** + * Name: esp32_iramheap_malloc + * + * Description: + * Allocate memory from the IRAM heap. + * + ****************************************************************************/ + +void *esp32_iramheap_malloc(size_t size) +{ + return mm_malloc(&g_iramheap, size); +} + +/**************************************************************************** + * Name: esp32_iramheap_calloc + * + * Description: + * Calculates the size of the allocation and allocate memory from + * the IRAM heap. + * + ****************************************************************************/ + +void *esp32_iramheap_calloc(size_t n, size_t elem_size) +{ + return mm_calloc(&g_iramheap, n, elem_size); +} + +/**************************************************************************** + * Name: esp32_iramheap_realloc + * + * Description: + * Reallocate memory from the IRAM heap. + * + ****************************************************************************/ + +void *esp32_iramheap_realloc(void *ptr, size_t size) +{ + return mm_realloc(&g_iramheap, ptr, size); +} + +/**************************************************************************** + * Name: esp32_iramheap_zalloc + * + * Description: + * Allocate and zero memory from the IRAM heap. + * + ****************************************************************************/ + +void *esp32_iramheap_zalloc(size_t size) +{ + return mm_zalloc(&g_iramheap, size); +} + +/**************************************************************************** + * Name: esp32_iramheap_free + * + * Description: + * Free memory from the IRAM heap. + * + ****************************************************************************/ + +void esp32_iramheap_free(void *mem) +{ + mm_free(&g_iramheap, mem); +} + +/**************************************************************************** + * Name: esp32_iramheap_memalign + * + * Description: + * memalign requests more than enough space from malloc, finds a region + * within that chunk that meets the alignment request and then frees any + * leading or trailing space. + * + * The alignment argument must be a power of two (not checked). 8-byte + * alignment is guaranteed by normal malloc calls. + * + ****************************************************************************/ + +void *esp32_iramheap_memalign(size_t alignment, size_t size) +{ + return mm_memalign(&g_iramheap, alignment, size); +} + +/**************************************************************************** + * Name: esp32_iramheap_heapmember + * + * Description: + * Check if an address lies in the IRAM heap. + * + * Parameters: + * mem - The address to check + * + * Return Value: + * true if the address is a member of the IRAM heap. false if not + * + ****************************************************************************/ + +bool esp32_iramheap_heapmember(void *mem) +{ + return mm_heapmember(&g_iramheap, mem); +} + +/**************************************************************************** + * Name: esp32_iramheap_mallinfo + * + * Description: + * mallinfo returns a copy of updated current heap information for the + * user heap. + * + ****************************************************************************/ + +int esp32_iramheap_mallinfo(struct mallinfo *info) +{ + return mm_mallinfo(&g_iramheap, info); +} diff --git a/arch/xtensa/src/esp32/esp32_iramheap.h b/arch/xtensa/src/esp32/esp32_iramheap.h new file mode 100644 index 00000000000..2a846440e8a --- /dev/null +++ b/arch/xtensa/src/esp32/esp32_iramheap.h @@ -0,0 +1,146 @@ +/**************************************************************************** + * arch/xtensa/src/esp32/esp32_iramheap.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_XTENSA_SRC_ESP32_ESP32_IRAMHEAP_H +#define __ARCH_XTENSA_SRC_ESP32_ESP32_IRAMHEAP_H + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +struct mallinfo; /* Forward reference, see malloc.h */ + +/**************************************************************************** + * Name: esp32_iramheap_initialize + * + * Description: + * Initialize the IRAM heap. + * + ****************************************************************************/ + +void esp32_iramheap_initialize(void); + +/**************************************************************************** + * Name: esp32_iramheap_malloc + * + * Description: + * Allocate memory from the IRAM heap. + * + ****************************************************************************/ + +void *esp32_iramheap_malloc(size_t size); + +/**************************************************************************** + * Name: esp32_iramheap_calloc + * + * Description: + * Calculates the size of the allocation and allocate memory from + * the IRAM heap. + * + ****************************************************************************/ + +void *esp32_iramheap_calloc(size_t n, size_t elem_size); + +/**************************************************************************** + * Name: esp32_iramheap_realloc + * + * Description: + * Reallocate memory from the IRAM heap. + * + ****************************************************************************/ + +void *esp32_iramheap_realloc(void *ptr, size_t size); + +/**************************************************************************** + * Name: esp32_iramheap_zalloc + * + * Description: + * Allocate and zero memory from the IRAM heap. + * + ****************************************************************************/ + +void *esp32_iramheap_zalloc(size_t size); + +/**************************************************************************** + * Name: esp32_iramheap_free + * + * Description: + * Free memory from the IRAM heap. + * + ****************************************************************************/ + +void esp32_iramheap_free(void *mem); + +/**************************************************************************** + * Name: esp32_iramheap_memalign + * + * Description: + * memalign requests more than enough space from malloc, finds a region + * within that chunk that meets the alignment request and then frees any + * leading or trailing space. + * + * The alignment argument must be a power of two (not checked). 8-byte + * alignment is guaranteed by normal malloc calls. + * + ****************************************************************************/ + +void *esp32_iramheap_memalign(size_t alignment, size_t size); + +/**************************************************************************** + * Name: esp32_iramheap_heapmember + * + * Description: + * Check if an address lies in the IRAM heap. + * + * Parameters: + * mem - The address to check + * + * Return Value: + * true if the address is a member of the IRAM heap. false if not + * + ****************************************************************************/ + +bool esp32_iramheap_heapmember(void *mem); + +/**************************************************************************** + * Name: esp32_iramheap_mallinfo + * + * Description: + * mallinfo returns a copy of updated current heap information for the + * user heap. + * + ****************************************************************************/ + +int esp32_iramheap_mallinfo(struct mallinfo *info); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __ARCH_XTENSA_SRC_ESP32_ESP32_IRAMHEAP_H */ diff --git a/arch/xtensa/src/esp32/esp32_user.c b/arch/xtensa/src/esp32/esp32_user.c index 418fe794308..95620a26d79 100644 --- a/arch/xtensa/src/esp32/esp32_user.c +++ b/arch/xtensa/src/esp32/esp32_user.c @@ -39,8 +39,8 @@ ****************************************************************************/ #ifdef CONFIG_ARCH_USE_TEXT_HEAP -extern uint32_t _stextheap; -extern uint32_t _etextheap; +extern uint32_t _siramheap; +extern uint32_t _eiramheap; #endif /**************************************************************************** @@ -338,8 +338,8 @@ uint32_t *xtensa_user(int exccause, uint32_t *regs) */ if (exccause == XCHAL_EXCCAUSE_LOAD_STORE_ERROR && - (uintptr_t)&_stextheap <= regs[REG_EXCVADDR] && - (uintptr_t)&_etextheap > regs[REG_EXCVADDR]) + (uintptr_t)&_siramheap <= regs[REG_EXCVADDR] && + (uintptr_t)&_eiramheap > regs[REG_EXCVADDR]) { uint8_t *pc = (uint8_t *)regs[REG_PC]; uint8_t imm8; diff --git a/boards/xtensa/esp32/esp32-devkitc/scripts/esp32.template.ld b/boards/xtensa/esp32/esp32-devkitc/scripts/esp32.template.ld index e37e49cdff2..6b017492c85 100644 --- a/boards/xtensa/esp32/esp32-devkitc/scripts/esp32.template.ld +++ b/boards/xtensa/esp32/esp32-devkitc/scripts/esp32.template.ld @@ -78,9 +78,9 @@ MEMORY _eheap = 0x40000000 - CONFIG_ESP32_TRACEMEM_RESERVE_DRAM; -/* Text heap ends at top of dram0_0_seg */ +/* IRAM heap ends at top of dram0_0_seg */ -_etextheap = 0x400a0000; +_eiramheap = 0x400a0000; /* Mark the end of the RTC heap (top of the RTC region) */ diff --git a/boards/xtensa/esp32/esp32-devkitc/scripts/esp32_flash.ld b/boards/xtensa/esp32/esp32-devkitc/scripts/esp32_flash.ld index 56e4b9f91cb..835e62e7daa 100644 --- a/boards/xtensa/esp32/esp32-devkitc/scripts/esp32_flash.ld +++ b/boards/xtensa/esp32/esp32-devkitc/scripts/esp32_flash.ld @@ -63,10 +63,10 @@ SECTIONS *(.phyiram .phyiram.*) _iram_text_end = ABSOLUTE(.); - /* Text heap starts at the end of iram0_0_seg */ + /* IRAM heap starts at the end of iram0_0_seg */ . = ALIGN (4); - _stextheap = ABSOLUTE(.); + _siramheap = ABSOLUTE(.); } > iram0_0_seg /* Shared RAM */ diff --git a/boards/xtensa/esp32/esp32-devkitc/scripts/esp32_iram.ld b/boards/xtensa/esp32/esp32-devkitc/scripts/esp32_iram.ld index 672972b184a..6f4a838e83a 100644 --- a/boards/xtensa/esp32/esp32-devkitc/scripts/esp32_iram.ld +++ b/boards/xtensa/esp32/esp32-devkitc/scripts/esp32_iram.ld @@ -70,10 +70,10 @@ SECTIONS _text_end = ABSOLUTE(.); _etext = .; - /* Text heap starts at the end of iram0_0_seg */ + /* IRAM heap starts at the end of iram0_0_seg */ . = ALIGN (4); - _stextheap = ABSOLUTE(.); + _siramheap = ABSOLUTE(.); } > iram0_0_seg /* Shared RAM */ diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32.template.ld b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32.template.ld index 35d9c3ddb6a..b84624d7f23 100644 --- a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32.template.ld +++ b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32.template.ld @@ -78,9 +78,9 @@ MEMORY _eheap = 0x40000000 - CONFIG_ESP32_TRACEMEM_RESERVE_DRAM; -/* Text heap ends at top of dram0_0_seg */ +/* IRAM heap ends at top of dram0_0_seg */ -_etextheap = 0x400a0000; +_eiramheap = 0x400a0000; /* Mark the end of the RTC heap (top of the RTC region) */ diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32_flash.ld b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32_flash.ld index c1dfdd14fd7..1848a9ffe51 100644 --- a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32_flash.ld +++ b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32_flash.ld @@ -66,10 +66,10 @@ SECTIONS *(.phyiram .phyiram.*) _iram_text_end = ABSOLUTE(.); - /* Text heap starts at the end of iram0_0_seg */ + /* IRAM heap starts at the end of iram0_0_seg */ . = ALIGN (4); - _stextheap = ABSOLUTE(.); + _siramheap = ABSOLUTE(.); } > iram0_0_seg /* Shared RAM */ diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32_iram.ld b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32_iram.ld index 927e177ff54..d2e5333ab86 100644 --- a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32_iram.ld +++ b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/esp32_iram.ld @@ -70,10 +70,10 @@ SECTIONS _text_end = ABSOLUTE(.); _etext = .; - /* Text heap starts at the end of iram0_0_seg */ + /* IRAM heap starts at the end of iram0_0_seg */ . = ALIGN (4); - _stextheap = ABSOLUTE(.); + _siramheap = ABSOLUTE(.); } > iram0_0_seg /* Shared RAM */ diff --git a/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32.template.ld b/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32.template.ld index 7745cebc12b..ea98d727d92 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32.template.ld +++ b/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32.template.ld @@ -78,9 +78,9 @@ MEMORY _eheap = 0x40000000 - CONFIG_ESP32_TRACEMEM_RESERVE_DRAM; -/* Text heap ends at top of dram0_0_seg */ +/* IRAM heap ends at top of dram0_0_seg */ -_etextheap = 0x400a0000; +_eiramheap = 0x400a0000; /* Mark the end of the RTC heap (top of the RTC region) */ diff --git a/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32_flash.ld b/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32_flash.ld index ec4e40056a3..c6bf9ee3c79 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32_flash.ld +++ b/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32_flash.ld @@ -66,10 +66,10 @@ SECTIONS *(.phyiram .phyiram.*) _iram_text_end = ABSOLUTE(.); - /* Text heap starts at the end of iram0_0_seg */ + /* iram heap starts at the end of iram0_0_seg */ . = ALIGN (4); - _stextheap = ABSOLUTE(.); + _siramheap = ABSOLUTE(.); } > iram0_0_seg /* Shared RAM */ diff --git a/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32_iram.ld b/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32_iram.ld index 613ac15a846..427988369a1 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32_iram.ld +++ b/boards/xtensa/esp32/esp32-wrover-kit/scripts/esp32_iram.ld @@ -70,10 +70,10 @@ SECTIONS _text_end = ABSOLUTE(.); _etext = .; - /* Text heap starts at the end of iram0_0_seg */ + /* IRAM heap starts at the end of iram0_0_seg */ . = ALIGN (4); - _stextheap = ABSOLUTE(.); + _siramheap = ABSOLUTE(.); } > iram0_0_seg /* Shared RAM */