-
Notifications
You must be signed in to change notification settings - Fork 2
/
lnDebug.cpp
84 lines (74 loc) · 1.52 KB
/
lnDebug.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
75
76
77
78
79
80
81
82
83
84
/*
* (C) 2021 MEAN00 fixounet@free.fr
* See license file
*/
#include "lnArduino.h"
#include "lnSerial.h"
#include "stdarg.h"
#define LOGGER_USE_DMA 1
extern lnSerialTxOnly *serial0;
lnSerialTxOnly *serial0 = NULL;
volatile uint32_t lnScratchRegister;
static lnMutex *loggerMutex;
extern "C" void Logger_crash(const char *st)
{
serial0->init();
serial0->setSpeed(115200);
serial0->rawWrite(strlen(st), (const uint8_t *)st);
}
extern "C" int Logger_C(const char *fmt, ...)
{
static char buffer[128];
va_list va;
va_start(va, fmt);
vsnprintf(buffer, 127, fmt, va);
buffer[127] = 0;
va_end(va);
Logger_chars(strlen(buffer), buffer);
return 0;
}
/**
*/
extern "C" void Logger_chars(int n, const char *data)
{
if (!n)
return; // 0 sized dma does not work...
serial0->transmit(n, (uint8_t *)data);
}
/**
*
* @param fmt
*/
void Logger(const char *fmt...)
{
static char buffer[128];
if (fmt[0] == 0)
return;
va_list va;
va_start(va, fmt);
vsnprintf(buffer, 127, fmt, va);
buffer[127] = 0;
va_end(va);
loggerMutex->lock();
Logger_chars(strlen(buffer), buffer);
loggerMutex->unlock();
}
/**
*
*/
void LoggerInit()
{
int debugUart = 0;
#ifdef LN_DEBUG_UART
debugUart = LN_DEBUG_UART;
#endif
bool dma = false;
#ifdef LOGGER_USE_DMA
dma = true;
#endif
loggerMutex = new lnMutex;
bool buffered = true;
serial0 = createLnSerialTxOnly(debugUart, dma, buffered);
serial0->init();
serial0->setSpeed(115200);
}