Common module

group nrfx_common

Common module.

Defines

NRFX_CHECK(module_enabled)

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_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.

Note

API version to be used is configured using following symbols:

Parameters:
  • major[in] Major API version.

  • minor[in] Minor API version.

  • micro[in] Micro API version.

Return values:
  • true – Configured API version is greater than or equal to the specified API version.

  • false – Configured API version is smaller than the specified API version.

NRFX_BIT(x)

Macro for creating unsigned integer with bit position x set.

Parameters:
  • x[in] Bit position to be set.

Returns:

Unsigned integer with requested bit position set.

NRFX_BIT_MASK(x)

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

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

Returns:

Bit mask.

NRFX_BIT_SIZE(x)

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

Parameters:
  • x[in] Size in bytes.

Returns:

Size in bits.

NRFX_CONCAT_2(p1, p2)

Macro for concatenating two tokens in macro expansion.

See also

NRFX_CONCAT_3

Note

This macro is expanded in two steps so that tokens given as macros themselves are fully expanded before they are merged.

Parameters:
  • p1[in] First token.

  • p2[in] Second 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).

NRFX_CONCAT_2_(p1, p2)

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

NRFX_CONCAT_3(p1, p2, p3)

Macro for concatenating three tokens in macro expansion.

See also

NRFX_CONCAT_2

Note

This macro is expanded in two steps so that tokens given as macros themselves are fully expanded before they are merged.

Parameters:
  • p1[in] First token.

  • p2[in] Second token.

  • p3[in] Third 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).

NRFX_CONCAT_3_(p1, p2, p3)

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

NRFX_ABS(a)

Macro for computing the absolute value of an integer number.

Parameters:
  • a[in] Input value.

Returns:

Absolute value.

NRFX_FEATURE_PRESENT(periph_name, feature_name)

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:
  • periph_name[in] Peripheral name, e.g. SPIM.

  • feature_name[in] Feature flag name suffix following an instance name, e.g. _FEATURE_HARDWARE_CSN_PRESENT.

Return values:
  • 1 – At least one instance on current device supports a given feature.

  • 0 – None of peripheral instances supports a given feature.

NRFX_FOREACH_ENABLED(periph_name, macro, sep, off_code, ...)

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:
  • periph_name[in] Peripheral name, e.g. SPIM.

  • macro[in] Macro which is resolved if driver instance is enabled. Macro has following arguments: macro(periph_name, prefix, i, …).

  • sep[in] Separator added between all evaluations, in parentheses.

  • off_code[in] Code injected for disabled instances, in parentheses.

NRFX_FOREACH_PRESENT(periph_name, macro, sep, off_code, ...)

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:
  • periph_name[in] Peripheral name, e.g. SPIM.

  • macro[in] Macro which is resolved if peripheral instance is present. Macro has following arguments: macro(periph_name, prefix, i, …).

  • sep[in] Separator added between all evaluations, in parentheses.

  • off_code[in] Code injected for disabled instances, in parentheses.

NRFX_INSTANCE_CONCAT(periph_name, prefix, i, macro, ...)

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:
  • i[in] Instance index.

  • periph_name[in] Peripheral name, e.g. SPIM.

  • prefix[in] Prefix added before instance index, e.g. some device has instances named like SPIM00. First 0 is passed here as prefix.

  • macro[in] Macro which is executed.

  • ...[in] Variable length arguments passed to the macro. Macro has following arguments: macro(instance, …).

NRFX_INSTANCE_ENUM_LIST(periph_name)

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:
  • periph_name[in] Peripheral name (e.g. SPIM).

NRFX_INSTANCE_IRQ_HANDLERS(periph_name, 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:
  • periph_name[in] Peripheral name, e.g. SPIM.

  • periph_name_small[in] Peripheral name written with small letters, e.g. spim.

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.

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:
  • periph_name[in] Peripheral name, e.g. SPIM.

  • periph_name_small[in] Peripheral name written with small letters, e.g. rtc.

  • ext_macro[in] External macro to be executed for each instance.

NRFX_INSTANCE_IRQ_HANDLERS_DECLARE(periph_name, 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:
  • periph_name[in] Peripheral name, e.g. SPIM.

  • periph_name_small[in] Peripheral name written with small letters, e.g. spim.

NRFX_INSTANCE_IRQ_HANDLERS_LIST(periph_name, 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:
  • periph_name[in] Peripheral name, e.g. SPIM.

  • periph_name_small[in] Peripheral name written with small letters, e.g. spim.

NRFX_INSTANCE_PRESENT(_inst)

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:
  • _inst[in] Instance, .e.g SPIM10.

Return values:
  • 1 – If instance is present.

  • 0 – If instance is not present.

NRFX_MIN(a, b)

Macro for getting the smaller value between two arguments.

Parameters:
  • a[in] First argument.

  • b[in] Second argument.

Returns:

Smaller value between two arguments.

NRFX_MAX(a, b)

Macro for getting the larger value between two arguments.

Parameters:
  • a[in] First argument.

  • b[in] Second argument.

Returns:

Larger value between two arguments.

NRFX_IN_RANGE(val, min, max)

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

Note

val is evaluated twice.

Parameters:
  • val[in] A value to be checked.

  • min[in] The lower bound (inclusive).

  • max[in] The upper bound (inclusive).

Return values:
  • true – The value is in the given range.

  • false – The value is out of the given range.

NRFX_ROUNDED_DIV(a, b)

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

Parameters:
  • a[in] Numerator.

  • b[in] Denominator.

Returns:

Rounded (integer) result of dividing a by b.

NRFX_CEIL_DIV(a, b)

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:
  • a[in] Numerator.

  • b[in] Denominator.

Returns:

Integer result of dividing a by b, rounded up.

NRFX_ARRAY_SIZE(array)

Macro for getting the number of elements in an array.

Parameters:
  • array[in] Name of the array.

Returns:

Array element count.

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.

Parameters:
  • type[in] Structure type.

  • member[in] Structure member whose offset is searched for.

Returns:

Member offset in bytes.

NRFX_IS_POWER_OF_TWO(val)

Macro for checking whether given number is power of 2.

Parameters:
  • val[in] Tested value.

Return values:
  • true – The value is power of 2.

  • false – The value is not power of 2.

NRFX_IS_EVEN(val)

Macro for checking whether a given number is even.

Parameters:
  • val[in] Tested value.

Return values:
  • true – The value is even.

  • false – The value is odd.

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.

Parameters:
  • peripheral[in] Peripheral to check the lengths against.

  • length1[in] First length to be checked.

  • length2[in] Second length to be checked (pass 0 if not needed).

Return values:
  • true – The length of buffers does not exceed the limit of the specified peripheral.

  • false – The length of buffers exceeds the limit of the specified peripheral.

NRFX_WAIT_FOR(condition, attempts, delay_us, result)

Macro for waiting until condition is met.

Parameters:
  • condition[in] Condition to meet.

  • attempts[in] Maximum number of condition checks. Must not be 0.

  • delay_us[in] Delay between consecutive checks, in microseconds.

  • result[out] Boolean variable to store the result of the wait process. Set to true if the condition is met or false otherwise.

NRFX_PERIPHERAL_ID_GET(base_addr)

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:
  • base_addr[in] Peripheral base address or pointer.

Returns:

ID number associated with the specified peripheral.

NRFX_IRQ_NUMBER_GET(base_addr)

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.

Parameters:
  • base_addr[in] Peripheral base address or pointer.

Returns:

Interrupt number associated with the specified peripheral.

NRFX_KHZ_TO_HZ(freq)

Macro for converting frequency in kHz to Hz.

Parameters:
  • freq[in] Frequency value in kHz.

Returns:

Number of Hz in freq kHz.

NRFX_MHZ_TO_HZ(freq)

Macro for converting frequency in MHz to Hz.

Parameters:
  • freq[in] Frequency value in MHz.

Returns:

Number of Hz in freq MHz.

Typedefs

typedef void (*nrfx_irq_handler_t)(void)

IRQ handler type.

Enums

enum nrfx_drv_state_t

Driver state.

Values:

enumerator NRFX_DRV_STATE_UNINITIALIZED

Uninitialized.

enumerator NRFX_DRV_STATE_INITIALIZED

Initialized but powered off.

enumerator NRFX_DRV_STATE_POWERED_ON

Initialized and powered on.

Functions

__STATIC_INLINE bool nrfx_is_in_ram(void const *p_object)

Function for checking if an object is placed in the Data RAM region.

Several peripherals (the ones using EasyDMA) require the transfer buffers to be placed in the Data RAM region. This function can be used to check if this condition is met.

Parameters:
  • p_object[in] Pointer to an object whose location is to be checked.

Return values:
  • true – The pointed object is located in the Data RAM region.

  • false – The pointed object is not located in the Data RAM region.

__STATIC_INLINE bool nrfx_is_word_aligned(void const *p_object)

Function for checking if an object is aligned to a 32-bit word.

Several peripherals (the ones using EasyDMA) require the transfer buffers to be aligned to a 32-bit word. This function can be used to check if this condition is met.

Parameters:
  • p_object[in] Pointer to an object whose location is to be checked.

Return values:
  • true – The pointed object is aligned to a 32-bit word.

  • false – The pointed object is not aligned to a 32-bit word.

__STATIC_INLINE IRQn_Type nrfx_get_irq_number(void const *p_reg)

Function for getting the interrupt number for the specified peripheral.

Parameters:
  • p_reg[in] Peripheral base pointer.

Returns:

Interrupt number associated with the pointed peripheral.

__STATIC_INLINE uint32_t nrfx_bitpos_to_event(uint32_t bit)

Function for converting an INTEN register bit position to the corresponding event identifier.

The event identifier is the offset between the event register address and the peripheral base address, and is equal (thus, can be directly cast) to the corresponding value of the enumerated type from HAL (nrf_*_event_t).

Parameters:
  • bit[in] INTEN register bit position.

Returns:

Event identifier.

__STATIC_INLINE uint32_t nrfx_event_to_bitpos(uint32_t event)

Function for converting an event identifier to the corresponding INTEN register bit position.

The event identifier is the offset between the event register address and the peripheral base address, and is equal (thus, can be directly cast) to the corresponding value of the enumerated type from HAL (nrf_*_event_t).

Parameters:
  • event[in] Event identifier.

Returns:

INTEN register bit position.