aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-11-06 22:11:24 +0200
committerFred Sundvik <fsundvik@gmail.com>2016-11-06 22:11:24 +0200
commita377017c95b826d83ac7a46ef176d39a58294b44 (patch)
treeb8f9959f82ae34e80b7413011ddc70444d0dc38d
parentf519b94be7086852f2afe4ec248786b47968f7ff (diff)
downloadqmk_firmware-a377017c95b826d83ac7a46ef176d39a58294b44.tar.gz
qmk_firmware-a377017c95b826d83ac7a46ef176d39a58294b44.zip
Add possibility to control variable trace from make
-rw-r--r--build_keyboard.mk8
-rw-r--r--quantum/variable_trace.c10
-rw-r--r--quantum/variable_trace.h25
3 files changed, 38 insertions, 5 deletions
diff --git a/build_keyboard.mk b/build_keyboard.mk
index 461b17cd7..61aebf393 100644
--- a/build_keyboard.mk
+++ b/build_keyboard.mk
@@ -180,7 +180,13 @@ ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes)
180 VAPTH += $(SERIAL_PATH) 180 VAPTH += $(SERIAL_PATH)
181endif 181endif
182 182
183SRC += $(QUANTUM_DIR)/variable_trace.c 183ifneq ($(strip $(VARIABLE_TRACE)),)
184 SRC += $(QUANTUM_DIR)/variable_trace.c
185 OPT_DEFS += -DNUM_TRACED_VARIABLES=$(strip $(VARIABLE_TRACE))
186ifneq ($(strip $(MAX_VARIABLE_TRACE_SIZE)),)
187 OPT_DEFS += -DMAX_VARIABLE_TRACE_SIZE=$(strip $(MAX_VARIABLE_TRACE_SIZE))
188endif
189endif
184 190
185# Optimize size but this may cause error "relocation truncated to fit" 191# Optimize size but this may cause error "relocation truncated to fit"
186#EXTRALDFLAGS = -Wl,--relax 192#EXTRALDFLAGS = -Wl,--relax
diff --git a/quantum/variable_trace.c b/quantum/variable_trace.c
index dfa37bdef..de580244c 100644
--- a/quantum/variable_trace.c
+++ b/quantum/variable_trace.c
@@ -12,7 +12,9 @@
12 12
13 13
14#define NUM_TRACED_VARIABLES 1 14#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
16 18
17typedef struct { 19typedef struct {
18 const char* name; 20 const char* name;
@@ -20,7 +22,7 @@ typedef struct {
20 unsigned size; 22 unsigned size;
21 const char* func; 23 const char* func;
22 int line; 24 int line;
23 uint8_t last_value[MAX_TRACE_SIZE]; 25 uint8_t last_value[MAX_VARIABLE_TRACE_SIZE];
24 26
25} traced_variable_t; 27} traced_variable_t;
26 28
@@ -28,13 +30,13 @@ static traced_variable_t traced_variables[NUM_TRACED_VARIABLES];
28 30
29void add_traced_variable(const char* name, void* addr, unsigned size, const char* func, int line) { 31void add_traced_variable(const char* name, void* addr, unsigned size, const char* func, int line) {
30 verify_traced_variables(func, line); 32 verify_traced_variables(func, line);
31 if (size > MAX_TRACE_SIZE) { 33 if (size > MAX_VARIABLE_TRACE_SIZE) {
32#if defined(__AVR__) 34#if defined(__AVR__)
33 xprintf("Traced variable \"%S\" exceeds the maximum size %d\n", name, size); 35 xprintf("Traced variable \"%S\" exceeds the maximum size %d\n", name, size);
34#else 36#else
35 xprintf("Traced variable \"%s\" exceeds the maximum size %d\n", name, size); 37 xprintf("Traced variable \"%s\" exceeds the maximum size %d\n", name, size);
36#endif 38#endif
37 size = MAX_TRACE_SIZE; 39 size = MAX_VARIABLE_TRACE_SIZE;
38 } 40 }
39 int index = -1; 41 int index = -1;
40 for (int i = 0; i < NUM_TRACED_VARIABLES; i++) { 42 for (int i = 0; i < NUM_TRACED_VARIABLES; i++) {
diff --git a/quantum/variable_trace.h b/quantum/variable_trace.h
new file mode 100644
index 000000000..9899816f6
--- /dev/null
+++ b/quantum/variable_trace.h
@@ -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
22void add_traced_variable(const char* name, void* addr, unsigned size, const char* func, int line);
23void remove_traced_variable(const char* name, const char* func, int line);
24void verify_traced_variables(const char* func, int line);
25#endif