Functions for controlling memory object. More...
Macros |
|
| #define | NRF_MEMOBJ_STD_HEADER_SIZE sizeof(uint32_t) |
| #define | NRF_MEMOBJ_POOL_DEF (_name, _element_size, _pool_size) NRF_BALLOC_DEF (_name, ((_element_size)+ NRF_MEMOBJ_STD_HEADER_SIZE ), (_pool_size)) |
|
Macro for creating a nrf_memobj pool.
More...
|
|
Typedefs |
|
| typedef nrf_balloc_t | nrf_memobj_pool_t |
|
Pool of memobj.
|
|
| typedef void * | nrf_memobj_t |
|
Memobj 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 memobj with requested size.
More...
|
|
| void | nrf_memobj_get ( nrf_memobj_t const *p_obj) |
|
Function for indicating that 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, uint32_t len, uint32_t offset) |
|
Function for writing data to the memory object.
More...
|
|
| void | nrf_memobj_read ( nrf_memobj_t *p_obj, void *p_data, uint32_t len, uint32_t offset) |
|
Function for reading data from the memory object.
More...
|
|
Detailed Description
Functions for controlling memory object.
Macro Definition Documentation
| #define NRF_MEMOBJ_POOL_DEF | ( | _name, | |
| _element_size, | |||
| _pool_size | |||
| ) | NRF_BALLOC_DEF (_name, ((_element_size)+ NRF_MEMOBJ_STD_HEADER_SIZE ), (_pool_size)) |
Macro for creating a nrf_memobj pool.
Macro declares nrf_balloc object. Element in the pool contains user defined data part and memobj header.
| #define NRF_MEMOBJ_STD_HEADER_SIZE sizeof(uint32_t) |
Memory object can consist of multiple object with the same size. Each object has header and data part. First element in memory object is memory object head which has special header, remaining objects has the same header. Model of memory object is presented below.
|------------------—| |------------------—| |------------------—| | head header (u32): | —>| std header - p_next |----—>| p_memobj_pool | | num_of_chunks, | | |------------------—| |------------------—|
| ref counter | |||||
|---|---|---|---|---|---|
| std header - 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 memobj with requested size.
Fixed length elements in the pool are linked together to provide amount of memory requested by the user. If memory object is successfully allocated then user can use memory however it is fragmented into multiple object so it has to be access through the API: nrf_memobj_write , nrf_memobj_read .
This function initializes the pool.
- Parameters
-
[in] p_pool Pointer to the memobj pool instance structure. [in] size Data size of requested object.
- Returns
- Pointer to memory object or NULL if 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 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 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 , | ||
| uint32_t | len , | ||
| uint32_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 , | ||
| uint32_t | len , | ||
| uint32_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.