aboutsummaryrefslogtreecommitdiffstats
path: root/quantum/variable_trace.h
blob: 46bd8278610f863cd9f547713f86c202058ab902 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef VARIABLE_TRACE_H
#define VARIABLE_TRACE_H

// For more information about the variable tracing see the readme.

#include "print.h"

#ifdef NUM_TRACED_VARIABLES

// Start tracing a variable at the memory address addr
// The name can be anything and is used only for reporting
// The size should usually be the same size as the variable you are interested in
#define ADD_TRACED_VARIABLE(name, addr, size) \
    add_traced_variable(PSTR(name), (void*)addr, size, PSTR(__FILE__), __LINE__)

// Stop tracing the variable with the given name
#define REMOVE_TRACED_VARIABLE(name) remove_traced_variable(PSTR(name), PSTR(__FILE__), __LINE__)

// Call to get messages when the variable has been changed
#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
an class="cp">#include "hal.h" #include "test.h" /* * Blinker thread #1. */ static THD_WORKING_AREA(waThread1, 128); static THD_FUNCTION(Thread1, arg) { (void)arg; chRegSetThreadName("blinker"); while (true) { palSetPad(GPIOB, GPIOB_LED4); chThdSleepMilliseconds(250); palClearPad(GPIOB, GPIOB_LED4); chThdSleepMilliseconds(250); } } /* * Blinker thread #2. */ static THD_WORKING_AREA(waThread2, 128); static THD_FUNCTION(Thread2, arg) { (void)arg; chRegSetThreadName("blinker"); while (true) { palSetPad(GPIOB, GPIOB_LED3); chThdSleepMilliseconds(500); palClearPad(GPIOB, GPIOB_LED3); chThdSleepMilliseconds(500); } } /* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Activates the serial driver 1 using the driver default configuration. * PA9(TX) and PA10(RX) are routed to USART1. */ sdStart(&SD1, NULL); palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7)); palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(7)); /* * Creates the example threads. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+1, Thread1, NULL); chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO+1, Thread2, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state, when the button is * pressed the test procedure is launched. */ while (true) { if (palReadPad(GPIOA, GPIOA_BUTTON)) TestThread(&SD1); chThdSleepMilliseconds(500); } }