Functions for controlling a memory object. More...
Macros |
|
| #define | NRF_MEMOBJ_STD_HEADER_SIZE sizeof(uint32_t) |
| #define | NRF_MEMOBJ_POOL_DEF (_name, _chunk_size, _pool_size) |
|
Macro for creating an nrf_memobj pool.
More...
|
|
Typedefs |
|
| typedef nrf_balloc_t | nrf_memobj_pool_t |
|
Pool of memory objects.
|
|
| typedef void * | nrf_memobj_t |
|
Memory object handle.
|
|
Functions |
|
| ret_code_t | nrf_memobj_pool_init ( nrf_memobj_pool_t const *p_pool) |
|
Function for initializing the memobj pool instance.
More...
|
|
| nrf_memobj_t * | nrf_memobj_alloc ( nrf_memobj_pool_t const *p_pool, size_t size) |
|
Function for allocating a memobj with a requested size.
More...
|
|
| void | nrf_memobj_get ( nrf_memobj_t const *p_obj) |
|
Function for indicating that a memory object is used and cannot be freed.
More...
|
|
| void | nrf_memobj_put ( nrf_memobj_t *p_obj) |
|
Function for indicated that memory object is no longer used by the module and can be freed if no other module is using it.
More...
|
|
| void | nrf_memobj_free ( nrf_memobj_t *p_obj) |
|
Function for forcing freeing of the memory object.
More...
|
|
| void | nrf_memobj_write ( nrf_memobj_t *p_obj, void *p_data, size_t len, size_t offset) |
|
Function for writing data to the memory object.
More...
|
|
| void | nrf_memobj_read ( nrf_memobj_t *p_obj, void *p_data, size_t len, size_t offset) |
|
Function for reading data from the memory object.
More...
|
|
Detailed Description
Functions for controlling a memory object.
Macro Definition Documentation
| #define NRF_MEMOBJ_POOL_DEF | ( | _name, | |
| _chunk_size, | |||
| _pool_size | |||
| ) |
Macro for creating an nrf_memobj pool.
This macro declares an nrf_balloc object. The element in the pool contains a user-defined data part and a memory object header.
- Parameters
-
_name Name of the instance. _chunk_size Size of a single chunk. _pool_size Number of chunks in the pool.
| #define NRF_MEMOBJ_STD_HEADER_SIZE sizeof(uint32_t) |
A memory object can consist of multiple chunks with the same size. Each object has a header part and a data part. The first element in a memory object is memory object head which has a special header. The remaining objects have a header of the same size.
_____________________ _____________________ _____________________
| | | | | |
|4 B head header | --> |4 B p_next |------->|4 B p_memobj_pool |
|_____________________| | |_____________________| |_____________________|
| | | | | | |
|4 B p_next |--| | | | |
|_____________________| | | .... | |
| | | data | | data |
| | | | | |
| data | | | | |
| | | | | |
|_____________________| |_____________________| |_____________________|
head mid_element last_element
Function Documentation
| nrf_memobj_t * nrf_memobj_alloc | ( | nrf_memobj_pool_t const * | p_pool , |
| size_t | size | ||
| ) |
Function for allocating a memobj with a requested size.
Fixed length elements in the pool are linked together to provide the amount of memory requested by the user. If a memory object is successfully allocated, then the users can use the memory. However, it is fragmented into multiple objects so it must be accessed through the API: nrf_memobj_write and nrf_memobj_read .
- Parameters
-
[in] p_pool Pointer to the memobj pool instance structure. [in] size Data size of requested object.
- Returns
- Pointer to a memory object or NULL if the requested size cannot be allocated.
| void nrf_memobj_free | ( | nrf_memobj_t * | p_obj | ) |
Function for forcing freeing of the memory object.
- Note
- This function should be use with caution because it can lead to undefined behavior of the modules since modules using the memory object are not aware that it has been freed.
- Parameters
-
[in] p_obj Pointer to memory object.
| void nrf_memobj_get | ( | nrf_memobj_t const * | p_obj | ) |
Function for indicating that a memory object is used and cannot be freed.
Memory object can be shared and reused between multiple modules and this mechanism ensures that object is freed when no longer used by any module. Memory object has a counter which is incremented whenever this function is called. nrf_memobj_put function decrements the counter.
- Parameters
-
[in] p_obj Pointer to memory object.
| ret_code_t nrf_memobj_pool_init | ( | nrf_memobj_pool_t const * | p_pool | ) |
Function for initializing the memobj pool instance.
This function initializes the pool.
- Parameters
-
[in] p_pool Pointer to the memobj pool instance structure.
- Returns
- NRF_SUCCESS on success, otherwise an error code.
| void nrf_memobj_put | ( | nrf_memobj_t * | p_obj | ) |
Function for indicated that memory object is no longer used by the module and can be freed if no other module is using it.
Memory object is returned to the pool if internal counter reaches 0 after decrementing. It means that no other module is needing it anymore.
- Note
- Memory object holds pointer to the pool which was used to allocate it so it does not have to be provided explicitly to this function.
- Parameters
-
[in] p_obj Pointer to memory object.
| void nrf_memobj_read | ( | nrf_memobj_t * | p_obj , |
| void * | p_data , | ||
| size_t | len , | ||
| size_t | offset | ||
| ) |
Function for reading data from the memory object.
- Parameters
-
[in] p_obj Pointer to memory object. [in] p_data Pointer to the destination buffer. [in] len Amount of data to be read from the memory object. [in] offset Offset.
| void nrf_memobj_write | ( | nrf_memobj_t * | p_obj , |
| void * | p_data , | ||
| size_t | len , | ||
| size_t | offset | ||
| ) |
Function for writing data to the memory object.
- Parameters
-
[in] p_obj Pointer to memory object. [in] p_data Pointer to data to be written to the memory object. [in] len Amount of data to be written to the memory object. [in] offset Offset.