You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/06/18 05:53:55 UTC
[incubator-nuttx] 06/06: arch/risc-v/esp32c3/esp32c3_modtext.c:
Prioritise allocation from the RTC heap when available.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 79e934755103b56557caa0cde4ab13e45ce0a2c7
Author: Abdelatif Guettouche <ab...@espressif.com>
AuthorDate: Wed Jun 16 23:38:25 2021 +0100
arch/risc-v/esp32c3/esp32c3_modtext.c: Prioritise allocation from the
RTC heap when available.
Signed-off-by: Abdelatif Guettouche <ab...@espressif.com>
---
arch/risc-v/src/esp32c3/esp32c3_modtext.c | 56 +++++++++++++++++++++++++++----
1 file changed, 49 insertions(+), 7 deletions(-)
diff --git a/arch/risc-v/src/esp32c3/esp32c3_modtext.c b/arch/risc-v/src/esp32c3/esp32c3_modtext.c
index 92b41cb..0277cb6 100644
--- a/arch/risc-v/src/esp32c3/esp32c3_modtext.c
+++ b/arch/risc-v/src/esp32c3/esp32c3_modtext.c
@@ -33,6 +33,12 @@
#include <nuttx/arch.h>
#include <nuttx/kmalloc.h>
+#include "hardware/esp32c3_soc.h"
+
+#ifdef CONFIG_ESP32C3_RTC_HEAP
+#include "esp32c3_rtc_heap.h"
+#endif
+
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -49,20 +55,44 @@
void up_module_text_init()
{
+#ifdef CONFIG_ESP32C3_RTC_HEAP
+ /* Initialize the RTC heap */
+
+ esp32c3_rtc_heap_initialize();
+#endif
}
/****************************************************************************
* 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 *ret;
+ FAR void *ret = NULL;
- ret = kmm_memalign(align, size);
- if (ret)
+ /* Prioritise allocating from RTC. If that fails, allocate from the
+ * 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;
@@ -70,14 +100,26 @@ FAR void *up_module_text_memalign(size_t align, size_t size)
/****************************************************************************
* Name: up_module_text_free()
+ *
+ * Description:
+ * Free memory for module text.
+ *
****************************************************************************/
void up_module_text_free(FAR void *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);
}