1 /*
2  * Percepio DFM v2.0.0
3  * Copyright 2023 Percepio AB
4  * www.percepio.com
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 /**
10  * @file
11  *
12  * @brief DFM Crash Catcher integration defines
13  */
14 
15 #ifndef DFM_CRASHCATCHER_H
16 #define DFM_CRASHCATCHER_H
17 
18 #include <dfmCrashCatcherConfig.h>
19 
20 #define CRASH_DUMP_NAME "crash.dmp"
21 
22 /**
23  * @brief Should call a function that reboots device
24  * Example: #define CRASH_STRATEGY_RESET() HAL_NVIC_SystemReset()
25  */
26 #define CRASH_STRATEGY_RESET() HAL_NVIC_SystemReset()
27 
28 /**
29  * @brief Endless loop
30  * Example: #define CRASH_STRATEGY_LOOP() while(1)
31  */
32 #define CRASH_STRATEGY_LOOP() while(1)
33 
34 /**
35  * @brief Strategy to use after crash has been handled
36  * Values: CRASH_STRATEGY_RESET() or CRASH_STRATEGY_LOOP()
37  */
38 #define CRASH_FINALIZE() DFM_DEBUG_PRINT("DFM: Restarting...\n\n\n"); CRASH_STRATEGY_RESET()
39 
40 /* CRASH_STACK_CAPTURE_SIZE
41  * The number of bytes from the current stack to capture, relative to the stack pointer.
42  * The capture is from SP to SP + CRASH_PSP_CAPTURE_SIZE, so only the most recent stack
43  * frames are included. Since relative to the current stack pointer, you don't need to
44  * specify a stack memory range manually.
45  * */
46 #include <dfmConfig.h> // For accessing the Demo settings
47 #define CRASH_STACK_CAPTURE_SIZE DFM_CFG_STACKDUMP_SIZE
48 
49 /* Additional memory ranges to include in the crash dump (e.g. heap memory) */
50 #define CRASH_MEM_REGION1_START	0xFFFFFFFF /* 0xFFFFFFFF = not used */
51 #define CRASH_MEM_REGION1_SIZE	0
52 
53 #define CRASH_MEM_REGION2_START	0xFFFFFFFF /* 0xFFFFFFFF = not used */
54 #define CRASH_MEM_REGION2_SIZE	0
55 
56 #define CRASH_MEM_REGION3_START	0xFFFFFFFF /* 0xFFFFFFFF = not used */
57 #define CRASH_MEM_REGION3_SIZE	0
58 
59 /* CRASH_DUMP_MAX_SIZE - The size of the temporary RAM buffer for crash dumps.
60  * Any attempt to write outside this buffer will be caught in CrashCatcher_DumpMemory() and give an error.
61  * Enable DFM_CFG_USE_DEBUG_LOGGING to see the actual usage.
62  * */
63 #define CRASH_DUMP_BUFFER_SIZE (300 + (CRASH_STACK_CAPTURE_SIZE) + (CRASH_MEM_REGION1_SIZE) + (CRASH_MEM_REGION2_SIZE) + (CRASH_MEM_REGION3_SIZE))
64 
65 typedef struct{
66 	int alertType;
67 	char* message;
68 	char* file;
69 	int line;
70 } dfmTrapInfo_t;
71 
72 extern dfmTrapInfo_t dfmTrapInfo;
73 
74 // This is specific for Arm Cortex-M devices, but so is CrashCatcher.
75 #define DFM_TRIGGER_NMI() SCB->ICSR |= SCB_ICSR_NMIPENDSET_Msk;
76 
77 #define DFM_TRAP(type, msg) { dfmTrapInfo.alertType = type; dfmTrapInfo.message = msg; dfmTrapInfo.file = __FILE__; dfmTrapInfo.line = __LINE__; DFM_TRIGGER_NMI(); }
78 
79 #endif
80