nRF51 SDK: Utility Functions and Definitions

| nRF51 SDK

- Home
- Related Pages
- API Reference
- Data Structures

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Data Structures | Macros | Typedefs | Enumerations
Utility Functions and Definitions
SDK Common Libraries

Various types and definitions available to all applications. More...

## Data Structures

struct | uint8_array_t
| Byte array type. More...

## Macros

#define | NRF_APP_PRIORITY_THREAD 4
#define | PACKED(TYPE) __packed TYPE
#define | STATIC_ASSERT(EXPR) typedef char static_assert_failed[(EXPR) ? 1 : -1]
| Macro for doing static (i.e. compile time) assertion. More...
#define | CRITICAL_REGION_ENTER()
| Macro for entering a critical region. More...
#define | CRITICAL_REGION_EXIT()
| Macro for leaving a critical region. More...
#define | ROUNDED_DIV(A, B) (((A) + ((B) / 2)) / (B))
| Perform rounded integer division (as opposed to truncating the result). More...
#define | IS_POWER_OF_TWO(A) ( ((A) != 0) && ((((A) - 1) & (A)) == 0) )
| Check if the integer provided is a power of two. More...
#define | MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION))
| To convert ticks to millisecond. More...
#define | CEIL_DIV(A, B)
| Perform integer division, making sure the result is rounded up. More...

## Typedefs

typedef uint8_t | uint16_le_t [2]
| type for holding an encoded (i.e. little endian) 16 bit unsigned integer.
typedef uint8_t | uint32_le_t [4]
| type for holding an encoded (i.e. little endian) 32 bit unsigned integer.

## Enumerations

enum | app_irq_priority_t { APP_IRQ_PRIORITY_HIGH = 1, APP_IRQ_PRIORITY_LOW = 3 }
| The interrupt priorities available to the application while the SoftDevice is active.
enum | { UNIT_0_625_MS = 625, UNIT_1_25_MS = 1250, UNIT_10_MS = 10000 }

## Detailed Description

Various types and definitions available to all applications.

## Macro Definition Documentation

#define CEIL_DIV | ( |  | A,
|  |  | B
| ) |  |

Value:
/*lint -save -e573 */ \
((((A) - 1) / (B)) + 1) \
/*lint -restore */

Perform integer division, making sure the result is rounded up.

One typical use for this is to compute the number of objects with size B is needed to hold A number of bytes.

Parameters

  [in] | A | Numerator.
  [in] | B | Denominator.

Returns
  Integer result of dividing A by B, rounded up.

#define CRITICAL_REGION_ENTER | ( |  | ) |

Value:
{ \
uint8_t IS_NESTED_CRITICAL_REGION = 0; \
uint32_t CURRENT_INT_PRI = current_int_priority_get(); \
if (CURRENT_INT_PRI != APP_IRQ_PRIORITY_HIGH) \
{ \
uint32_t ERR_CODE = sd_nvic_critical_region_enter(&IS_NESTED_CRITICAL_REGION); \
if (ERR_CODE == NRF_ERROR_SOFTDEVICE_NOT_ENABLED) \
{ \
__disable_irq(); \
} \
else \
{ \
APP_ERROR_CHECK(ERR_CODE); \
} \
}

Macro for entering a critical region.

Note
  Due to implementation details, there must exist one and only one call to CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located in the same scope.

#define CRITICAL_REGION_EXIT | ( |  | ) |

Value:
if (CURRENT_INT_PRI != APP_IRQ_PRIORITY_HIGH) \
{ \
uint32_t ERR_CODE; \
__enable_irq(); \
ERR_CODE = sd_nvic_critical_region_exit(IS_NESTED_CRITICAL_REGION); \
if (ERR_CODE != NRF_ERROR_SOFTDEVICE_NOT_ENABLED) \
{ \
APP_ERROR_CHECK(ERR_CODE); \
} \
} \
}

Macro for leaving a critical region.

Note
  Due to implementation details, there must exist one and only one call to CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located in the same scope.

#define IS_POWER_OF_TWO | ( |  | A | ) | ( ((A) != 0) && ((((A) - 1) & (A)) == 0) )

Check if the integer provided is a power of two.

Parameters

  [in] | A | Number to be tested.

Returns
  true if value is power of two.
  false if value not power of two.

#define MSEC_TO_UNITS | ( |  | TIME,
|  |  | RESOLUTION
| ) |  | (((TIME) * 1000) / (RESOLUTION))

To convert ticks to millisecond.

Parameters

  [in] | time | Number of millseconds that needs to be converted.
  [in] | resolution | Units to be converted.

#define NRF_APP_PRIORITY_THREAD 4

"Interrupt level" when running in Thread Mode.

#define ROUNDED_DIV | ( |  | A,
|  |  | B
| ) |  | (((A) + ((B) / 2)) / (B))

Perform rounded integer division (as opposed to truncating the result).

Parameters

  [in] | A | Numerator.
  [in] | B | Denominator.

Returns
  Rounded (integer) result of dividing A by B.

#define STATIC_ASSERT | ( |  | EXPR | ) | typedef char static_assert_failed[(EXPR) ? 1 : -1]

Macro for doing static (i.e. compile time) assertion.

Note
  If the assertion fails when compiling using Keil, the compiler will report error message "error: #94: the size of an array must be greater than zero" (while gcc will list the symbol static_assert_failed, making the error message more readable). If the supplied expression can not be evaluated at compile time, Keil will report "error: #28: expression must have a constant value".
  The macro is intentionally implemented not using do while(0), allowing it to be used outside function blocks (e.g. close to global type- and variable declarations). If used in a code block, it must be used before any executable code in this block.

Parameters

  [in] | EXPR | Constant expression to be verified.

## Enumeration Type Documentation

anonymous enum

Enumerator
UNIT_0_625_MS | Number of microseconds in 0.625 milliseconds.
UNIT_1_25_MS | Number of microseconds in 1.25 milliseconds.
UNIT_10_MS | Number of microseconds in 10 milliseconds.