This repository has been archived by the owner on Jan 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdebug.c
103 lines (83 loc) · 1.76 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
#include "debug.h"
#include "port.h"
#include "basic.h"
static bool enable_output = true;
static void (*put_serial_func)(UB) = put_serial;
extern B get_serial(void);
extern void put_serial(UB);
void tv_set_serial_func(void (*func)(UB)){
put_serial_func = func;
}
void tv_print_hex(UD val)
{
tv_puts("0x");
char str[20];
int i=0;
do {
int x = val&0xf;
if(x>=0xa) str[i++] = x-0xa+'a';
else str[i++] = x+'0';
val >>= 4;
} while(val>0);
int j;
for(j=0;j<i/2;j++){
char tmp = str[j];
str[j] = str[i-j-1];
str[i-j-1] = tmp;
}
str[i] = '\0';
tv_puts(str);
}
void tv_puts(UB* str){
while(*str!='\0'){
if(*str=='\n') put_serial_func('\r');
put_serial_func(*str);
str++;
}
}
void tv_error_message(UB* str){
bool tmp = enable_output;
enable_output = true;
tv_puts(str);
enable_output = tmp;
// tv_getc();
}
UB tv_getc(){
bool tmp = enable_output;
enable_output =true;
tv_puts("key input\n");
enable_output = tmp;
return get_serial();
}
void tv_message(UW val){
tv_puts("debug: ");
tv_print_hex(val);
tv_puts("\n");
}
void tv_print_lr(void){
tv_puts("lr value: ");
UW r0;
Asm("mov %0, lr":"=r"(r0));
tv_print_hex(r0);
tv_puts("\n");
}
void tv_disable_print(void){
enable_output = false;
}
void tv_enable_print(void){
enable_output = true;
}
void tv_print_string_hex(UB *str, UD val){
tv_puts(str);
tv_print_hex(val);
tv_puts("\n");
}
void __attribute__((weak))tv_abort(UB *str){
enable_output = true;
tv_puts(str);
tv_getc();
}
void __attribute__((weak))tv_display_boot_process(UW num){
// tv_print_string_hex("# now booting...:",num);
return;
}