Smart Remote 3 nRF52 v1.2
app_error.h
1 /*$$$LICENCE_NORDIC_STANDARD<2013>$$$*/
11 #ifndef APP_ERROR_H__
12 #define APP_ERROR_H__
13 
14 #include <stdint.h>
15 #include <stdio.h>
16 #include <stdbool.h>
17 #include "nrf.h"
18 #include "sdk_errors.h"
19 #include "nordic_common.h"
20 #include "app_error_weak.h"
21 #ifdef ANT_STACK_SUPPORT_REQD
22 #include "ant_error.h"
23 #endif // ANT_STACK_SUPPORT_REQD
24 
25 #include "sr3_config.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #define NRF_FAULT_ID_SDK_RANGE_START 0x00004000
35 #define NRF_FAULT_ID_SDK_ERROR NRF_FAULT_ID_SDK_RANGE_START + 1
36 #define NRF_FAULT_ID_SDK_ASSERT NRF_FAULT_ID_SDK_RANGE_START + 2
41 typedef struct
42 {
43  uint16_t line_num;
44  uint8_t const * p_file_name;
45  uint32_t err_code;
46 } error_info_t;
47 
50 typedef struct
51 {
52  uint16_t line_num;
53  uint8_t const * p_file_name;
55 
62 void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name);
63 
68 void app_error_handler_bare(ret_code_t error_code);
69 
78 void app_error_save_and_stop(uint32_t id, uint32_t pc, uint32_t info);
79 
91 static __INLINE void app_error_log(uint32_t id, uint32_t pc, uint32_t info)
92 {
93  switch (id)
94  {
96  //NRF_LOG_INFO(NRF_LOG_COLOR_RED "\r\n*** ASSERTION FAILED ***\r\n");
97  if (((assert_info_t *)(info))->p_file_name)
98  {
99  // NRF_LOG_INFO(NRF_LOG_COLOR_WHITE "Line Number: %u\r\n", (unsigned int) ((assert_info_t *)(info))->line_num);
100  //NRF_LOG_INFO("File Name: %s\r\n", ((assert_info_t *)(info))->p_file_name);
101  }
102  //NRF_LOG_INFO(NRF_LOG_COLOR_DEFAULT "\r\n");
103  break;
104 
106  //NRF_LOG_INFO(NRF_LOG_COLOR_RED "\r\n*** APPLICATION ERROR *** \r\n" NRF_LOG_COLOR_WHITE);
107  if (((error_info_t *)(info))->p_file_name)
108  {
109  //NRF_LOG_INFO("Line Number: %u\r\n", (unsigned int) ((error_info_t *)(info))->line_num);
110  //NRF_LOG_INFO("File Name: %s\r\n", ((error_info_t *)(info))->p_file_name);
111  }
112  //NRF_LOG_INFO("Error Code: 0x%X\r\n" NRF_LOG_COLOR_DEFAULT "\r\n", (unsigned int) ((error_info_t *)(info))->err_code);
113  break;
114  }
115 }
116 
125 //lint -save -e438
126 static __INLINE void app_error_print(uint32_t id, uint32_t pc, uint32_t info)
127 {
128  unsigned int tmp = id;
129  printf("app_error_print():\r\n");
130  printf("Fault identifier: 0x%X\r\n", tmp);
131  printf("Program counter: 0x%X\r\n", tmp = pc);
132  printf("Fault information: 0x%X\r\n", tmp = info);
133 
134  switch (id)
135  {
137  printf("Line Number: %u\r\n", tmp = ((assert_info_t *)(info))->line_num);
138  printf("File Name: %s\r\n", ((assert_info_t *)(info))->p_file_name);
139  break;
140 
142  printf("Line Number: %u\r\n", tmp = ((error_info_t *)(info))->line_num);
143  printf("File Name: %s\r\n", ((error_info_t *)(info))->p_file_name);
144  printf("Error Code: 0x%X\r\n", tmp = ((error_info_t *)(info))->err_code);
145  break;
146  }
147 }
148 //lint -restore
149 
150 
155 #if CONFIG_DEBUG_ENABLED
156 #define APP_ERROR_HANDLER(ERR_CODE) \
157  do \
158  { \
159  app_error_handler((ERR_CODE), __LINE__, (uint8_t*) __FILE__); \
160  } while (0)
161 #else
162 #define APP_ERROR_HANDLER(ERR_CODE) \
163  do \
164  { \
165  app_error_handler_bare((ERR_CODE)); \
166  } while (0)
167 #endif
168 
172 #define APP_ERROR_CHECK(ERR_CODE) \
173  do \
174  { \
175  const uint32_t LOCAL_ERR_CODE = (ERR_CODE); \
176  if (LOCAL_ERR_CODE != NRF_SUCCESS) \
177  { \
178  APP_ERROR_HANDLER(LOCAL_ERR_CODE); \
179  } \
180  } while (0)
181 
186 #define APP_ERROR_CHECK_BOOL(BOOLEAN_VALUE) \
187  do \
188  { \
189  const uint32_t LOCAL_BOOLEAN_VALUE = (BOOLEAN_VALUE); \
190  if (!LOCAL_BOOLEAN_VALUE) \
191  { \
192  APP_ERROR_HANDLER(0); \
193  } \
194  } while (0)
195 
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 
201 #endif // APP_ERROR_H__
202 

Documentation feedback | Developer Zone | Subscribe | Updated