-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdebug.c
118 lines (101 loc) · 3.18 KB
/
debug.c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* @file debug.c
*
* @date 2019-10-27
* @author twatorowski
*
* @brief Debugging related stuff
*/
#include <stdint.h>
#include "compiler.h"
#include "err.h"
#include "version.h"
#include "dev/systime.h"
#include "sys/sem.h"
#define DEBUG
#include "debug.h"
#include "debug_dump.h"
/** storage space for storing mcu state during critical failures */
debug_scb_info_t SECTION(".no_init") debug_scb_info;
debug_exc_info_t SECTION(".no_init") debug_exc_info;
debug_stack_frame_t SECTION(".no_init") debug_stack_frame;
debug_assert_info_t SECTION(".no_init") debug_assert_info;
/* print the introduction message */
static void Debug_PrintIntro(void)
{
/* initial string */
dprintf("\n", 0);
dprintf("-------------------------------------------------------\n", 0);
dprintf("Radio 2.4.0, hw = %s, sw = %s\n", VERSION_HW_STR,
VERSION_HW_STR);
dprintf("-------------------------------------------------------\n", 0);
}
/* display the stack frame */
static void Debug_PrintStackFrame(debug_stack_frame_t *sf)
{
/* not a valid entry? */
if ((sf->valid ^= DEBUG_VALID_ENTRY) != 0)
return;
/* intro message */
dprintf("STACK FRAME:\n", 0);
/* show the values of the registers r0-r3 */
dprintf("r0 = %#x, r1 = %#x, r2 = %#x, r3 = %#x\n",
sf->r0, sf->r1, sf->r2, sf->r3);
/* show the values of the rest of the registers */
dprintf("r12 = %#x, lr = %#x, pc = %#x, xpsr = %#x\n",
sf->r12, sf->lr, sf->pc, sf->xpsr);
}
/* print the exception information */
static void Debug_PrintExcInfo(debug_exc_info_t *ei)
{
/* not a valid entry? */
if ((ei->valid ^= DEBUG_VALID_ENTRY) != 0)
return;
/* intro message */
dprintf("EXCEPTION INFO:\n", 0);
/* show the values of the interrupt program status register */
dprintf("ipsr = %#x\n", ei->ipsr);
}
/* print the system control block information */
static void Debug_PrintSCBInfo(debug_scb_info_t *si)
{
/* not a valid entry? */
if ((si->valid ^= DEBUG_VALID_ENTRY) != 0)
return;
/* intro message */
dprintf("SYSTEM CONTROL BLOCK:\n", 0);
/* show the values of scb registers */
dprintf("cfsr = %#x, hfsr = %#x\n", si->cfsr, si->hfsr);
/* show pending exceptions */
dprintf("mmar = %#x, bfar = %#x, shcsr = %#x\n",
si->mmar, si->bfar, si->shcsr);
}
/* print the system control block information */
static void Debug_PrintAssertInfo(debug_assert_info_t *ai)
{
/* not a valid entry? */
if (ai->valid != DEBUG_VALID_ENTRY)
return;
/* intro message */
dprintf("LAST ASSERT INFO:\n", 0);
/* show last assert message */
dprintf("message = %.128s\n", ai->message);
dprintf("additional info = %#x\n", ai->additional_info);
/* invalidate */
ai->valid = 0;
}
/* initialize debugging */
int Debug_Init(void)
{
/* print intro message */
Debug_PrintIntro();
/* print all the information */
Debug_PrintStackFrame(&debug_stack_frame);
Debug_PrintExcInfo(&debug_exc_info);
Debug_PrintSCBInfo(&debug_scb_info);
Debug_PrintAssertInfo(&debug_assert_info);
/* give it some time to flow out of the debug interfaces */
SysTime_Delay(100);
/* report status */
return EOK;
}