• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description:  PANIC module interface
15  * Author:
16  * Create:
17  */
18 
19 #ifndef LIB_PANIC_PANIC_H
20 #define LIB_PANIC_PANIC_H
21 
22 #include "std_def.h"
23 #include "stdint.h"
24 
25 /**
26  * @defgroup connectivity_libs_panic PANIC
27  * @ingroup  connectivity_libs
28  * @{
29  */
30 typedef enum panic_id {
31     // No panic
32     PANIC_NONE = 0,
33     PANIC_ARM_CORE = 1,
34     PANIC_HAL = 2,
35     PANIC_DSP = 3,
36     PANIC_IRMALLOC_FAIL = 4,
37     PANIC_UART = 5,
38     PANIC_IFLASH = 6,
39     PANIC_ADC = 7,
40     PANIC_WATCHDOG = 8,
41     PANIC_LOG = 9,
42     PANIC_DMA = 10,
43     PANIC_ASSERT = 11,
44     PANIC_REBOOT = 12,
45     PANIC_UPDATEPKG = 13,
46     PANIC_I2C = 14,
47     PANIC_SPI = 15,
48     PANIC_RPC = 22,
49     PANIC_MEM_MONITOR = 23,
50 
51     // Someone calling abort() / exit()
52     PANIC_EXIT = 24,
53 
54     // RTOS related panics
55     PANIC_TASK_CREATE_FAILED = 25,
56 
57     PANIC_MEMCPY_BUFFER_OVERLAP = 26,
58     PANIC_XIP = 27,
59     PANIC_BTC_MALLOC_FAIL = 28,
60     PANIC_LOW_POWER = 29,
61     PANIC_SYSTEM_STATUS = 30,
62     PANIC_BTC_INT_ERR = 31,
63     PANIC_LPC_WKUP_FAIL = 32,
64     PANIC_CLOCKS_GLB_ERR = 33,
65     PANIC_PMU_CMU = 34,
66     PANIC_PMU_LDO = 35,
67     PANIC_CHIP_WDT_FRST = 36,
68     PANIC_NON_OS = 37,
69     PANIC_LPC_VETO = 38,
70     PANIC_TIMER = 39,
71     PANIC_LPC = 40,
72     PANIC_RTC = 41,
73     PANIC_MEMORY = 42,
74     PANIC_CPU_HIFI = 43,
75     PANIC_EXCEPTION_TEST = 44,
76     PANIC_KV = 45,
77     PANIC_EFLASH = 46,
78     PANIC_LIB = 47,
79     PANIC_CODELOADER = 48,
80     PANIC_CRITICLA = 49,
81     PANIC_IPC = 50,
82     PANIC_INT = 51,
83     PANIC_OS = 52,
84     PANIC_LPC_WAKEUP_TIME = 53,
85     PANIC_BTC_BT_FRM_DISMATCH1 = 54,
86     PANIC_BTC_BT_FRM_DISMATCH2 = 55,
87     PANIC_BTC_BLE_FRM_DISMATCH = 56,
88     PANIC_BTC_WAKEUP_TO = 57,
89     PANIC_BTH_MEMORY = 58,
90     PANIC_MPU_CONFIG_ERR = 59,
91     PANIC_GPU = 60,
92     PANIC_SDIO_DEVICE = 61,
93     PANIC_IR = 62,
94     PANIC_BTC_CMD_NUM_ZERO = 63,
95     PANIC_CAP = 64,
96     PANIC_EPMU = 65,
97     PANIC_BTS_WRITE_PROPERTY_FAIL = 66,
98     PANIC_MMC_HOST = 67,
99     PANIC_BTC_OSCEN_TO = 68,
100     PANIC_RGB888 = 70,
101     PANIC_AP_COMMU = 71,
102     PANIC_CPU_CLOCKS = 72,
103     PANIC_CLOCKS_SWITCH = 73,
104     PANIC_PMU = 74,
105     PANIC_LOG_DUMP = 75,
106     PANIC_COUL = 76,
107     PANIC_DSP0_POWER = 77,
108     PANIC_DSP1_POWER = 78,
109     PANIC_BT_DEBUG = 79,
110     PANIC_PIN_NULL = 80,
111     PANIC_UNITTEST = 98,
112     PANIC_TESTSUIT = 99,
113     PANIC_DSS_MIPI_ERR = 100,
114     PANIC_GNSS_DFR_ERR = 101,
115     PANIC_BT_SEC_BOOT_ERR = 102,
116     PANIC_ROM_WEAK_FUNCTION = 103,
117     PANIC_GLP = 104,
118     PANIC_UICC = 105,
119     PANIC_CRYPTO = 106,
120 } panic_id_t;
121 
122 typedef struct {
123     panic_id_t origin;
124     uint32_t code;
125     uint32_t timestamp_ms;
126     uint32_t caller;
127 } panic_desc_t;
128 
129 /**
130  * @brief  Panic callback
131  * @param  none
132  */
133 typedef void (*lib_panic_dump_callback)(void);
134 
135 /**
136  * @brief  hook function panic handler
137  * @param  source the origin of the panic
138  * @param  code panic origin specific information
139  * @param  caller who call panic
140  */
141 typedef void(*panic_deal_handler)(panic_id_t source, uint32_t code, uint32_t caller);
142 
143 /**
144  * @brief  Register panic deal callback
145  * @param  callback: if system panic, the callback is called to handle the exception.
146  */
147 void panic_register_deal_callback(panic_deal_handler callback);
148 
149 /**
150  * @brief  Ungister panic deal callback
151  */
152 void panic_unregister_deal_callback(void);
153 
154 /**
155  * @brief  Register panic callback
156  * @param  callback: if system panic, the callback is called to handle the exception.
157  */
158 void register_panic_dump_callback(lib_panic_dump_callback callback);
159 
160 /**
161  * @brief  Panic callback
162  * @param  str display which type leads to panic
163  */
164 typedef void (*lib_panic_dump_callback_with_param)(char *str);
165 
166 /**
167  * @brief  Register panic callback
168  * @param  callback: if system panic, the callback is called to handle the exception.
169  */
170 void register_panic_dump_callback_with_param(lib_panic_dump_callback_with_param callback);
171 
172 /** Initialise the panic module */
173 void panic_init(void);
174 
175 /** De-initialise the panic module */
176 void panic_deinit(void);
177 
178 /**
179  * @brief  Get var already_panicking
180  * @return already_panicking
181  */
182 bool get_already_panicking(void);
183 
184 /**
185  * @brief  Enter into infinite loop so that a debugger can break in and see the stack trace
186  * @param  source the origin of the panic
187  * @param  code panic origin specific information
188  * @note   This can be called before the panic_init is called to support panics during start-up and it will cope
189  */
190 void panic(panic_id_t source, uint32_t code);
191 
192 
193 /** Wait forever */
194 void panic_wait_forever(void);
195 
196 /**
197  * @brief  Enter into infinite loop so that a debugger can break in and see the stack trace
198  * @param  origin the origin of the panic
199  * @param  code panic origin specific information
200  * @param  caller who call panic.
201  */
202 void panic_deal(panic_id_t origin, uint32_t code, uint32_t caller);
203 
204 /**
205  * @}
206  */
207 #endif
208