arch: cxd56xx: Add new feature to use GNSS RAM

As long as the GNSS feature is not used, GNSS RAM can be used as general memory.
This memory is 640KByte total, which is lower performance than the application RAM.
It is possible to locate text, data and bss into GNSS RAM and to use as heap area.
This commit is contained in:
SPRESENSE 2024-02-05 19:08:29 +09:00 committed by Xiang Xiao
parent fc5ae43dda
commit a303ec8653
7 changed files with 502 additions and 0 deletions

View File

@ -0,0 +1,186 @@
/****************************************************************************
* arch/arm/include/cxd56xx/gnssram.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_ARM_INCLUDE_CXD56XX_GNSSRAM_H
#define __ARCH_ARM_INCLUDE_CXD56XX_GNSSRAM_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <sys/types.h>
#include <stdint.h>
#ifndef __ASSEMBLY__
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define SECTION_GNSSRAM_TEXT ".gnssram.text"
#define SECTION_GNSSRAM_DATA ".gnssram.data"
#define SECTION_GNSSRAM_BSS ".gnssram.bss"
/* Locate code and data into GNSS RAM */
#ifdef CONFIG_CXD56_GNSS_RAM
# define GNSSRAM_CODE locate_code(SECTION_GNSSRAM_TEXT)
# define GNSSRAM_DATA locate_data(SECTION_GNSSRAM_DATA)
# define GNSSRAM_BSS locate_data(SECTION_GNSSRAM_BSS)
#else
# define GNSSRAM_CODE
# define GNSSRAM_DATA
# define GNSSRAM_BSS
#endif
/****************************************************************************
* Public Functions Prototypes
****************************************************************************/
/****************************************************************************
* Name: up_gnssram_initialize
*
* Description:
* Initialize the GNSS heap.
*
****************************************************************************/
void up_gnssram_initialize(void);
/****************************************************************************
* Name: up_gnssram_uninitialize
*
* Description:
* Uninitialize the GNSS heap.
*
****************************************************************************/
void up_gnssram_uninitialize(void);
/****************************************************************************
* Name: up_gnssram_malloc
*
* Description:
* Allocate memory from the GNSS heap.
*
****************************************************************************/
void *up_gnssram_malloc(size_t size);
/****************************************************************************
* Name: up_gnssram_calloc
*
* Description:
* Calculates the size of the allocation and allocate memory from
* the GNSS heap.
*
****************************************************************************/
void *up_gnssram_calloc(size_t n, size_t elem_size);
/****************************************************************************
* Name: up_gnssram_realloc
*
* Description:
* Reallocate memory from the GNSS heap.
*
****************************************************************************/
void *up_gnssram_realloc(void *ptr, size_t size);
/****************************************************************************
* Name: up_gnssram_zalloc
*
* Description:
* Allocate and zero memory from the GNSS heap.
*
****************************************************************************/
void *up_gnssram_zalloc(size_t size);
/****************************************************************************
* Name: up_gnssram_free
*
* Description:
* Free memory from the GNSS heap.
*
****************************************************************************/
void up_gnssram_free(void *mem);
/****************************************************************************
* Name: up_gnssram_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 *up_gnssram_memalign(size_t alignment, size_t size);
/****************************************************************************
* Name: up_gnssram_heapmember
*
* Description:
* Check if an address lies in the GNSS heap.
*
* Parameters:
* mem - The address to check
*
* Return Value:
* true if the address is a member of the GNSS heap. false if not
*
****************************************************************************/
bool up_gnssram_heapmember(void *mem);
/****************************************************************************
* Name: up_gnssram_mallinfo
*
* Description:
* mallinfo returns a copy of updated current heap information for the
* GNSS heap.
*
****************************************************************************/
struct mallinfo up_gnssram_mallinfo(void);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_ARM_INCLUDE_CXD56XX_GNSSRAM_H */

View File

@ -1436,4 +1436,22 @@ config CXD56_USE_SYSBUS
---help---
To make ldrex/strex work correctly, this option must be enabled
config CXD56_GNSS_RAM
bool "Use GNSS RAM as general memory"
default !CXD56_SUBCORE
---help---
Enable to use GNSS RAM as general memory. As long as the GNSS feature
is not used, GNSS RAM can be used as general memory. This memory is
640KByte total, which is lower performance than the application RAM.
if CXD56_GNSS_RAM
config CXD56_GNSS_HEAP
bool "Use GNSS RAM as heap memory"
default y
---help---
Enable to use GNSS RAM as heap memory.
endif # CXD56_GNSS_RAM
endmenu

View File

@ -169,3 +169,7 @@ endif
ifeq ($(CONFIG_CXD56_HOSTIF),y)
CHIP_CSRCS += cxd56_hostif.c
endif
ifeq ($(CONFIG_CXD56_GNSS_HEAP),y)
CHIP_CSRCS += cxd56_gnssheap.c
endif

View File

@ -0,0 +1,196 @@
/****************************************************************************
* arch/arm/src/cxd56xx/cxd56_gnssheap.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 <nuttx/config.h>
#include <nuttx/arch.h>
#include <nuttx/mm/mm.h>
#include <arch/chip/gnssram.h>
#include "cxd56_clock.h"
/****************************************************************************
* Private Data
****************************************************************************/
static struct mm_heap_s *g_gnssheap;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: up_gnssram_initialize
*
* Description:
* Initialize the GNSS heap.
*
****************************************************************************/
void up_gnssram_initialize(void)
{
void *start;
size_t size;
/* These values come from the linker scripts. */
extern uint8_t _sgnssheap[];
extern uint8_t _egnssheap[];
cxd56_gnssram_clock_enable();
start = (void *)_sgnssheap;
size = (size_t)(_egnssheap - _sgnssheap);
g_gnssheap = mm_initialize("gnssheap", start, size);
}
/****************************************************************************
* Name: up_gnssram_uninitialize
*
* Description:
* Uninitialize the GNSS heap.
*
****************************************************************************/
void up_gnssram_uninitialize(void)
{
mm_uninitialize(g_gnssheap);
}
/****************************************************************************
* Name: up_gnssram_malloc
*
* Description:
* Allocate memory from the GNSS heap.
*
****************************************************************************/
void *up_gnssram_malloc(size_t size)
{
return mm_malloc(g_gnssheap, size);
}
/****************************************************************************
* Name: up_gnssram_calloc
*
* Description:
* Calculates the size of the allocation and allocate memory from
* the GNSS heap.
*
****************************************************************************/
void *up_gnssram_calloc(size_t n, size_t elem_size)
{
return mm_calloc(g_gnssheap, n, elem_size);
}
/****************************************************************************
* Name: up_gnssram_realloc
*
* Description:
* Reallocate memory from the GNSS heap.
*
****************************************************************************/
void *up_gnssram_realloc(void *ptr, size_t size)
{
return mm_realloc(g_gnssheap, ptr, size);
}
/****************************************************************************
* Name: up_gnssram_zalloc
*
* Description:
* Allocate and zero memory from the GNSS heap.
*
****************************************************************************/
void *up_gnssram_zalloc(size_t size)
{
return mm_zalloc(g_gnssheap, size);
}
/****************************************************************************
* Name: up_gnssram_free
*
* Description:
* Free memory from the GNSS heap.
*
****************************************************************************/
void up_gnssram_free(void *mem)
{
mm_free(g_gnssheap, mem);
}
/****************************************************************************
* Name: up_gnssram_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 *up_gnssram_memalign(size_t alignment, size_t size)
{
return mm_memalign(g_gnssheap, alignment, size);
}
/****************************************************************************
* Name: up_gnssram_heapmember
*
* Description:
* Check if an address lies in the GNSS heap.
*
* Parameters:
* mem - The address to check
*
* Return Value:
* true if the address is a member of the GNSS heap. false if not
*
****************************************************************************/
bool up_gnssram_heapmember(void *mem)
{
return mm_heapmember(g_gnssheap, mem);
}
/****************************************************************************
* Name: up_gnssram_mallinfo
*
* Description:
* mallinfo returns a copy of updated current heap information for the
* user heap.
*
****************************************************************************/
struct mallinfo up_gnssram_mallinfo(void)
{
return mm_mallinfo(g_gnssheap);
}

View File

@ -164,6 +164,18 @@ void __start(void)
*dest++ = 0;
}
#ifdef CONFIG_CXD56_GNSS_RAM
/* Clear .gnssram.bss section. */
extern uint8_t _gnssramsbss[];
extern uint8_t _gnssramebss[];
for (dest = (uint32_t *)_gnssramsbss; dest < (uint32_t *)_gnssramebss; )
{
*dest++ = 0;
}
#endif
/* Initialize the FPU (if configured) */
arm_fpuconfig();

View File

@ -21,6 +21,7 @@
MEMORY
{
ram (rwx) : ORIGIN = 0x0d000000, LENGTH = 1536K
gnssram (rwx) : ORIGIN = 0x09000000, LENGTH = 640K
}
OUTPUT_ARCH(arm)
@ -29,6 +30,48 @@ EXTERN(_vectors) /* Force the vectors to be included in the output */
EXTERN(__stack) /* Force the __stack to be included in the output */
SECTIONS
{
/* GNSS memory */
.gnssram.text : {
_sgnsstext = ABSOLUTE(.);
/* Possible to locate text of any object file.
* *libxxx.a:*.o(.text .text.*)
* *libxxx.a:*.o(.rodata .rodata.*)
*/
} > gnssram
.gnssram.data . : ALIGN(4) {
/* Possible to locate data of any object file.
* *libxxx.a:*.o(.data .data.*)
*/
} > gnssram
.gnssram.bss . (NOLOAD) : {
. = ALIGN(4);
_gnssramsbss = ABSOLUTE(.);
/* Possible to locate bss of any object file.
* *libxxx.a:*.o(.bss .bss.*)
* *libxxx.a:*.o(COMMON)
*/
} > gnssram
. = ALIGN(4);
_gnssramebss = ABSOLUTE(.);
/* Whatever is left from the GNSS memory is used as a special heap. */
_sgnssheap = ABSOLUTE(.);
_egnssheap = ORIGIN(gnssram) + LENGTH(gnssram);
ASSERT(_sgnssheap < _egnssheap, "Error: Out of memory")
/* Application memory */
.text : {
_stext = ABSOLUTE(.);
*(.vectors)

View File

@ -21,6 +21,7 @@
MEMORY
{
ram (rwx) : ORIGIN = 0x0d000000, LENGTH = 1536K
gnssram (rwx) : ORIGIN = 0x09000000, LENGTH = 640K
}
OUTPUT_ARCH(arm)
@ -29,6 +30,48 @@ EXTERN(_vectors) /* Force the vectors to be included in the output */
EXTERN(__stack) /* Force the __stack to be included in the output */
SECTIONS
{
/* GNSS memory */
.gnssram.text : {
_sgnsstext = ABSOLUTE(.);
/* Possible to locate text of any object file.
* *libxxx.a:*.o(.text .text.*)
* *libxxx.a:*.o(.rodata .rodata.*)
*/
} > gnssram
.gnssram.data . : ALIGN(4) {
/* Possible to locate data of any object file.
* *libxxx.a:*.o(.data .data.*)
*/
} > gnssram
.gnssram.bss . (NOLOAD) : {
. = ALIGN(4);
_gnssramsbss = ABSOLUTE(.);
/* Possible to locate bss of any object file.
* *libxxx.a:*.o(.bss .bss.*)
* *libxxx.a:*.o(COMMON)
*/
} > gnssram
. = ALIGN(4);
_gnssramebss = ABSOLUTE(.);
/* Whatever is left from the GNSS memory is used as a special heap. */
_sgnssheap = ABSOLUTE(.);
_egnssheap = ORIGIN(gnssram) + LENGTH(gnssram);
ASSERT(_sgnssheap < _egnssheap, "Error: Out of memory")
/* Application memory */
.text : {
_stext = ABSOLUTE(.);
*(.vectors)