summaryrefslogtreecommitdiff
path: root/nuttx/mm
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/mm')
-rw-r--r--nuttx/mm/mm_environment.h3
-rw-r--r--nuttx/mm/mm_initialize.c21
-rw-r--r--nuttx/mm/mm_internal.h64
-rw-r--r--nuttx/mm/mm_malloc.c2
-rw-r--r--nuttx/mm/mm_memalign.c2
-rw-r--r--nuttx/mm/mm_test.c1
6 files changed, 70 insertions, 23 deletions
diff --git a/nuttx/mm/mm_environment.h b/nuttx/mm/mm_environment.h
index 3525eccc0..ef4f14f7a 100644
--- a/nuttx/mm/mm_environment.h
+++ b/nuttx/mm/mm_environment.h
@@ -1,7 +1,7 @@
/****************************************************************************
* mm/mm_environment.h
*
- * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -76,6 +76,7 @@
# define FAR /* Normally in compiler.h */
# define CONFIG_CPP_HAVE_VARARGS 1 /* Normally in compiler.h */
# define CONFIG_MM_REGIONS 2 /* Normally in config.h */
+# undef CONFIG_MM_SMALL /* Normally in config.h */
# define CONFIG_CAN_PASS_STRUCTS 1 /* Normally in config.h */
# undef CONFIG_SMALL_MEMORY /* Normally in config.h */
diff --git a/nuttx/mm/mm_initialize.c b/nuttx/mm/mm_initialize.c
index 9a580cd89..351948c2f 100644
--- a/nuttx/mm/mm_initialize.c
+++ b/nuttx/mm/mm_initialize.c
@@ -1,7 +1,7 @@
/****************************************************************************
* mm/mm_initialize.c
*
- * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -124,7 +124,7 @@ void mm_initialize(FAR void *heapstart, size_t heapsize)
}
/* Initialize the malloc semaphore to one (to support one-at-
- * a-time access to private data sets.
+ * a-time access to private data sets).
*/
mm_seminitialize();
@@ -155,20 +155,29 @@ void mm_initialize(FAR void *heapstart, size_t heapsize)
void mm_addregion(FAR void *heapstart, size_t heapsize)
{
FAR struct mm_freenode_s *node;
- size_t heapbase;
- size_t heapend;
+ uintptr_t heapbase;
+ uintptr_t heapend;
#if CONFIG_MM_REGIONS > 1
int IDX = g_nregions;
#else
# define IDX 0
#endif
+ /* If the MCU handles wide addresses but the memory manager
+ * is configured for a small heap, then verify that the caller
+ * not doing something crazy.
+ */
+
+#if defined(CONFIG_MM_SMALL) && !defined(CONFIG_SMALL_MEMORY)
+ DEBUGASSERT(heapsize <= MMSIZE_MAX+1);
+#endif
+
/* Adjust the provide heap start and size so that they are
* both aligned with the MM_MIN_CHUNK size.
*/
- heapbase = MM_ALIGN_UP((size_t)heapstart);
- heapend = MM_ALIGN_DOWN((size_t)heapstart + (size_t)heapsize);
+ heapbase = MM_ALIGN_UP((uintptr_t)heapstart);
+ heapend = MM_ALIGN_DOWN((uintptr_t)heapstart + (uintptr_t)heapsize);
heapsize = heapend - heapbase;
mlldbg("Region %d: base=%p size=%u\n", IDX+1, heapstart, heapsize);
diff --git a/nuttx/mm/mm_internal.h b/nuttx/mm/mm_internal.h
index 0649122a2..429559328 100644
--- a/nuttx/mm/mm_internal.h
+++ b/nuttx/mm/mm_internal.h
@@ -1,7 +1,7 @@
/************************************************************************
* mm/mm_internal.h
*
- * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -43,7 +43,24 @@
/************************************************************************
* Pre-processor Definitions
************************************************************************/
+/* Configuration ********************************************************/
+/* If the MCU has a small (16-bit) address capability, then we will use
+ * a smaller chunk header that contains 16-bit size/offset information.
+ * We will also use the smaller header on MCUs with wider addresses if
+ * CONFIG_MM_SMALL is selected. This configuration is common with MCUs
+ * that have a large FLASH space, but only a tiny internal SRAM.
+ */
+
+#ifdef CONFIG_SMALL_MEMORY
+ /* If the MCU has a small addressing capability, then for the smaller
+ * chunk header.
+ */
+
+# undef CONFIG_MM_SMALL
+# define CONFIG_MM_SMALL 1
+#endif
+/* Chunk Header Definitions *********************************************/
/* These definitions define the characteristics of allocator
*
* MM_MIN_SHIFT is used to define MM_MIN_CHUNK.
@@ -61,7 +78,7 @@
* losses.
*/
-#ifdef CONFIG_SMALL_MEMORY
+#ifdef CONFIG_MM_SMALL
# define MM_MIN_SHIFT 4 /* 16 bytes */
# define MM_MAX_SHIFT 15 /* 32 Kb */
#else
@@ -84,7 +101,7 @@
* an allocated chunk.
*/
-#ifdef CONFIG_SMALL_MEMORY
+#ifdef CONFIG_MM_SMALL
# define MM_ALLOC_BIT 0x8000
#else
# define MM_ALLOC_BIT 0x80000000
@@ -96,18 +113,30 @@
* Public Types
************************************************************************/
+/* Determine the size of the chunk size/offset type */
+
+#ifdef CONFIG_MM_SMALL
+ typedef uint16_t mmsize_t;
+# define MMSIZE_MAX 0xffff
+#else
+ typedef size_t mmsize_t;
+# define MMSIZE_MAX SIZE_MAX
+#endif
+
/* This describes an allocated chunk. An allocated chunk is
- * distinguished from a free chunk by bit 31 of the 'precding'
- * chunk size. If set, then this is an allocated chunk.
+ * distinguished from a free chunk by bit 15/31 of the 'preceding' chunk
+ * size. If set, then this is an allocated chunk.
*/
struct mm_allocnode_s
{
- size_t size; /* Size of this chunk */
- size_t preceding; /* Size of the preceding chunk */
+ mmsize_t size; /* Size of this chunk */
+ mmsize_t preceding; /* Size of the preceding chunk */
};
-#ifdef CONFIG_SMALL_MEMORY
+/* What is the size of the allocnode? */
+
+#ifdef CONFIG_MM_SMALL
# define SIZEOF_MM_ALLOCNODE 4
#else
# define SIZEOF_MM_ALLOCNODE 8
@@ -120,18 +149,25 @@ struct mm_allocnode_s
struct mm_freenode_s
{
- size_t size; /* Size of this chunk */
- size_t preceding; /* Size of the preceding chunk */
+ mmsize_t size; /* Size of this chunk */
+ mmsize_t preceding; /* Size of the preceding chunk */
FAR struct mm_freenode_s *flink; /* Supports a doubly linked list */
FAR struct mm_freenode_s *blink;
};
-#ifdef CONFIG_SMALL_MEMORY
-# define SIZEOF_MM_FREENODE 8
+/* Free is the size of the freenode */
+
+#ifdef CONFIG_MM_SMALL
+# ifdef CONFIG_SMALL_MEMORY
+# define SIZEOF_MM_FREENODE 8
+# else
+# define SIZEOF_MM_FREENODE 12
+# endif
#else
-# define SIZEOF_MM_FREENODE 16
+# define SIZEOF_MM_FREENODE 16
#endif
-#define CHECK_FREENODE_SIZE \
+
+#define CHECK_FREENODE_SIZE \
DEBUGASSERT(sizeof(struct mm_freenode_s) == SIZEOF_MM_FREENODE)
/* Normally defined in stdlib.h */
diff --git a/nuttx/mm/mm_malloc.c b/nuttx/mm/mm_malloc.c
index 5d5257716..dbcba33a8 100644
--- a/nuttx/mm/mm_malloc.c
+++ b/nuttx/mm/mm_malloc.c
@@ -199,6 +199,6 @@ FAR void *malloc(size_t size)
}
mm_givesemaphore();
- mvdbg("Allocated %p\n", ret);
+ mvdbg("Allocated %p, size %d\n", ret, size);
return ret;
}
diff --git a/nuttx/mm/mm_memalign.c b/nuttx/mm/mm_memalign.c
index a4d9cabd5..d40f72348 100644
--- a/nuttx/mm/mm_memalign.c
+++ b/nuttx/mm/mm_memalign.c
@@ -94,7 +94,7 @@ FAR void *memalign(size_t alignment, size_t size)
* The do not include SIZEOF_MM_ALLOCNODE.
*/
- size = MM_ALIGN_UP(size); /* Make mutliples of our granule size */
+ size = MM_ALIGN_UP(size); /* Make multiples of our granule size */
allocsize = size + 2*alignment; /* Add double full alignment size */
/* Then malloc that size */
diff --git a/nuttx/mm/mm_test.c b/nuttx/mm/mm_test.c
index 48f380221..e7a44dec7 100644
--- a/nuttx/mm/mm_test.c
+++ b/nuttx/mm/mm_test.c
@@ -41,6 +41,7 @@
#define FAR
#define CONFIG_MM_REGIONS 2
+#undef CONFIG_MM_SMALL
#define CONFIG_CAN_PASS_STRUCTS 1
#undef CONFIG_SMALL_MEMORY