From 6568f70bd826ba1b49c28d8709934fb5db18d0a3 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 1 Oct 2017 12:07:01 +0000 Subject: Fixed bug #888. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10726 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/common/oslib/include/chmemcore.h | 71 ++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 5 deletions(-) (limited to 'os/common/oslib/include') 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 } @@ -93,6 +115,45 @@ extern "C" { /* Module inline functions. */ /*===========================================================================*/ +/** + * @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 @@ -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 */ -- cgit v1.2.3