|
Zephyr API Documentation
2.7.0-rc2
A Scalable Open Source RTOS
|
Macros | |
| #define | K_MEM_SLAB_DEFINE(name, slab_block_size, slab_num_blocks, slab_align) |
| Statically define and initialize a memory slab. More... | |
Functions | |
| int | k_mem_slab_init (struct k_mem_slab *slab, void *buffer, size_t block_size, uint32_t num_blocks) |
| Initialize a memory slab. More... | |
| int | k_mem_slab_alloc (struct k_mem_slab *slab, void **mem, k_timeout_t timeout) |
| Allocate memory from a memory slab. More... | |
| void | k_mem_slab_free (struct k_mem_slab *slab, void **mem) |
| Free memory allocated from a memory slab. More... | |
| static uint32_t | k_mem_slab_num_used_get (struct k_mem_slab *slab) |
| Get the number of used blocks in a memory slab. More... | |
| static uint32_t | k_mem_slab_max_used_get (struct k_mem_slab *slab) |
| Get the number of maximum used blocks so far in a memory slab. More... | |
| static uint32_t | k_mem_slab_num_free_get (struct k_mem_slab *slab) |
| Get the number of unused blocks in a memory slab. More... | |
| #define K_MEM_SLAB_DEFINE | ( | name, | |
| slab_block_size, | |||
| slab_num_blocks, | |||
| slab_align | |||
| ) |
#include <include/kernel.h>
Statically define and initialize a memory slab.
The memory slab's buffer contains slab_num_blocks memory blocks that are slab_block_size bytes long. The buffer is aligned to a slab_align -byte boundary. To ensure that each memory block is similarly aligned to this boundary, slab_block_size must also be a multiple of slab_align.
The memory slab can be accessed outside the module where it is defined using:
| name | Name of the memory slab. |
| slab_block_size | Size of each memory block (in bytes). |
| slab_num_blocks | Number memory blocks. |
| slab_align | Alignment of the memory slab's buffer (power of 2). |
| int k_mem_slab_alloc | ( | struct k_mem_slab * | slab, |
| void ** | mem, | ||
| k_timeout_t | timeout | ||
| ) |
#include <include/kernel.h>
Allocate memory from a memory slab.
This routine allocates a memory block from a memory slab.
| slab | Address of the memory slab. |
| mem | Pointer to block address area. |
| timeout | Non-negative waiting period to wait for operation to complete. Use K_NO_WAIT to return without waiting, or K_FOREVER to wait as long as necessary. |
| 0 | Memory allocated. The block address area pointed at by mem is set to the starting address of the memory block. |
| -ENOMEM | Returned without waiting. |
| -EAGAIN | Waiting period timed out. |
| -EINVAL | Invalid data supplied |
#include <include/kernel.h>
Free memory allocated from a memory slab.
This routine releases a previously allocated memory block back to its associated memory slab.
| slab | Address of the memory slab. |
| mem | Pointer to block address area (as set by k_mem_slab_alloc()). |
| int k_mem_slab_init | ( | struct k_mem_slab * | slab, |
| void * | buffer, | ||
| size_t | block_size, | ||
| uint32_t | num_blocks | ||
| ) |
#include <include/kernel.h>
Initialize a memory slab.
Initializes a memory slab, prior to its first use.
The memory slab's buffer contains slab_num_blocks memory blocks that are slab_block_size bytes long. The buffer must be aligned to an N-byte boundary matching a word boundary, where N is a power of 2 (i.e. 4 on 32-bit systems, 8, 16, ...). To ensure that each memory block is similarly aligned to this boundary, slab_block_size must also be a multiple of N.
| slab | Address of the memory slab. |
| buffer | Pointer to buffer used for the memory blocks. |
| block_size | Size of each memory block (in bytes). |
| num_blocks | Number of memory blocks. |
| 0 | on success |
| -EINVAL | invalid data supplied |
|
inlinestatic |
#include <include/kernel.h>
Get the number of maximum used blocks so far in a memory slab.
This routine gets the maximum number of memory blocks that were allocated in slab.
| slab | Address of the memory slab. |
|
inlinestatic |
#include <include/kernel.h>
Get the number of unused blocks in a memory slab.
This routine gets the number of memory blocks that are currently unallocated in slab.
| slab | Address of the memory slab. |
|
inlinestatic |
#include <include/kernel.h>
Get the number of used blocks in a memory slab.
This routine gets the number of memory blocks that are currently allocated in slab.
| slab | Address of the memory slab. |