nrf_assert.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2006 Nordic Semiconductor. All Rights Reserved.
  3. *
  4. * The information contained herein is confidential property of Nordic Semiconductor. The use,
  5. * copying, transfer or disclosure of such information is prohibited except by express written
  6. * agreement with Nordic Semiconductor.
  7. *
  8. */
  9. /** @file
  10. * @brief Utilities for verifying program logic
  11. */
  12. #ifndef NRF_ASSERT_H_
  13. #define NRF_ASSERT_H_
  14. #include <stdint.h>
  15. #include "nrf.h"
  16. #include "app_error.h"
  17. #if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER)
  18. /** @brief Function for handling assertions.
  19. *
  20. *
  21. * @note
  22. * This function is called when an assertion has triggered.
  23. *
  24. *
  25. * @post
  26. * All hardware is put into an idle non-emitting state (in particular the radio is highly
  27. * important to switch off since the radio might be in a state that makes it send
  28. * packets continiously while a typical final infinit ASSERT loop is executing).
  29. *
  30. *
  31. * @param line_num The line number where the assertion is called
  32. * @param file_name Pointer to the file name
  33. */
  34. void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name);
  35. /*lint -emacro(506, ASSERT) */ /* Suppress "Constant value Boolean */
  36. /*lint -emacro(774, ASSERT) */ /* Suppress "Boolean within 'if' always evaluates to True" */ \
  37. /** @brief Function for checking intended for production code.
  38. *
  39. * Check passes if "expr" evaluates to true. */
  40. #define ASSERT(expr) \
  41. if (expr) \
  42. { \
  43. } \
  44. else \
  45. { \
  46. assert_nrf_callback((uint16_t)__LINE__, (uint8_t *)__FILE__); \
  47. }
  48. #else
  49. #define ASSERT(expr) //!< Assert empty when disabled
  50. __WEAK void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name);
  51. #endif /* defined(DEBUG_NRF) || defined(DEBUG_NRF_USER) */
  52. #endif /* NRF_ASSERT_H_ */