[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Want to place __func__ in program memory

From: Alex Iljin
Subject: [avr-gcc-list] Want to place __func__ in program memory
Date: Mon, 30 Apr 2012 01:46:12 +0700

Good day.

I use simple macro to define custom function for debug message.
It seems like this:

#define DebugMessageFromProgMem(...) xprintf(__VA_ARGS__)

#define DEBUG_MESSAGE_FROM_PROG(message, args...) {\
                static char progmem_debug_message_local[] PROGMEM = message;\
                DebugMessageFromProgMem(progmem_debug_message_local, ##args);\

Here, xprintf - is extendet printf, which get format from program memory.
Also xprintf can get argumets from program memory, if you specify %S
in format string.

So, it is simply to use:

DEBUG_MESSAGE_FROM_PROG("We are here\r\n");
DEBUG_MESSAGE_FROM_PROG("value = %d\r\n", myValue);

And it is cheap for RAM.

Further, I want to add trace and assert function.
Now I use such macro:

#define STRING_HELPER(arg) #arg
#define DEBUG_TRACE_PROGMEM(messageLine) \
                static const char progmem_trace_file[] PROGMEM = __FILE__;\
                static const char progmem_trace_line[] PROGMEM = 
                static const char progmem_trace_messasge[] PROGMEM = 
                DEBUG_MESSAGE_FROM_PROG("Function %s\r\nin file %S:%S %S", \
                        __func__, \
                        progmem_trace_file, \
                        progmem_trace_line, \

In the same way I define DEBUG_ASSERT_PROGMEM macro.
It is OK, but I want to use many trace and assert functions, so there
is a question.
Is there way to place function name in program memory?
Maybe there are specific __FUNC_PROGMEM__ marco, or some compiler parameters,
which switch __func__ from charecter array to string literal?

Alexander Iljin

reply via email to

[Prev in Thread] Current Thread [Next in Thread]