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); } |
From: Erik M. <J.A...@it...> - 2002-02-05 16:49:02
|
On Tue, Feb 05, 2002 at 05:40:48AM -0800, Abraham vd Merwe wrote: > 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. I'd prefer if you could move it to src/lib/printf.c and just call the function printf(). No difference in functionality, but it makes the source easier to browse and to read. Erik PS: If this is Brad Parker's printf() be sure to put a correct copyright on top of the file. The last thing we want is copyright issues. -- J.A.K. (Erik) Mouw, Information and Communication Theory Group, Faculty of Information Technology and Systems, Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands Phone: +31-15-2783635 Fax: +31-15-2781843 Email: J.A...@it... WWW: http://www-ict.its.tudelft.nl/~erik/ |
From: Abraham vd M. <ab...@2d...> - 2002-02-06 07:34:11
|
Hi Erik! > > Update of /cvsroot/blob/blob/src/lib > > In directory usw-pr-cvs1:/tmp/cvs-serv15305/src/lib > >=20 > > Modified Files: > > serial.c=20 > > Log Message: > > Added a printf()-like function for printing to the serial port. Also so= me > > minor code cleanup in the memory checking routines. >=20 > I'd prefer if you could move it to src/lib/printf.c and just call the > function printf(). No difference in functionality, but it makes the > source easier to browse and to read. As you might have seen, I backed out the changes in anycase since there's no portable way to do variable arguments (I realised that after I wrote the damn function) and we don't include the standard C library headers. I looked at the way diet libc does it's stdarg.h, but that is a great example of why you don't want to write your own stdarg routines :P (Besides the fact that those routines doesn't work for uncast numeric parameters e.g. printf("%x",15); ) > PS: If this is Brad Parker's printf() be sure to put a correct > copyright on top of the file. The last thing we want is copyright > issues. No, I wrote that one yesterday. --=20 Regards Abraham He knows not how to know who knows not also how to unknow. -- Sir Richard Burton __________________________________________________________ Abraham vd Merwe - 2d3D, Inc. Device Driver Development, Outsourcing, Embedded Systems Cell: +27 82 565 4451 Snailmail: Tel: +27 21 761 7549 Block C, Antree Park Fax: +27 21 761 7648 Doncaster Road Email: ab...@2d... Kenilworth, 7700 Http: http://www.2d3d.com South Africa |
From: Erik M. <J.A...@it...> - 2002-02-06 08:33:16
|
On Wed, Feb 06, 2002 at 09:31:30AM +0200, Abraham vd Merwe wrote: > Hi Erik! > > > > 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. > > > > I'd prefer if you could move it to src/lib/printf.c and just call the > > function printf(). No difference in functionality, but it makes the > > source easier to browse and to read. > > As you might have seen, I backed out the changes in anycase since there's no > portable way to do variable arguments (I realised that after I wrote the > damn function) and we don't include the standard C library headers. Yeah, I realised that too late. > I looked at the way diet libc does it's stdarg.h, but that is a great > example of why you don't want to write your own stdarg routines :P (Besides > the fact that those routines doesn't work for uncast numeric parameters e.g. > printf("%x",15); ) > > > PS: If this is Brad Parker's printf() be sure to put a correct > > copyright on top of the file. The last thing we want is copyright > > issues. > > No, I wrote that one yesterday. You might want to look at Brad's IDE code, it contains a printf() implementation and he somehow solved the stdarg problem. IIRC he posted the URL to the LART mailing list. Erik -- J.A.K. (Erik) Mouw, Information and Communication Theory Group, Faculty of Information Technology and Systems, Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands Phone: +31-15-2783635 Fax: +31-15-2781843 Email: J.A...@it... WWW: http://www-ict.its.tudelft.nl/~erik/ |