diff options
author | Virgil-Adrian Teaca <darkstarlinux@gmail.com> | 2012-04-30 23:11:06 +0000 |
---|---|---|
committer | Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de> | 2012-04-30 23:11:06 +0000 |
commit | da7c545b06195185e9df9a88ef6437c61d64a225 (patch) | |
tree | 08bfe3653a11370baf4c5e1ad51d83da0012d8fc /serial.c | |
parent | 2abab94c18721181c8d517b8e31ffada22145ea9 (diff) | |
download | flashrom-da7c545b06195185e9df9a88ef6437c61d64a225.tar.gz flashrom-da7c545b06195185e9df9a88ef6437c61d64a225.tar.bz2 flashrom-da7c545b06195185e9df9a88ef6437c61d64a225.zip |
Add serial port bitbanging code
This adds the pony_spi driver which supports the SI_Prog adapter, which
is commonly used for SPI chips with PonyProg 2000, and a custom adapter
called "SERBANG" which differs in the logic of two pins.
Corresponding to flashrom svn r1525.
Signed-off-by: Virgil-Adrian Teaca <darkstarlinux@gmail.com>
Acked-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de>
Diffstat (limited to 'serial.c')
-rw-r--r-- | serial.c | 55 |
1 files changed, 55 insertions, 0 deletions
@@ -32,6 +32,9 @@ #include <conio.h> #else #include <termios.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/ioctl.h> #endif #include "flash.h" #include "programmer.h" @@ -172,6 +175,58 @@ fdtype sp_openserport(char *dev, unsigned int baud) #endif } +void sp_set_pin(enum SP_PIN pin, int val) { +#ifdef _WIN32 + DWORD ctl; + + if(pin == PIN_TXD) { + ctl = val ? SETBREAK: CLRBREAK; + } + else if(pin == PIN_DTR) { + ctl = val ? SETDTR: CLRDTR; + } + else { + ctl = val ? SETRTS: CLRRTS; + } + EscapeCommFunction(sp_fd, ctl); +#else + int ctl, s; + + if(pin == PIN_TXD) { + ioctl(sp_fd, val ? TIOCSBRK : TIOCCBRK, 0); + } + else { + s = (pin == PIN_DTR) ? TIOCM_DTR : TIOCM_RTS; + ioctl(sp_fd, TIOCMGET, &ctl); + + if (val) { + ctl |= s; + } + else { + ctl &= ~s; + } + ioctl(sp_fd, TIOCMSET, &ctl); + } +#endif +} + +int sp_get_pin(enum SP_PIN pin) { + int s; +#ifdef _WIN32 + DWORD ctl; + + s = (pin == PIN_CTS) ? MS_CTS_ON : MS_DSR_ON; + GetCommModemStatus(sp_fd, &ctl); +#else + int ctl; + s = (pin == PIN_CTS) ? TIOCM_CTS : TIOCM_DSR; + ioctl(sp_fd, TIOCMGET, &ctl); +#endif + + return ((ctl & s) ? 1 : 0); + +} + void sp_flush_incoming(void) { #ifdef _WIN32 |