Hey Luc

that's great, can you send me the patch for the serial driver?

Many Thanks
Clemens

Luc Hermans wrote:

> Best Clemens,
>
> I've posted this problem before
> here some history
> If you want my solution (described below) I will be happy to give it.
>
> Best Regards,
> Luc
>
> Luc Hermans wrote:
> >
> > > From:                   Luc Hermans <[EMAIL PROTECTED]>
> > > > Hi,
> > > > In my embedded linux application I've written a modbus interface (RS485)
> > > > on /dev/ttyS1 (cfmakeraw) the RTS is used to enable/disable the RS485
> > > > driver.
> > > >
> > > > I use the  ioctl(fd[c], TIOCMSET, &status)  fucntion.to change RTS'
> > > >
> > > > Before sending I enable RTS, send all data, (the RS485 echo's all)
> > > > wait until all data is received,  and then disable RTS.
> > > >
> > > > The problem is that the RTS is sometimes dropped to slow, up to 5ms,
> > > > witch is to long (because I get an answer from the polled device withing
> > > > 3ms)
> > > > but sometimes also fas, lesser then 500us.
> > > >
> > > > What is the cause of this ?
> > > > I work with an i386 40MHz cpu at 9600 baud
> > >
> > > Interupt latency and kernel to application latency...
> > >
> > > This is the biggest pain in the butt with RS-485. After you send your
> > > data you need to flip the direction of the transceivers. The hardware
> > > that people try to use for RS-485, is pretty strapped to do the job
> > > correctly (ie in hardware).
> > >
> > > Basically if you want any chance of making this work you will need to
> > > handle the ISR yourself and you need to flip the direction control
> > > (aka RTS) in the ISR. Note: You can NOT use the transmit interrupt to
> > > do the flipping because the TX ISR will happen when the last byte
> > > begins to shift out of the UART, not when it's finished shifting
> > > out!!  The way most people handle this is to listen to what you are
> > > transmitting, and flip when you receive your last byte.
> > >
> > > So we are to the point where you are going to rewrite the serial port
> > > driver. That shouldn't be too bad since it's just a minor mod.
> > >
> > > The good news here is it's a lot easier to write a driver for Linux
> > > than it is for say, Micros~1 windows.
> > >
> > > But you still have the problrm of interrupt latency. You're new
> > > driver, although it works a lot better, will still NOT be bullet
> > > proof. Why... because you are still at the mercy of ethernet and
> > > harddrive drivers that may disable interrupts for longer than you're
> > > maximum letency requirement of 500uS.
> > >
> > > To get around this you might want to look at the RT-Linux stuff. With
> > > that you can make you RS-485 ISRs top dog in the processing chain.
> > >
> > > http://www.rtlinux.org/~rtlinux/
> > >
> > > Good luck...
> > >
>
> For Real-time capability on Linux, you will also want to check out the
> RTAI derivative of rtlinux (which offers many enhanced features) at:
> http://server.aero.polimi.it/projects/rtai/index.html
> with a short descriptive document at:
>
> http://www.zentropix.com/support/document/helpdox/rtai.pdf
>
> Also, the www.realtimelinux.org site includes links and documentation to
> all of the known real-time linux alternatives.
>
> -dave
>
> > > Hey by the way, MODBUS ???  That sounds like industrial automation,
> > > PLC stuff right. I've been watching with anticipation for a while and
> > > so far your one of the first that I've seen playing with Linux in
> > > that arena. I'm happy to see that not everyone in the industrial
> > > automation world is in bed with WinCE. Have you ever done anything
> > > with DeviceNet?
> > >
> > > -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
> > > -_ Gary A James
> > > -_ Critical Link, LLC         Voice:  315.425.4045 x218
> > > -_ 404 Oak St.                Fax:    315.425.4048
> > > -_ Syracuse, NY 13203
> > > -_
> > > -_ E-Mail: [EMAIL PROTECTED]
> > > -_ WEB:    http://www.criticallink.com
> > > -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
> > > -_          __   _
> > > -_ Try...  / /  (_)__  __ ____  __
> > > -_        / /__/ / _ \/ // /\ \/ /
> > > -_       /____/_/_//_/\_,_/ /_/\_\  http://www.linux.org
> > > -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
> >
> > Hi Thanks all for your tips
> >
> > I have solved this problem by modifying the driver serial.c,serial.h, ioctls.h
> >
> > and add a new ioctl( TIOCMRTSOFF, x) call which tells serial.c to
> > swtich RTS off after receiving x chars. (done in the ISR)
> > This works the following way ex. sending a command of 10 chars.
> >
> >     - put RTS on (RS485 tx enable)    ioctl( TIOCMSET)
> >     - call ioctl( TIOCMRTSOFF, 10) if I had to send a command of 10 chars
> >     - write ( the 10 data chars)
> >    - after  the 10 chars are echoed (because the RS485 receiver is allways
> > enabled)
> >       the RTS will automaticly switch off.
> >
> > I you want this modification I will be happy to give it.
> >
> > Luc


--
To unsubscribe from this list, send a message to [EMAIL PROTECTED]
with the command "unsubscribe linux-embedded" in the message body.
For more information, see <http://waste.org/mail/linux-embedded>.

Reply via email to