nRF5 SDK v15.0.0
Macros
SDK Common Header

Macros for parameter checking and similar tasks. More...

Macros

#define NRF_PARAM_CHECK(_module, _cond, _err, _printfn)
 Macro for parameter checking. More...
 
#define VERIFY_TRUE(statement, err_code)
 Macro for verifying statement to be true. It will cause the exterior function to return err_code if the statement is not true. More...
 
#define VERIFY_TRUE_VOID(statement)   VERIFY_TRUE((statement), )
 Macro for verifying statement to be true. It will cause the exterior function to return if the statement is not true. More...
 
#define VERIFY_FALSE(statement, err_code)
 Macro for verifying statement to be false. It will cause the exterior function to return err_code if the statement is not false. More...
 
#define VERIFY_FALSE_VOID(statement)   VERIFY_FALSE((statement), )
 Macro for verifying statement to be false. It will cause the exterior function to return if the statement is not false. More...
 
#define VERIFY_SUCCESS(statement)
 Macro for verifying that a function returned NRF_SUCCESS. It will cause the exterior function to return error code of statement if it is not NRF_SUCCESS. More...
 
#define VERIFY_SUCCESS_VOID(err_code)   VERIFY_TRUE_VOID((err_code) == NRF_SUCCESS)
 Macro for verifying that a function returned NRF_SUCCESS. It will cause the exterior function to return if the err_code is not NRF_SUCCESS. More...
 
#define VERIFY_MODULE_INITIALIZED()   VERIFY_TRUE((MODULE_INITIALIZED), NRF_ERROR_INVALID_STATE)
 Macro for verifying that the module is initialized. It will cause the exterior function to return NRF_ERROR_INVALID_STATE if not. More...
 
#define VERIFY_MODULE_INITIALIZED_VOID()   VERIFY_TRUE_VOID((MODULE_INITIALIZED))
 Macro for verifying that the module is initialized. It will cause the exterior function to return if not. More...
 
#define VERIFY_PARAM_NOT_NULL(param)   VERIFY_FALSE(((param) == NULL), NRF_ERROR_NULL)
 Macro for verifying that the module is initialized. It will cause the exterior function to return if not. More...
 
#define VERIFY_PARAM_NOT_NULL_VOID(param)   VERIFY_FALSE_VOID(((param) == NULL))
 Macro for verifying that the module is initialized. It will cause the exterior function to return if not. More...
 

Detailed Description

Macros for parameter checking and similar tasks.

Macro Definition Documentation

#define NRF_PARAM_CHECK (   _module,
  _cond,
  _err,
  _printfn 
)

Macro for parameter checking.

If _cond evaluates to true, does nothing. Otherwise, if _module ## _PARAM_CHECK_DISABLED is not set (default), prints an error message if _printfn is provided, and returns from the calling function context with code _err. If _module ## _PARAM_CHECK_DISABLED is set, behaves like the ASSERT macro.

Parameter checking implemented using this macro can be optionally turned off for release code. Only disable runtime parameter checks if size if a major concern.

Parameters
_moduleThe module name.
_condThe condition to be evaluated.
_errThe error to be returned.
_printfnA printf-compatible function used to log the error. Leave empty if no logging is needed.
#define VERIFY_FALSE (   statement,
  err_code 
)
Value:
do \
{ \
if ((statement)) \
{ \
return err_code; \
} \
} while (0)

Macro for verifying statement to be false. It will cause the exterior function to return err_code if the statement is not false.

Parameters
[in]statementStatement to test.
[in]err_codeError value to return if test was invalid.
Return values
nothing,butwill cause the exterior function to return err_code if statement is true.
#define VERIFY_FALSE_VOID (   statement)    VERIFY_FALSE((statement), )

Macro for verifying statement to be false. It will cause the exterior function to return if the statement is not false.

Parameters
[in]statementStatement to test.
#define VERIFY_MODULE_INITIALIZED ( )    VERIFY_TRUE((MODULE_INITIALIZED), NRF_ERROR_INVALID_STATE)

Macro for verifying that the module is initialized. It will cause the exterior function to return NRF_ERROR_INVALID_STATE if not.

Note
MODULE_INITIALIZED must be defined in each module using this macro. MODULE_INITIALIZED should be true if the module is initialized, false if not.
#define VERIFY_MODULE_INITIALIZED_VOID ( )    VERIFY_TRUE_VOID((MODULE_INITIALIZED))

Macro for verifying that the module is initialized. It will cause the exterior function to return if not.

Note
MODULE_INITIALIZED must be defined in each module using this macro. MODULE_INITIALIZED should be true if the module is initialized, false if not.
#define VERIFY_PARAM_NOT_NULL (   param)    VERIFY_FALSE(((param) == NULL), NRF_ERROR_NULL)

Macro for verifying that the module is initialized. It will cause the exterior function to return if not.

Parameters
[in]paramThe variable to check if is NULL.
#define VERIFY_PARAM_NOT_NULL_VOID (   param)    VERIFY_FALSE_VOID(((param) == NULL))

Macro for verifying that the module is initialized. It will cause the exterior function to return if not.

Parameters
[in]paramThe variable to check if is NULL.
#define VERIFY_SUCCESS (   statement)
Value:
do \
{ \
uint32_t _err_code = (uint32_t) (statement); \
if (_err_code != NRF_SUCCESS) \
{ \
return _err_code; \
} \
} while(0)

Macro for verifying that a function returned NRF_SUCCESS. It will cause the exterior function to return error code of statement if it is not NRF_SUCCESS.

Parameters
[in]statementStatement to check against NRF_SUCCESS.
#define VERIFY_SUCCESS_VOID (   err_code)    VERIFY_TRUE_VOID((err_code) == NRF_SUCCESS)

Macro for verifying that a function returned NRF_SUCCESS. It will cause the exterior function to return if the err_code is not NRF_SUCCESS.

Parameters
[in]err_codeThe error code to check.
#define VERIFY_TRUE (   statement,
  err_code 
)
Value:
do \
{ \
if (!(statement)) \
{ \
return err_code; \
} \
} while (0)

Macro for verifying statement to be true. It will cause the exterior function to return err_code if the statement is not true.

Parameters
[in]statementStatement to test.
[in]err_codeError value to return if test was invalid.
Return values
nothing,butwill cause the exterior function to return err_code if statement is false.
#define VERIFY_TRUE_VOID (   statement)    VERIFY_TRUE((statement), )

Macro for verifying statement to be true. It will cause the exterior function to return if the statement is not true.

Parameters
[in]statementStatement to test.

Documentation feedback | Developer Zone | Subscribe | Updated