unified: Tweak K_MEMORY_POOL_DEFINE() macro

- Renames to K_MEM_POOL_DEFINE() for consistency
- Adds alignment parameter to align the pool buffer.

Jira: ZEP-926
Change-Id: I6cf0a1ce45c3a0fc5f0675047d8928659df1e75e
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
This commit is contained in:
Peter Mitsis 2016-10-06 16:27:01 -04:00 committed by Benjamin Walsh
commit 2a2b075826
3 changed files with 25 additions and 7 deletions

View file

@ -121,7 +121,8 @@ A memory pool can only be defined and initialized at compile time
by calling :c:macro:`K_MEM_POOL_DEFINE()`.
The following code defines and initializes a memory pool that has 3 blocks
of 4096 bytes each, which can be partitioned into blocks as small as 64 bytes.
of 4096 bytes each, which can be partitioned into blocks as small as 64 bytes
and is aligned to a 4-byte boundary.
(That is, the memory pool supports block sizes of 4096, 1024, 256,
and 64 bytes.)
Observe that the macro defines all of the memory pool data structures,
@ -129,7 +130,7 @@ as well as its buffer.
.. code-block:: c
K_MEM_POOL_DEFINE(my_map, 64, 4096, 3);
K_MEM_POOL_DEFINE(my_map, 64, 4096, 3, 4);
Allocating a Memory Block
=========================

View file

@ -1399,13 +1399,30 @@ __asm__(".macro _build_mem_pool name, min_size, max_size, n_max\n\t"
extern uint32_t _mem_pool_block_set_count_##name; \
extern struct k_mem_pool_block_set _mem_pool_block_sets_##name[]
#define _MEMORY_POOL_BUFFER_DEFINE(name, max_size, n_max) \
char __noinit _mem_pool_buffer_##name[(max_size) * (n_max)]
#define _MEMORY_POOL_BUFFER_DEFINE(name, max_size, n_max, align) \
char __noinit __aligned(align) \
_mem_pool_buffer_##name[(max_size) * (n_max)]
#define K_MEMORY_POOL_DEFINE(name, min_size, max_size, n_max) \
/**
* @brief Define a memory pool
*
* This declares and initializes a memory pool whose buffer is aligned to
* a @a align -byte boundary. The new memory pool can be passed to the
* kernel's memory pool functions.
*
* Note that for each of the minimum sized blocks to be aligned to @a align
* bytes, then @a min_size must be a multiple of @a align.
*
* @param name Name of the memory pool
* @param min_size Minimum block size in the pool
* @param max_size Maximum block size in the pool
* @param n_max Number of maximum sized blocks in the pool
* @param align Alignment of the memory pool's buffer
*/
#define K_MEM_POOL_DEFINE(name, min_size, max_size, n_max, align) \
_MEMORY_POOL_QUAD_BLOCK_DEFINE(name, min_size, max_size, n_max); \
_MEMORY_POOL_BLOCK_SETS_DEFINE(name, min_size, max_size, n_max); \
_MEMORY_POOL_BUFFER_DEFINE(name, max_size, n_max); \
_MEMORY_POOL_BUFFER_DEFINE(name, max_size, n_max, align); \
__asm__("_build_mem_pool " STRINGIFY(name) " " STRINGIFY(min_size) " " \
STRINGIFY(max_size) " " STRINGIFY(n_max) "\n\t"); \
extern struct k_mem_pool name

View file

@ -895,7 +895,7 @@ def kernel_main_c_pools():
min_block_size = pool[1]
max_block_size = pool[2]
num_maximal_blocks = pool[3]
pool_descriptors += "K_MEMORY_POOL_DEFINE(_k_mem_pool_obj_%s, %d, %d, %d);\n" % \
pool_descriptors += "K_MEM_POOL_DEFINE(_k_mem_pool_obj_%s, %d, %d, %d, 4);\n" % \
(pool[0], min_block_size, max_block_size,
num_maximal_blocks)
kernel_main_c_out(pool_descriptors)