|
Zephyr Project API 4.0.0
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 in a public (non-static) scope. | |
| #define | K_MEM_SLAB_DEFINE_STATIC(name, slab_block_size, slab_num_blocks, slab_align) |
| Statically define and initialize a memory slab in a private (static) scope. | |
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. | |
| int | k_mem_slab_alloc (struct k_mem_slab *slab, void **mem, k_timeout_t timeout) |
| Allocate memory from a memory slab. | |
| void | k_mem_slab_free (struct k_mem_slab *slab, void *mem) |
| Free memory allocated from a memory slab. | |
| static uint32_t | k_mem_slab_num_used_get (struct k_mem_slab *slab) |
| Get the number of used blocks in a memory slab. | |
| 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. | |
| static uint32_t | k_mem_slab_num_free_get (struct k_mem_slab *slab) |
| Get the number of unused blocks in a memory slab. | |
| int | k_mem_slab_runtime_stats_get (struct k_mem_slab *slab, struct sys_memory_stats *stats) |
| Get the memory stats for a memory slab. | |
| int | k_mem_slab_runtime_stats_reset_max (struct k_mem_slab *slab) |
| Reset the maximum memory usage for a slab. | |
| #define K_MEM_SLAB_DEFINE | ( | name, | |
| slab_block_size, | |||
| slab_num_blocks, | |||
| slab_align | |||
| ) |
#include <include/zephyr/kernel.h>
Statically define and initialize a memory slab in a public (non-static) scope.
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). |
| #define K_MEM_SLAB_DEFINE_STATIC | ( | name, | |
| slab_block_size, | |||
| slab_num_blocks, | |||
| slab_align | |||
| ) |
#include <include/zephyr/kernel.h>
Statically define and initialize a memory slab in a private (static) scope.
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.
| 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). |
|
isr-ok |
#include <include/zephyr/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 | 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 |
| void k_mem_slab_free | ( | struct k_mem_slab * | slab, |
| void * | mem | ||
| ) |
#include <include/zephyr/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 the memory block (as returned 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/zephyr/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/zephyr/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/zephyr/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/zephyr/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. |
| int k_mem_slab_runtime_stats_get | ( | struct k_mem_slab * | slab, |
| struct sys_memory_stats * | stats | ||
| ) |
#include <include/zephyr/kernel.h>
Get the memory stats for a memory slab.
This routine gets the runtime memory usage stats for the slab slab.
| slab | Address of the memory slab |
| stats | Pointer to memory into which to copy memory usage statistics |
| 0 | Success |
| -EINVAL | Any parameter points to NULL |
| int k_mem_slab_runtime_stats_reset_max | ( | struct k_mem_slab * | slab | ) |
#include <include/zephyr/kernel.h>
Reset the maximum memory usage for a slab.
This routine resets the maximum memory usage for the slab slab to its current usage.
| slab | Address of the memory slab |
| 0 | Success |
| -EINVAL | Memory slab is NULL |