Generic flag allocator.
More...
Generic flag allocator.
◆ nrfx_flag32_alloc()
Function for allocating a flag in the mask.
- Note
- Function is thread safe, it uses NRFX_ATOMIC_CAS macro. No further synchronization mechanism is needed, provided the macro is properly implemented (see nrfx_glue.h).
Mask must be initialized before first allocation. Flags are allocated from the highest bit position, e.g. if mask is set to 0x0000000A, 3 is returned and bit 3 is cleared in the mask. Mask is set to 0x00000002 on return after successful allocation.
- Parameters
-
[in,out] | p_mask | Mask with available flags set. On successful allocation flag is cleared. |
[out] | p_flag | Index of the allocated flag. |
- Return values
-
NRFX_SUCCESS | Allocation was successful. |
NRFX_ERROR_NO_MEM | No resource available. |
◆ nrfx_flag32_free()
Function for freeing a flag allocated with nrfx_flag32_alloc.
- Note
- Function is thread safe, it uses NRFX_ATOMIC_CAS macro. No further synchronization mechanism is needed, provided the macro is properly implemented (see nrfx_glue.h).
- Parameters
-
[in,out] | p_mask | Mask with available flags set. On successful allocation flag is set. |
[in] | flag | Flag index. |
- Return values
-
NRFX_SUCCESS | Freeing was successful. |
NRFX_ERROR_INVALID_PARAM | Flag was not allocated. |
◆ nrfx_flag32_init()
__STATIC_INLINE void nrfx_flag32_init |
( |
nrfx_atomic_t * |
p_mask, |
|
|
uint32_t |
init_mask |
|
) |
| |
Function for initializing allocator mask.
Initialization value contains mask where each bit indicates availablility of a given flag, e.g. init value 0x0000000A indicates that flag 3 and 1 (counting from 0) can be allocated.
Alternatively, mask can be set to init value by direct assignment.
- Parameters
-
[out] | p_mask | Mask to be initilized. |
[in] | init_mask | Mask with pool of available flags where bit being set means that flag is free and can be allocated. |
◆ nrfx_flag32_is_allocated()
bool nrfx_flag32_is_allocated |
( |
nrfx_atomic_t |
mask, |
|
|
uint8_t |
bitpos |
|
) |
| |
Function for checking if given flag is allocated.
- Note
- This check may not be valid if context is preempted and state is changed.
- Parameters
-
[in] | mask | Mask. |
[in] | bitpos | Flag bit position. |
- Returns
- True if specified flag is allocated, false otherwise.