-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.c
70 lines (58 loc) · 1.39 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
/**
* @file debug.c
*
* @author Tomasz Watorowski ([email protected])
* @date 2021-04-05
*
* @brief Printf Debugging
*/
#include <stdint.h>
#include <stddef.h>
#include "err.h"
#include "config.h"
#include "debug.h"
/* debug interfaces */
#include "dev/usart.h"
#include "dev/usart_dev.h"
#include "dev/usb_vcp.h"
/* debug line buffer */
char debug_buf[DEBUG_MAX_LINE_LEN];
/* current debug buffer contents length */
size_t debug_buf_len;
/* global level of debug */
int debug_global_lvl = DEBUG_DEFAULT_LEVEL;
/* get debug level name */
const char * Debug_GetLevelName(int lvl)
{
/* switch on the enum and return the string name */
switch (lvl) {
case DLVL_DEBUG: return "DEBUG";
case DLVL_INFO: return "INFO";
case DLVL_WARN: return "WARN";
case DLVL_ERROR: return "ERROR";
}
/* unknown level name */
return "UNKNOWN";
}
/* set global debug level */
err_t Debug_SetGlobalLevel(int lvl)
{
/* switch on the enum and return the string name */
switch (lvl) {
case DLVL_DEBUG:
case DLVL_INFO:
case DLVL_WARN:
case DLVL_ERROR:
debug_global_lvl = lvl; return EOK;
}
/* unknown level */
return EARGVAL;
}
/* send message over debug interfaces */
err_t Debug_Send(const void *ptr, size_t size)
{
/* send over uart */
USART_Send(&usart1, debug_buf, debug_buf_len, 0);
/* report status */
return EOK;
}