linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christer Weinigel <christer@weinigel.se>
To: Andy Parkins <andyparkins@gmail.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: tcdrain / TCSBRK / wait_until_sent delay
Date: 09 May 2005 11:15:43 +0200	[thread overview]
Message-ID: <m3br7klpz4.fsf@zoo.weinigel.se> (raw)
In-Reply-To: <200505051650.38471.andyparkins@gmail.com>

Andy Parkins <andyparkins@gmail.com> writes:

> I wonder if anyone can help me with this as a problem?  I'm trying to send 
> commands to a device along a two wire RS485 connection.  I'm using an RS232 
> to RS485 converter that changes the buffer direction based on RTS.  With that 
> in mind I therefore do things like (error detection left out for brevity)
> 
>       ______________________________________
> RTS __|                                    |_____
>        _____ ___ ___ ___
> TXD ___|   |_| |_| |_| |_________________________
>         S 1 0 1 0 1 0 1 0 s
>                            <-----delay---->
> 
> There is a small delay between RTS going high and the data starting - no 
> problem there, however, when the transmission finishes there is a 2 byte 
> delay before RTS goes low.  The device I'm talking to has (apparently) a 
> response time of 200us; I'm seeing a delay before restoration of RTS of 2ms. 
> write() returns immediately - the delay is coming from tcdrain() - but I 
> cannot see from where.

As others have told you, the granularity of HZ in the stock Linux
kernel isn't good enough to give you a 200us RTS shutoff.  What you
should be able to do is something like this:

    usigned int lsr;

    bit = TIOCM_RTS;
    ioctl( fd, TIOCMBIS, &bit );

    do {
        ioctl(fd, TIOCSERGETLSR, &lsr);
    } while (lsr & TIOCSER_TEMT);

    ioctl( fd, TIOCMBIC, &bit );

This will busy wait until the transmitter is empty.  It's wasteful,
but it'll probably work.  Remember to add error checking to the above
code, and you may want to run it with a realtime priority when you've
seen that it works.

  /Christer

-- 
"Just how much can I get away with and still go to heaven?"

Freelance consultant specializing in device driver programming for Linux 
Christer Weinigel <christer@weinigel.se>  http://www.weinigel.se

  parent reply	other threads:[~2005-05-09  9:15 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-05 15:50 tcdrain / TCSBRK / wait_until_sent delay Andy Parkins
2005-05-05 17:51 ` rich+ml
2005-05-06  8:01   ` Andy Parkins
2005-05-06 19:14     ` rich+ml
2005-05-07  9:35       ` Andy Parkins
2005-05-07 18:09         ` rich+ml
2005-05-09  8:01           ` Andy Parkins
     [not found]             ` <Pine.LNX.4.58.0505090825470.750@deadrat.localdomain>
2005-05-10  7:44               ` Andy Parkins
2005-05-09  8:16         ` Tosoni
2005-05-09  8:59           ` Russell King
2005-05-09 10:03             ` Tosoni
2005-05-09 10:13               ` Russell King
2005-05-09 15:43                 ` Theodore Ts'o
2005-05-07 10:32       ` Gerald Emig
2005-05-09  9:15 ` Christer Weinigel [this message]
2005-05-09  9:22   ` Christer Weinigel
2005-05-09 11:05     ` Andy Parkins
2005-05-09 15:53     ` Andy Parkins
2005-05-09 19:45     ` rich+ml

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3br7klpz4.fsf@zoo.weinigel.se \
    --to=christer@weinigel.se \
    --cc=andyparkins@gmail.com \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).