-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfault_reporter.h
executable file
·70 lines (51 loc) · 3.47 KB
/
fault_reporter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
Teensy Fault Reporter
Copyright (C) 2019 TACTIF CIE <www.tactif.com> / Bordeaux - France
Author Christophe Gimenez <christophe.gimenez@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>
*/
#ifndef TEENSY_FAULT_REPORTER_H
#define TEENSY_FAULT_REPORTER_H
#define FAULT_REPORTER_ENABLE
#ifdef FAULT_REPORTER_ENABLE
#define FAULT_REPORTER_PATTERN 0x4655434B42554753
#define FAULT_REPORTER_BUFSIZE 4096
#define FAULT_REPORTER_USE_BUILTIN_LED
#define SCB_SHCSR_USGFAULTENA (uint32_t)1 << 18
#define SCB_SHCSR_BUSFAULTENA (uint32_t)1 << 17
#define SCB_SHCSR_MEMFAULTENA (uint32_t)1 << 16
#define ACTLR (*(volatile uint32_t *)0xE000E008)
__attribute__((section(".noinit"))) extern uint64_t fault_reporter_pattern;
__attribute__((section(".noinit"))) extern char fault_reporter_s[FAULT_REPORTER_BUFSIZE];
void fault_reporter_init();
void fault_reporter_report();
void fault_handler(int kind, uint32_t stack[]);
enum { r0, r1, r2, r3, r12, lr, pc, psr };
#define FAULT_HANDLER(L, FN) \
void __attribute__((naked)) FN() { \
uint32_t *sp = 0; \
asm volatile("TST LR, #0x4\n\t" \
"ITE EQ\n\t" \
"MRSEQ %0, MSP\n\t" \
"MRSNE %0, PSP\n\t" \
: "=r"(sp) \
: \
: "cc"); \
fault_handler(L, sp); \
}
#define FAULT_REPORTER_INIT fault_reporter_init();
#define FAULT_REPORTER_REPORT fault_reporter_report();
#else
#define FAULT_REPORTER_INIT
#define FAULT_REPORTER_REPORT
#endif
#endif