aboutsummaryrefslogtreecommitdiffstats
path: root/os/common/oslib/include
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2017-10-01 12:07:01 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2017-10-01 12:07:01 +0000
commit6568f70bd826ba1b49c28d8709934fb5db18d0a3 (patch)
treef0837be60056aaeaa24632cae7bac5e196abc317 /os/common/oslib/include
parent0daa851127bc9065dcbb025cd4142c5e37caed14 (diff)
downloadChibiOS-6568f70bd826ba1b49c28d8709934fb5db18d0a3.tar.gz
ChibiOS-6568f70bd826ba1b49c28d8709934fb5db18d0a3.tar.bz2
ChibiOS-6568f70bd826ba1b49c28d8709934fb5db18d0a3.zip
Fixed bug #888.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10726 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/common/oslib/include')
-rw-r--r--os/common/oslib/include/chmemcore.h71
1 files changed, 66 insertions, 5 deletions
diff --git a/os/common/oslib/include/chmemcore.h b/os/common/oslib/include/chmemcore.h
index 539d71ecf..401e9b1a9 100644
--- a/os/common/oslib/include/chmemcore.h
+++ b/os/common/oslib/include/chmemcore.h
@@ -68,7 +68,21 @@
/**
* @brief Memory get function.
*/
-typedef void *(*memgetfunc_t)(size_t size, unsigned align);
+typedef void *(*memgetfunc_t)(size_t size, unsigned align, size_t offset);
+
+/**
+ * @brief Type of memory core object.
+ */
+typedef struct {
+ /**
+ * @brief Next free address.
+ */
+ uint8_t *nextmem;
+ /**
+ * @brief Final address.
+ */
+ uint8_t *endmem;
+} memcore_t;
/*===========================================================================*/
/* Module macros. */
@@ -78,12 +92,20 @@ typedef void *(*memgetfunc_t)(size_t size, unsigned align);
/* External declarations. */
/*===========================================================================*/
+#if !defined(__DOXYGEN__)
+extern memcore_t ch_memcore;
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
void _core_init(void);
- void *chCoreAllocAlignedI(size_t size, unsigned align);
- void *chCoreAllocAligned(size_t size, unsigned align);
+ void *chCoreAllocAlignedWithOffsetI(size_t size,
+ unsigned align,
+ size_t offset);
+ void *chCoreAllocAlignedWithOffset(size_t size,
+ unsigned align,
+ size_t offset);
size_t chCoreGetStatusX(void);
#ifdef __cplusplus
}
@@ -95,6 +117,45 @@ extern "C" {
/**
* @brief Allocates a memory block.
+ * @details The allocated block is guaranteed to be properly aligned to the
+ * specified alignment.
+ *
+ * @param[in] size the size of the block to be allocated.
+ * @param[in] align desired memory alignment
+ * @return A pointer to the allocated memory block.
+ * @retval NULL allocation failed, core memory exhausted.
+ *
+ * @iclass
+ */
+static inline void *chCoreAllocAlignedI(size_t size, unsigned align) {
+
+ return chCoreAllocAlignedWithOffsetI(size, align, 0U);
+}
+
+/**
+ * @brief Allocates a memory block.
+ * @details The allocated block is guaranteed to be properly aligned to the
+ * specified alignment.
+ *
+ * @param[in] size the size of the block to be allocated
+ * @param[in] align desired memory alignment
+ * @return A pointer to the allocated memory block.
+ * @retval NULL allocation failed, core memory exhausted.
+ *
+ * @api
+ */
+static inline void *chCoreAllocAligned(size_t size, unsigned align) {
+ void *p;
+
+ chSysLock();
+ p = chCoreAllocAlignedWithOffsetI(size, align, 0U);
+ chSysUnlock();
+
+ return p;
+}
+
+/**
+ * @brief Allocates a memory block.
* @details The allocated block is guaranteed to be properly aligned for a
* pointer data type.
*
@@ -106,7 +167,7 @@ extern "C" {
*/
static inline void *chCoreAllocI(size_t size) {
- return chCoreAllocAlignedI(size, PORT_NATURAL_ALIGN);
+ return chCoreAllocAlignedWithOffsetI(size, PORT_NATURAL_ALIGN, 0U);
}
/**
@@ -122,7 +183,7 @@ static inline void *chCoreAllocI(size_t size) {
*/
static inline void *chCoreAlloc(size_t size) {
- return chCoreAllocAligned(size, PORT_NATURAL_ALIGN);
+ return chCoreAllocAlignedWithOffsetI(size, PORT_NATURAL_ALIGN, 0U);
}
#endif /* CH_CFG_USE_MEMCORE == TRUE */