BLE_Nano nRF51 Central heart rate
nRF51_SDK_11/components/libraries/util/app_error.h@0:2b9b5764efb5, 2016-05-26 (annotated)
- Committer:
- FranKP2138
- Date:
- Thu May 26 10:12:27 2016 +0000
- Revision:
- 0:2b9b5764efb5
RedBearLab BLE_Nano Central role for heart rate
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
FranKP2138 | 0:2b9b5764efb5 | 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. |
FranKP2138 | 0:2b9b5764efb5 | 2 | * |
FranKP2138 | 0:2b9b5764efb5 | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
FranKP2138 | 0:2b9b5764efb5 | 4 | * Terms and conditions of usage are described in detail in NORDIC |
FranKP2138 | 0:2b9b5764efb5 | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
FranKP2138 | 0:2b9b5764efb5 | 6 | * |
FranKP2138 | 0:2b9b5764efb5 | 7 | * Licensees are granted free, non-transferable use of the information. NO |
FranKP2138 | 0:2b9b5764efb5 | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
FranKP2138 | 0:2b9b5764efb5 | 9 | * the file. |
FranKP2138 | 0:2b9b5764efb5 | 10 | * |
FranKP2138 | 0:2b9b5764efb5 | 11 | */ |
FranKP2138 | 0:2b9b5764efb5 | 12 | |
FranKP2138 | 0:2b9b5764efb5 | 13 | /** @file |
FranKP2138 | 0:2b9b5764efb5 | 14 | * |
FranKP2138 | 0:2b9b5764efb5 | 15 | * @defgroup app_error Common application error handler |
FranKP2138 | 0:2b9b5764efb5 | 16 | * @{ |
FranKP2138 | 0:2b9b5764efb5 | 17 | * @ingroup app_common |
FranKP2138 | 0:2b9b5764efb5 | 18 | * |
FranKP2138 | 0:2b9b5764efb5 | 19 | * @brief Common application error handler and macros for utilizing a common error handler. |
FranKP2138 | 0:2b9b5764efb5 | 20 | */ |
FranKP2138 | 0:2b9b5764efb5 | 21 | |
FranKP2138 | 0:2b9b5764efb5 | 22 | #ifndef APP_ERROR_H__ |
FranKP2138 | 0:2b9b5764efb5 | 23 | #define APP_ERROR_H__ |
FranKP2138 | 0:2b9b5764efb5 | 24 | |
FranKP2138 | 0:2b9b5764efb5 | 25 | #include <stdint.h> |
FranKP2138 | 0:2b9b5764efb5 | 26 | #include <stdio.h> |
FranKP2138 | 0:2b9b5764efb5 | 27 | #include <stdbool.h> |
FranKP2138 | 0:2b9b5764efb5 | 28 | #include "nrf.h" |
FranKP2138 | 0:2b9b5764efb5 | 29 | #include "sdk_errors.h" |
FranKP2138 | 0:2b9b5764efb5 | 30 | #include "nordic_common.h" |
FranKP2138 | 0:2b9b5764efb5 | 31 | #include "nrf_log.h" |
FranKP2138 | 0:2b9b5764efb5 | 32 | #include "app_error_weak.h" |
FranKP2138 | 0:2b9b5764efb5 | 33 | |
FranKP2138 | 0:2b9b5764efb5 | 34 | #define NRF_FAULT_ID_SDK_RANGE_START 0x00004000 /**< The start of the range of error IDs defined in the SDK. */ |
FranKP2138 | 0:2b9b5764efb5 | 35 | |
FranKP2138 | 0:2b9b5764efb5 | 36 | /**@defgroup APP_ERROR_FAULT_IDS Fault ID types |
FranKP2138 | 0:2b9b5764efb5 | 37 | * @{ */ |
FranKP2138 | 0:2b9b5764efb5 | 38 | #define NRF_FAULT_ID_SDK_ERROR NRF_FAULT_ID_SDK_RANGE_START + 1 /**< An error stemming from a call to @ref APP_ERROR_CHECK or @ref APP_ERROR_CHECK_BOOL. The info parameter is a pointer to an @ref error_info_t variable. */ |
FranKP2138 | 0:2b9b5764efb5 | 39 | #define NRF_FAULT_ID_SDK_ASSERT NRF_FAULT_ID_SDK_RANGE_START + 2 /**< An error stemming from a call to ASSERT (nrf_assert.h). The info parameter is a pointer to an @ref assert_info_t variable. */ |
FranKP2138 | 0:2b9b5764efb5 | 40 | /**@} */ |
FranKP2138 | 0:2b9b5764efb5 | 41 | |
FranKP2138 | 0:2b9b5764efb5 | 42 | /**@brief Structure containing info about an error of the type @ref NRF_FAULT_ID_SDK_ERROR. |
FranKP2138 | 0:2b9b5764efb5 | 43 | */ |
FranKP2138 | 0:2b9b5764efb5 | 44 | typedef struct |
FranKP2138 | 0:2b9b5764efb5 | 45 | { |
FranKP2138 | 0:2b9b5764efb5 | 46 | uint16_t line_num; /**< The line number where the error occurred. */ |
FranKP2138 | 0:2b9b5764efb5 | 47 | uint8_t const * p_file_name; /**< The file in which the error occurred. */ |
FranKP2138 | 0:2b9b5764efb5 | 48 | uint32_t err_code; /**< The error code representing the error that occurred. */ |
FranKP2138 | 0:2b9b5764efb5 | 49 | } error_info_t; |
FranKP2138 | 0:2b9b5764efb5 | 50 | |
FranKP2138 | 0:2b9b5764efb5 | 51 | /**@brief Structure containing info about an error of the type @ref NRF_FAULT_ID_SDK_ASSERT. |
FranKP2138 | 0:2b9b5764efb5 | 52 | */ |
FranKP2138 | 0:2b9b5764efb5 | 53 | typedef struct |
FranKP2138 | 0:2b9b5764efb5 | 54 | { |
FranKP2138 | 0:2b9b5764efb5 | 55 | uint16_t line_num; /**< The line number where the error occurred. */ |
FranKP2138 | 0:2b9b5764efb5 | 56 | uint8_t const * p_file_name; /**< The file in which the error occurred. */ |
FranKP2138 | 0:2b9b5764efb5 | 57 | } assert_info_t; |
FranKP2138 | 0:2b9b5764efb5 | 58 | |
FranKP2138 | 0:2b9b5764efb5 | 59 | /**@brief Function for error handling, which is called when an error has occurred. |
FranKP2138 | 0:2b9b5764efb5 | 60 | * |
FranKP2138 | 0:2b9b5764efb5 | 61 | * @param[in] error_code Error code supplied to the handler. |
FranKP2138 | 0:2b9b5764efb5 | 62 | * @param[in] line_num Line number where the handler is called. |
FranKP2138 | 0:2b9b5764efb5 | 63 | * @param[in] p_file_name Pointer to the file name. |
FranKP2138 | 0:2b9b5764efb5 | 64 | */ |
FranKP2138 | 0:2b9b5764efb5 | 65 | void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name); |
FranKP2138 | 0:2b9b5764efb5 | 66 | |
FranKP2138 | 0:2b9b5764efb5 | 67 | /**@brief Function for error handling, which is called when an error has occurred. |
FranKP2138 | 0:2b9b5764efb5 | 68 | * |
FranKP2138 | 0:2b9b5764efb5 | 69 | * @param[in] error_code Error code supplied to the handler. |
FranKP2138 | 0:2b9b5764efb5 | 70 | */ |
FranKP2138 | 0:2b9b5764efb5 | 71 | void app_error_handler_bare(ret_code_t error_code); |
FranKP2138 | 0:2b9b5764efb5 | 72 | |
FranKP2138 | 0:2b9b5764efb5 | 73 | /**@brief Function for saving the parameters and entering an eternal loop, for debug purposes. |
FranKP2138 | 0:2b9b5764efb5 | 74 | * |
FranKP2138 | 0:2b9b5764efb5 | 75 | * @param[in] id Fault identifier. See @ref NRF_FAULT_IDS. |
FranKP2138 | 0:2b9b5764efb5 | 76 | * @param[in] pc The program counter of the instruction that triggered the fault, or 0 if |
FranKP2138 | 0:2b9b5764efb5 | 77 | * unavailable. |
FranKP2138 | 0:2b9b5764efb5 | 78 | * @param[in] info Optional additional information regarding the fault. Refer to each fault |
FranKP2138 | 0:2b9b5764efb5 | 79 | * identifier for details. |
FranKP2138 | 0:2b9b5764efb5 | 80 | */ |
FranKP2138 | 0:2b9b5764efb5 | 81 | void app_error_save_and_stop(uint32_t id, uint32_t pc, uint32_t info); |
FranKP2138 | 0:2b9b5764efb5 | 82 | |
FranKP2138 | 0:2b9b5764efb5 | 83 | /**@brief Function for printing all error info (using nrf_log). |
FranKP2138 | 0:2b9b5764efb5 | 84 | * |
FranKP2138 | 0:2b9b5764efb5 | 85 | * @details Nrf_log library must be initialized using NRF_LOG_INIT macro before calling |
FranKP2138 | 0:2b9b5764efb5 | 86 | * this function. |
FranKP2138 | 0:2b9b5764efb5 | 87 | * |
FranKP2138 | 0:2b9b5764efb5 | 88 | * @param[in] id Fault identifier. See @ref NRF_FAULT_IDS. |
FranKP2138 | 0:2b9b5764efb5 | 89 | * @param[in] pc The program counter of the instruction that triggered the fault, or 0 if |
FranKP2138 | 0:2b9b5764efb5 | 90 | * unavailable. |
FranKP2138 | 0:2b9b5764efb5 | 91 | * @param[in] info Optional additional information regarding the fault. Refer to each fault |
FranKP2138 | 0:2b9b5764efb5 | 92 | * identifier for details. |
FranKP2138 | 0:2b9b5764efb5 | 93 | */ |
FranKP2138 | 0:2b9b5764efb5 | 94 | static __INLINE void app_error_log(uint32_t id, uint32_t pc, uint32_t info) |
FranKP2138 | 0:2b9b5764efb5 | 95 | { |
FranKP2138 | 0:2b9b5764efb5 | 96 | switch (id) |
FranKP2138 | 0:2b9b5764efb5 | 97 | { |
FranKP2138 | 0:2b9b5764efb5 | 98 | case NRF_FAULT_ID_SDK_ASSERT: |
FranKP2138 | 0:2b9b5764efb5 | 99 | NRF_LOG(NRF_LOG_COLOR_RED "\n*** ASSERTION FAILED ***\n"); |
FranKP2138 | 0:2b9b5764efb5 | 100 | if (((assert_info_t *)(info))->p_file_name) |
FranKP2138 | 0:2b9b5764efb5 | 101 | { |
FranKP2138 | 0:2b9b5764efb5 | 102 | NRF_LOG_PRINTF(NRF_LOG_COLOR_WHITE "Line Number: %u\n", (unsigned int) ((assert_info_t *)(info))->line_num); |
FranKP2138 | 0:2b9b5764efb5 | 103 | NRF_LOG_PRINTF("File Name: %s\n", ((assert_info_t *)(info))->p_file_name); |
FranKP2138 | 0:2b9b5764efb5 | 104 | } |
FranKP2138 | 0:2b9b5764efb5 | 105 | NRF_LOG_PRINTF(NRF_LOG_COLOR_DEFAULT "\n"); |
FranKP2138 | 0:2b9b5764efb5 | 106 | break; |
FranKP2138 | 0:2b9b5764efb5 | 107 | |
FranKP2138 | 0:2b9b5764efb5 | 108 | case NRF_FAULT_ID_SDK_ERROR: |
FranKP2138 | 0:2b9b5764efb5 | 109 | NRF_LOG(NRF_LOG_COLOR_RED "\n*** APPLICATION ERROR *** \n" NRF_LOG_COLOR_WHITE); |
FranKP2138 | 0:2b9b5764efb5 | 110 | if (((error_info_t *)(info))->p_file_name) |
FranKP2138 | 0:2b9b5764efb5 | 111 | { |
FranKP2138 | 0:2b9b5764efb5 | 112 | NRF_LOG_PRINTF("Line Number: %u\n", (unsigned int) ((error_info_t *)(info))->line_num); |
FranKP2138 | 0:2b9b5764efb5 | 113 | NRF_LOG_PRINTF("File Name: %s\n", ((error_info_t *)(info))->p_file_name); |
FranKP2138 | 0:2b9b5764efb5 | 114 | } |
FranKP2138 | 0:2b9b5764efb5 | 115 | NRF_LOG_PRINTF("Error Code: 0x%X\n" NRF_LOG_COLOR_DEFAULT "\n", (unsigned int) ((error_info_t *)(info))->err_code); |
FranKP2138 | 0:2b9b5764efb5 | 116 | break; |
FranKP2138 | 0:2b9b5764efb5 | 117 | } |
FranKP2138 | 0:2b9b5764efb5 | 118 | } |
FranKP2138 | 0:2b9b5764efb5 | 119 | |
FranKP2138 | 0:2b9b5764efb5 | 120 | /**@brief Function for printing all error info (using printf). |
FranKP2138 | 0:2b9b5764efb5 | 121 | * |
FranKP2138 | 0:2b9b5764efb5 | 122 | * @param[in] id Fault identifier. See @ref NRF_FAULT_IDS. |
FranKP2138 | 0:2b9b5764efb5 | 123 | * @param[in] pc The program counter of the instruction that triggered the fault, or 0 if |
FranKP2138 | 0:2b9b5764efb5 | 124 | * unavailable. |
FranKP2138 | 0:2b9b5764efb5 | 125 | * @param[in] info Optional additional information regarding the fault. Refer to each fault |
FranKP2138 | 0:2b9b5764efb5 | 126 | * identifier for details. |
FranKP2138 | 0:2b9b5764efb5 | 127 | */ |
FranKP2138 | 0:2b9b5764efb5 | 128 | //lint -save -e438 |
FranKP2138 | 0:2b9b5764efb5 | 129 | static __INLINE void app_error_print(uint32_t id, uint32_t pc, uint32_t info) |
FranKP2138 | 0:2b9b5764efb5 | 130 | { |
FranKP2138 | 0:2b9b5764efb5 | 131 | unsigned int tmp = id; |
FranKP2138 | 0:2b9b5764efb5 | 132 | printf("app_error_print():\r\n"); |
FranKP2138 | 0:2b9b5764efb5 | 133 | printf("Fault identifier: 0x%X\r\n", tmp); |
FranKP2138 | 0:2b9b5764efb5 | 134 | printf("Program counter: 0x%X\r\n", tmp = pc); |
FranKP2138 | 0:2b9b5764efb5 | 135 | printf("Fault information: 0x%X\r\n", tmp = info); |
FranKP2138 | 0:2b9b5764efb5 | 136 | |
FranKP2138 | 0:2b9b5764efb5 | 137 | switch (id) |
FranKP2138 | 0:2b9b5764efb5 | 138 | { |
FranKP2138 | 0:2b9b5764efb5 | 139 | case NRF_FAULT_ID_SDK_ASSERT: |
FranKP2138 | 0:2b9b5764efb5 | 140 | printf("Line Number: %u\r\n", tmp = ((assert_info_t *)(info))->line_num); |
FranKP2138 | 0:2b9b5764efb5 | 141 | printf("File Name: %s\r\n", ((assert_info_t *)(info))->p_file_name); |
FranKP2138 | 0:2b9b5764efb5 | 142 | break; |
FranKP2138 | 0:2b9b5764efb5 | 143 | |
FranKP2138 | 0:2b9b5764efb5 | 144 | case NRF_FAULT_ID_SDK_ERROR: |
FranKP2138 | 0:2b9b5764efb5 | 145 | printf("Line Number: %u\r\n", tmp = ((error_info_t *)(info))->line_num); |
FranKP2138 | 0:2b9b5764efb5 | 146 | printf("File Name: %s\r\n", ((error_info_t *)(info))->p_file_name); |
FranKP2138 | 0:2b9b5764efb5 | 147 | printf("Error Code: 0x%X\r\n", tmp = ((error_info_t *)(info))->err_code); |
FranKP2138 | 0:2b9b5764efb5 | 148 | break; |
FranKP2138 | 0:2b9b5764efb5 | 149 | } |
FranKP2138 | 0:2b9b5764efb5 | 150 | } |
FranKP2138 | 0:2b9b5764efb5 | 151 | //lint -restore |
FranKP2138 | 0:2b9b5764efb5 | 152 | |
FranKP2138 | 0:2b9b5764efb5 | 153 | |
FranKP2138 | 0:2b9b5764efb5 | 154 | /**@brief Macro for calling error handler function. |
FranKP2138 | 0:2b9b5764efb5 | 155 | * |
FranKP2138 | 0:2b9b5764efb5 | 156 | * @param[in] ERR_CODE Error code supplied to the error handler. |
FranKP2138 | 0:2b9b5764efb5 | 157 | */ |
FranKP2138 | 0:2b9b5764efb5 | 158 | #ifdef DEBUG |
FranKP2138 | 0:2b9b5764efb5 | 159 | #define APP_ERROR_HANDLER(ERR_CODE) \ |
FranKP2138 | 0:2b9b5764efb5 | 160 | do \ |
FranKP2138 | 0:2b9b5764efb5 | 161 | { \ |
FranKP2138 | 0:2b9b5764efb5 | 162 | app_error_handler((ERR_CODE), __LINE__, (uint8_t*) __FILE__); \ |
FranKP2138 | 0:2b9b5764efb5 | 163 | } while (0) |
FranKP2138 | 0:2b9b5764efb5 | 164 | #else |
FranKP2138 | 0:2b9b5764efb5 | 165 | #define APP_ERROR_HANDLER(ERR_CODE) \ |
FranKP2138 | 0:2b9b5764efb5 | 166 | do \ |
FranKP2138 | 0:2b9b5764efb5 | 167 | { \ |
FranKP2138 | 0:2b9b5764efb5 | 168 | app_error_handler_bare((ERR_CODE)); \ |
FranKP2138 | 0:2b9b5764efb5 | 169 | } while (0) |
FranKP2138 | 0:2b9b5764efb5 | 170 | #endif |
FranKP2138 | 0:2b9b5764efb5 | 171 | /**@brief Macro for calling error handler function if supplied error code any other than NRF_SUCCESS. |
FranKP2138 | 0:2b9b5764efb5 | 172 | * |
FranKP2138 | 0:2b9b5764efb5 | 173 | * @param[in] ERR_CODE Error code supplied to the error handler. |
FranKP2138 | 0:2b9b5764efb5 | 174 | */ |
FranKP2138 | 0:2b9b5764efb5 | 175 | #define APP_ERROR_CHECK(ERR_CODE) \ |
FranKP2138 | 0:2b9b5764efb5 | 176 | do \ |
FranKP2138 | 0:2b9b5764efb5 | 177 | { \ |
FranKP2138 | 0:2b9b5764efb5 | 178 | const uint32_t LOCAL_ERR_CODE = (ERR_CODE); \ |
FranKP2138 | 0:2b9b5764efb5 | 179 | if (LOCAL_ERR_CODE != NRF_SUCCESS) \ |
FranKP2138 | 0:2b9b5764efb5 | 180 | { \ |
FranKP2138 | 0:2b9b5764efb5 | 181 | APP_ERROR_HANDLER(LOCAL_ERR_CODE); \ |
FranKP2138 | 0:2b9b5764efb5 | 182 | } \ |
FranKP2138 | 0:2b9b5764efb5 | 183 | } while (0) |
FranKP2138 | 0:2b9b5764efb5 | 184 | |
FranKP2138 | 0:2b9b5764efb5 | 185 | /**@brief Macro for calling error handler function if supplied boolean value is false. |
FranKP2138 | 0:2b9b5764efb5 | 186 | * |
FranKP2138 | 0:2b9b5764efb5 | 187 | * @param[in] BOOLEAN_VALUE Boolean value to be evaluated. |
FranKP2138 | 0:2b9b5764efb5 | 188 | */ |
FranKP2138 | 0:2b9b5764efb5 | 189 | #define APP_ERROR_CHECK_BOOL(BOOLEAN_VALUE) \ |
FranKP2138 | 0:2b9b5764efb5 | 190 | do \ |
FranKP2138 | 0:2b9b5764efb5 | 191 | { \ |
FranKP2138 | 0:2b9b5764efb5 | 192 | const uint32_t LOCAL_BOOLEAN_VALUE = (BOOLEAN_VALUE); \ |
FranKP2138 | 0:2b9b5764efb5 | 193 | if (!LOCAL_BOOLEAN_VALUE) \ |
FranKP2138 | 0:2b9b5764efb5 | 194 | { \ |
FranKP2138 | 0:2b9b5764efb5 | 195 | APP_ERROR_HANDLER(0); \ |
FranKP2138 | 0:2b9b5764efb5 | 196 | } \ |
FranKP2138 | 0:2b9b5764efb5 | 197 | } while (0) |
FranKP2138 | 0:2b9b5764efb5 | 198 | |
FranKP2138 | 0:2b9b5764efb5 | 199 | #endif // APP_ERROR_H__ |
FranKP2138 | 0:2b9b5764efb5 | 200 | |
FranKP2138 | 0:2b9b5764efb5 | 201 | /** @} */ |
FranKP2138 | 0:2b9b5764efb5 | 202 |