Generic flag allocator

group nrfx_flag32_allocator

Generic flag allocator.

Functions

__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
  • p_mask[out] Mask to be initilized.

  • init_mask[in] Mask with pool of available flags where bit being set means that flag is free and can be 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
  • mask[in] Mask.

  • bitpos[in] Flag bit position.

Returns

True if specified flag is allocated, false otherwise.

nrfx_err_t nrfx_flag32_alloc(nrfx_atomic_t *p_mask, uint8_t *p_flag)

Function for allocating a flag in the mask.

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.

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
  • p_mask[inout] Mask with available flags set. On successful allocation flag is cleared.

  • p_flag[out] Index of the allocated flag.

Return values
  • NRFX_SUCCESS – Allocation was successful.

  • NRFX_ERROR_NO_MEM – No resource available.

nrfx_err_t nrfx_flag32_free(nrfx_atomic_t *p_mask, uint8_t flag)

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
  • p_mask[inout] Mask with available flags set. On successful allocation flag is set.

  • flag[in] Flag index.

Return values
  • NRFX_SUCCESS – Freeing was successful.

  • NRFX_ERROR_INVALID_PARAM – Flag was not allocated.