From: Jan-Benedict G. <jb...@us...> - 2004-09-30 18:05:49
|
Update of /cvsroot/linux-vax/usr/firmware_dumper In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20161 Modified Files: serial.c serial.h Log Message: - KA49 crashes if I send multiple bytes down to it, while not fetching their echo off the machine. So here are helper functions to support that. Index: serial.c =================================================================== RCS file: /cvsroot/linux-vax/usr/firmware_dumper/serial.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- serial.c 23 Jul 2004 17:44:47 -0000 1.1 +++ serial.c 30 Sep 2004 18:05:39 -0000 1.2 @@ -303,6 +303,24 @@ return 0; } +int +serial_write_byte_rb (int fd, unsigned char byte) +{ + ssize_t ret; + int ret2; + unsigned char readback_byte; + + ret = write (fd, &byte, 1); + if (ret != 1) + return -1; + + ret2 = serial_read_byte (fd, &readback_byte, 1, 0); + if (ret2 != 0) + return -2; + else + return 0; +} + size_t serial_write (int fd, unsigned char *buf, size_t len) { @@ -336,6 +354,24 @@ return 0; } +size_t +serial_write_rb (int fd, unsigned char *buf, size_t len) +{ + int i; + size_t written = 0; + int ret; + + for (i = 0; i < len; i++) { + ret = serial_write_byte_rb (fd, buf[i]); + if (ret == 0) + written++; + else + break; + } + + return len - written; +} + int serial_read_byte (int fd, unsigned char *byte, time_t sec, suseconds_t usec) { Index: serial.h =================================================================== RCS file: /cvsroot/linux-vax/usr/firmware_dumper/serial.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- serial.h 23 Jul 2004 17:44:47 -0000 1.1 +++ serial.h 30 Sep 2004 18:05:39 -0000 1.2 @@ -25,7 +25,9 @@ extern int serial_set_stop (int fd, unsigned char stop); extern int serial_set_one_byte_each (int fd); extern int serial_write_byte (int fd, unsigned char byte); +extern int serial_write_byte_rb (int fd, unsigned char byte); /* with readback */ extern size_t serial_write (int fd, unsigned char *buf, size_t len); /* returning remaining byte # not sent */ +extern size_t serial_write_rb (int fd, unsigned char *buf, size_t len); /* returning remaining byte # not sent, with readback */ extern int serial_read_byte (int fd, unsigned char *byte, time_t sec, suseconds_t usec); extern int serial_get_modem (int fd, int what, int *result); |