Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 09 Mar 1999 13:06:29 +0200
From:      Oleg Yurkovsky <oleg@allonge.com.ua>
To:        freebsd-questions@FreeBSD.ORG
Subject:   RS-485 Support
Message-ID:  <36E500B4.2D2040FC@allonge.com.ua>

next in thread | raw e-mail | index | archive | help
Hi.

My name is Oleg, I'm from Kiev, Ukraine.

I'm developer for embedded FreeBSD (PicoBSD) system,
based on OCTAGON 5066 CPU.

I need in RS-485 driver for industry solution.
I have to switch between transmitting/receiving by RTS signal.

I'm use the next code fragment

  int    mcs = TIOCM_RTS;
  ioctl(fd, TIOCMBIS, &mcs)

  write(fd, buf, buf_len);

  ioctl(fd, TIOCMBIC, &mcs)

But there is a problem: I have to clear RTS exactly after shift register
of UART is empty.
In other words, I have to wait after write() call before last ioctl()
until Line Status Register of UART (base+0x05), bit 6 (0x40) is set.

But in user address space, I haven't privilege level to read IO port.
The simplest, but not the safe solution for this problem, offered by
Linux serial driver.
Linux kernel have an additional ioctl() call TIOCSERGETLSR, which return

relevant status.

Therefore, I have modified sio driver, with support for additional
ioctl() call,
say TIOCLSRGET.
This call is simply return one byte value of IO port (base+0x05).
And now, I can add the next delay loop after write() call:

do {
    if (ioctl(fd, TIOCLSRGET, &s) == -1) {
        perror("ioctl: get LSR");
        break;
    }
} while((s & 0x40) == 0);

This code works quite well, but sometime (very seldom) invalid response
from RS-485
device was occurred.
The small part of response is lost, only from beginning of response.
The problem is in delay due to task switching in UNIX (this is my
opinion).

Therefore, I need support from sio driver to control RTS line during
write() call.

Btw, different implementations of RS-485 interface are generally use DTR
or RTS line
to perform TRANSFER/RECEIVE switching.

Thank for pay attention for my request.

Best regards.
Oleg.




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?36E500B4.2D2040FC>