Skip to content

Commit 1f715de

Browse files
authored
Merge pull request #4385 from iNavFlight/agh_log
Replace DEBUG_TRACE with LOG
2 parents 56474ce + 44201f0 commit 1f715de

File tree

23 files changed

+347
-223
lines changed

23 files changed

+347
-223
lines changed

make/source.mk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ COMMON_SRC = \
77
build/debug.c \
88
build/version.c \
99
common/bitarray.c \
10+
common/calibration.c \
11+
common/colorconversion.c \
1012
common/crc.c \
1113
common/encoding.c \
1214
common/filter.c \
15+
common/gps_conversion.c \
16+
common/log.c \
1317
common/logic_condition.c \
1418
common/maths.c \
15-
common/calibration.c \
1619
common/memory.c \
1720
common/olc.c \
1821
common/printf.c \
@@ -146,8 +149,6 @@ COMMON_SRC = \
146149
cms/cms_menu_vtx_smartaudio.c \
147150
cms/cms_menu_vtx_tramp.c \
148151
cms/cms_menu_vtx_ffpv.c \
149-
common/colorconversion.c \
150-
common/gps_conversion.c \
151152
drivers/display_ug2864hsweg01.c \
152153
drivers/rangefinder/rangefinder_hcsr04.c \
153154
drivers/rangefinder/rangefinder_hcsr04_i2c.c \

src/main/build/debug.c

Lines changed: 0 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -15,176 +15,11 @@
1515
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
#include <stdbool.h>
19-
#include <stdint.h>
20-
#include <stdarg.h>
21-
#include <ctype.h>
22-
2318
#include "build/debug.h"
24-
#include "build/version.h"
25-
26-
#include "drivers/serial.h"
27-
#include "drivers/time.h"
28-
29-
#include "common/printf.h"
30-
#include "common/utils.h"
31-
32-
#include "config/feature.h"
33-
34-
#include "io/serial.h"
35-
36-
#include "fc/config.h"
37-
38-
#include "msp/msp.h"
39-
#include "msp/msp_serial.h"
40-
#include "msp/msp_protocol.h"
4119

4220
#ifdef DEBUG_SECTION_TIMES
4321
timeUs_t sectionTimes[2][4];
4422
#endif
4523

4624
int32_t debug[DEBUG32_VALUE_COUNT];
4725
uint8_t debugMode;
48-
49-
#if defined(USE_DEBUG_TRACE)
50-
51-
#define DEBUG_TRACE_PREFIX "[%6d.%03d] "
52-
#define DEBUG_TRACE_PREFIX_FORMATTED_SIZE 13
53-
54-
static serialPort_t * tracePort = NULL;
55-
static mspPort_t * mspTracePort = NULL;
56-
57-
void debugTraceInit(void)
58-
{
59-
if (!feature(FEATURE_DEBUG_TRACE)) {
60-
return;
61-
}
62-
63-
const serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_DEBUG_TRACE);
64-
if (!portConfig) {
65-
return;
66-
}
67-
68-
bool tracePortIsSharedWithMSP = false;
69-
70-
if (determinePortSharing(portConfig, FUNCTION_DEBUG_TRACE) == PORTSHARING_SHARED) {
71-
// We support sharing a DEBUG_TRACE port only with MSP
72-
if (portConfig->functionMask != (FUNCTION_DEBUG_TRACE | FUNCTION_MSP)) {
73-
return;
74-
}
75-
tracePortIsSharedWithMSP = true;
76-
}
77-
78-
// If the port is shared with MSP, reuse the port
79-
if (tracePortIsSharedWithMSP) {
80-
const serialPort_t *traceAndMspPort = findSharedSerialPort(FUNCTION_DEBUG_TRACE, FUNCTION_MSP);
81-
if (!traceAndMspPort) {
82-
return;
83-
}
84-
85-
mspTracePort = mspSerialPortFind(traceAndMspPort);
86-
if (!mspTracePort) {
87-
return;
88-
}
89-
90-
} else {
91-
tracePort = openSerialPort(portConfig->identifier, FUNCTION_DEBUG_TRACE, NULL, NULL, baudRates[BAUD_921600], MODE_TX, SERIAL_NOT_INVERTED);
92-
if (!tracePort) {
93-
return;
94-
}
95-
}
96-
// Initialization done
97-
DEBUG_TRACE_SYNC("%s/%s %s %s / %s (%s)",
98-
FC_FIRMWARE_NAME,
99-
targetName,
100-
FC_VERSION_STRING,
101-
buildDate,
102-
buildTime,
103-
shortGitRevision
104-
);
105-
}
106-
107-
static void debugTracePutcp(void *p, char ch)
108-
{
109-
*(*((char **) p))++ = ch;
110-
}
111-
112-
static void debugTracePrint(bool synchronous, const char *buf, size_t size)
113-
{
114-
if (tracePort) {
115-
// Send data via trace UART (if configured & connected - a safeguard against zombie VCP)
116-
if (serialIsConnected(tracePort)) {
117-
serialPrint(tracePort, buf);
118-
if (synchronous) {
119-
waitForSerialPortToFinishTransmitting(tracePort);
120-
}
121-
}
122-
} else if (mspTracePort) {
123-
mspSerialPushPort(MSP_DEBUGMSG, (uint8_t*)buf, size, mspTracePort, MSP_V2_NATIVE);
124-
}
125-
}
126-
127-
static size_t debugTraceFormatPrefix(char *buf, const timeMs_t timeMs)
128-
{
129-
// Write timestamp
130-
return tfp_sprintf(buf, DEBUG_TRACE_PREFIX, timeMs / 1000, timeMs % 1000);
131-
}
132-
133-
void debugTracePrintf(bool synchronous, const char *format, ...)
134-
{
135-
char buf[128];
136-
char *bufPtr;
137-
int charCount;
138-
139-
STATIC_ASSERT(MSP_PORT_OUTBUF_SIZE >= sizeof(buf), MSP_PORT_OUTBUF_SIZE_not_big_enough_for_debug_trace);
140-
141-
if (!feature(FEATURE_DEBUG_TRACE))
142-
return;
143-
144-
charCount = debugTraceFormatPrefix(buf, millis());
145-
bufPtr = &buf[charCount];
146-
147-
// Write message
148-
va_list va;
149-
va_start(va, format);
150-
charCount += tfp_format(&bufPtr, debugTracePutcp, format, va);
151-
debugTracePutcp(&bufPtr, '\n');
152-
debugTracePutcp(&bufPtr, 0);
153-
charCount += 2;
154-
va_end(va);
155-
156-
debugTracePrint(synchronous, buf, charCount);
157-
}
158-
159-
void debugTracePrintBufferHex(bool synchronous, const void *buffer, size_t size)
160-
{
161-
// Print lines of up to maxBytes bytes. We need 5 characters per byte
162-
// 0xAB[space|\n]
163-
const size_t charsPerByte = 5;
164-
const size_t maxBytes = 8;
165-
char buf[DEBUG_TRACE_PREFIX_FORMATTED_SIZE + charsPerByte * maxBytes + 1]; // +1 for the null terminator
166-
size_t bufPos = DEBUG_TRACE_PREFIX_FORMATTED_SIZE;
167-
const uint8_t *inputPtr = buffer;
168-
169-
debugTraceFormatPrefix(buf, millis());
170-
171-
for (size_t ii = 0; ii < size; ii++) {
172-
tfp_sprintf(buf + bufPos, "0x%02x ", inputPtr[ii]);
173-
bufPos += charsPerByte;
174-
if (bufPos == sizeof(buf)-1) {
175-
buf[bufPos-1] = '\n';
176-
buf[bufPos] = '\0';
177-
debugTracePrint(synchronous, buf, bufPos + 1);
178-
bufPos = DEBUG_TRACE_PREFIX_FORMATTED_SIZE;
179-
}
180-
}
181-
182-
if (bufPos > DEBUG_TRACE_PREFIX_FORMATTED_SIZE) {
183-
buf[bufPos-1] = '\n';
184-
buf[bufPos] = '\0';
185-
debugTracePrint(synchronous, buf, bufPos + 1);
186-
}
187-
}
188-
189-
190-
#endif

src/main/build/debug.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,3 @@ typedef enum {
7171
DEBUG_GENERIC,
7272
DEBUG_COUNT
7373
} debugType_e;
74-
75-
#if defined(USE_DEBUG_TRACE)
76-
void debugTraceInit(void);
77-
void debugTracePrintf(bool synchronous, const char *format, ...);
78-
void debugTracePrintBufferHex(bool synchronous, const void *buffer, size_t size);
79-
#define DEBUG_TRACE(fmt, ...) debugTracePrintf(false, fmt, ##__VA_ARGS__)
80-
#define DEBUG_TRACE_SYNC(fmt, ...) debugTracePrintf(true, fmt, ##__VA_ARGS__)
81-
#define DEBUG_TRACE_BUFFER_HEX(buf, size) debugTracePrintBufferHex(false, buf, size)
82-
#define DEBUG_TRACE_BUFFER_HEX_SYNC(buf, size) debugTracePrintBufferHex(true, buf, size)
83-
#else
84-
#define DEBUG_TRACE(fmt, ...)
85-
#define DEBUG_TRACE_SYNC(fmt, ...)
86-
#define DEBUG_TRACE_BUFFER_HEX(buf, size)
87-
#define DEBUG_TRACE_BUFFER_HEX_SYNC(buf, size)
88-
#endif

0 commit comments

Comments
 (0)