[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: off topic - Assembler using GCC



> In a message dated 2/3/99 12:54:34 PM Central Standard Time,
> d.wright@open.ac.uk writes:
> 
> > That's just not possible with a multi-user multi-tasking OS,
> >  particularly one like unix which has to present the same abstract
> >  model on completely different hardware.
> >  
> >  If one program "messes with" interrupts, how is any other program
> >  meant to perform its function when it doesn't know what the first
> >  one did?
> 
> I'm not replying to be argumentative, but I am curious about this...
> 
> I suppose there are cases where this is valid, but for my original point about
> communciations - it just isn't feasible to use IRQ4 (the first comm port) by
> more than one program concurrently, is it?  
> 
Of course not - only one program can use one particular serial device at a 
time.

> In my case, I had reprogrammed IRQ4 so when a char came in from the modem, I
> could stuff it to a buffer for use later on, and send data to the buffer (and
> ultimately use the IRQ to send it back out again when the buffer was full)
> when I had my reply ready.  
Linux has device drivers doing this for you already!  No problem!
The device drivers handles irq's, io-addresses and buffering.  
A linux program simply open a serial device as if it were a file
and reads from it and writes to it using normal stuff like
fread(), fwrite(), fprintf() etc.  
It can't get much simpler than that.  This approach is even possible
under msdos [i.e. fopen("COM1:", "w+")] but it is usually not done that
way because the dos serial driver suck badly.  

The linux serial driver is good, so messing with irq's is simply
not necessary.  Just do a fopen("/dev/ttyS0", "w+") and use the file handle.
Take a look at the sources for various linux comm programs such
as minicom if you want details on how to do this.

> I certainly wouldn't want another program taking
> chars from my modem while I'm using it.

fopen() will simply fail for other programs trying to use
the device while you use it.  "device or resource busy".
No problem at all.
> 
> How would you accomplish the same in Linux without using interrupt routines?
See above.

Using device drivers has lots of other advantages too:
You can run several serial programs (each using different ports of course)
simultaneously.  Try that with dos.  
And you don't need to change your program if
you get one of those high-performance multi-port cards - all you need
is to open a different device.  The fact such cards has a very different
hardware implementation (all ports share the same irq, different registers...)
is something your program don't need to worry about.  That's the 
serial driver's responsibility.

Helge Hafting





Reply to: