-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcatch_errors.cpp
74 lines (63 loc) · 1.48 KB
/
catch_errors.cpp
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
71
72
73
74
/*
* See header for notes.
*/
#include "board_defs.h"
#include <stdbool.h>
// Must include catch_errors.h here to apply extern C to these functions
// and disable C++ name mangling for compatibility with C callers.
#include "catch_errors.h"
// All errors / warnings / infos timeouts feed to here.
// Allows using a single breakpoint.
void catchAll()
{
__asm volatile("nop");
}
// A more reasonable default breakpoint location.
// Excludes breaking on common benignTimeout().
void catchDefault()
{
catchAll();
}
// Set a breakpoint here to cycle through all blocking tasks
void allTimeouts()
{
__asm volatile("nop");
}
// Checks if value is true.
// Crashes if value is false.
void assert(bool value)
{
if (!value) {
critical();
}
}
// For trapping critical errors
void critical()
{
catchDefault();
// Maybe this should blink instead to avoid confusion with other red LEDs on board.
// Note that multiple tasks can encounter this critical loop, so blink should not
// have 50-50 duty cycle, since that can conceal LED.
LL_GPIO_SetOutputPin(RedLedPort, RedLedPin);
while (1)
;
}
// For trapping nonCritical errors / warnings
void nonCritical()
{
catchDefault();
}
// This is a timeout to indicate non-optimal behavior,
// such as waiting to write to a full buffer.
void timeout()
{
catchDefault();
allTimeouts();
}
// This is a timeout to indicate expected blocking,
// such as waiting to read from an empty buffer.
void benignTimeout()
{
allTimeouts();
catchAll();
}