From 2c46df1916a25b7880416aee974a518cc607717a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 16 Oct 2009 17:45:19 +0000 Subject: New heap manager. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1221 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 os/kernel/src/chmemcore.c (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c new file mode 100644 index 000000000..87ef6037a --- /dev/null +++ b/os/kernel/src/chmemcore.c @@ -0,0 +1,99 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file chmemcore.c + * @brief Core memory manager code. + * @addtogroup memcore + * @{ + */ + +#include + +#if CH_USE_MEMCORE + +#if CH_MEMCORE_SIZE == 0 + extern align_t __heap_base__; + extern align_t __heap_end__; +#else +align_t buffer[ALIGN_SIZE(CH_MEMCORE_SIZE) / sizeof(align_t)]; +#endif + +static align_t *nextmem; +static align_t *endmem; + +/** + * @brief Low level memory manager initialization. + * + * @note Internal use only. + */ +void core_init(void) { +#if CH_MEMCORE_SIZE == 0 + nextmem = &__heap_base__; + endmem = &__heap_end__; +#else + nextmem = &buffer[0]; + endmem = &buffer[ALIGN_SIZE(CH_MEMCORE_SIZE) / sizeof(align_t)]; +#endif +} + +/** + * @brief Allocates a block of memory. + * @details The size of the returned block is aligned to the alignment + * type @p align_t so it is not possible to allocate less than + * sizeof(align_t). + * + * + * @param[in] the size of the block to be allocated + * @return A pointer to the allocated memory block. + * @retval NULL allocation failed, core memory exhausted. + */ +void *chCoreAlloc(size_t size) { + void *p; + + chSysLock(); + p = chCoreAllocI(size); + chSysUnlock(); + return p; +} + +/** + * @brief Allocates a block of memory. + * @details The size of the returned block is aligned to the alignment + * type @p align_t so it is not possible to allocate less than + * sizeof(align_t). + * + * @param[in] the size of the block to be allocated. + * @return A pointer to the allocated memory block. + * @retval NULL allocation failed, core memory exhausted. + */ +void *chCoreAllocI(size_t size) { + void *p; + + size = MEM_ALIGN_SIZE(size); + if (nextmem + size > endmem) + return NULL; + p = nextmem; + nextmem += size; + return p; +} + +#endif /* CH_USE_MEMCORE */ + +/** @} */ -- cgit v1.2.3 From d61cb88dab424a8edcf3b2a06a0c7ea18890208a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 17 Oct 2009 07:35:31 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1224 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 87ef6037a..4efc63e52 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -32,7 +32,7 @@ extern align_t __heap_base__; extern align_t __heap_end__; #else -align_t buffer[ALIGN_SIZE(CH_MEMCORE_SIZE) / sizeof(align_t)]; +align_t buffer[MEM_ALIGN_SIZE(CH_MEMCORE_SIZE) / sizeof(align_t)]; #endif static align_t *nextmem; @@ -49,7 +49,7 @@ void core_init(void) { endmem = &__heap_end__; #else nextmem = &buffer[0]; - endmem = &buffer[ALIGN_SIZE(CH_MEMCORE_SIZE) / sizeof(align_t)]; + endmem = &buffer[MEM_ALIGN_SIZE(CH_MEMCORE_SIZE) / sizeof(align_t)]; #endif } -- cgit v1.2.3 From a7cfbdaf10a03aa10236958bdba38479b301fc4f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 17 Oct 2009 08:05:52 +0000 Subject: Coverage for the new modules. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1225 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 4efc63e52..00e04a2d6 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -87,7 +87,7 @@ void *chCoreAllocI(size_t size) { void *p; size = MEM_ALIGN_SIZE(size); - if (nextmem + size > endmem) + if ((size_t)((uint8_t *)endmem - (uint8_t *)nextmem) < size) return NULL; p = nextmem; nextmem += size; -- cgit v1.2.3 From 34fd822f84d409fa649934251fae01994de7888b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 17 Oct 2009 09:21:59 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1226 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 00e04a2d6..7177fe432 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -60,7 +60,7 @@ void core_init(void) { * sizeof(align_t). * * - * @param[in] the size of the block to be allocated + * @param[in] size the size of the block to be allocated * @return A pointer to the allocated memory block. * @retval NULL allocation failed, core memory exhausted. */ @@ -79,7 +79,7 @@ void *chCoreAlloc(size_t size) { * type @p align_t so it is not possible to allocate less than * sizeof(align_t). * - * @param[in] the size of the block to be allocated. + * @param[in] size the size of the block to be allocated. * @return A pointer to the allocated memory block. * @retval NULL allocation failed, core memory exhausted. */ -- cgit v1.2.3 From bdb7f4ab20bd3daf261ab93dfe733e0ff11dca0f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 8 Dec 2009 17:37:49 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1397 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 7177fe432..47c579432 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -24,7 +24,7 @@ * @{ */ -#include +#include "ch.h" #if CH_USE_MEMCORE -- cgit v1.2.3 From f2c5dc67eab392655278f2d34b31190dbf94bac1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 11 Dec 2009 15:55:08 +0000 Subject: Fixed bug 2912528. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1414 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 47c579432..214504df7 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -28,15 +28,8 @@ #if CH_USE_MEMCORE -#if CH_MEMCORE_SIZE == 0 - extern align_t __heap_base__; - extern align_t __heap_end__; -#else -align_t buffer[MEM_ALIGN_SIZE(CH_MEMCORE_SIZE) / sizeof(align_t)]; -#endif - -static align_t *nextmem; -static align_t *endmem; +static uint8_t *nextmem; +static uint8_t *endmem; /** * @brief Low level memory manager initialization. @@ -45,11 +38,14 @@ static align_t *endmem; */ void core_init(void) { #if CH_MEMCORE_SIZE == 0 + extern uint8_t __heap_base__; + extern uint8_t __heap_end__; nextmem = &__heap_base__; endmem = &__heap_end__; #else - nextmem = &buffer[0]; - endmem = &buffer[MEM_ALIGN_SIZE(CH_MEMCORE_SIZE) / sizeof(align_t)]; + static align_t buffer[MEM_ALIGN_SIZE(CH_MEMCORE_SIZE) / sizeof(align_t)]; + nextmem = (uint8_t *)&buffer[0]; + endmem = (uint8_t *)&buffer[MEM_ALIGN_SIZE(CH_MEMCORE_SIZE) / sizeof(align_t)]; #endif } @@ -87,7 +83,7 @@ void *chCoreAllocI(size_t size) { void *p; size = MEM_ALIGN_SIZE(size); - if ((size_t)((uint8_t *)endmem - (uint8_t *)nextmem) < size) + if ((size_t)(endmem - nextmem) < size) return NULL; p = nextmem; nextmem += size; -- cgit v1.2.3 From 320a3f140e693a0d8647fd05ec6d2d4cb10c523a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 30 Dec 2009 13:28:10 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1484 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 214504df7..65962bde1 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -50,7 +50,7 @@ void core_init(void) { } /** - * @brief Allocates a block of memory. + * @brief Allocates a memory block. * @details The size of the returned block is aligned to the alignment * type @p align_t so it is not possible to allocate less than * sizeof(align_t). @@ -70,7 +70,7 @@ void *chCoreAlloc(size_t size) { } /** - * @brief Allocates a block of memory. + * @brief Allocates a memory block. * @details The size of the returned block is aligned to the alignment * type @p align_t so it is not possible to allocate less than * sizeof(align_t). -- cgit v1.2.3 From 217d1529c1a126054fbdb9e071cd103194fd499e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 3 Feb 2010 18:40:10 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1564 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 65962bde1..6cf42788b 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -32,9 +32,8 @@ static uint8_t *nextmem; static uint8_t *endmem; /** - * @brief Low level memory manager initialization. - * - * @note Internal use only. + * @brief Low level memory manager initialization. + * @note Internal use only. */ void core_init(void) { #if CH_MEMCORE_SIZE == 0 @@ -50,15 +49,15 @@ void core_init(void) { } /** - * @brief Allocates a memory block. + * @brief Allocates a memory block. * @details The size of the returned block is aligned to the alignment * type @p align_t so it is not possible to allocate less than * sizeof(align_t). * * - * @param[in] size the size of the block to be allocated - * @return A pointer to the allocated memory block. - * @retval NULL allocation failed, core memory exhausted. + * @param[in] size the size of the block to be allocated + * @return A pointer to the allocated memory block. + * @retval NULL allocation failed, core memory exhausted. */ void *chCoreAlloc(size_t size) { void *p; @@ -70,14 +69,14 @@ void *chCoreAlloc(size_t size) { } /** - * @brief Allocates a memory block. + * @brief Allocates a memory block. * @details The size of the returned block is aligned to the alignment * type @p align_t so it is not possible to allocate less than * sizeof(align_t). * - * @param[in] size the size of the block to be allocated. - * @return A pointer to the allocated memory block. - * @retval NULL allocation failed, core memory exhausted. + * @param[in] size the size of the block to be allocated. + * @return A pointer to the allocated memory block. + * @retval NULL allocation failed, core memory exhausted. */ void *chCoreAllocI(size_t size) { void *p; @@ -90,6 +89,15 @@ void *chCoreAllocI(size_t size) { return p; } +/** + * @brief Core memory left. + * + * @return The size, in bytes, of the free core memory. + */ +size_t chCoreFree(void) { + + return (size_t)(endmem - nextmem); +} #endif /* CH_USE_MEMCORE */ /** @} */ -- cgit v1.2.3 From f17db1931e95f5ebb42f557b6eead2bf1320db5a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 6 Feb 2010 10:55:53 +0000 Subject: Reformatted doxygen tags into the kernel sources to make them more readable. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1567 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 6cf42788b..8269deb48 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -18,8 +18,9 @@ */ /** - * @file chmemcore.c - * @brief Core memory manager code. + * @file chmemcore.c + * @brief Core memory manager code. + * * @addtogroup memcore * @{ */ @@ -55,9 +56,9 @@ void core_init(void) { * sizeof(align_t). * * - * @param[in] size the size of the block to be allocated - * @return A pointer to the allocated memory block. - * @retval NULL allocation failed, core memory exhausted. + * @param[in] size the size of the block to be allocated + * @return A pointer to the allocated memory block. + * @retval NULL allocation failed, core memory exhausted. */ void *chCoreAlloc(size_t size) { void *p; @@ -74,9 +75,9 @@ void *chCoreAlloc(size_t size) { * type @p align_t so it is not possible to allocate less than * sizeof(align_t). * - * @param[in] size the size of the block to be allocated. - * @return A pointer to the allocated memory block. - * @retval NULL allocation failed, core memory exhausted. + * @param[in] size the size of the block to be allocated. + * @return A pointer to the allocated memory block. + * @retval NULL allocation failed, core memory exhausted. */ void *chCoreAllocI(size_t size) { void *p; @@ -92,7 +93,7 @@ void *chCoreAllocI(size_t size) { /** * @brief Core memory left. * - * @return The size, in bytes, of the free core memory. + * @return The size, in bytes, of the free core memory. */ size_t chCoreFree(void) { -- cgit v1.2.3 From 0c85d7906646524a75121867ba02dd1bb809cd21 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 16 Feb 2010 19:21:42 +0000 Subject: Tentative fix for bug 2952961. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1619 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 8269deb48..d5adbef48 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -43,17 +43,19 @@ void core_init(void) { nextmem = &__heap_base__; endmem = &__heap_end__; #else - static align_t buffer[MEM_ALIGN_SIZE(CH_MEMCORE_SIZE) / sizeof(align_t)]; + static stkalign_t buffer[MEM_ALIGN_SIZE(CH_MEMCORE_SIZE) / + sizeof(stkalign_t)]; nextmem = (uint8_t *)&buffer[0]; - endmem = (uint8_t *)&buffer[MEM_ALIGN_SIZE(CH_MEMCORE_SIZE) / sizeof(align_t)]; + endmem = (uint8_t *)&buffer[MEM_ALIGN_SIZE(CH_MEMCORE_SIZE) / + sizeof(stkalign_t)]; #endif } /** * @brief Allocates a memory block. * @details The size of the returned block is aligned to the alignment - * type @p align_t so it is not possible to allocate less than - * sizeof(align_t). + * type @p stkalign_t so it is not possible to allocate less + * than sizeof(stkalign_t). * * * @param[in] size the size of the block to be allocated -- cgit v1.2.3 From 157b6f9695e7f72f2d54b231c19cb4045710ed01 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 21 Feb 2010 07:24:53 +0000 Subject: Updated license dates. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1646 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index d5adbef48..435120a33 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. This file is part of ChibiOS/RT. @@ -60,7 +60,7 @@ void core_init(void) { * * @param[in] size the size of the block to be allocated * @return A pointer to the allocated memory block. - * @retval NULL allocation failed, core memory exhausted. + * @retval NULL allocation failed, core memory exhausted. */ void *chCoreAlloc(size_t size) { void *p; @@ -95,7 +95,7 @@ void *chCoreAllocI(size_t size) { /** * @brief Core memory left. * - * @return The size, in bytes, of the free core memory. + * @return The size, in bytes, of the free core memory. */ size_t chCoreFree(void) { -- cgit v1.2.3 From ad3d21e81592481539a56e93234f5bf1fa2c0504 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 16 Mar 2010 19:36:21 +0000 Subject: Documentation reorganization. Moved the description from kernel.dox into the source code for ease of editing and reference. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1746 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 435120a33..d0c657a48 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -22,6 +22,22 @@ * @brief Core memory manager code. * * @addtogroup memcore + * @details Core Memory Manager related APIs and services. + *

Operation mode

+ * The core memory manager is a simplified allocator that only allows + * to allocate memory blocks without the possibility to free them.
+ * This allocator is meant as a memory blocks provider for the other + * allocators such as: + * - C-Runtime allocator (through a compiler specific adapter module). + * - Heap allocator (see @ref heaps). + * - Memory pools allocator (see @ref pools). + * . + * By having a centralized memory provider the various allocators can + * coexist and share the main memory.
+ * This allocator, alone, is also useful for very simple applications + * that just require a simple way to get memory blocks.
+ * In order to use the core memory manager APIs the @p CH_USE_MEMCORE + * option must be enabled in @p chconf.h. * @{ */ -- cgit v1.2.3 From bc9d319ddb279f973404c2b1abf15ec1091bd891 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 4 May 2010 12:31:05 +0000 Subject: Improved code coverage. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1902 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index d0c657a48..f835e2111 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -109,11 +109,11 @@ void *chCoreAllocI(size_t size) { } /** - * @brief Core memory left. + * @brief Core memory status. * * @return The size, in bytes, of the free core memory. */ -size_t chCoreFree(void) { +size_t chCoreStatus(void) { return (size_t)(endmem - nextmem); } -- cgit v1.2.3 From 9ffea7e261ec4016d788abbbf7c4a6d3a78e0a04 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 18 Sep 2010 06:48:56 +0000 Subject: Documentation improvements, renamed some event APIs. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2179 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index f835e2111..04edb7dae 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -35,15 +35,15 @@ * By having a centralized memory provider the various allocators can * coexist and share the main memory.
* This allocator, alone, is also useful for very simple applications - * that just require a simple way to get memory blocks.
- * In order to use the core memory manager APIs the @p CH_USE_MEMCORE + * that just require a simple way to get memory blocks. + * @pre In order to use the core memory manager APIs the @p CH_USE_MEMCORE * option must be enabled in @p chconf.h. * @{ */ #include "ch.h" -#if CH_USE_MEMCORE +#if CH_USE_MEMCORE || defined(__DOXYGEN__) static uint8_t *nextmem; static uint8_t *endmem; @@ -73,7 +73,6 @@ void core_init(void) { * type @p stkalign_t so it is not possible to allocate less * than sizeof(stkalign_t). * - * * @param[in] size the size of the block to be allocated * @return A pointer to the allocated memory block. * @retval NULL allocation failed, core memory exhausted. -- cgit v1.2.3 From 07351222e6d0b6b3dcd4f50ecb18bc09e7402d1c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 21 Sep 2010 10:22:06 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2184 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 04edb7dae..69d3014a5 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -50,7 +50,8 @@ static uint8_t *endmem; /** * @brief Low level memory manager initialization. - * @note Internal use only. + * + * @notapi */ void core_init(void) { #if CH_MEMCORE_SIZE == 0 @@ -76,6 +77,8 @@ void core_init(void) { * @param[in] size the size of the block to be allocated * @return A pointer to the allocated memory block. * @retval NULL allocation failed, core memory exhausted. + * + * @api */ void *chCoreAlloc(size_t size) { void *p; @@ -95,6 +98,8 @@ void *chCoreAlloc(size_t size) { * @param[in] size the size of the block to be allocated. * @return A pointer to the allocated memory block. * @retval NULL allocation failed, core memory exhausted. + * + * @iclass */ void *chCoreAllocI(size_t size) { void *p; @@ -111,6 +116,8 @@ void *chCoreAllocI(size_t size) { * @brief Core memory status. * * @return The size, in bytes, of the free core memory. + * + * @api */ size_t chCoreStatus(void) { -- cgit v1.2.3 From 24594525990ee1769ee933261b821211b4c299e8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 24 Feb 2011 14:57:38 +0000 Subject: Fixed bugs 3191107 and 3191112. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2762 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 69d3014a5..1fed481c5 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -24,18 +24,20 @@ * @addtogroup memcore * @details Core Memory Manager related APIs and services. *

Operation mode

- * The core memory manager is a simplified allocator that only allows - * to allocate memory blocks without the possibility to free them.
- * This allocator is meant as a memory blocks provider for the other - * allocators such as: + * The core memory manager is a simplified allocator that only + * allows to allocate memory blocks without the possibility to + * free them.
+ * This allocator is meant as a memory blocks provider for the + * other allocators such as: * - C-Runtime allocator (through a compiler specific adapter module). * - Heap allocator (see @ref heaps). * - Memory pools allocator (see @ref pools). * . - * By having a centralized memory provider the various allocators can - * coexist and share the main memory.
- * This allocator, alone, is also useful for very simple applications - * that just require a simple way to get memory blocks. + * By having a centralized memory provider the various allocators + * can coexist and share the main memory.
+ * This allocator, alone, is also useful for very simple + * applications that just require a simple way to get memory + * blocks. * @pre In order to use the core memory manager APIs the @p CH_USE_MEMCORE * option must be enabled in @p chconf.h. * @{ @@ -57,22 +59,20 @@ void core_init(void) { #if CH_MEMCORE_SIZE == 0 extern uint8_t __heap_base__; extern uint8_t __heap_end__; - nextmem = &__heap_base__; - endmem = &__heap_end__; + nextmem = (uint8_t *)MEM_ALIGN_NEXT(&__heap_base__); + endmem = (uint8_t *)MEM_ALIGN_PREV(&__heap_end__); #else - static stkalign_t buffer[MEM_ALIGN_SIZE(CH_MEMCORE_SIZE) / - sizeof(stkalign_t)]; + static stkalign_t buffer[MEM_ALIGN_NEXT(CH_MEMCORE_SIZE)/MEM_ALIGN_SIZE]; nextmem = (uint8_t *)&buffer[0]; - endmem = (uint8_t *)&buffer[MEM_ALIGN_SIZE(CH_MEMCORE_SIZE) / - sizeof(stkalign_t)]; + endmem = (uint8_t *)&buffer[MEM_ALIGN_NEXT(CH_MEMCORE_SIZE)/MEM_ALIGN_SIZE]; #endif } /** * @brief Allocates a memory block. * @details The size of the returned block is aligned to the alignment - * type @p stkalign_t so it is not possible to allocate less - * than sizeof(stkalign_t). + * type so it is not possible to allocate less + * than MEM_ALIGN_SIZE. * * @param[in] size the size of the block to be allocated * @return A pointer to the allocated memory block. @@ -92,8 +92,8 @@ void *chCoreAlloc(size_t size) { /** * @brief Allocates a memory block. * @details The size of the returned block is aligned to the alignment - * type @p align_t so it is not possible to allocate less than - * sizeof(align_t). + * type so it is not possible to allocate less than + * MEM_ALIGN_SIZE. * * @param[in] size the size of the block to be allocated. * @return A pointer to the allocated memory block. @@ -104,7 +104,7 @@ void *chCoreAlloc(size_t size) { void *chCoreAllocI(size_t size) { void *p; - size = MEM_ALIGN_SIZE(size); + size = MEM_ALIGN_NEXT(size); if ((size_t)(endmem - nextmem) < size) return NULL; p = nextmem; -- cgit v1.2.3 From 1d00697fe4f8bbe42e0c0d59f76879bd1e575883 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 26 Feb 2011 13:43:07 +0000 Subject: Fixed bug 3193062 (RVCT). git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2766 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 1fed481c5..c28d150fa 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -57,10 +57,10 @@ static uint8_t *endmem; */ void core_init(void) { #if CH_MEMCORE_SIZE == 0 - extern uint8_t __heap_base__; - extern uint8_t __heap_end__; - nextmem = (uint8_t *)MEM_ALIGN_NEXT(&__heap_base__); - endmem = (uint8_t *)MEM_ALIGN_PREV(&__heap_end__); + extern uint8_t __heap_base__[]; + extern uint8_t __heap_end__[]; + nextmem = (uint8_t *)MEM_ALIGN_NEXT(__heap_base__); + endmem = (uint8_t *)MEM_ALIGN_PREV(__heap_end__); #else static stkalign_t buffer[MEM_ALIGN_NEXT(CH_MEMCORE_SIZE)/MEM_ALIGN_SIZE]; nextmem = (uint8_t *)&buffer[0]; -- cgit v1.2.3 From e7e79a6ccb4f3e320b2b8b7bad1b14d65218641d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 18 Mar 2011 18:38:08 +0000 Subject: License updated. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2827 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index c28d150fa..d66ef5f1c 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From f5ae2552307f20f3fa3d987591fa60576981ce3d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 29 Mar 2011 14:51:08 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2850 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index d66ef5f1c..311d170c5 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -56,7 +56,7 @@ static uint8_t *endmem; * * @notapi */ -void core_init(void) { +void _core_init(void) { #if CH_MEMCORE_SIZE == 0 extern uint8_t __heap_base__[]; extern uint8_t __heap_end__[]; -- cgit v1.2.3 From 43752ee8d132fc57028a9ff15156c5bfcd81c013 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 12 Aug 2011 11:10:19 +0000 Subject: Extended state check to all kernel I-class and s-class APIs, corrected some test cases where call protocol rules were not strictly observerd. No the whole test suite pass with the state checker enabled. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3223 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 311d170c5..0eac9a429 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -105,6 +105,8 @@ void *chCoreAlloc(size_t size) { void *chCoreAllocI(size_t size) { void *p; + chDbgCheckClassI(); + size = MEM_ALIGN_NEXT(size); if ((size_t)(endmem - nextmem) < size) return NULL; -- cgit v1.2.3 From de5dcbba856524599a8f06d3a9bdbf1b01db44c2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 21 Jan 2012 14:29:42 +0000 Subject: License text updated with new year. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3846 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 0eac9a429..a13a85873 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From 184a71345c6a36a9a8664eda8fbcc3ea728267a8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 2 Feb 2013 10:58:09 +0000 Subject: Updated license years. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5102 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chmemcore.c') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index a13a85873..0ff26bc76 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3