diff options
author | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2010-01-06 16:09:10 +0000 |
---|---|---|
committer | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2010-01-06 16:09:10 +0000 |
commit | 27ad83348dcd2077dff41d270a88380ce462bb9e (patch) | |
tree | 9f8668bc80e08d5a0293b27f608f4e40b17d9943 /serial.c | |
parent | c146822bc19bf2b03ab443dd1b197f22ea79c5b9 (diff) | |
download | flashrom-27ad83348dcd2077dff41d270a88380ce462bb9e.zip flashrom-27ad83348dcd2077dff41d270a88380ce462bb9e.tar.gz |
Move OS-dependent serial code from buspirate_spi.c to serial.c and rename a few functions to make it obvious that they are generic and not
Specific to the Bus Pirate.
Corresponding to flashrom svn r830.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Patrick Georgi <patrick.georgi@coresystems.de>
Diffstat (limited to 'serial.c')
-rw-r--r-- | serial.c | 52 |
1 files changed, 52 insertions, 0 deletions
@@ -2,6 +2,7 @@ * This file is part of the flashrom project. * * Copyright (C) 2009 Urja Rannikko <urjaman@gmail.com> + * Copyright (C) 2009,2010 Carl-Daniel Hailfinger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -140,3 +141,54 @@ void sp_flush_incoming(void) } return; } + +int serialport_shutdown(void) +{ + close(sp_fd); + return 0; +} + +int serialport_write(unsigned char *buf, unsigned int writecnt) +{ + int tmp = 0; + + while (tmp != writecnt) { + tmp = write(sp_fd, buf + tmp, writecnt - tmp); + if (tmp == -1) + return 1; + if (!tmp) + printf_debug("Empty write\n"); + } + + return 0; +} + +int serialport_read(unsigned char *buf, unsigned int readcnt) +{ + int tmp = 0; + + while (tmp != readcnt) { + tmp = read(sp_fd, buf + tmp, readcnt - tmp); + if (tmp == -1) + return 1; + if (!tmp) + printf_debug("Empty read\n"); + } + + 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; +} |