|
|
View previous topic :: View next topic |
Author |
Message |
silelis
Joined: 12 Jun 2007 Posts: 68 Location: Poland, podlaskie district
|
Logging function - request |
Posted: Fri Oct 07, 2016 8:16 am |
|
|
Do some of you have some logging function routine?
At the moment I am using something like this:
Code: |
#define __USE_log__
main()
{
#ifdef __USE_log__
disable_interrupt(GLOBAL);
fprintf(LOG_PORT,"log message %u %s", number, string);
enable_interrupt(GLOBAL);
delay_ms(500);
#endif
}
|
but this makes code very messy. A function with variable parameter list is required. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1354
|
|
Posted: Fri Oct 07, 2016 10:46 am |
|
|
when I am using the version 5 compiler I generally have some iteration of:
Code: |
#ifdef DEBUG_ENABLED
#use rs232(ICD,DISABLE_INTS,stream=ICD_DBG)
#define dbg_putc(c) fputc(c, ICD_DBG)
#define dbg_printf(fmt,...) fprintf(ICD_DBG,fmt,__VA_ARGS__)
#else
#define dbg_putc(c)
#define dbg_printf(fmt,...)
#endif
|
That way if I have DEBUG_ENABLED defined, then I get the debug messages, and if not, it removes the code completely. Notice that for software UARTS, you can tell CCS to disable interrupts so you don't have to manually (you shouldn't need to disable interrupts for hardware debug UARTS).
For more complex projects I add some #if options for various levels of debug messages or blocks of debug code so I can have some more fidelity in the output.
With the method above, I can just type:
Code: |
dbg_printf("My Debug string: %02x", some_var);
|
which I feel is pretty clean.
EDIT: however, you should post questions in the C Discussion forum. The code library forum is for posting code only. Keeps the signal to noise ratio down and it helps increase the chances that someone will read your thread. |
|
|
silelis
Joined: 12 Jun 2007 Posts: 68 Location: Poland, podlaskie district
|
|
Posted: Mon Oct 10, 2016 1:24 am |
|
|
Thank You for the answer. I will try the code and in case of question will back to thread. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|