arch/risc-v/esp32c3/esp32c3_modtext.c: Prioritise allocation from the
RTC heap when available. Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
This commit is contained in:
parent
f54804bafc
commit
79e9347551
1 changed files with 49 additions and 7 deletions
|
@ -33,6 +33,12 @@
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/kmalloc.h>
|
#include <nuttx/kmalloc.h>
|
||||||
|
|
||||||
|
#include "hardware/esp32c3_soc.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32C3_RTC_HEAP
|
||||||
|
#include "esp32c3_rtc_heap.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -49,20 +55,44 @@
|
||||||
|
|
||||||
void up_module_text_init()
|
void up_module_text_init()
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_ESP32C3_RTC_HEAP
|
||||||
|
/* Initialize the RTC heap */
|
||||||
|
|
||||||
|
esp32c3_rtc_heap_initialize();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: up_module_text_memalign()
|
* Name: up_module_text_memalign()
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Allocate memory for module text with the specified alignment.
|
||||||
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
FAR void *up_module_text_memalign(size_t align, size_t size)
|
FAR void *up_module_text_memalign(size_t align, size_t size)
|
||||||
{
|
{
|
||||||
FAR void *ret;
|
FAR void *ret = NULL;
|
||||||
|
|
||||||
ret = kmm_memalign(align, size);
|
/* Prioritise allocating from RTC. If that fails, allocate from the
|
||||||
if (ret)
|
* main heap.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32C3_RTC_HEAP
|
||||||
|
ret = esp32c3_rtc_heap_memalign(align, size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (ret == NULL)
|
||||||
{
|
{
|
||||||
ret += D_I_BUS_OFFSET;
|
ret = kmm_memalign(align, size);
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
/* kmm_memalign buffer is at the Data bus offset. Adjust it so we
|
||||||
|
* can access it from the Instruction bus.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ret += D_I_BUS_OFFSET;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -70,14 +100,26 @@ FAR void *up_module_text_memalign(size_t align, size_t size)
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: up_module_text_free()
|
* Name: up_module_text_free()
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Free memory for module text.
|
||||||
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void up_module_text_free(FAR void *p)
|
void up_module_text_free(FAR void *p)
|
||||||
{
|
{
|
||||||
if (p)
|
if (p)
|
||||||
{
|
{
|
||||||
p -= D_I_BUS_OFFSET;
|
#ifdef CONFIG_ESP32C3_RTC_HEAP
|
||||||
|
if (esp32c3_ptr_rtc(p))
|
||||||
|
{
|
||||||
|
esp32c3_rtc_heap_free(p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
p -= D_I_BUS_OFFSET;
|
||||||
|
kmm_free(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kmm_free(p);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue