Skip to content

Commit c994e50

Browse files
committed
Drop _SYNC logging macros
Make all logging asynchronous
1 parent 39497b6 commit c994e50

File tree

3 files changed

+20
-43
lines changed

3 files changed

+20
-43
lines changed

src/main/common/log.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void logInit(void)
8686
}
8787
}
8888
// Initialization done
89-
LOG_I_SYNC(SYSTEM, "%s/%s %s %s / %s (%s)",
89+
LOG_I(SYSTEM, "%s/%s %s %s / %s (%s)",
9090
FC_FIRMWARE_NAME,
9191
targetName,
9292
FC_VERSION_STRING,
@@ -101,15 +101,12 @@ static void logPutcp(void *p, char ch)
101101
*(*((char **) p))++ = ch;
102102
}
103103

104-
static void logPrint(bool synchronous, const char *buf, size_t size)
104+
static void logPrint(const char *buf, size_t size)
105105
{
106106
if (logPort) {
107107
// Send data via UART (if configured & connected - a safeguard against zombie VCP)
108108
if (serialIsConnected(logPort)) {
109109
serialPrint(logPort, buf);
110-
if (synchronous) {
111-
waitForSerialPortToFinishTransmitting(logPort);
112-
}
113110
}
114111
} else if (mspLogPort) {
115112
mspSerialPushPort(MSP_DEBUGMSG, (uint8_t*)buf, size, mspLogPort, MSP_V2_NATIVE);
@@ -132,7 +129,7 @@ static bool logIsEnabled(logTopic_e topic, unsigned level)
132129
return logHasOutput() && (level <= logConfig()->level || (logConfig()->topics & (1 << topic)));
133130
}
134131

135-
void _logf(logTopic_e topic, unsigned level, bool synchronous, const char *fmt, ...)
132+
void _logf(logTopic_e topic, unsigned level, const char *fmt, ...)
136133
{
137134
char buf[128];
138135
char *bufPtr;
@@ -156,10 +153,10 @@ void _logf(logTopic_e topic, unsigned level, bool synchronous, const char *fmt,
156153
charCount += 2;
157154
va_end(va);
158155

159-
logPrint(synchronous, buf, charCount);
156+
logPrint(buf, charCount);
160157
}
161158

162-
void _logBufferHex(logTopic_e topic, unsigned level, bool synchronous, const void *buffer, size_t size)
159+
void _logBufferHex(logTopic_e topic, unsigned level, const void *buffer, size_t size)
163160
{
164161
// Print lines of up to maxBytes bytes. We need 5 characters per byte
165162
// 0xAB[space|\n]
@@ -181,15 +178,15 @@ void _logBufferHex(logTopic_e topic, unsigned level, bool synchronous, const voi
181178
if (bufPos == sizeof(buf)-1) {
182179
buf[bufPos-1] = '\n';
183180
buf[bufPos] = '\0';
184-
logPrint(synchronous, buf, bufPos + 1);
181+
logPrint(buf, bufPos + 1);
185182
bufPos = LOG_PREFIX_FORMATTED_SIZE;
186183
}
187184
}
188185

189186
if (bufPos > LOG_PREFIX_FORMATTED_SIZE) {
190187
buf[bufPos-1] = '\n';
191188
buf[bufPos] = '\0';
192-
logPrint(synchronous, buf, bufPos + 1);
189+
logPrint(buf, bufPos + 1);
193190
}
194191
}
195192

src/main/common/log.h

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ typedef struct logConfig_s {
4242
PG_DECLARE(logConfig_t, logConfig);
4343

4444
void logInit(void);
45-
void _logf(logTopic_e topic, unsigned level, bool synchronous, const char *fmt, ...) __attribute__ ((format (printf, 4, 5)));
46-
void _logBufferHex(logTopic_e topic, unsigned level, bool synchronous, const void *buffer, size_t size);
45+
void _logf(logTopic_e topic, unsigned level, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
46+
void _logBufferHex(logTopic_e topic, unsigned level, const void *buffer, size_t size);
4747

4848
// LOG_* macro definitions
4949

@@ -52,61 +52,41 @@ void _logBufferHex(logTopic_e topic, unsigned level, bool synchronous, const voi
5252
#endif
5353

5454
#if defined(USE_LOG) && LOG_LEVEL_MAXIMUM >= LOG_LEVEL_ERROR
55-
#define LOG_E(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_ERROR, false, fmt, ##__VA_ARGS__)
56-
#define LOG_E_SYNC(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_ERROR, true, fmt, ##__VA_ARGS__)
57-
#define LOG_BUFFER_E(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_ERROR, false, buf, size)
58-
#define LOG_BUFFER_E_SYNC(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_ERROR, true, buf, size)
55+
#define LOG_E(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)
56+
#define LOG_BUFFER_E(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_ERROR, buf, size)
5957
#else
6058
#define LOG_E(...)
61-
#define LOG_E_SYNC(...)
6259
#define LOG_BUFFER_E(...)
63-
#define LOG_BUFFER_E_SYNC(...)
6460
#endif
6561

6662
#if defined(USE_LOG) && LOG_LEVEL_MAXIMUM >= LOG_LEVEL_WARNING
67-
#define LOG_W(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_WARNING, false, fmt, ##__VA_ARGS__)
68-
#define LOG_W_SYNC(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_WARNING, true, fmt, ##__VA_ARGS__)
69-
#define LOG_BUF_W(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_WARNING, false, buf, size)
70-
#define LOG_BUF_W_SYNC(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_WARNING, true, buf, size)
63+
#define LOG_W(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_WARNING, fmt, ##__VA_ARGS__)
64+
#define LOG_BUF_W(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_WARNING, buf, size)
7165
#else
7266
#define LOG_W(...)
73-
#define LOG_W_SYNC(...)
7467
#define LOG_BUF_W(...)
75-
#define LOG_BUF_W_SYNC(...)
7668
#endif
7769

7870
#if defined(USE_LOG) && LOG_LEVEL_MAXIMUM >= LOG_LEVEL_INFO
79-
#define LOG_I(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_INFO, false, fmt, ##__VA_ARGS__)
80-
#define LOG_I_SYNC(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_INFO, true, fmt, ##__VA_ARGS__)
81-
#define LOG_BUF_I(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_INFO, false, buf, size)
82-
#define LOG_BUF_I_SYNC(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_INFO, true, buf, size)
71+
#define LOG_I(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_INFO, fmt, ##__VA_ARGS__)
72+
#define LOG_BUF_I(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_INFO, buf, size)
8373
#else
8474
#define LOG_I(...)
85-
#define LOG_I_SYNC(...)
8675
#define LOG_BUF_I(...)
87-
#define LOG_BUF_I_SYNC(...)
8876
#endif
8977

9078
#if defined(USE_LOG) && LOG_LEVEL_MAXIMUM >= LOG_LEVEL_VERBOSE
91-
#define LOG_V(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_VERBOSE, false, fmt, ##__VA_ARGS__)
92-
#define LOG_V_SYNC(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_VERBOSE, true, fmt, ##__VA_ARGS__)
93-
#define LOG_BUF_V(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_VERBOSE, false, buf, size)
94-
#define LOG_BUF_V_SYNC(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_VERBOSE, true, buf, size)
79+
#define LOG_V(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_VERBOSE, fmt, ##__VA_ARGS__)
80+
#define LOG_BUF_V(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_VERBOSE, buf, size)
9581
#else
9682
#define LOG_V(...)
97-
#define LOG_V_SYNC(...)
9883
#define LOG_BUF_V(...)
99-
#define LOG_BUF_V_SYNC(...)
10084
#endif
10185

10286
#if defined(USE_LOG) && LOG_LEVEL_MAXIMUM >= LOG_LEVEL_DEBUG
103-
#define LOG_D(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_DEBUG, false, fmt, ##__VA_ARGS__)
104-
#define LOG_D_SYNC(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_DEBUG, true, fmt, ##__VA_ARGS__)
105-
#define LOG_BUF_D(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_DEBUG, false, buf, size)
106-
#define LOG_BUF_D_SYNC(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_DEBUG, true, buf, size)
87+
#define LOG_D(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
88+
#define LOG_BUF_D(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_DEBUG, buf, size)
10789
#else
10890
#define LOG_D(...)
109-
#define LOG_D_SYNC(...)
11091
#define LOG_BUF_D(...)
111-
#define LOG_BUF_D_SYNC(...)
11292
#endif

src/main/sensors/gyro.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ STATIC_UNIT_TESTED void performGyroCalibration(gyroDev_t *dev, zeroCalibrationVe
382382
dev->gyroZero[1] = v.v[1];
383383
dev->gyroZero[2] = v.v[2];
384384

385-
LOG_D_SYNC(GYRO, "Gyro calibration complete (%d, %d, %d)", dev->gyroZero[0], dev->gyroZero[1], dev->gyroZero[2]);
385+
LOG_D(GYRO, "Gyro calibration complete (%d, %d, %d)", dev->gyroZero[0], dev->gyroZero[1], dev->gyroZero[2]);
386386
schedulerResetTaskStatistics(TASK_SELF); // so calibration cycles do not pollute tasks statistics
387387
}
388388
else {

0 commit comments

Comments
 (0)