CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Logging function - request

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
silelis



Joined: 12 Jun 2007
Posts: 68
Location: Poland, podlaskie district

View user's profile Send private message

Logging function - request
PostPosted: Fri Oct 07, 2016 8:16 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 07, 2016 10:46 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Oct 10, 2016 1:24 am     Reply with quote

Thank You for the answer. I will try the code and in case of question will back to thread.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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