From d0c7529cb9833ede3595051df5599a11fe03be48 Mon Sep 17 00:00:00 2001 From: Reinhard Tartler Date: Thu, 5 Apr 2007 15:25:19 +0200 Subject: import new upstream --- drv_generic_serial.c | 118 +++++++++------------------------------------------ 1 file changed, 19 insertions(+), 99 deletions(-) (limited to 'drv_generic_serial.c') diff --git a/drv_generic_serial.c b/drv_generic_serial.c index 4644903..a2b5506 100644 --- a/drv_generic_serial.c +++ b/drv_generic_serial.c @@ -1,4 +1,5 @@ -/* $Id: drv_generic_serial.c,v 1.17 2005/05/08 04:32:44 reinelt Exp $ +/* $Id: drv_generic_serial.c 728 2007-01-14 11:14:38Z michael $ + * $URL: https://ssl.bulix.org/svn/lcd4linux/branches/0.10.1/drv_generic_serial.c $ * * generic driver helper for serial and usbserial displays * @@ -21,93 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * - * $Log: drv_generic_serial.c,v $ - * Revision 1.17 2005/05/08 04:32:44 reinelt - * CodingStyle added and applied - * - * Revision 1.16 2005/01/18 06:30:23 reinelt - * added (C) to all copyright statements - * - * Revision 1.15 2004/06/26 12:04:59 reinelt - * - * uh-oh... the last CVS log message messed up things a lot... - * - * Revision 1.14 2004/06/26 09:27:21 reinelt - * - * added '-W' to CFLAGS - * changed all C++ comments to C ones - * cleaned up a lot of signed/unsigned mistakes - * - * Revision 1.13 2004/06/26 06:12:15 reinelt - * - * support for Beckmann+Egle Compact Terminals - * some mostly cosmetic changes in the MatrixOrbital and USBLCD driver - * added debugging to the generic serial driver - * fixed a bug in the generic text driver where icons could be drawn outside - * the display bounds - * - * Revision 1.12 2004/06/20 10:09:55 reinelt - * - * 'const'ified the whole source - * - * Revision 1.11 2004/06/01 06:45:30 reinelt - * - * some Fixme's processed - * documented some code - * - * Revision 1.10 2004/05/31 21:05:13 reinelt - * - * fixed lots of bugs in the Cwlinux driver - * do not emit EAGAIN error on the first retry - * made plugin_i2c_sensors a bit less 'chatty' - * moved init and exit functions to the bottom of plugin_pop3 - * - * Revision 1.9 2004/05/28 13:51:42 reinelt - * - * ported driver for Beckmann+Egle Mini-Terminals - * added 'flags' parameter to serial_init() - * - * Revision 1.8 2004/03/03 04:44:16 reinelt - * changes (cosmetics?) to the big patch from Martin - * hash patch un-applied - * - * Revision 1.7 2004/03/03 03:47:04 reinelt - * big patch from Martin Hejl: - * - use qprintf() where appropriate - * - save CPU cycles on gettimeofday() - * - add quit() functions to free allocated memory - * - fixed lots of memory leaks - * - * Revision 1.6 2004/02/14 11:56:17 reinelt - * M50530 driver ported - * changed lots of 'char' to 'unsigned char' - * - * Revision 1.5 2004/02/04 19:10:51 reinelt - * Crystalfontz driver nearly finished - * - * Revision 1.4 2004/02/01 08:05:12 reinelt - * Crystalfontz 633 extensions (CRC checking and stuff) - * Models table for HD44780 - * Noritake VFD BVrightness patch from Bill Paxton - * - * Revision 1.3 2004/01/29 04:40:02 reinelt - * every .c file includes "config.h" now - * - * Revision 1.2 2004/01/25 05:30:09 reinelt - * plugin_netdev for parsing /proc/net/dev added - * - * Revision 1.1 2004/01/20 14:26:09 reinelt - * moved drv_generic to drv_generic_serial - * - * Revision 1.2 2004/01/20 05:36:59 reinelt - * moved text-display-specific stuff to drv_generic_text - * moved all the bar stuff from drv_generic_bar to generic_text - * - * Revision 1.1 2004/01/20 04:51:39 reinelt - * moved generic stuff from drv_MatrixOrbital to drv_generic - * implemented new-stylish bars which are nearly finished - * */ /* @@ -153,6 +67,8 @@ #include "drv_generic_serial.h" +extern int got_signal; + static char *Section; static char *Driver; static char *Port; @@ -412,33 +328,37 @@ int drv_generic_serial_read(char *string, const int len) void drv_generic_serial_write(const char *string, const int len) { + static int error = 0; int run, ret; -#if 0 - int i; - for (i = 0; i < len; i++) { - int c = string[i]; - debug("serial_write: %03d %03o 0x%02x %c", c, c, c, iscntrl(c) ? '*' : c); + if (Device == -1) { + error("%s: write to closed port %s failed!", Driver, Port); + return; } -#endif - if (Device == -1) - return; for (run = 0; run < 10; run++) { ret = write(Device, string, len); - if (ret >= 0 || errno != EAGAIN) + if (ret >= 0 || errno != EAGAIN) { break; - if (run > 0) + } + /* EAGAIN: retry 10 times, emit message after 2nd retry */ + if (run > 0) { info("%s: write(%s): EAGAIN #%d", Driver, Port, run); + } usleep(1000); } if (ret < 0) { error("%s: write(%s) failed: %s", Driver, Port, strerror(errno)); + if (++error > 10) { + error("%s: too much errors, giving up", Driver); + got_signal = -1; + } } else if (ret != len) { error("%s: partial write(%s): len=%d ret=%d", Driver, Port, len, ret); + } else { + error = 0; } - return; } -- cgit v1.2.3