sdk_common.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. /** @cond */
  13. /**@file
  14. *
  15. * @ingroup experimental_api
  16. * @defgroup sdk_common SDK Common Header
  17. * @breif All common headers needed for SDK examples will be included here so that application
  18. * developer does not have to include headers on him/herself.
  19. * @{
  20. */
  21. #ifndef SDK_COMMON_H__
  22. #define SDK_COMMON_H__
  23. #include <stdint.h>
  24. #include <stdbool.h>
  25. #include <string.h>
  26. #include "nordic_common.h"
  27. #include "compiler_abstraction.h"
  28. #include "sdk_os.h"
  29. #include "sdk_errors.h"
  30. #include "app_util.h"
  31. /**@brief Macro for verifying that the module is initialized. It will cause the function to return
  32. * if not.
  33. *
  34. * @param[in] param The variable to check if is NULL.
  35. */
  36. #ifndef DISABLE_PARAM_CHECK
  37. #define VERIFY_PARAM_NOT_NULL(param) \
  38. do \
  39. { \
  40. if (param == NULL) \
  41. { \
  42. return NRF_ERROR_NULL; \
  43. } \
  44. } while(0)
  45. #else
  46. #define VERIFY_PARAM_NOT_NULL()
  47. #endif /* DISABLE_PARAM_CHECK */
  48. /**@brief Macro for verifying that the module is initialized. It will cause the function to return
  49. * if not.
  50. *
  51. * @param[in] param The variable to check if is NULL.
  52. */
  53. #ifndef DISABLE_PARAM_CHECK
  54. #define VERIFY_PARAM_NOT_NULL_VOID(param) \
  55. do \
  56. { \
  57. if (param == NULL) \
  58. { \
  59. return; \
  60. } \
  61. } while(0)
  62. #else
  63. #define VERIFY_PARAM_NOT_NULL_VOID()
  64. #endif /* DISABLE_PARAM_CHECK */
  65. /**@brief Macro for verifying that a function returned NRF_SUCCESS. Will return the err code
  66. * if not.
  67. *
  68. * @param[in] err_code The error code to check.
  69. */
  70. #ifndef DISABLE_PARAM_CHECK
  71. #define VERIFY_SUCCESS(err_code) \
  72. do \
  73. { \
  74. if (err_code != NRF_SUCCESS) \
  75. { \
  76. return err_code; \
  77. } \
  78. } while(0)
  79. #else
  80. #define VERIFY_SUCCESS()
  81. #endif /* DISABLE_PARAM_CHECK */
  82. /**@brief Macro for verifying that a function returned NRF_SUCCESS. Will return if not.
  83. *
  84. * @param[in] err_code The error code to check.
  85. */
  86. #ifndef DISABLE_PARAM_CHECK
  87. #define VERIFY_SUCCESS_VOID(err_code) \
  88. do \
  89. { \
  90. if (err_code != NRF_SUCCESS) \
  91. { \
  92. return; \
  93. } \
  94. } while(0)
  95. #else
  96. #define VERIFY_SUCCESS_VOID()
  97. #endif /* DISABLE_PARAM_CHECK */
  98. /**@brief Macro for verifying statement to be true. Will return err_code if not.
  99. *
  100. * @param[in] statement Statement to test.
  101. * @param[in] err_code Error value to return if test was invalid.
  102. *
  103. * @retval err_code if test fails.
  104. */
  105. #define VERIFY_TRUE(statement, err_code) \
  106. do \
  107. { \
  108. if (!(statement)) \
  109. { \
  110. return err_code; \
  111. } \
  112. } while(0)
  113. /**@brief Macro for verifying statement to be true. Will return if not.
  114. *
  115. * @param[in] statement Statement to test.
  116. */
  117. #define VERIFY_TRUE_VOID(statement) \
  118. do \
  119. { \
  120. if (!(statement)) \
  121. { \
  122. return; \
  123. } \
  124. } while(0)
  125. /**@brief Macro for verifying statement to be false. Will return err_code if not.
  126. *
  127. * @param[in] statement Statement to test.
  128. * @param[in] err_code Error value to return if test was invalid.
  129. *
  130. * @retval err_code if test fails.
  131. */
  132. #define VERIFY_FALSE(statement, err_code) \
  133. do \
  134. { \
  135. if ((statement)) \
  136. { \
  137. return err_code; \
  138. } \
  139. } while(0)
  140. /**@brief Macro for verifying statement to be false. Will return if not.
  141. *
  142. * @param[in] statement Statement to test.
  143. */
  144. #define VERIFY_FALSE_VOID(statement) \
  145. do \
  146. { \
  147. if ((statement)) \
  148. { \
  149. return; \
  150. } \
  151. } while(0)
  152. /** @} */
  153. /** @endcond */
  154. #endif // SDK_COMMON_H__