]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/nordic_sdk/components/libraries/util/app_error.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / hal / TARGET_NORDIC / TARGET_MCU_NRF51822 / Lib / nordic_sdk / components / libraries / util / app_error.h
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  
13 /** @file
14  *
15  * @defgroup app_error Common application error handler
16  * @{
17  * @ingroup app_common
18  *
19  * @brief Common application error handler and macros for utilizing a common error handler.
20  */
21
22 #ifndef APP_ERROR_H__
23 #define APP_ERROR_H__
24
25 #include <stdint.h>
26 #include <stdbool.h>
27 #include "nrf_error.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 /**@brief Function for error handling, which is called when an error has occurred. 
34  *
35  * @param[in] error_code  Error code supplied to the handler.
36  * @param[in] line_num    Line number where the handler is called.
37  * @param[in] p_file_name Pointer to the file name. 
38  */
39 void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name);
40
41 #ifdef __cplusplus
42 }
43 #endif
44
45 /**@brief Macro for calling error handler function. 
46  *
47  * @param[in] ERR_CODE Error code supplied to the error handler.
48  */
49 #ifdef DEBUG
50 #define APP_ERROR_HANDLER(ERR_CODE)                         \
51     do                                                      \
52     {                                                       \
53         app_error_handler((ERR_CODE), __LINE__, (uint8_t*) __FILE__);  \
54     } while (0)
55 #else
56 #define APP_ERROR_HANDLER(ERR_CODE)                         \
57     do                                                      \
58     {                                                       \
59         app_error_handler((ERR_CODE), 0, 0);  \
60     } while (0)
61 #endif
62 /**@brief Macro for calling error handler function if supplied error code any other than NRF_SUCCESS. 
63  *
64  * @param[in] ERR_CODE Error code supplied to the error handler.
65  */    
66 #define APP_ERROR_CHECK(ERR_CODE)                           \
67     do                                                      \
68     {                                                       \
69         const uint32_t LOCAL_ERR_CODE = (ERR_CODE);         \
70         if (LOCAL_ERR_CODE != NRF_SUCCESS)                  \
71         {                                                   \
72             APP_ERROR_HANDLER(LOCAL_ERR_CODE);              \
73         }                                                   \
74     } while (0)    
75     
76 /**@brief Macro for calling error handler function if supplied boolean value is false. 
77  *
78  * @param[in] BOOLEAN_VALUE Boolean value to be evaluated.
79  */
80 #define APP_ERROR_CHECK_BOOL(BOOLEAN_VALUE)                   \
81     do                                                        \
82     {                                                         \
83         const uint32_t LOCAL_BOOLEAN_VALUE = (BOOLEAN_VALUE); \
84         if (!LOCAL_BOOLEAN_VALUE)                             \
85         {                                                     \
86             APP_ERROR_HANDLER(0);                             \
87         }                                                     \
88     } while (0)        
89
90 #endif // APP_ERROR_H__
91
92 /** @} */