Add logic to add external memory to heap

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2455 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2009-12-29 16:04:14 +00:00
parent 6b40c11717
commit 33043234be
2 changed files with 111 additions and 0 deletions

View File

@ -53,6 +53,62 @@
* Pre-processor Definitions
************************************************************************/
/* Configuration ********************************************************/
/* Some sanity checking. If external memory regions are defined, verify
* that CONFIG_MM_REGIONS is set to match, exactly, the number of external
* memory regions that we have been asked to add to the heap.
*/
#if defined(CONFIG_LPC313X_EXTSRAM0) && defined(CONFIG_LPC313X_EXTSRAM0HEAP)
# if defined(CONFIG_LPC313X_EXTSRAM1) && defined(CONFIG_LPC313X_EXTSRAM1HEAP)
# if defined(CONFIG_LPC313X_EXTSDRAM) && defined(CONFIG_LPC313X_EXTSDRAMHEAP)
# /* SRAM+EXTSRAM0+EXTSRAM1+EXTSDRAM */
# define LPC313X_NEXT_REGIONS 4
# else
# /* SRAM+EXTSRAM0+EXTSRAM1 */
# define LPC313X_NEXT_REGIONS 3
# endif
# elif defined(CONFIG_LPC313X_EXTSDRAM) && defined(CONFIG_LPC313X_EXTSDRAMHEAP)
# /* SRAM+EXTSRAM0+EXTSDRAM */
# define LPC313X_NEXT_REGIONS 3
# else
# /* SRAM+EXTSRAM0 */
# define LPC313X_NEXT_REGIONS 2
# endif
#elif defined(CONFIG_LPC313X_EXTSRAM1) && defined(CONFIG_LPC313X_EXTSRAM1HEAP)
# if defined(CONFIG_LPC313X_EXTSDRAM) && defined(CONFIG_LPC313X_EXTSDRAMHEAP)
# /* SRAM+EXTSRAM1+EXTSDRAM */
# define LPC313X_NEXT_REGIONS 3
# else
# /* SRAM+EXTSRAM1 */
# define LPC313X_NEXT_REGIONS 2
# endif
#elif defined(CONFIG_LPC313X_EXTSDRAM) && defined(CONFIG_LPC313X_EXTSDRAMHEAP)
# /* SRAM+EXTSDRAM */
# define LPC313X_NEXT_REGIONS 2
#else
# /* SRAM */
# define LPC313X_NEXT_REGIONS 1
#endif
#if CONFIG_MM_REGIONS != LPC313X_NEXT_REGIONS
# if CONFIG_MM_REGIONS < LPC313X_NEXT_REGIONS
# error "CONFIG_MM_REGIONS is large enough for the selected memory regions"
# else
# error "CONFIG_MM_REGIONS is too large for the selected memory regions"
# endif
# if defined(CONFIG_LPC313X_EXTSRAM0) && defined(CONFIG_LPC313X_EXTSRAM0HEAP)
# error "External SRAM0 is selected for heap"
# endif
# if defined(CONFIG_LPC313X_EXTSRAM1) && defined(CONFIG_LPC313X_EXTSRAM1HEAP)
# error "External SRAM1 is selected for heap"
# endif
# if defined(CONFIG_LPC313X_EXTSDRAM) && defined(CONFIG_LPC313X_EXTSDRAMHEAP)
# error "External SRAM1 is selected for heap"
# endif
#endif
/************************************************************************
* Private Data
************************************************************************/
@ -91,3 +147,29 @@ void up_allocate_heap(FAR void **heap_start, size_t *heap_size)
*heap_start = (FAR void*)g_heapbase;
*heap_size = (LPC313X_SRAM_VADDR + CONFIG_DRAM_SIZE) - g_heapbase;
}
/************************************************************************
* Name: up_addregion
*
* Description:
* Memory may be added in non-contiguous chunks. Additional chunks are
* added by calling this function.
*
************************************************************************/
#if CONFIG_MM_REGIONS > 1
void up_addregion(void)
{
#if defined(CONFIG_LPC313X_EXTSRAM0) && defined(CONFIG_LPC313X_EXTSRAM0HEAP)
mm_addregion((FAR void*)LPC313X_EXTSRAM0_VSECTION, CONFIG_LPC313X_EXTSRAM0SIZE);
#endif
#if defined(CONFIG_LPC313X_EXTSRAM1) && defined(CONFIG_LPC313X_EXTSRAM1HEAP)
mm_addregion((FAR void*)LPC313X_EXTSRAM1_VSECTION, CONFIG_LPC313X_EXTSRAM1SIZE);
#endif
#if defined(CONFIG_LPC313X_EXTSDRAM) && defined(CONFIG_LPC313X_EXTSDRAMHEAP)
mm_addregion((FAR void*)LPC313X_EXTSDRAM_VSECTION, CONFIG_LPC313X_EXTSDRAMSIZE);
#endif
}
#endif

View File

@ -105,6 +105,35 @@ CONFIG_LPC313X_MCI=n
CONFIG_LPC313X_SPI=n
CONFIG_LPC313X_UART=y
#
# Exernal memory available on the board (see also CONFIG_MM_REGIONS)
#
# CONFIG_LPC313X_EXTSRAM0 - Select if external SRAM0 is present
# CONFIG_LPC313X_EXTSRAM0HEAP - Select if external SRAM0 should be
# configured as part of the NuttX heap.
# CONFIG_LPC313X_EXTSRAM0SIZE - Size (in bytes) of the installed
# external SRAM0 memory
# CONFIG_LPC313X_EXTSRAM1 - Select if external SRAM1 is present
# CONFIG_LPC313X_EXTSRAM1HEAP - Select if external SRAM1 should be
# configured as part of the NuttX heap.
# CONFIG_LPC313X_EXTSRAM1SIZE - Size (in bytes) of the installed
# external SRAM1 memory
# CONFIG_LPC313X_EXTSDRAM - Select if external SDRAM is present
# CONFIG_LPC313X_EXTSDRAMHEAP - Select if external SDRAM should be
# configured as part of the NuttX heap.
# CONFIG_LPC313X_EXTSDRAMSIZE - Size (in bytes) of the installed
# external SDRAM memory
#
CONFIG_LPC313X_EXTSRAM0=n
CONFIG_LPC313X_EXTSRAM0HEAP=n
CONFIG_LPC313X_EXTSRAM0SIZE=(128*1024)
CONFIG_LPC313X_EXTSRAM1=n
CONFIG_LPC313X_EXTSRAM1HEAP=n
CONFIG_LPC313X_EXTSRAM1SIZE=(128*1024)
CONFIG_LPC313X_EXTSDRAM=n
CONFIG_LPC313X_EXTSDRAMHEAP=n
CONFIG_LPC313X_EXTSDRAMSIZE=(64*1024*1024)
#
# LPC313X specific device driver settings
#