summaryrefslogtreecommitdiff
path: root/nuttx/mm/mm_granfree.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-09-11 20:33:58 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-09-11 20:33:58 +0000
commit63240531781806cb440108ebd5ad0c3dc62510d3 (patch)
tree386d184c161ad982f82fe673bdf69319f84cca6b /nuttx/mm/mm_granfree.c
parent205242a575697630d073edc02a6341e6d9be22a6 (diff)
downloadpx4-nuttx-63240531781806cb440108ebd5ad0c3dc62510d3.tar.gz
px4-nuttx-63240531781806cb440108ebd5ad0c3dc62510d3.tar.bz2
px4-nuttx-63240531781806cb440108ebd5ad0c3dc62510d3.zip
Update to granule allocator; Update to ENC28j60 driver
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5130 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/mm/mm_granfree.c')
-rw-r--r--nuttx/mm/mm_granfree.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/nuttx/mm/mm_granfree.c b/nuttx/mm/mm_granfree.c
index 4679ae62b..e359cded8 100644
--- a/nuttx/mm/mm_granfree.c
+++ b/nuttx/mm/mm_granfree.c
@@ -39,8 +39,14 @@
#include <nuttx/config.h>
+#include <assert.h>
+
#include <nuttx/gran.h>
+#include "mm_gran.h"
+
+#ifdef CONFIG_GRAN
+
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -66,18 +72,29 @@ static inline void gran_common_free(FAR struct gran_s *priv,
unsigned int granno;
unsigned int gatidx;
unsigned int gatbit;
+ unsigned int granmask;
+ unsigned int ngranules;
unsigned int avail;
- uint32_t mask;
+ uint32_t gatmask;
+
+ DEBUGASSERT(priv && memory && size <= 32 * (1 << priv->log2gran));
- /* Determine the granule number of the allocation */
+ /* Determine the granule number of the first granule in the allocation */
- granno = (alloc - priv->heapstart) >> priv->log2gran;
+ granno = ((uintptr_t)memory - priv->heapstart) >> priv->log2gran;
- /* Determine the GAT table index associated with the allocation */
+ /* Determine the GAT table index and bit number associated with the
+ * allocation.
+ */
gatidx = granno >> 5;
gatbit = granno & 31;
+ /* Determine the number of granules in the allocation */
+
+ granmask = (1 << priv->log2gran) - 1;
+ ngranules = (size + granmask) >> priv->log2gran;
+
/* Clear bits in the first GAT entry */
avail = 32 - gatbit;
@@ -91,15 +108,15 @@ static inline void gran_common_free(FAR struct gran_s *priv,
else
{
- mask = 0xffffffff >> (32 - ngranules);
- priv->gat[gatidx] &= ~(mask << gatbit);
+ gatmask = 0xffffffff >> (32 - ngranules);
+ priv->gat[gatidx] &= ~(gatmask << gatbit);
return;
}
/* Clear bits in the second GAT entry */
- mask = 0xffffffff >> (32 - ngranules);
- priv->gat[gatidx+1] &= ~(mask << gatbit);
+ gatmask = 0xffffffff >> (32 - ngranules);
+ priv->gat[gatidx+1] &= ~(gatmask << gatbit);
}
/****************************************************************************
@@ -132,3 +149,5 @@ void gran_free(GRAN_HANDLE handle, FAR void *memory, size_t size)
return gran_common_free((FAR struct gran_s *)handle, memory, size);
}
#endif
+
+#endif /* CONFIG_GRAN */