Skip to content

Commit

Permalink
Add possibility to control variable trace from make
Browse files Browse the repository at this point in the history
  • Loading branch information
fredizzimo committed Nov 6, 2016
1 parent f519b94 commit a377017
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
8 changes: 7 additions & 1 deletion build_keyboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,13 @@ ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes)
VAPTH += $(SERIAL_PATH)
endif

SRC += $(QUANTUM_DIR)/variable_trace.c
ifneq ($(strip $(VARIABLE_TRACE)),)
SRC += $(QUANTUM_DIR)/variable_trace.c
OPT_DEFS += -DNUM_TRACED_VARIABLES=$(strip $(VARIABLE_TRACE))
ifneq ($(strip $(MAX_VARIABLE_TRACE_SIZE)),)
OPT_DEFS += -DMAX_VARIABLE_TRACE_SIZE=$(strip $(MAX_VARIABLE_TRACE_SIZE))
endif
endif

# Optimize size but this may cause error "relocation truncated to fit"
#EXTRALDFLAGS = -Wl,--relax
Expand Down
10 changes: 6 additions & 4 deletions quantum/variable_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,31 @@


#define NUM_TRACED_VARIABLES 1
#define MAX_TRACE_SIZE 4
#ifndef MAX_VARIABLE_TRACE_SIZE
#define MAX_VARIABLE_TRACE_SIZE 4
#endif

typedef struct {
const char* name;
void* addr;
unsigned size;
const char* func;
int line;
uint8_t last_value[MAX_TRACE_SIZE];
uint8_t last_value[MAX_VARIABLE_TRACE_SIZE];

} traced_variable_t;

static traced_variable_t traced_variables[NUM_TRACED_VARIABLES];

void add_traced_variable(const char* name, void* addr, unsigned size, const char* func, int line) {
verify_traced_variables(func, line);
if (size > MAX_TRACE_SIZE) {
if (size > MAX_VARIABLE_TRACE_SIZE) {
#if defined(__AVR__)
xprintf("Traced variable \"%S\" exceeds the maximum size %d\n", name, size);
#else
xprintf("Traced variable \"%s\" exceeds the maximum size %d\n", name, size);
#endif
size = MAX_TRACE_SIZE;
size = MAX_VARIABLE_TRACE_SIZE;
}
int index = -1;
for (int i = 0; i < NUM_TRACED_VARIABLES; i++) {
Expand Down
25 changes: 25 additions & 0 deletions quantum/variable_trace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef VARIABLE_TRACE_H
#define VARIABLE_TRACE_H

#include "print.h"

#ifdef NUM_TRACED_VARIABLES

#define ADD_TRACED_VARIABLE(name, addr, size) \
add_traced_variable(PSTR(name), (void*)addr, size, PSTR(__FILE__), __LINE__)
#define REMOVE_TRACED_VARIABLE(name) remove_traced_variable(PSTR(name), PSTR(__FILE__), __LINE__)
#define VERIFY_TRACED_VARIABLES() verify_traced_variables(PSTR(__FILE__), __LINE__)

#else

#define ADD_TRACED_VARIABLE(name, addr, size)
#define REMOVE_TRACED_VARIABLE(name)
#define VERIFY_TRACED_VARIABLES()

#endif

// Don't call directly, use the macros instead
void add_traced_variable(const char* name, void* addr, unsigned size, const char* func, int line);
void remove_traced_variable(const char* name, const char* func, int line);
void verify_traced_variables(const char* func, int line);
#endif

0 comments on commit a377017

Please sign in to comment.