diff --git a/arch/arm/include/cxd56xx/gnssram.h b/arch/arm/include/cxd56xx/gnssram.h new file mode 100644 index 0000000000000..c7a1e33f1f11a --- /dev/null +++ b/arch/arm/include/cxd56xx/gnssram.h @@ -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 + +#include +#include +#include + +#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 */ diff --git a/arch/arm/src/cxd56xx/Kconfig b/arch/arm/src/cxd56xx/Kconfig index 8d3b7c27b39aa..f28d0692e10a2 100644 --- a/arch/arm/src/cxd56xx/Kconfig +++ b/arch/arm/src/cxd56xx/Kconfig @@ -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 diff --git a/arch/arm/src/cxd56xx/Make.defs b/arch/arm/src/cxd56xx/Make.defs index c7fef91031ed1..54c653c050d1b 100644 --- a/arch/arm/src/cxd56xx/Make.defs +++ b/arch/arm/src/cxd56xx/Make.defs @@ -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 diff --git a/arch/arm/src/cxd56xx/cxd56_gnssheap.c b/arch/arm/src/cxd56xx/cxd56_gnssheap.c new file mode 100644 index 0000000000000..cd7c93b456776 --- /dev/null +++ b/arch/arm/src/cxd56xx/cxd56_gnssheap.c @@ -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 + +#include +#include +#include + +#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); +} diff --git a/arch/arm/src/cxd56xx/cxd56_start.c b/arch/arm/src/cxd56xx/cxd56_start.c index efca5ffc45c64..078f05d3a0568 100644 --- a/arch/arm/src/cxd56xx/cxd56_start.c +++ b/arch/arm/src/cxd56xx/cxd56_start.c @@ -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(); diff --git a/boards/arm/cxd56xx/spresense/scripts/ramconfig-new.ld b/boards/arm/cxd56xx/spresense/scripts/ramconfig-new.ld index 521fd8c58bbc9..ba2de421eafce 100644 --- a/boards/arm/cxd56xx/spresense/scripts/ramconfig-new.ld +++ b/boards/arm/cxd56xx/spresense/scripts/ramconfig-new.ld @@ -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) diff --git a/boards/arm/cxd56xx/spresense/scripts/ramconfig.ld b/boards/arm/cxd56xx/spresense/scripts/ramconfig.ld index b2842e960c32b..0a0235886bc3e 100644 --- a/boards/arm/cxd56xx/spresense/scripts/ramconfig.ld +++ b/boards/arm/cxd56xx/spresense/scripts/ramconfig.ld @@ -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)