From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mark Rejhon Subject: Re: I have a patch for dosemu-1.0.2.1 to enhance rs232 "break" support Date: Fri, 23 Aug 2002 12:04:31 -0400 Sender: linux-msdos-owner@vger.kernel.org Message-ID: <3D665D0F.ECAD81E5@marky.com> References: <20020823021342.K43474@tesla.madscientistroom.org> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: List-Id: Content-Type: text/plain; charset="us-ascii" To: Randy Thelen Cc: marky@magmacom.com, ag115@freenet.carleton.ca, linux-msdos@vger.kernel.org Hi! Thanks, but I stopped working on DOSEMU years ago -- so I'm going to forward this to the Linux-MSDOS mailing list: linux-msdos@vger.kernel.org Glad you're enjoying the software! Randy Thelen wrote: > > Hi Mark! > > My name is Randy Thelen and I've hacked on src/base/serial/ser_ports.c > for dosemu-1.0.2.1. I've added support for programs that create break > sequences on the COM ports. > > In my particular case, I've been trying to run Parallax's stamp2 > program (see http://www.parallaxinc.com/ ) for the Basic Stamp2. > The stamp2 programmer sends breaks across the rs232 line to get > the attention of the Basic Stamp. I trouble shot the problem to > a few simple changes, and I include those here for you to review > and possibly apply to other changes being considered for a rev > of dosemu. > > DosEmu is a great program and I've used it for about a year and half. > I love it! This is the best way I know to express my gratitude! > > -- Randy Thelen diff -urN dosemu-1.0.2.1/src/base/serial/ser_ports.c dosemu-1.0.2.2/src/base/serial/ser_ports.c --- dosemu-1.0.2.1/src/base/serial/ser_ports.c 2001-03-11 05:27:25.000000000 -0800 +++ dosemu-1.0.2.2/src/base/serial/ser_ports.c 2002-08-23 09:34:22.000000000 -0700 @@ -33,6 +33,7 @@ #include #include #include +#include #include "config.h" #include "emu.h" @@ -534,6 +535,34 @@ } +/* + * This function updates the msr and mcr with respect to the hardware. + * It is necessary because the hardware can change state out from under + * neath us, and some DOS code will sit and spin looking at registers + * that are alterable from a remote host. + */ +static void +get_update(int num) +{ + int control; + + ioctl(com[num].fd, TIOCMGET, &control); + + if (control & TIOCM_RTS) com[num].MCR |= UART_MCR_RTS; + else com[num].MCR &= ~UART_MCR_RTS; + if (control & TIOCM_DTR) com[num].MCR |= UART_MCR_DTR; + else com[num].MCR &= ~UART_MCR_DTR; + if (control & TIOCM_CAR) com[num].MSR |= UART_MSR_DCD; + else com[num].MSR &= ~UART_MSR_DCD; + if (control & TIOCM_RNG) com[num].MSR |= UART_MSR_RI; + else com[num].MSR &= ~UART_MSR_RI; + if (control & TIOCM_DSR) com[num].MSR |= UART_MSR_DSR; + else com[num].MSR &= ~UART_MSR_DSR; + if (control & TIOCM_CTS) com[num].MSR |= UART_MSR_CTS; + else com[num].MSR &= ~UART_MSR_CTS; +} + + /* This function returns the value in the MSR (Modem Status Register) * and does the expected UART operation whenever the MSR is read. * [num = port] @@ -543,6 +572,8 @@ { int val; + get_update(num); + val = com[num].MSR; /* Save old MSR value */ com[num].MSR &= UART_MSR_STAT; /* Clear delta bits */ com[num].int_condition &= ~MS_INTR; /* MSI condition satisfied */ @@ -568,6 +599,8 @@ { static int val; + if ((com[num].LSR & 1) == 0) sleep(1); + val = com[num].LSR; /* Save old LSR value */ com[num].int_condition &= ~LS_INTR; /* RLSI int condition satisfied */ com[num].LSR &= ~UART_LSR_ERR; /* Clear error bits */ @@ -764,6 +797,10 @@ static void put_lcr(int num, int val) { + int changed; + int control; + changed = com[num].LCR ^ val; /* Bitmask of changed bits */ + com[num].LCR = val; /* Set new LCR value */ if (val & UART_LCR_DLAB) { /* Is Baudrate Divisor Latch set? */ s_printf("SER%d: LCR = 0x%x, DLAB high.\n", num, val); @@ -779,6 +816,16 @@ com[num].DLAB = 0; /* Baudrate Divisor Latch flag */ ser_termios(num); /* Sets new line settings */ } + + /* Set or Clear Break on serial device only if Break state changed */ + if (changed & UART_LCR_SBC) { + if(s1_printf) s_printf("SER%d: LCR: SBC -> %d\n",num,(val & UART_LCR_SBC)); + control = 0; /* UNUSED for TIOCSBRK and TIOCCBRK */ + if (val & UART_LCR_SBC) + ioctl(com[num].fd, TIOCSBRK, &control); + else + ioctl(com[num].fd, TIOCCBRK, &control); + } } @@ -831,7 +878,7 @@ com[num].int_enab = (val & UART_MCR_OUT2); /* Force RTS & DTR reinitialization if the loopback state has changed */ - if (UART_MCR_LOOP) changed |= UART_MCR_RTS | UART_MCR_DTR; + if (changed & UART_MCR_LOOP) changed |= UART_MCR_RTS | UART_MCR_DTR; /* Update DTR setting on serial device only if DTR state changed */ if (changed & UART_MCR_DTR) { @@ -977,6 +1024,7 @@ break; case UART_MCR: /* Read from Modem Control Register */ + get_update(num); val = com[num].MCR; if(s2_printf) s_printf("SER%d: Read MCR = 0x%x\n",num,val); break;