FreeCalypso > hg > freecalypso-reveng
changeset 344:2bd27d940023
fluid-mnf/serial.c: serial_recv() implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 13 Mar 2020 05:53:20 +0000 |
parents | 917e05f03ad2 |
children | b595ff13547b |
files | fluid-mnf/serial.c |
diffstat | 1 files changed, 26 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/fluid-mnf/serial.c Fri Mar 13 05:40:23 2020 +0000 +++ b/fluid-mnf/serial.c Fri Mar 13 05:53:20 2020 +0000 @@ -29,11 +29,14 @@ #include <sys/ioctl.h> #include <asm/ioctls.h> #include <asm/termbits.h> +#include <sys/errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> +extern int errno; + /****************************************************************************** * Linux Driver @@ -208,7 +211,29 @@ int serial_recv(char *buf, int size, int timeout) { - /* to be filled */ + fd_set fds; + struct timeval tv; + int cc; + + for (;;) { + FD_ZERO(&fds); + FD_SET(target_fd, &fds); + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout % 1000) * 1000; + cc = select(target_fd+1, &fds, NULL, NULL, &tv); + if (cc < 0) { + if (errno == EINTR) + continue; + return E_OS + E_UART_DRV_RECV; + } + break; + } + if (cc == 0) + return cc; + cc = read(target_fd, buf, size); + if (cc <= 0) + cc = E_OS + E_UART_DRV_RECV; + return cc; }