|I'm working on an embedded ARM-project (STM32F) and I'm programming in C programming language and compiling with Eclipse/GCC. In the project there is TRACE functionality implemented that, if enabled, logs various things over UART using queues and DMA:
#define TRACE(grp, lvl, ...) traceToPrintStream(grp, __FILE__, __FUNCTION__, __LINE__, lvl, __VA_ARGS__)It can be used, e.g. like this:
TRACE("regCallbacks", T_D, "The user pressed the button");
TRACE("regCallbacks", T_D, "Write to reg %d. First written byte: 0x%X", regAddr, regValues);I need a different trace that is not queued, does not use DMA and does not include the file name, function name and line number, but the other persons in this project do not agree to throw out the existing TRACE, so I need to make something in parallel. I want to be able to enable my TRACE in two ways, either by #defines:
#define ENABLE_COMMUNICATOIN_BUS_LOGGINGor by setting a varible during runtime:
Bool_t enableUserEventsLogging;I need a different grouping (the grp parameter) than the others, so the example TRACEings above would have to be augmented with my grouping as well:
TRACE_EX("regCallbacks", USER_EVENTS, T_D, "The user pressed the button");
TRACE_EX("regCallbacks", COMMUNICATION_BUS, T_D, "Write to reg %d. First written byte: 0x%X", regAddr, regValues);The rules I would like to apply are:
1. If my TRACE is enabled using the macros (hardcode enabled), then the other TRACE can not be used (hardcode disabled).
2. If my TRACE is not enabled using the macros, then both TRACEs can be enabled/disabled during runtime independently of each other. However, they are enabled per groups!
Does anybody know how I can solve this? I found a great website (C Preprocessor tricks, tips, and idioms · pfultz2/Cloak Wiki · GitHub[^]) that shows some really neat macro-tricks, but I'm not sure how to apply it my case.