[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avrdude-dev] Patch for (5.1) ser_posix.c for O_NONBLOCK open and restor

From: Ned Konz
Subject: [avrdude-dev] Patch for (5.1) ser_posix.c for O_NONBLOCK open and restoring serial port state on close
Date: Mon, 3 Apr 2006 11:47:44 -0700

The attached patch for ser_posix.c (from the avrdude-5.1 distribution) does the following things, all of which I consider to be improvements <g>:

* Adds the O_NONBLOCK flag to the open arguments. I (and others) have found that this prevents blocking at open using certain USB to serial adapters. The problem is that if the CLOCAL flag happens to be clear (previously, which we have no control over), then the open will wait (forever, on the jtagmkII) for the carrier detect.

This won't affect reads or writes, because we're using select() to wait till the fd is ready to read or write.

* Saves the original termios structure, before we start modifying it from ser_open().
* Restores the original termios structure at ser_close() time.

* Changes the printf spec for "long baud" in serial_baud_lookup() to be "%ld" instead of "%d"

* Factors reporting of strerror(errno) out of ser_setspeed(); we're already returning a value of -errno, so we can just call strerror() once, in ser_open() where we see that ser_setspeed returned with an error code.

* Ensures that if we try to open a non-tty that we get an explanatory error message ("inappropriate ioctl for device").

* Ensures that the termios structure is properly set to raw mode by calling cfmakeraw() instead of trying to set individual struct fields manually.

* Makes sure that the CSIZE bits in the termios.c_cflag are all reset before or'ing CS8 into them.

* Adds TCSAFLUSH to the tcsetattr() call in ser_setspeed() to throw away any pending input garbage

* Adds TCSADRAIN to the tcsetattr() call in ser_close() to wait for output to complete before changing data rate and other flags.

Attachment: patch-ser_posix.c
Description: Binary data

Ned Konz

reply via email to

[Prev in Thread] Current Thread [Next in Thread]