Skip to content

Commit a377017

Browse files
committed
Add possibility to control variable trace from make
1 parent f519b94 commit a377017

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

build_keyboard.mk

+7-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,13 @@ ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes)
180180
VAPTH += $(SERIAL_PATH)
181181
endif
182182

183-
SRC += $(QUANTUM_DIR)/variable_trace.c
183+
ifneq ($(strip $(VARIABLE_TRACE)),)
184+
SRC += $(QUANTUM_DIR)/variable_trace.c
185+
OPT_DEFS += -DNUM_TRACED_VARIABLES=$(strip $(VARIABLE_TRACE))
186+
ifneq ($(strip $(MAX_VARIABLE_TRACE_SIZE)),)
187+
OPT_DEFS += -DMAX_VARIABLE_TRACE_SIZE=$(strip $(MAX_VARIABLE_TRACE_SIZE))
188+
endif
189+
endif
184190

185191
# Optimize size but this may cause error "relocation truncated to fit"
186192
#EXTRALDFLAGS = -Wl,--relax

quantum/variable_trace.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,31 @@
1212

1313

1414
#define NUM_TRACED_VARIABLES 1
15-
#define MAX_TRACE_SIZE 4
15+
#ifndef MAX_VARIABLE_TRACE_SIZE
16+
#define MAX_VARIABLE_TRACE_SIZE 4
17+
#endif
1618

1719
typedef struct {
1820
const char* name;
1921
void* addr;
2022
unsigned size;
2123
const char* func;
2224
int line;
23-
uint8_t last_value[MAX_TRACE_SIZE];
25+
uint8_t last_value[MAX_VARIABLE_TRACE_SIZE];
2426

2527
} traced_variable_t;
2628

2729
static traced_variable_t traced_variables[NUM_TRACED_VARIABLES];
2830

2931
void add_traced_variable(const char* name, void* addr, unsigned size, const char* func, int line) {
3032
verify_traced_variables(func, line);
31-
if (size > MAX_TRACE_SIZE) {
33+
if (size > MAX_VARIABLE_TRACE_SIZE) {
3234
#if defined(__AVR__)
3335
xprintf("Traced variable \"%S\" exceeds the maximum size %d\n", name, size);
3436
#else
3537
xprintf("Traced variable \"%s\" exceeds the maximum size %d\n", name, size);
3638
#endif
37-
size = MAX_TRACE_SIZE;
39+
size = MAX_VARIABLE_TRACE_SIZE;
3840
}
3941
int index = -1;
4042
for (int i = 0; i < NUM_TRACED_VARIABLES; i++) {

quantum/variable_trace.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef VARIABLE_TRACE_H
2+
#define VARIABLE_TRACE_H
3+
4+
#include "print.h"
5+
6+
#ifdef NUM_TRACED_VARIABLES
7+
8+
#define ADD_TRACED_VARIABLE(name, addr, size) \
9+
add_traced_variable(PSTR(name), (void*)addr, size, PSTR(__FILE__), __LINE__)
10+
#define REMOVE_TRACED_VARIABLE(name) remove_traced_variable(PSTR(name), PSTR(__FILE__), __LINE__)
11+
#define VERIFY_TRACED_VARIABLES() verify_traced_variables(PSTR(__FILE__), __LINE__)
12+
13+
#else
14+
15+
#define ADD_TRACED_VARIABLE(name, addr, size)
16+
#define REMOVE_TRACED_VARIABLE(name)
17+
#define VERIFY_TRACED_VARIABLES()
18+
19+
#endif
20+
21+
// Don't call directly, use the macros instead
22+
void add_traced_variable(const char* name, void* addr, unsigned size, const char* func, int line);
23+
void remove_traced_variable(const char* name, const char* func, int line);
24+
void verify_traced_variables(const char* func, int line);
25+
#endif

0 commit comments

Comments
 (0)