Since debugging has been a topic of discussion, I decided to post this.
This is a way to redirect a "printf" to any output device:
..... C function
debugPrintf ("This is test #%d", 10);
....
Rabbit Version::::
/*
. Name:
debugPrintf ()
.
. Description: A printf() style
routine with output redirect.
*/
int debugPrintf (char *fmt, ...)
{
static unsigned long elapsed;
auto int count, __cnt;
auto int local_len;
auto int __printfcnt;
auto char __printfbuf[BUFFLEN256];
auto char smode_pins;
__printfcnt = 0;
local_len = BUFFLEN256;
count = 0;
#ifdef _DEBUG
doprnt(__qe_telnet, fmt, (char *) ((char *) &fmt +
sizeof (fmt)), (void *)(&local_len), __printfbuf, &count);
__cnt = count;
__qe_telnet(0, __printfbuf, &count, (void
*)(&local_len)); // Null Terminator
printf("%s",__printfbuf); // change this line to you
desired output device, such as Ethernet or USB
#endif
return(0);
}
ANSII C version that uses minimal stack space and prevents reentrancy::
(Assumes some type of real time operating system for the semaphore
support)
(On some real time OS's printf is not reentrant, so some type of
blocking call is needed)
#define MAX_DEBUG_PRINTF 512 //Maximuim length of the debugPrintf
buffer
char g_cDebugPrintBuf[MAX_DEBUG_PRINTF];
//Global variables
SEMAPHOREHANDLE_t printfSemaphore; //
Semaphore Handle
void debugPrintfInit(void)
{
//create a Binary semaphore
//#ifdef EN_SEMAPHORE
#ifdef _DEBUG_STDIO
printf(" \nCreating DBG_PRINT semaphore\n ");
#endif
printfSemaphore = CreateSemaphore(( NAME_t * )
"DBG_PRINT",MAX_ALLOWED_IN ,RECV_ORDER_FIFO);
if(printfSemaphore == NULL)
{
#ifdef _DEBUG_ERROR
printf("\n!!!Unable to create DBG_PRINT,
error description is");
#endif
FormatError(GetErrorNum()) ;
}
//#endif
}
reentrant void debugPrintf(const char *format, ...)
{
va_list ap;
if (printfSemaphore)
{
ThreadLockForDelete();
AcquireSemaphore(printfSemaphore,MAX_INFINITE_SUSPEND);
}
va_start(ap,format);
vsprintf(g_cDebugPrintBuf, format, ap);
va_end(ap);
printf("%s", g_cDebugPrintBuf); // change this line to you desired
output device, such as Ethernet or USB
if (printfSemaphore)
{
ReleaseSemaphore(printfSemaphore);
ThreadUnLockForDelete();
}
}

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )
Yes, you can redirect the printf output to a serial port. Add some #defines
as follows to your program to do it:
#define STDIO_DEBUG_SERIAL SDDR //select the serial port, eg here uses port
D on the processor
#define STDIO_DEBUG_BAUD 115200 //set the baud rate
#define STDIO_DEBUG_ADDCR //which converts \n to CR + LF
Using the Rabbit programming cable you can view the output on a PC using
hyperterminal or a similar serial program. Change the programming cable
from connecting using PROG to DIAG.
Paul
www.beartech.com.au
--
View this message in context:
http://www.nabble.com/redirectable-printf-tp15885851p15891052.html
Sent from the Rabbit Semiconductor mailing list archive at Nabble.com.

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )