diff --git a/docs/src/articles.dox b/docs/src/articles.dox index ac534a0c9..ca35c3f14 100644 --- a/docs/src/articles.dox +++ b/docs/src/articles.dox @@ -20,15 +20,16 @@ /** * @page articles Articles and Code Samples * ChibiOS/RT Articles and Code Examples: + * - @subpage article_interrupts + * - @subpage article_create_thread + * - @subpage article_manage_memory * - @subpage article_stacks * - @subpage article_mutual_exclusion * - @subpage article_atomic * - @subpage article_saveram - * - @subpage article_interrupts * - @subpage article_jitter * - @subpage article_timing * - @subpage article_portguide * - @subpage article_design - * - @subpage article_create_thread * . */ diff --git a/docs/src/interrupts.dox b/docs/src/interrupts.dox index 95bd6c281..b85db6efd 100644 --- a/docs/src/interrupts.dox +++ b/docs/src/interrupts.dox @@ -18,7 +18,7 @@ */ /** - * @page article_interrupts Writing interrupt handlers under ChibiOS/RT + * @page article_interrupts How to write interrupt handlers * Since version 1.1.0 ChibiOS/RT offers a cross-platform method for writing * interrupt handlers. Port-related and compiler-related details are * encapsulated within standard system macros.
diff --git a/os/kernel/include/heap.h b/os/kernel/include/heap.h index 1f07faa91..aa2f7458e 100644 --- a/os/kernel/include/heap.h +++ b/os/kernel/include/heap.h @@ -19,8 +19,8 @@ /** * @file heap.h - * @brief Heap macros and structures. - * @addtogroup heap + * @brief Heaps macros and structures. + * @addtogroup heaps * @{ */ diff --git a/os/kernel/include/memcore.h b/os/kernel/include/memcore.h index c60d3ad9d..7c11e03c3 100644 --- a/os/kernel/include/memcore.h +++ b/os/kernel/include/memcore.h @@ -34,6 +34,7 @@ typedef void *align_t; /** * @brief Memory get function. + * * @note This type must be assignment compatible with the @p chMemAlloc() * function. */ diff --git a/os/kernel/include/mempools.h b/os/kernel/include/mempools.h index a458b8e34..553534dd3 100644 --- a/os/kernel/include/mempools.h +++ b/os/kernel/include/mempools.h @@ -40,12 +40,11 @@ struct pool_header { * @brief Memory pool descriptor. */ typedef struct { - struct pool_header *mp_next; /**< Pointer to the header. */ - size_t mp_object_size; /**< Memory pool objects size. */ -#if CH_USE_MEMCORE - bool_t mp_usecore; /**< Feed from the memory code - allocator if empty. */ -#endif + struct pool_header *mp_next; /**< @brief Pointer to the header. */ + size_t mp_object_size; /**< @brief Memory pool objects + size. */ + memgetfunc_t mp_provider; /**< @brief Memory blocks provider for + this pool. */ } MemoryPool; /** @@ -53,42 +52,30 @@ typedef struct { * @details This macro should be used when statically initializing a * memory pool that is part of a bigger structure. * - * @param name the name of the memory pool variable - * @param size size of the memory pool contained objects + * @param[in] name the name of the memory pool variable + * @param[in] size size of the memory pool contained objects + * @param[in] provider memory provider function for the memory pool */ -#if CH_USE_MEMCORE || defined(__DOXYGEN__) -#define _MEMORYPOOL_DATA(name, size) {NULL, MEM_ALIGN_SIZE(size), FALSE} -#else -#define _MEMORYPOOL_DATA(name, size) {NULL, MEM_ALIGN_SIZE(size)} -#endif +#define _MEMORYPOOL_DATA(name, size, provider) \ + {NULL, MEM_ALIGN_SIZE(size), provider} /** - * @brief Static memory pool initializer. + * @brief Static memory pool initializer in hungry mode. * @details Statically initialized memory pools require no explicit * initialization using @p chPoolInit(). * - * @param name the name of the memory pool variable - * @param size size of the memory pool contained objects + * @param[in] name the name of the memory pool variable + * @param[in] size size of the memory pool contained objects + * @param[in] provider memory provider function for the memory pool or @p NULL + * if the pool is not allowed to grow automatically */ -#define MEMORYPOOL_DECL(name, size) \ - MemoryPool name = _MEMORYPOOL_DATA(name, size) - -#if CH_USE_MEMCORE || defined(__DOXYGEN__) -/** - * @brief Enables or disables the hungry mode. - * @details If enabled, the hungry mode, makes an empty memory pool feed - * new objects from the core memory manager. - * - * @param[in] mp pointer to a @p MemoryPool structure - * @param[in] mode hungry mode flag - */ -#define chPoolSetHungryMode(mp, mode) ((mp)->mp_usecore = (mode)) -#endif +#define MEMORYPOOL_DECL(name, size, provider) \ + MemoryPool name = _MEMORYPOOL_DATA(name, size, provider) #ifdef __cplusplus extern "C" { #endif - void chPoolInit(MemoryPool *mp, size_t size); + void chPoolInit(MemoryPool *mp, size_t size, memgetfunc_t provider); void *chPoolAllocI(MemoryPool *mp); void *chPoolAlloc(MemoryPool *mp); void chPoolFreeI(MemoryPool *mp, void *objp); diff --git a/os/kernel/src/chheap.c b/os/kernel/src/chheap.c index e7a975f3d..d1dab1580 100644 --- a/os/kernel/src/chheap.c +++ b/os/kernel/src/chheap.c @@ -19,8 +19,8 @@ /** * @file chheap.c - * @brief Heap code. - * @addtogroup heap + * @brief Heaps code. + * @addtogroup heaps * @{ */ @@ -47,7 +47,7 @@ static MemoryHeap default_heap; /** - * @brief Initializes the allocator subsystem. + * @brief Initializes the default heap. * * @note Internal use only. */ @@ -63,7 +63,7 @@ void heap_init(void) { } /** - * @brief Initializes a memory heap. + * @brief Initializes a memory heap from a static memory area. * * @param[out] heapp pointer to a memory heap descriptor to be initialized * @param[in] buf heap buffer base diff --git a/os/kernel/src/chmempools.c b/os/kernel/src/chmempools.c index 76ef39b58..97d619520 100644 --- a/os/kernel/src/chmempools.c +++ b/os/kernel/src/chmempools.c @@ -33,19 +33,19 @@ * @param[out] mp pointer to a @p MemoryPool structure * @param[in] size the size of the objects contained in this memory pool, * the minimum accepted size is the size of a pointer to void. + * @param[in] provider memory provider function for the memory pool or + * @p NULL if the pool is not allowed to grow automatically * * @note The size is internally aligned to be a multiple of the @p align_t * type size. */ -void chPoolInit(MemoryPool *mp, size_t size) { +void chPoolInit(MemoryPool *mp, size_t size, memgetfunc_t provider) { chDbgCheck((mp != NULL) && (size >= sizeof(void *)), "chPoolInit"); mp->mp_next = NULL; mp->mp_object_size = MEM_ALIGN_SIZE(size); -#if CH_USE_MEMCORE - mp->mp_usecore = FALSE; -#endif + mp->mp_provider = provider; } /** @@ -63,8 +63,8 @@ void *chPoolAllocI(MemoryPool *mp) { if ((objp = mp->mp_next) != NULL) mp->mp_next = mp->mp_next->ph_next; #if CH_USE_MEMCORE - else if (mp->mp_usecore) - objp = chCoreAllocI(mp->mp_object_size); + else if (mp->mp_provider != NULL) + objp = mp->mp_provider(mp->mp_object_size); #endif return objp; } diff --git a/readme.txt b/readme.txt index 73fb81919..e9fbcde48 100644 --- a/readme.txt +++ b/readme.txt @@ -15,8 +15,8 @@ - NEW: The heap allocator has been modified, now it is possible to have multiple heaps. The default heap gets its memory from the new core memory manager. -- NEW: Added a "hungry" mode to the memory pools allocator, when enabled, this - mode makes a memory pool to feed memory from the core memory manager. +- NEW: Now memory pools can optionally get new objects automatically from the + core memory manager. - NEW: Added newlib interface file syscalls.c under ./os/various for use with the newest YAGARTO releases. The file provides bindings between the C runtime and the core memory manager. diff --git a/test/testdyn.c b/test/testdyn.c index 07c3f92a0..5b024544f 100644 --- a/test/testdyn.c +++ b/test/testdyn.c @@ -145,7 +145,7 @@ static char *dyn2_gettest(void) { static void dyn2_setup(void) { - chPoolInit(&mp1, THD_WA_SIZE(THREADS_STACK_SIZE)); + chPoolInit(&mp1, THD_WA_SIZE(THREADS_STACK_SIZE), NULL); } static void dyn2_execute(void) { diff --git a/test/testheap.c b/test/testheap.c index ce127d2be..fe06a0cf5 100644 --- a/test/testheap.c +++ b/test/testheap.c @@ -25,10 +25,10 @@ * @page test_heap Memory Heap test * *

Description

- * This module implements the test sequence for the @ref heap subsystem. + * This module implements the test sequence for the @ref heaps subsystem. * *

Objective

- * Objective of the test module is to cover 100% of the @ref heap subsystem. + * Objective of the test module is to cover 100% of the @ref heaps subsystem. * *

Preconditions

* The module requires the following kernel options: diff --git a/test/testpools.c b/test/testpools.c index 97356126e..b48290b87 100644 --- a/test/testpools.c +++ b/test/testpools.c @@ -48,7 +48,7 @@ #if CH_USE_MEMPOOLS -static MEMORYPOOL_DECL(mp1, THD_WA_SIZE(THREADS_STACK_SIZE)); +static MEMORYPOOL_DECL(mp1, THD_WA_SIZE(THREADS_STACK_SIZE), NULL); /** * @page test_pools_001 Allocation and enqueuing test @@ -66,7 +66,7 @@ static char *pools1_gettest(void) { static void pools1_setup(void) { - chPoolInit(&mp1, THD_WA_SIZE(THREADS_STACK_SIZE)); + chPoolInit(&mp1, THD_WA_SIZE(THREADS_STACK_SIZE), NULL); } static void pools1_execute(void) {