ser_conn_error_handling.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**
  2. * Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #include "nrf_assert.h"
  41. #include "app_error.h"
  42. #include "ser_config.h"
  43. #include "boards.h"
  44. /** @file
  45. *
  46. * @defgroup ser_conn_error_handling Errors handling for the Connectivity Chip.
  47. * @{
  48. * @ingroup sdk_lib_serialization
  49. *
  50. * @brief A module to handle the Connectivity Chip errors and warnings.
  51. *
  52. * @details This file contains definitions of functions used for handling the Connectivity Chip
  53. * errors and warnings.
  54. */
  55. /**@brief Function for handling the Connectivity Chip errors and warnings.
  56. *
  57. * @details This function will be called if the ASSERT macro in the connectivity application fails.
  58. * Function declaration can be found in the app_error.h file.
  59. *
  60. * @param[in] error_code Error code supplied to the handler.
  61. * @param[in] line_num Line number where the handler is called.
  62. * @param[in] p_file_name Pointer to the file name.
  63. */
  64. #include "app_util_platform.h"
  65. #include "nrf_soc.h"
  66. #include "nrf_log.h"
  67. #include "nrf_log_ctrl.h"
  68. // uint32_t m_error_code;
  69. // uint32_t m_error_line_num;
  70. // const uint8_t *m_p_error_file_name;
  71. /*lint -save -e14 */
  72. void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
  73. {
  74. // disable INTs
  75. CRITICAL_REGION_ENTER();
  76. NRF_LOG_ERROR("Fatal error");
  77. NRF_LOG_FINAL_FLUSH();
  78. #if LEDS_NUMBER > 0
  79. /* Light a LED on error or warning. */
  80. // nrf_gpio_cfg_output(SER_CONN_ASSERT_LED_PIN);
  81. // nrf_gpio_pin_set(SER_CONN_ASSERT_LED_PIN);
  82. #endif
  83. // m_p_error_file_name = p_file_name;
  84. // m_error_code = error_code;
  85. // m_error_line_num = line_num;
  86. /* Do not reset when warning. */
  87. if (SER_WARNING_CODE != id)
  88. {
  89. /* This call can be used for debug purposes during application development.
  90. * @note CAUTION: Activating code below will write the stack to flash on an error.
  91. * This function should NOT be used in a final product.
  92. * It is intended STRICTLY for development/debugging purposes.
  93. * The flash write will happen EVEN if the radio is active, thus interrupting any communication.
  94. * Use with care. Un-comment the line below to use. */
  95. /* ble_debug_assert_handler(error_code, line_num, p_file_name); */
  96. #ifndef DEBUG
  97. /* Reset the chip. Should be used in the release version. */
  98. NVIC_SystemReset();
  99. #else /* Debug version. */
  100. /* To be able to see function parameters in a debugger. */
  101. uint32_t temp = 1;
  102. while (temp);
  103. #endif
  104. }
  105. CRITICAL_REGION_EXIT();
  106. }
  107. /*lint -restore */
  108. /**@brief Callback function for asserts in the SoftDevice.
  109. *
  110. * @details This function will be called if the ASSERT macro in the SoftDevice fails. Function
  111. * declaration can be found in the nrf_assert.h file.
  112. *
  113. * @param[in] line_num Line number of the failing ASSERT call.
  114. * @param[in] p_file_name File name of the failing ASSERT call.
  115. */
  116. void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name)
  117. {
  118. app_error_handler(SER_SD_ERROR_CODE, line_num, p_file_name);
  119. }
  120. /** @} */