nrfx 4.5.0
Loading...
Searching...
No Matches
Preprocessor utility macros

Preprocessor utility macros. More...

Macros

#define NRFX_CHECK(module_enabled)
 Macro for checking if the specified identifier is defined and it has a non-zero value.
 
#define NRFX_RELEASE_VER_AT_LEAST(major, minor, micro)
 Macro for checking if the nrfx version is greater than or equal to the specified version.
 
#define NRFX_API_VER_AT_LEAST(major, minor, micro)
 Macro for checking if the configured API version is greater than or equal to the specified API version.
 
#define NRFX_BIT(x)
 Macro for creating unsigned integer with bit position x set.
 
#define NRFX_BIT_MASK(x)
 Macro for returning bit mask or 0 if x is 0.
 
#define NRFX_BIT_SIZE(x)
 Macro for returning size in bits for given size in bytes.
 
#define NRFX_CONCAT_2(p1, p2)
 Macro for concatenating two tokens in macro expansion.
 
#define NRFX_CONCAT_2_(p1, p2)
 Internal macro used by NRFX_CONCAT_2 to perform the expansion in two steps.
 
#define NRFX_CONCAT_3(p1, p2, p3)
 Macro for concatenating three tokens in macro expansion.
 
#define NRFX_CONCAT_3_(p1, p2, p3)
 Internal macro used by NRFX_CONCAT_3 to perform the expansion in two steps.
 
#define NRFX_ABS(a)
 Macro for computing the absolute value of an integer number.
 
#define NRFX_DIFF(a, b)
 Macro for computing the difference between two unsigned values.
 
#define NRFX_FEATURE_PRESENT(periph_name, feature_name)
 Macro for checking whether any of the instance of the specified peripheral supports a given feature.
 
#define NRFX_FOREACH_ENABLED(periph_name, macro, sep, off_code, ...)
 Macro for resolving provided user macro for enabled instances of a driver.
 
#define NRFX_FOREACH_INDEXED_PRESENT(periph_name, macro, sep, off_code, ...)
 Macro for resolving provided user macro for present indexed instances of a peripheral.
 
#define NRFX_FOREACH_PRESENT(periph_name, macro, sep, off_code, ...)
 Macro for resolving provided user macro for present instances of a peripheral.
 
#define NRFX_INSTANCE_CONCAT(periph_name, prefix, i, macro, ...)
 Macro for resolving provided user macro on concatenated peripheral name and instance index.
 
#define NRFX_INSTANCE_ENUM_LIST(periph_name)
 Macro for creating a content for enum which is listing enabled driver instances.
 
#define NRFX_INSTANCE_PRESENT_ENUM_LIST(periph_name)
 Macro for creating a content for enum which is listing potential driver instances.
 
#define NRFX_REG_TO_INSTANCE(periph_name, reg)
 Macro for translating peripheral address to its instance number.
 
#define NRFX_INSTANCE_IRQ_HANDLERS(periph_name, periph_name_small)
 Macro for creating an interrupt handler for all enabled driver instances.
 
#define NRFX_INSTANCE_IRQ_HANDLERS_EXT(periph_name, periph_name_small, ext_macro)
 Macro for creating an interrupt handler for all enabled driver instances with the specified extra parameter.
 
#define NRFX_INSTANCE_IRQ_HANDLERS_DECLARE(periph_name, periph_name_small)
 Macro for declaring an interrupt handler for all enabled driver instances.
 
#define NRFX_INSTANCE_IRQ_HANDLERS_LIST(periph_name, periph_name_small)
 Macro for generating comma-separated list of interrupt handlers for all enabled driver instances.
 
#define NRFX_INSTANCE_IRQ_HANDLER_DEFINE(periph_name_small, inst_idx, p_instance)
 Macro for generating instance specific interrupt handler for a specific driver.
 
#define NRFX_INSTANCE_PRESENT(_inst)
 Macro for checking if given peripheral instance is present on the target.
 
#define NRFX_MIN(a, b)
 Macro for getting the smaller value between two arguments.
 
#define NRFX_MAX(a, b)
 Macro for getting the larger value between two arguments.
 
#define NRFX_IN_RANGE(val, min, max)
 Macro for checking if a given value is in a given range.
 
#define NRFX_ROUNDED_DIV(a, b)
 Macro for performing rounded integer division (as opposed to truncating the result).
 
#define NRFX_CEIL_DIV(a, b)
 Macro for performing integer division, making sure the result is rounded up.
 
#define NRFX_ARRAY_SIZE(array)
 Macro for getting the number of elements in an array.
 
#define NRFX_OFFSETOF(type, member)
 Macro for getting the offset (in bytes) from the beginning of a structure of the specified type to its specified member.
 
#define NRFX_IS_POWER_OF_TWO(val)
 Macro for checking whether given number is power of 2.
 
#define NRFX_IS_EVEN(val)
 Macro for checking whether a given number is even.
 
#define NRFX_EASYDMA_LENGTH_VALIDATE(peripheral, length1, length2)
 Macro for checking if given lengths of EasyDMA transfers do not exceed the limit of the specified peripheral.
 
#define NRFX_WAIT_FOR(condition, attempts, delay_us, result)
 Macro for waiting until condition is met.
 
#define NRFX_PERIPHERAL_ID_GET(base_addr)
 Macro for getting the ID number of the specified peripheral.
 
#define NRFX_IRQ_NUMBER_GET(base_addr)
 Macro for getting the interrupt number assigned to a specific peripheral.
 
#define NRFX_KHZ_TO_HZ(freq)
 Macro for converting frequency in kHz to Hz.
 
#define NRFX_MHZ_TO_HZ(freq)
 Macro for converting frequency in MHz to Hz.
 
#define NRFX_COND_CODE_1(_flag, _if_1_code, _else_code)
 Macro for inserting code depending on whether _flag exists and expands to 1 or not.
 
#define NRFX_COND_CODE_0(_flag, _if_0_code, _else_code)
 Macro for inserting code depending on whether _flag exists and expands to 0 or not.
 
#define NRFX_IS_ENABLED(config_macro)
 Macro for checking for macro definition in compiler-visible expressions.
 
#define NRFX_LISTIFY(LEN, F, sep, ...)
 Macro for generating a sequence of code with configurable separator.
 
#define NRFX_IS_EMPTY(arg)
 Macro for checking if input argument is empty.
 
#define NRFX_NUM_VA_ARGS_LESS_1(...)
 Macro for calculating number of arguments in the variable arguments list minus one.
 
#define NRFX_CONCAT(...)
 Macro for concatenating multiple arguments.
 
#define NRFX_ARG_HAS_PARENTHESIS(x)
 Macro for checking if argument starts with opening round bracket and contains matching closing bracket (parenthesis).
 
#define NRFX_FOR_EACH(F, sep, ...)
 Macro for calling a macro F on each provided argument with a given separator between each call.
 
#define NRFX_FOR_EACH_IDX(F, sep, ...)
 Call macro F on each provided argument, with the argument's index as an additional parameter.
 
#define NRFX_FOR_EACH_FIXED_ARG(F, sep, fixed_arg, ...)
 Macro for calling macro F on each provided argument, with an additional fixed argument as a parameter.
 
#define NRFX_FOR_EACH_IDX_FIXED_ARG(F, sep, fixed_arg, ...)
 Macro from calling macro F for each variable argument with an index and fixed argument.
 
#define NRFX_REVERSE_ARGS(...)
 Macro for reversing arguments order.
 
#define NRFX_MAX_N(...)
 Macro for getting the highest value from input arguments.
 
#define NRFX_BITMASK_TO_BITPOS(_bitmask)
 Macro for getting a position of a bit in a bit mask with only one bit set.
 

Detailed Description

Preprocessor utility macros.

Macro Definition Documentation

◆ NRFX_ABS

#define NRFX_ABS ( a)
Value:
((a) < (0) ? -(a) : (a))

Macro for computing the absolute value of an integer number.

Parameters
[in]aInput value.
Returns
Absolute value.

◆ NRFX_API_VER_AT_LEAST

#define NRFX_API_VER_AT_LEAST ( major,
minor,
micro )
Value:
(((NRFX_CONFIG_API_VER_MAJOR > (major))) || \
((NRFX_CONFIG_API_VER_MAJOR == major) && (NRFX_CONFIG_API_VER_MINOR > (minor))) || \
#define NRFX_CONFIG_API_VER_MICRO
Symbol specifying micro version of the nrfx API to be used.
Definition nrfx_common_dox_config.h:14
#define NRFX_CONFIG_API_VER_MINOR
Symbol specifying minor version of the nrfx API to be used.
Definition nrfx_common_dox_config.h:11
#define NRFX_CONFIG_API_VER_MAJOR
Symbol specifying major version of the nrfx API to be used.
Definition nrfx_common_dox_config.h:8

Macro for checking if the configured API version is greater than or equal to the specified API version.

Note
API version to be used is configured using following symbols:
Parameters
[in]majorMajor API version.
[in]minorMinor API version.
[in]microMicro API version.
Return values
trueConfigured API version is greater than or equal to the specified API version.
falseConfigured API version is smaller than the specified API version.

◆ NRFX_ARG_HAS_PARENTHESIS

#define NRFX_ARG_HAS_PARENTHESIS ( x)
Value:
_NRFX_GET_ARG3(_NRFX_EVAL(_NRFX_ARG_HAS_PARENTHESIS x, 1, 0))

Macro for checking if argument starts with opening round bracket and contains matching closing bracket (parenthesis).

Parameters
[in]xInput argument.
Return values
1If input argument starts with opening bracket and contains closing bracket.
0If input argument does not match above mentioned condition.

◆ NRFX_ARRAY_SIZE

#define NRFX_ARRAY_SIZE ( array)
Value:
(sizeof(array) / sizeof((array)[0]))

Macro for getting the number of elements in an array.

Parameters
[in]arrayName of the array.
Returns
Array element count.

◆ NRFX_BIT

#define NRFX_BIT ( x)
Value:
(1UL << (x))

Macro for creating unsigned integer with bit position x set.

Parameters
[in]xBit position to be set.
Returns
Unsigned integer with requested bit position set.

◆ NRFX_BIT_MASK

#define NRFX_BIT_MASK ( x)
Value:
(((x) == 32) ? UINT32_MAX : ((1UL << (x)) - 1))

Macro for returning bit mask or 0 if x is 0.

Parameters
[in]xBit mask size. Bit mask has bits 0 through x-1 (inclusive) set.
Returns
Bit mask.

◆ NRFX_BIT_SIZE

#define NRFX_BIT_SIZE ( x)
Value:
((x) << 3)

Macro for returning size in bits for given size in bytes.

Parameters
[in]xSize in bytes.
Returns
Size in bits.

◆ NRFX_BITMASK_TO_BITPOS

#define NRFX_BITMASK_TO_BITPOS ( _bitmask)

Macro for getting a position of a bit in a bit mask with only one bit set.

Macro shall be used only on fixed value so that it can be resolved at compile time.

Parameters
_bitmask32 bit mask with one bit set.
Returns
Index of a bit.

◆ NRFX_CEIL_DIV

#define NRFX_CEIL_DIV ( a,
b )
Value:
((((a) - 1) / (b)) + 1)

Macro for performing integer division, making sure the result is rounded up.

A typical use case for this macro is to compute the number of objects with size b required to hold a number of bytes.

Parameters
[in]aNumerator.
[in]bDenominator.
Returns
Integer result of dividing a by b, rounded up.

◆ NRFX_CHECK

#define NRFX_CHECK ( module_enabled)
Value:
NRFX_IS_ENABLED(module_enabled)
#define NRFX_IS_ENABLED(config_macro)
Macro for checking for macro definition in compiler-visible expressions.
Definition nrfx_utils.h:709

Macro for checking if the specified identifier is defined and it has a non-zero value.

Normally, preprocessors treat all undefined identifiers as having the value zero. However, some tools, like static code analyzers, can issue a warning when such identifier is evaluated. This macro gives the possibility to suppress such warnings only in places where this macro is used for evaluation, not in the whole analyzed code.

◆ NRFX_CONCAT

#define NRFX_CONCAT ( ...)
Value:
NRFX_CONCAT_2(_NRFX_CONCAT_, NRFX_NUM_VA_ARGS_LESS_1(__VA_ARGS__))(__VA_ARGS__)
#define NRFX_NUM_VA_ARGS_LESS_1(...)
Macro for calculating number of arguments in the variable arguments list minus one.
Definition nrfx_utils.h:761
#define NRFX_CONCAT_2(p1, p2)
Macro for concatenating two tokens in macro expansion.
Definition nrfx_utils.h:143

Macro for concatenating multiple arguments.

Support up to 8 arguments.

Parameters
[in]...Arguments to concatenate.

◆ NRFX_CONCAT_2

#define NRFX_CONCAT_2 ( p1,
p2 )
Value:
#define NRFX_CONCAT_2_(p1, p2)
Internal macro used by NRFX_CONCAT_2 to perform the expansion in two steps.
Definition nrfx_utils.h:146

Macro for concatenating two tokens in macro expansion.

Note
This macro is expanded in two steps so that tokens given as macros themselves are fully expanded before they are merged.
Parameters
[in]p1First token.
[in]p2Second token.
Returns
The two tokens merged into one, unless they cannot together form a valid token (in such case, the preprocessor issues a warning and does not perform the concatenation).
See also
NRFX_CONCAT_3

◆ NRFX_CONCAT_2_

#define NRFX_CONCAT_2_ ( p1,
p2 )
Value:
p1 ## p2

Internal macro used by NRFX_CONCAT_2 to perform the expansion in two steps.

◆ NRFX_CONCAT_3

#define NRFX_CONCAT_3 ( p1,
p2,
p3 )
Value:
NRFX_CONCAT_3_(p1, p2, p3)
#define NRFX_CONCAT_3_(p1, p2, p3)
Internal macro used by NRFX_CONCAT_3 to perform the expansion in two steps.
Definition nrfx_utils.h:167

Macro for concatenating three tokens in macro expansion.

Note
This macro is expanded in two steps so that tokens given as macros themselves are fully expanded before they are merged.
Parameters
[in]p1First token.
[in]p2Second token.
[in]p3Third token.
Returns
The three tokens merged into one, unless they cannot together form a valid token (in such case, the preprocessor issues a warning and does not perform the concatenation).
See also
NRFX_CONCAT_2

◆ NRFX_CONCAT_3_

#define NRFX_CONCAT_3_ ( p1,
p2,
p3 )
Value:
p1 ## p2 ## p3

Internal macro used by NRFX_CONCAT_3 to perform the expansion in two steps.

◆ NRFX_COND_CODE_0

#define NRFX_COND_CODE_0 ( _flag,
_if_0_code,
_else_code )
Value:
_NRFX_COND_CODE_0(_flag, _if_0_code, _else_code)

Macro for inserting code depending on whether _flag exists and expands to 0 or not.

This is like NRFX_COND_CODE_1(), except that it tests whether _flag expands to the integer literal 0. It expands to _if_0_code if so, and _else_code otherwise; both of these must be enclosed in parentheses.

Parameters
[in]_flagEvaluated flag
[in]_if_0_codeResult if _flag expands to 0; must be in parentheses
[in]_else_codeResult otherwise; must be in parentheses

◆ NRFX_COND_CODE_1

#define NRFX_COND_CODE_1 ( _flag,
_if_1_code,
_else_code )
Value:
_NRFX_COND_CODE_1(_flag, _if_1_code, _else_code)

Macro for inserting code depending on whether _flag exists and expands to 1 or not.

To prevent the preprocessor from treating commas as argument separators, the _if_1_code and _else_code expressions must be inside brackets/parentheses: (). These are stripped away during macro expansion.

Example:

NRFX_COND_CODE_1(CONFIG_FLAG, (uint32_t x;), (there_is_no_flag();))

If CONFIG_FLAG is defined to 1, this expands to:

uint32_t x;

It expands to there_is_no_flag(); otherwise.

This could be used as an alternative to:

#if defined(CONFIG_FLAG) && (CONFIG_FLAG == 1)
#define MAYBE_DECLARE(x) uint32_t x
#else
#define MAYBE_DECLARE(x) there_is_no_flag()
#endif

MAYBE_DECLARE(x);

However, the advantage of COND_CODE_1() is that code is resolved in place where it is used, while the #if method defines MAYBE_DECLARE on two lines and requires it to be invoked again on a separate line. This makes COND_CODE_1() more concise and also sometimes more useful when used within another macro's expansion.

Note
_flag can be the result of preprocessor expansion, however _if_1_code is only expanded if _flag expands to the integer literal 1. Integer expressions that evaluate to 1, e.g. after doing some arithmetic, will not work.
Parameters
[in]_flagEvaluated flag
[in]_if_1_codeResult if _flag expands to 1; must be in parentheses
[in]_else_codeResult otherwise; must be in parentheses

◆ NRFX_DIFF

#define NRFX_DIFF ( a,
b )
Value:
((a) < (b) ? ((b) - (a)) : ((a) - (b)))

Macro for computing the difference between two unsigned values.

Parameters
[in]aFirst input value.
[in]bSecond input value.
Returns
Difference.

◆ NRFX_EASYDMA_LENGTH_VALIDATE

#define NRFX_EASYDMA_LENGTH_VALIDATE ( peripheral,
length1,
length2 )
Value:
(((length1) < (1U << NRFX_CONCAT_2(peripheral, _EASYDMA_MAXCNT_SIZE))) && \
((length2) < (1U << NRFX_CONCAT_2(peripheral, _EASYDMA_MAXCNT_SIZE))))

Macro for checking if given lengths of EasyDMA transfers do not exceed the limit of the specified peripheral.

Parameters
[in]peripheralPeripheral to check the lengths against.
[in]length1First length to be checked.
[in]length2Second length to be checked (pass 0 if not needed).
Return values
trueThe length of buffers does not exceed the limit of the specified peripheral.
falseThe length of buffers exceeds the limit of the specified peripheral.

◆ NRFX_FEATURE_PRESENT

#define NRFX_FEATURE_PRESENT ( periph_name,
feature_name )
Value:
_NRFX_FEATURE_PRESENT(periph_name, feature_name, 256), \
_NRFX_FEATURE_PRESENT(NRFX_CONCAT(periph_name, 0), feature_name, 100), \
_NRFX_FEATURE_PRESENT(NRFX_CONCAT(periph_name, 00), feature_name, 10) \
), \
(0), (1))
#define NRFX_CONCAT(...)
Macro for concatenating multiple arguments.
Definition nrfx_utils.h:777
#define NRFX_COND_CODE_0(_flag, _if_0_code, _else_code)
Macro for inserting code depending on whether _flag exists and expands to 0 or not.
Definition nrfx_utils.h:682

Macro for checking whether any of the instance of the specified peripheral supports a given feature.

Macro checks flags set in <device>_peripherals.h file.

Macro supports check on instances with following names:

  • <periph_name>0 - <periph_name>255 - e.g. SPIM0, SPIM255
  • <periph_name>00 - <periph_name>099 - e.g. SPIM00, SPIM099
  • <periph_name>000 - <periph_name>009 - e.g. SPIM000, SPIM009
Parameters
[in]periph_namePeripheral name, e.g. SPIM.
[in]feature_nameFeature flag name suffix following an instance name, e.g. _FEATURE_HARDWARE_CSN_PRESENT.
Return values
1At least one instance on current device supports a given feature.
0None of peripheral instances supports a given feature.

◆ NRFX_FOR_EACH

#define NRFX_FOR_EACH ( F,
sep,
... )
Value:
_NRFX_FOR_EACH(F, sep, NRFX_REVERSE_ARGS(__VA_ARGS__))
#define NRFX_REVERSE_ARGS(...)
Macro for reversing arguments order.
Definition nrfx_utils.h:905

Macro for calling a macro F on each provided argument with a given separator between each call.

Example:

#define F(x) int a##x
NRFX_FOR_EACH(F, (;), 4, 5, 6);

This expands to:

int a4;
int a5;
int a6;
Parameters
FMacro to invoke
sepSeparator (e.g. comma or semicolon). Must be in parentheses; this is required to enable providing a comma as a separator.
...Variable argument list. The macro F is invoked as F(element) for each element in the list.

◆ NRFX_FOR_EACH_FIXED_ARG

#define NRFX_FOR_EACH_FIXED_ARG ( F,
sep,
fixed_arg,
... )
Value:
_NRFX_FOR_EACH_FIXED_ARG(F, sep, fixed_arg, NRFX_REVERSE_ARGS(__VA_ARGS__))

Macro for calling macro F on each provided argument, with an additional fixed argument as a parameter.

This is like NRFX_FOR_EACH(), except F should be a macro which takes two arguments: F(variable_arg, fixed_arg).

Example:

static void func(int val, void *dev);
NRFX_FOR_EACH_FIXED_ARG(func, (;), dev, 4, 5, 6);

This expands to:

func(4, dev);
func(5, dev);
func(6, dev);
Parameters
FMacro to invoke
sepSeparator (e.g. comma or semicolon). Must be in parentheses; this is required to enable providing a comma as a separator.
fixed_argFixed argument passed to F as the second macro parameter.
...Variable argument list. The macro F is invoked as F(element, fixed_arg) for each element in the list.

◆ NRFX_FOR_EACH_IDX

#define NRFX_FOR_EACH_IDX ( F,
sep,
... )
Value:
_NRFX_FOR_EACH_IDX(F, sep, NRFX_REVERSE_ARGS(__VA_ARGS__))

Call macro F on each provided argument, with the argument's index as an additional parameter.

This is like NRFX_FOR_EACH(), except F should be a macro which takes two arguments: F(index, variable_arg).

Example:

#define F(idx, x) int a##idx = x
NRFX_FOR_EACH_IDX(F, (;), 4, 5, 6);

This expands to:

int a0 = 4;
int a1 = 5;
int a2 = 6;
Parameters
FMacro to invoke
sepSeparator (e.g. comma or semicolon). Must be in parentheses; this is required to enable providing a comma as a separator.
...Variable argument list. The macro F is invoked as F(index, element) for each element in the list.

◆ NRFX_FOR_EACH_IDX_FIXED_ARG

#define NRFX_FOR_EACH_IDX_FIXED_ARG ( F,
sep,
fixed_arg,
... )
Value:
_NRFX_FOR_EACH_IDX_FIXED_ARG(F, sep, fixed_arg, NRFX_REVERSE_ARGS(__VA_ARGS__))

Macro from calling macro F for each variable argument with an index and fixed argument.

This is like the combination of NRFX_FOR_EACH_IDX() with NRFX_FOR_EACH_FIXED_ARG().

Example:

#define F(idx, x, fixed_arg) int fixed_arg##idx = x
NRFX_FOR_EACH_IDX_FIXED_ARG(F, (;), a, 4, 5, 6);

This expands to:

int a0 = 4;
int a1 = 5;
int a2 = 6;
Parameters
FMacro to invoke
sepSeparator (e.g. comma or semicolon). Must be in parentheses; This is required to enable providing a comma as a separator.
fixed_argFixed argument passed to F as the third macro parameter.
...Variable list of arguments. The macro F is invoked as F(index, element, fixed_arg) for each element in the list.

◆ NRFX_FOREACH_ENABLED

#define NRFX_FOREACH_ENABLED ( periph_name,
macro,
sep,
off_code,
... )
Value:
NRFX_LISTIFY(256, _NRFX_EVAL_IF_ENABLED, sep, \
off_code, periph_name, , macro, __VA_ARGS__) NRFX_DEBRACKET sep \
NRFX_LISTIFY(100, _NRFX_EVAL_IF_ENABLED, sep, \
off_code, periph_name, 0, macro, __VA_ARGS__) NRFX_DEBRACKET sep \
NRFX_LISTIFY(10, _NRFX_EVAL_IF_ENABLED, sep, \
off_code, periph_name, 00, macro, __VA_ARGS__)
#define NRFX_LISTIFY(LEN, F, sep,...)
Macro for generating a sequence of code with configurable separator.
Definition nrfx_utils.h:735

Macro for resolving provided user macro for enabled instances of a driver.

Macro checks if driver instances are enabled for all potential instaces of a peripheral. It takes peripheral name and checks whether NRFX_<peripheral><id>_ENABLED is set to 1 and if yes then provided macro is evaluated for given instance.

Macro supports check on instances with following names:

  • <periph_name>0 - <periph_name>255 - e.g. SPIM0, SPIM255
  • <periph_name>00 - <periph_name>099 - e.g. SPIM00, SPIM099
  • <periph_name>000 - <periph_name>009 - e.g. SPIM000, SPIM009
Parameters
[in]periph_namePeripheral name, e.g. SPIM.
[in]macroMacro which is resolved if driver instance is enabled. Macro has following arguments: macro(periph_name, prefix, i, ...).
[in]sepSeparator added between all evaluations, in parentheses.
[in]off_codeCode injected for disabled instances, in parentheses.

◆ NRFX_FOREACH_INDEXED_PRESENT

#define NRFX_FOREACH_INDEXED_PRESENT ( periph_name,
macro,
sep,
off_code,
... )
Value:
NRFX_LISTIFY(256, _NRFX_EVAL_IF_PRESENT, sep, \
off_code, periph_name, , macro, __VA_ARGS__) NRFX_DEBRACKET sep \
NRFX_LISTIFY(100, _NRFX_EVAL_IF_PRESENT, sep, \
off_code, periph_name, 0, macro, __VA_ARGS__) NRFX_DEBRACKET sep \
NRFX_LISTIFY(10, _NRFX_EVAL_IF_PRESENT, sep, \
off_code, periph_name, 00, macro, __VA_ARGS__) NRFX_DEBRACKET sep \

Macro for resolving provided user macro for present indexed instances of a peripheral.

Macro checks if peripheral instances are present by checking if there is a token NRF_<periph_name><id> defined with wrapped in parenthesis value.

Macro supports check on instances with following names:

  • <periph_name>0 - <periph_name>255 - e.g. SPIM0, SPIM255
  • <periph_name>00 - <periph_name>099 - e.g. SPIM00, SPIM099
  • <periph_name>000 - <periph_name>009 - e.g. SPIM000, SPIM009
Parameters
[in]periph_namePeripheral name, e.g. SPIM.
[in]macroMacro which is resolved if peripheral instance is present. Macro has following arguments: macro(periph_name, prefix, i, ...).
[in]sepSeparator added between all evaluations, in parentheses.
[in]off_codeCode injected for disabled instances, in parentheses.

◆ NRFX_FOREACH_PRESENT

#define NRFX_FOREACH_PRESENT ( periph_name,
macro,
sep,
off_code,
... )
Value:
NRFX_FOREACH_INDEXED_PRESENT(periph_name, macro, sep, off_code, __VA_ARGS__) \
_NRFX_EVAL_IF_PRESENT(, off_code, periph_name, , macro, __VA_ARGS__)
#define NRFX_FOREACH_INDEXED_PRESENT(periph_name, macro, sep, off_code,...)
Macro for resolving provided user macro for present indexed instances of a peripheral.
Definition nrfx_utils.h:256

Macro for resolving provided user macro for present instances of a peripheral.

Macro checks if peripheral instances are present by checking if there is a token NRF_<periph_name><id> defined with wrapped in parenthesis value.

Macro supports check on instances with following names:

  • <periph_name>0 - <periph_name>255 - e.g. SPIM0, SPIM255
  • <periph_name>00 - <periph_name>099 - e.g. SPIM00, SPIM099
  • <periph_name>000 - <periph_name>009 - e.g. SPIM000, SPIM009
  • <periph_name> - e.g. SPIM
Parameters
[in]periph_namePeripheral name, e.g. SPIM.
[in]macroMacro which is resolved if peripheral instance is present. Macro has following arguments: macro(periph_name, prefix, i, ...).
[in]sepSeparator added between all evaluations, in parentheses.
[in]off_codeCode injected for disabled instances, in parentheses.

◆ NRFX_IN_RANGE

#define NRFX_IN_RANGE ( val,
min,
max )
Value:
((val) >= (min) && (val) <= (max))

Macro for checking if a given value is in a given range.

Note
val is evaluated twice.
Parameters
[in]valA value to be checked.
[in]minThe lower bound (inclusive).
[in]maxThe upper bound (inclusive).
Return values
trueThe value is in the given range.
falseThe value is out of the given range.

◆ NRFX_INSTANCE_CONCAT

#define NRFX_INSTANCE_CONCAT ( periph_name,
prefix,
i,
macro,
... )
Value:
macro(NRFX_CONCAT(periph_name, prefix, i), __VA_ARGS__)

Macro for resolving provided user macro on concatenated peripheral name and instance index.

Execute provided macro with single argument <instance> that is the concatenation of periph_name, prefix and i.

Parameters
[in]iInstance index.
[in]periph_namePeripheral name, e.g. SPIM.
[in]prefixPrefix added before instance index, e.g. some device has instances named like SPIM00. First 0 is passed here as prefix.
[in]macroMacro which is executed.
[in]...Variable length arguments passed to the macro. Macro has following arguments: macro(instance, ...).

◆ NRFX_INSTANCE_ENUM_LIST

#define NRFX_INSTANCE_ENUM_LIST ( periph_name)
Value:
NRFX_FOREACH_ENABLED(periph_name, _NRFX_INST_ENUM, (), ())
#define NRFX_FOREACH_ENABLED(periph_name, macro, sep, off_code,...)
Macro for resolving provided user macro for enabled instances of a driver.
Definition nrfx_utils.h:231

Macro for creating a content for enum which is listing enabled driver instances.

It creates comma separated list of entries like NRFX_<instance_name>INST_IDX, e.g. (NRFX_SPIM0_INST_IDX) for all enabled instances (NRFX<instance_name>_ENABLED is set to 1). It should be called within enum declaration. Created enum is used by the driver to index all enabled instances of the driver.

Parameters
[in]periph_namePeripheral name (e.g. SPIM).

◆ NRFX_INSTANCE_IRQ_HANDLER_DEFINE

#define NRFX_INSTANCE_IRQ_HANDLER_DEFINE ( periph_name_small,
inst_idx,
p_instance )
Value:
void NRFX_CONCAT(nrfx_, periph_name_small, _, inst_idx, _irq_handler)(void * p_context) \
{ \
(void)p_context; \
NRFX_CONCAT(nrfx_, periph_name_small, _irq_handler)(p_instance); \
}

Macro for generating instance specific interrupt handler for a specific driver.

This macro should be called in user code outside of function if user wants to use interrupts with given peripheral instance.

Parameters
[in]periph_name_smallPeripheral name written with small letters, e.g. spim.
[in]inst_idxInstance index.
[in]p_instancePointer to the driver instance object.

◆ NRFX_INSTANCE_IRQ_HANDLERS

#define NRFX_INSTANCE_IRQ_HANDLERS ( periph_name,
periph_name_small )
Value:
NRFX_FOREACH_ENABLED(periph_name, _NRFX_IRQ_HANDLER, (), (), periph_name_small)

Macro for creating an interrupt handler for all enabled driver instances.

Macro creates a set of functions which calls generic irq_handler function with two parameters:

  • peripheral instance register pointer
  • pointer to a control block structure associated with the given instance

Generic interrupt handler function with above mentioned parameters named irq_handler must be implemented in the driver.

Note
Handlers are using enum which should be generated using NRFX_INSTANCE_ENUM_LIST.
Parameters
[in]periph_namePeripheral name, e.g. SPIM.
[in]periph_name_smallPeripheral name written with small letters, e.g. spim.

◆ NRFX_INSTANCE_IRQ_HANDLERS_DECLARE

#define NRFX_INSTANCE_IRQ_HANDLERS_DECLARE ( periph_name,
periph_name_small )
Value:
NRFX_FOREACH_ENABLED(periph_name, _NRFX_IRQ_HANDLER_DECLARE, (), (), periph_name_small)

Macro for declaring an interrupt handler for all enabled driver instances.

Macro creates set of function declarations. It is intended to be used in the driver header.

Parameters
[in]periph_namePeripheral name, e.g. SPIM.
[in]periph_name_smallPeripheral name written with small letters, e.g. spim.

◆ NRFX_INSTANCE_IRQ_HANDLERS_EXT

#define NRFX_INSTANCE_IRQ_HANDLERS_EXT ( periph_name,
periph_name_small,
ext_macro )
Value:
NRFX_FOREACH_ENABLED(periph_name, _NRFX_IRQ_HANDLER_EXT, (), (), periph_name_small, ext_macro)

Macro for creating an interrupt handler for all enabled driver instances with the specified extra parameter.

Macro creates set of function which calls generic irq_handler function with three parameters:

  • peripheral instance register pointer
  • pointer to a control block structure associated with the given instance
  • provided ext_macro called with peripheral name suffix (e.g. 01 for TIMER01)

Generic interrupt handler function with above mentioned parameters named irq_handler must be implemented in the driver.

Note
Handlers are using enum which should be generated using NRFX_INSTANCE_ENUM_LIST.
Parameters
[in]periph_namePeripheral name, e.g. SPIM.
[in]periph_name_smallPeripheral name written with small letters, e.g. rtc.
[in]ext_macroExternal macro to be executed for each instance.

◆ NRFX_INSTANCE_IRQ_HANDLERS_LIST

#define NRFX_INSTANCE_IRQ_HANDLERS_LIST ( periph_name,
periph_name_small )
Value:
NRFX_FOREACH_ENABLED(periph_name, _NRFX_IRQ_HANDLER_LIST, (), (), periph_name_small)

Macro for generating comma-separated list of interrupt handlers for all enabled driver instances.

Interrupt handlers are generated using NRFX_INSTANCE_IRQ_HANDLERS. It is intended to be used to create a list which is used for passing an interrupt handler function to the PRS driver.

Parameters
[in]periph_namePeripheral name, e.g. SPIM.
[in]periph_name_smallPeripheral name written with small letters, e.g. spim.

◆ NRFX_INSTANCE_PRESENT

#define NRFX_INSTANCE_PRESENT ( _inst)
Value:
#define NRFX_ARG_HAS_PARENTHESIS(x)
Macro for checking if argument starts with opening round bracket and contains matching closing bracke...
Definition nrfx_utils.h:789

Macro for checking if given peripheral instance is present on the target.

Macro utilizes the fact that for each existing instance a define is created which points to the memory mapped register set casted to a register set structure. It is wrapped in parenthesis and existance of parethesis wrapping is used to determine if instance exists. It if does not exist then token (e.g. NRF_SPIM10) is undefined so it does not have parenthesis wrapping.

Since macro returns literal 1 it can be used by other macros.

Parameters
[in]_instInstance, .e.g SPIM10.
Return values
1If instance is present.
0If instance is not present.

◆ NRFX_INSTANCE_PRESENT_ENUM_LIST

#define NRFX_INSTANCE_PRESENT_ENUM_LIST ( periph_name)
Value:
NRFX_FOREACH_INDEXED_PRESENT(periph_name, _NRFX_INST_ENUM, (), ())

Macro for creating a content for enum which is listing potential driver instances.

It creates comma separated list of entries like NRFX_<instance_name>INST_IDX, e.g. (NRFX_SPIM0_INST_IDX) for all present instances (NRF<instance_name> is present). It should be called within enum declaration.

Parameters
[in]periph_namePeripheral name (e.g. SPIM).

◆ NRFX_IRQ_NUMBER_GET

#define NRFX_IRQ_NUMBER_GET ( base_addr)
Value:
#define NRFX_PERIPHERAL_ID_GET(base_addr)
Macro for getting the ID number of the specified peripheral.
Definition nrfx_utils.h:588

Macro for getting the interrupt number assigned to a specific peripheral.

For peripherals in Nordic SoCs, the IRQ number assigned to a peripheral is equal to its ID number. See the chapter "Peripheral interface" (sections "Peripheral ID" and "Interrupts") in the Product Specification.

Warning
This macro is valid only for peripherals with a single interrupt line.
Parameters
[in]base_addrPeripheral base address or pointer.
Returns
Interrupt number associated with the specified peripheral.

◆ NRFX_IS_EMPTY

#define NRFX_IS_EMPTY ( arg)
Value:
_NRFX_IS_EMPTY(arg)

Macro for checking if input argument is empty.

Empty means that nothing is provided or provided value is resolved to nothing (e.g. empty define).

Macro idea is taken from P99 which is under Apache 2.0 license and described by Jens Gustedt https://gustedt.wordpress.com/2010/06/08/detect-empty-macro-arguments/

Parameters
argArgument.
Return values
1if argument is empty.
0if argument is not empty.

◆ NRFX_IS_ENABLED

#define NRFX_IS_ENABLED ( config_macro)
Value:
_NRFX_IS_ENABLED1(config_macro)

Macro for checking for macro definition in compiler-visible expressions.

It has the effect of taking a macro value that may be defined to "1" or may not be defined at all and turning it into a literal expression that can be handled by the C compiler instead of just the preprocessor.

That is, it works similarly to #if defined(CONFIG_FOO) except that its expansion is a C expression. Thus, much #ifdef usage can be replaced with equivalents like:

if (IS_ENABLED(CONFIG_FOO)) {
        do_something_with_foo
}

This is cleaner since the compiler can generate errors and warnings for do_something_with_foo even when CONFIG_FOO is undefined.

Parameters
[in]config_macroMacro to check
Returns
1 if config_macro is defined to 1, 0 otherwise (including if config_macro is not defined)

◆ NRFX_IS_EVEN

#define NRFX_IS_EVEN ( val)
Value:
(((val) % 2) == 0)

Macro for checking whether a given number is even.

Parameters
[in]valTested value.
Return values
trueThe value is even.
falseThe value is odd.

◆ NRFX_IS_POWER_OF_TWO

#define NRFX_IS_POWER_OF_TWO ( val)
Value:
(((val) != 0) && ((val) & ((val) - 1)) == 0)

Macro for checking whether given number is power of 2.

Parameters
[in]valTested value.
Return values
trueThe value is power of 2.
falseThe value is not power of 2.

◆ NRFX_KHZ_TO_HZ

#define NRFX_KHZ_TO_HZ ( freq)
Value:
((freq) * 1000)

Macro for converting frequency in kHz to Hz.

Parameters
[in]freqFrequency value in kHz.
Returns
Number of Hz in freq kHz.

◆ NRFX_LISTIFY

#define NRFX_LISTIFY ( LEN,
F,
sep,
... )
Value:
NRFX_CONCAT_2(_NRFX_LISTIFY_, LEN)(F, sep, __VA_ARGS__)

Macro for generating a sequence of code with configurable separator.

Example:

#define FOO(i, _) MY_PWM ## i
{ NRFX_LISTIFY(PWM_COUNT, FOO, (,)) }

The above two lines expand to:

{ MY_PWM0 , MY_PWM1 }

Parameters
[in]LENThe length of the sequence. Must be an integer literal less than 255.
[in]FA macro function that accepts at least two arguments: F(i, ...). F is called repeatedly in the expansion. Its first argument i is the index in the sequence, and the variable list of arguments passed to LISTIFY are passed through to F.
[in]sepSeparator (e.g. comma or semicolon). Must be in parentheses; this is required to enable providing a comma as separator.
Note
Calling NRFX_LISTIFY with undefined arguments has undefined behavior.

◆ NRFX_MAX

#define NRFX_MAX ( a,
b )
Value:
((a) > (b) ? (a) : (b))

Macro for getting the larger value between two arguments.

Parameters
[in]aFirst argument.
[in]bSecond argument.
Returns
Larger value between two arguments.

◆ NRFX_MAX_N

#define NRFX_MAX_N ( ...)
Value:
NRFX_EVAL(NRFX_FOR_EACH(_NRFX_MAX_P1, (), __VA_ARGS__) 0 \
NRFX_FOR_EACH(_NRFX_MAX_P2, (), __VA_ARGS__))
#define NRFX_FOR_EACH(F, sep,...)
Macro for calling a macro F on each provided argument with a given separator between each call.
Definition nrfx_utils.h:812

Macro for getting the highest value from input arguments.

It is similar to NRFX_MAX but accepts a variable number of arguments.

Note
Input arguments must be numeric variables.
Parameters
...Variable argument list.
Returns
Highest value from the input list.

◆ NRFX_MHZ_TO_HZ

#define NRFX_MHZ_TO_HZ ( freq)
Value:
((freq) * 1000 * 1000)

Macro for converting frequency in MHz to Hz.

Parameters
[in]freqFrequency value in MHz.
Returns
Number of Hz in freq MHz.

◆ NRFX_MIN

#define NRFX_MIN ( a,
b )
Value:
((a) < (b) ? (a) : (b))

Macro for getting the smaller value between two arguments.

Parameters
[in]aFirst argument.
[in]bSecond argument.
Returns
Smaller value between two arguments.

◆ NRFX_NUM_VA_ARGS_LESS_1

#define NRFX_NUM_VA_ARGS_LESS_1 ( ...)
Value:
_NRFX_NUM_VA_ARGS_LESS_1_IMPL(__VA_ARGS__, 63, 62, 61, \
60, 59, 58, 57, 56, 55, 54, 53, 52, 51, \
50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, ~)

Macro for calculating number of arguments in the variable arguments list minus one.

Parameters
[in]...List of arguments
Returns
Number of variadic arguments in the argument list, minus one

◆ NRFX_OFFSETOF

#define NRFX_OFFSETOF ( type,
member )
Value:
((size_t) & (((type *)0)->member))

Macro for getting the offset (in bytes) from the beginning of a structure of the specified type to its specified member.

Parameters
[in]typeStructure type.
[in]memberStructure member whose offset is searched for.
Returns
Member offset in bytes.

◆ NRFX_PERIPHERAL_ID_GET

#define NRFX_PERIPHERAL_ID_GET ( base_addr)
Value:
(uint16_t)(((uint32_t)(base_addr) >> 12) & 0x000001FF)

Macro for getting the ID number of the specified peripheral.

For peripherals in Nordic SoCs, there is a direct relationship between their ID numbers and their base addresses. See the chapter "Peripheral interface" (section "Peripheral ID") in the Product Specification.

Parameters
[in]base_addrPeripheral base address or pointer.
Returns
ID number associated with the specified peripheral.

◆ NRFX_REG_TO_INSTANCE

#define NRFX_REG_TO_INSTANCE ( periph_name,
reg )
Value:
NRFX_FOREACH_INDEXED_PRESENT(periph_name, _PERIPH_PTR_COMPARE, (), (), reg) \
255

Macro for translating peripheral address to its instance number.

Parameters
[in]periph_namePeripheral name, e.g. SPIM.
[in]regPeripheral address.
Returns
Peripheral instance number if address matches, 255 otherwise.

◆ NRFX_RELEASE_VER_AT_LEAST

#define NRFX_RELEASE_VER_AT_LEAST ( major,
minor,
micro )
Value:
(((NRFX_RELEASE_VER_MAJOR > (major))) || \
((NRFX_RELEASE_VER_MAJOR == major) && (NRFX_RELEASE_VER_MINOR > (minor))) || \
((NRFX_RELEASE_VER_MAJOR == major) && (NRFX_RELEASE_VER_MINOR == minor) && \
(NRFX_RELEASE_VER_MICRO >= (micro))))
#define NRFX_RELEASE_VER_MAJOR
Symbol specifying major number of the current nrfx version.
Definition nrfx_common.h:91
#define NRFX_RELEASE_VER_MINOR
Symbol specifying minor number of the current nrfx version.
Definition nrfx_common.h:94
#define NRFX_RELEASE_VER_MICRO
Symbol specifying micro number of the current nrfx version.
Definition nrfx_common.h:97

Macro for checking if the nrfx version is greater than or equal to the specified version.

Note
Current nrfx version is specified with the following symbols:
Parameters
[in]majorMajor version.
[in]minorMinor version.
[in]microMicro version.
Return values
trueCurrent nrfx version is greater than or equal to the specified version.
falseCurrent nrfx version is smaller than the specified version.

◆ NRFX_REVERSE_ARGS

#define NRFX_REVERSE_ARGS ( ...)
Value:
_NRFX_FOR_EACH_ENGINE(_NRFX_FOR_EACH_EXEC, (,), NRFX_EVAL, _, __VA_ARGS__)

Macro for reversing arguments order.

Parameters
...Variable argument list.
Returns
Input arguments in reversed order.

◆ NRFX_ROUNDED_DIV

#define NRFX_ROUNDED_DIV ( a,
b )
Value:
((((a) < 0) ^ ((b) < 0)) ? (((a) - (b) / 2) / (b)) : (((a) + (b) / 2) / (b)))

Macro for performing rounded integer division (as opposed to truncating the result).

Parameters
[in]aNumerator.
[in]bDenominator.
Returns
Rounded (integer) result of dividing a by b.

◆ NRFX_WAIT_FOR

#define NRFX_WAIT_FOR ( condition,
attempts,
delay_us,
result )
Value:
do { \
result = false; \
uint32_t remaining_attempts = (attempts); \
do { \
if (condition) \
{ \
result = true; \
break; \
} \
NRFX_DELAY_US(delay_us); \
} while (--remaining_attempts); \
} while(0)

Macro for waiting until condition is met.

Parameters
[in]conditionCondition to meet.
[in]attemptsMaximum number of condition checks. Must not be 0.
[in]delay_usDelay between consecutive checks, in microseconds.
[out]resultBoolean variable to store the result of the wait process. Set to true if the condition is met or false otherwise.