-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdebug.c
69 lines (53 loc) · 1.82 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
#include "ch.h"
#include "hal.h"
#include "debug.h"
//#include "portab.h"
mutex_t mtx; // Used internal to synchronize multiple chprintf in debug.h
char error_list[ERROR_LIST_SIZE][ERROR_LIST_LENGTH];
uint8_t error_counter;
//static const SerialConfig debug_config = {
// 115200,
// 0,
// 0,
// 0
//};
//#ifdef USB_TRACE_LEVEL
//uint8_t usb_trace_level = USB_TRACE_LEVEL; // Set in makefile UDEFS
//#else
uint8_t usb_trace_level = 4; // Level: Errors + Warnings + Info + Debug
//uint8_t usb_trace_level = 2; // Level: Errors + Warnings
//#endif
void debug_init(void) {
chMtxObjectInit(&mtx);
sdStart(&SD_console, NULL);
//palSetLineMode(LINE_IO_TXD, PAL_MODE_ALTERNATE(7));
//palSetLineMode(LINE_IO_RXD, PAL_MODE_ALTERNATE(7));
}
void debug_print(char *type, char* filename, uint32_t line, char* format, ...)
{
chMtxLock(&mtx);
uint8_t str[256];
va_list args;
va_start(args, format);
chsnprintf((char*)str, sizeof(str), format, args);
va_end(args);
// if(isConsoleOutputAvailable()) {
// if(TRACE_TIME) {
// chprintf((BaseSequentialStream*)&SD_console, "[%8d.%03d]", chVTGetSystemTime()/CH_CFG_ST_FREQUENCY, (chVTGetSystemTime()*1000/CH_CFG_ST_FREQUENCY)%1000);
// }
// chprintf((BaseSequentialStream*)&SD_console, "[%s]", type);
// if(TRACE_FILE) {
// chprintf((BaseSequentialStream*)&SD_console, "[%12s %04d]", filename, line);
// }
// chprintf((BaseSequentialStream*)&SD_console, " %s\r\n", str);
// }
if(TRACE_TIME) {
chprintf((BaseSequentialStream*)&SD_console, "[%8d.%03d]", chVTGetSystemTime()/CH_CFG_ST_FREQUENCY, (chVTGetSystemTime()*1000/CH_CFG_ST_FREQUENCY)%1000);
}
chprintf((BaseSequentialStream*)&SD_console, "[%s]", type);
if(TRACE_FILE) {
chprintf((BaseSequentialStream*)&SD_console, "[%12s %04d]", filename, line);
}
chprintf((BaseSequentialStream*)&SD_console, " %s\r\n", str);
chMtxUnlock(&mtx);
}