summaryrefslogtreecommitdiff
path: root/nuttx/arch/arm/src/lpc17xx/lpc17_allocateheap.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-03-11 17:51:42 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-03-11 17:51:42 +0000
commit3578c60ae17a31fef6486ba5c3a2f97b899fb243 (patch)
tree69156c78a6928e337491e60e93b707b1bf362c97 /nuttx/arch/arm/src/lpc17xx/lpc17_allocateheap.c
parent065661cbab0d8ca6f3739c02d0536de3de362402 (diff)
downloadpx4-nuttx-3578c60ae17a31fef6486ba5c3a2f97b899fb243.tar.gz
px4-nuttx-3578c60ae17a31fef6486ba5c3a2f97b899fb243.tar.bz2
px4-nuttx-3578c60ae17a31fef6486ba5c3a2f97b899fb243.zip
Add MPU support for the LPC17xx family
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5731 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/arm/src/lpc17xx/lpc17_allocateheap.c')
-rw-r--r--nuttx/arch/arm/src/lpc17xx/lpc17_allocateheap.c76
1 files changed, 75 insertions, 1 deletions
diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_allocateheap.c b/nuttx/arch/arm/src/lpc17xx/lpc17_allocateheap.c
index c49ceed36..b5cacce27 100644
--- a/nuttx/arch/arm/src/lpc17xx/lpc17_allocateheap.c
+++ b/nuttx/arch/arm/src/lpc17xx/lpc17_allocateheap.c
@@ -53,6 +53,7 @@
#include "chip/lpc17_memorymap.h"
#include "lpc17_emacram.h"
#include "lpc17_ohciram.h"
+#include "lpc17_mpuinit.h"
/****************************************************************************
* Private Definitions
@@ -195,11 +196,84 @@
void up_allocate_heap(FAR void **heap_start, size_t *heap_size)
{
+#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
+ /* Get the unaligned size of the user-space heap */
+
+ uintptr_t ubase = (uintptr_t)g_heapbase + CONFIG_MM_KERNEL_HEAPSIZE;
+ size_t usize = CONFIG_DRAM_END - ubase;
+ int log2;
+
+ DEBUGASSERT(ubase < (uintptr_t)CONFIG_DRAM_END);
+
+ /* Adjust that size to account for MPU alignment requirements.
+ * NOTE that there is an implicit assumption that the CONFIG_DRAM_END
+ * is aligned to the MPU requirement.
+ */
+
+ log2 = (int)mpu_log2regionsize(usize);
+ DEBUGASSERT((CONFIG_DRAM_END & ((1 << log2) - 1)) == 0);
+
+ usize = (1 << log2);
+ ubase = CONFIG_DRAM_END - usize
+
+ /* Return the user-space heap settings */
+
+ up_ledon(LED_HEAPALLOCATE);
+ *heap_start = (FAR void*)ubase;
+ *heap_size = usize;
+
+ /* Allow user-mode access to the user heap memory */
+
+ lpc17_mpu_uheap((uintptr_t)ubase, usize);
+#else
+
+ /* Return the heap settings */
+
up_ledon(LED_HEAPALLOCATE);
*heap_start = (FAR void*)g_heapbase;
- *heap_size = CONFIG_DRAM_END - g_heapbase;
+ *heap_size = CONFIG_DRAM_END - g_heapbase;
+#endif
}
+/****************************************************************************
+ * Name: up_allocate_kheap
+ *
+ * Description:
+ * For the kernel build (CONFIG_NUTTX_KERNEL=y) with both kernel- and
+ * user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function allocates
+ * (and protects) the kernel-space heap.
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
+void up_allocate_kheap(FAR void **heap_start, size_t *heap_size)
+{
+ /* Get the unaligned size of the user-space heap */
+
+ uintptr_t ubase = (uintptr_t)g_heapbase + CONFIG_MM_KERNEL_HEAPSIZE;
+ size_t usize = CONFIG_DRAM_END - ubase;
+ int log2;
+
+ DEBUGASSERT(ubase < (uintptr_t)CONFIG_DRAM_END);
+
+ /* Adjust that size to account for MPU alignment requirements.
+ * NOTE that there is an implicit assumption that the CONFIG_DRAM_END
+ * is aligned to the MPU requirement.
+ */
+
+ log2 = (int)mpu_log2regionsize(usize);
+ DEBUGASSERT((CONFIG_DRAM_END & ((1 << log2) - 1)) == 0);
+
+ usize = (1 << log2);
+ ubase = CONFIG_DRAM_END - usize
+
+ /* Return the kernel heap settings */
+
+ *heap_start = (FAR void*)g_heapbase;
+ *heap_size = ubase - (uintptr_t)g_heapbase;
+}
+#endif
+
/************************************************************************
* Name: up_addregion
*