| BlueNRG-1 HAL drivers APIs

- Main Page
- Classes
- Files

- File List
- File Members

crash_handler.h
Go to the documentation of this file.
1
22 #ifndef __CRASH_HANDLER_H_
23 #define __CRASH_HANDLER_H_
24
25 #include <stdint.h>
26 #include <string.h>
27
31 #define NMB_OF_EXCEP_RAM_WORD 10
32
36 #define CRASH_INFO_BASE_ADDRESS 0x20000008
37 #define CRASH_RAM_SIZE 40
38
42 #define ASSERT_SIGNATURE 0xBCEC0000
43
46 #define NMI_SIGNATURE 0xBCEC0001
47
50 #define HARD_FAULT_SIGNATURE 0xBCEC0002
51
54 #define WATCHDOG_SIGNATURE 0xBCEC0003
55
56
60 #define GET_CRASH_INFO(PTR) { PTR = *(crash_info_t *)CRASH_INFO_BASE_ADDRESS; \
61 memset((void *)CRASH_INFO_BASE_ADDRESS, 0, CRASH_RAM_SIZE);}
62
66 typedef PACKED(struct) crash_infoS {
67 uint32_t signature;
68 uint32_t SP;
69 uint32_t R0;
70 uint32_t R1;
71 uint32_t R2;
72 uint32_t R3;
73 uint32_t R12;
74 uint32_t LR;
75 uint32_t PC;
76 uint32_t xPSR;
77 } crash_info_t;
78
94 //__ASM volatile ("MOV %0, SP" : "=r" (reg_content) );
95 /* reg_content = __get_MSP() ; to be compliant with Keil */
96 #define CRASH_HANDLER(signature) { \
97 volatile uint32_t * crash_info = (volatile uint32_t *)CRASH_INFO_BASE_ADDRESS; \
98 register uint32_t reg_content; \
99 /* Init to zero the crash_info RAM locations */ \
100 for (reg_content=0; reg_content<NMB_OF_EXCEP_RAM_WORD; reg_content++) { \
101 *crash_info = 0; \
102 crash_info++; \
103 } \
104 crash_info = (volatile uint32_t *)CRASH_INFO_BASE_ADDRESS; \
105 /* Store Crash Signature */ \
106 *crash_info = signature; \
107 crash_info++; \
108 /* Store SP register */ \
109 reg_content = __get_MSP() ; \
110 *crash_info = reg_content; \
111 crash_info++; \
112 if ((reg_content >= 0x20000000) && (reg_content <= 0x20005FFF)) { \
113 /* Store exception R0 */ \
114 *crash_info = *(volatile uint32_t *)(reg_content+0x00); \
115 crash_info++; \
116 /* Store exception R1 */ \
117 *crash_info = *(volatile uint32_t *)(reg_content+0x04); \
118 crash_info++; \
119 /* Store exception R2 */ \
120 *crash_info = *(volatile uint32_t *)(reg_content+0x08); \
121 crash_info++; \
122 /* Store exception R3 */ \
123 *crash_info = *(volatile uint32_t *)(reg_content+0x0C); \
124 crash_info++; \
125 /* Store exception R12 */ \
126 *crash_info = *(volatile uint32_t *)(reg_content+0x10); \
127 crash_info++; \
128 /* Store exception LR */ \
129 *crash_info = *(volatile uint32_t *)(reg_content+0x14); \
130 crash_info++; \
131 /* Store exception PC */ \
132 *crash_info = *(volatile uint32_t *)(reg_content+0x18); \
133 crash_info++; \
134 /* Store exception xPSR */ \
135 *crash_info = *(volatile uint32_t *)(reg_content+0x1C); \
136 } \
137 } \
138
139
154 #define ASSERT_HANDLER(expression) { \
155 volatile uint32_t * crash_info = (volatile uint32_t *)CRASH_INFO_BASE_ADDRESS; \
156 register uint32_t reg_content; \
157 if (!(expression)) { \
158 /* Init to zero the crash_info RAM locations */ \
159 for (reg_content=0; reg_content<NMB_OF_EXCEP_RAM_WORD; reg_content++) { \
160 *crash_info = 0; \
161 crash_info++; \
162 } \
163 crash_info = (volatile uint32_t *)CRASH_INFO_BASE_ADDRESS; \
164 /* Store Crash Signature */ \
165 *crash_info = ASSERT_SIGNATURE; \
166 crash_info+=2; \
167 /* Store R0 register */ \
168 __ASM volatile ("MOV %0, R0" : "=r" (reg_content) ); \
169 *crash_info = reg_content; \
170 crash_info--; \
171 /* Store SP register */ \
172 __ASM volatile ("MOV %0, SP" : "=r" (reg_content) ); \
173 *crash_info = reg_content; \
174 crash_info+=2; \
175 /* Store R1 register */ \
176 __ASM volatile ("MOV %0, R1" : "=r" (reg_content) ); \
177 *crash_info = reg_content; \
178 crash_info++; \
179 /* Store R2 register */ \
180 __ASM volatile ("MOV %0, R2" : "=r" (reg_content) ); \
181 *crash_info = reg_content; \
182 crash_info++; \
183 /* Store R3 register */ \
184 __ASM volatile ("MOV %0, R3" : "=r" (reg_content) ); \
185 *crash_info = reg_content; \
186 crash_info++; \
187 /* Store R12 register */ \
188 __ASM volatile ("MOV %0, R12" : "=r" (reg_content) ); \
189 *crash_info = reg_content; \
190 crash_info++; \
191 /* Store LR register */ \
192 __ASM volatile ("MOV %0, LR" : "=r" (reg_content) ); \
193 *crash_info = reg_content; \
194 crash_info++; \
195 /* Store PC register */ \
196 __ASM volatile ("MOV %0, PC" : "=r" (reg_content) ); \
197 *crash_info = reg_content; \
198 crash_info++; \
199 /* Store xPSR register */ \
200 __ASM volatile ("MRS %0, PSR" : "=r" (reg_content) ); \
201 *crash_info = reg_content; \
202 crash_info++; \
203 } \
204 } \
205
206 #endif // __CRASH_HANDLER_H_
crash_info_t
crash_info_t
Definition: crash_handler.h:77
PACKED
typedef PACKED(struct) crash_infoS
Typedef for the overall crash information (stack pointer, programm counter, registers, ...)
Definition: crash_handler.h:66