summaryrefslogtreecommitdiffstats
path: root/serial.c
diff options
context:
space:
mode:
authorPatrick Georgi <patrick.georgi@coresystems.de>2010-01-06 19:09:40 +0000
committerPatrick Georgi <pgeorgi@google.com>2010-01-06 19:09:40 +0000
commit3b6237dbce5149c565a134394c6184118629464d (patch)
treeec6d0b820d2d153b32743d1d466ead3196fd677d /serial.c
parentefa151eb10a11796bd36cf0f32c8202e60d9de01 (diff)
downloadflashrom-3b6237dbce5149c565a134394c6184118629464d.tar.gz
flashrom-3b6237dbce5149c565a134394c6184118629464d.tar.bz2
flashrom-3b6237dbce5149c565a134394c6184118629464d.zip
Multiple unrelated changes
- replace the hand written serial input flush routine with the termios one. - serialport_discard_read isn't necessary anymore - it just wrapped sp_flush_incoming with no extra value. - serialport_read and serialport_write would misbehave if read or write didn't process everything in one go. - sp_flush_incoming should be #define'd out for FAKE_COMMUNICATION like serialport_discard_read was Corresponding to flashrom svn r831. Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de> Acked-by: Sean Nelson <audiohacked@gmail.com>
Diffstat (limited to 'serial.c')
-rw-r--r--serial.c38
1 files changed, 9 insertions, 29 deletions
diff --git a/serial.c b/serial.c
index be881667c..754dff904 100644
--- a/serial.c
+++ b/serial.c
@@ -129,16 +129,7 @@ int sp_openserport(char *dev, unsigned int baud)
void sp_flush_incoming(void)
{
- int i;
- for (i=0;i<100;i++) { /* In case the device doesnt do EAGAIN, just read 0 */
- unsigned char flush[16];
- ssize_t rv;
- rv = read(sp_fd, flush, sizeof(flush));
- if ((rv == -1) && (errno == EAGAIN))
- break;
- if (rv == -1)
- sp_die("flush read");
- }
+ tcflush(sp_fd, TCIFLUSH);
return;
}
@@ -152,12 +143,14 @@ int serialport_write(unsigned char *buf, unsigned int writecnt)
{
int tmp = 0;
- while (tmp != writecnt) {
- tmp = write(sp_fd, buf + tmp, writecnt - tmp);
+ while (writecnt > 0) {
+ tmp = write(sp_fd, buf, writecnt);
if (tmp == -1)
return 1;
if (!tmp)
printf_debug("Empty write\n");
+ writecnt -= tmp;
+ buf += tmp;
}
return 0;
@@ -167,28 +160,15 @@ int serialport_read(unsigned char *buf, unsigned int readcnt)
{
int tmp = 0;
- while (tmp != readcnt) {
- tmp = read(sp_fd, buf + tmp, readcnt - tmp);
+ while (readcnt > 0) {
+ tmp = read(sp_fd, buf, readcnt);
if (tmp == -1)
return 1;
if (!tmp)
printf_debug("Empty read\n");
+ readcnt -= tmp;
+ buf += tmp;
}
return 0;
}
-
-int serialport_discard_read(void)
-{
- int flags;
-
- printf_debug("%s\n", __func__);
- flags = fcntl(sp_fd, F_GETFL);
- flags |= O_NONBLOCK;
- fcntl(sp_fd, F_SETFL, flags);
- sp_flush_incoming();
- flags &= ~O_NONBLOCK;
- fcntl(sp_fd, F_SETFL, flags);
-
- return 0;
-}