From: Abraham vd M. <ab...@us...> - 2002-02-05 13:40:51
|
Update of /cvsroot/blob/blob/src/lib In directory usw-pr-cvs1:/tmp/cvs-serv15305/src/lib Modified Files: serial.c Log Message: Added a printf()-like function for printing to the serial port. Also some minor code cleanup in the memory checking routines. Index: serial.c =================================================================== RCS file: /cvsroot/blob/blob/src/lib/serial.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- serial.c 2002/01/05 20:14:34 1.7 +++ serial.c 2002/02/05 13:40:46 1.8 @@ -6,7 +6,7 @@ * Description: Serial utilities for blob * Created at: Tue Aug 24 20:25:00 1999 * Modified by: Erik Mouw <J.A...@it...> - * Modified at: Mon Oct 4 20:11:14 1999 + * Abraham van der Merwe <ab...@2d...> *-----------------------------------------------------------------------*/ /* * serial.c: Serial utilities for blob @@ -222,6 +222,87 @@ { while(bufsize--) serial_write(*buf++); +} + + + + +/* + * Write a single character to the serial port. + */ +void SerialOutputChar (const char c) +{ + serial_write (c); +} + + + + +/* + * Very primitive printf() support. This version can + * do the following conversions: + * + * c char + * s char * + * d,i int + * u unsigned int + * x unsigned int (hex) + * p void * + * + * There is no floating point support and no modifiers. + */ +void SerialPrintf(const char *fmt, ...) +{ + va_list ap; + int d; + + va_start (ap,fmt); + while (*fmt) + { + if (*fmt == '%') + { + switch (*++fmt) + { + case '%': + SerialOutputChar (*fmt); + break; + + case 'c': + SerialOutputChar (va_arg (ap,const char)); + break; + + case 's': + SerialOutputString (va_arg (ap,const char *)); + break; + + case 'd': + case 'i': + d = va_arg (ap,int); + if (d < 0) + { + SerialOutputChar ('-'); + d = -d; + } + SerialOutputDec (d); + break; + + case 'u': + SerialOutputDec (va_arg (ap,unsigned int)); + break; + + case 'x': + SerialOutputHex (va_arg (ap,unsigned int)); + break; + + case 'p': + SerialOutputHex ((unsigned int) va_arg (ap,void *)); + break; + } + } + else SerialOutputChar (*fmt); + fmt++; + } + va_end (ap); } |