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

MiNT device drivers



I'm trying to write a device driver for my new external keyboard. This is
a DEC LK201 which outputs key scan codes on a serial interface.

What the driver basically has to do is:

1) read and convert DEC key scans from the serial port and make them ready
for reading.

2) take characters written to it and echo them to the console.

Anyway does that sound right? Alternatively is there an easier way to do
it without having to go to the trouble of writing a complete driver? So
far I've written the main chunk of code which reads and converts DEC key
scans, and outputs ASCII on stdout.

I have half written a driver for FCON: which is suposed to duplicate the
standard CON: device. Its main problem is that it doesn't block if there
are no characters waiting to be read. According to The Atari Compendium,
returning 0L from select() should cause the process to block until
characters are available. I also check for blocking in ioctl() which I
suppose should help.

Another thing thats not clear is how I supposed to wake up processes once
they have been blocked. I understand I need to call wakeselect(), but where
from? I don't see how the device driver gets any CPU time if only one
process is using it, and its blocked. BTW I had a quick look at Thierry
Bousch's modm0dev. There the solution seems to be an interupt routine on
the 200ms clock. This seems a bit complicated - is it the correct solution?

Finally, although my driver accepts characters and echos them to the console
it seems to do it in RAW mode.eg:

ls -l > /dev/fcon

produces output with LFs but no CRs. Howver doing the same on /dev/con works
fine. Am I right in assuming I should be looking up the mode of the terminal
and doing the correct conversions?

Anything else I need to watch out for at this point?

Anyway here are my ioctl() and select() functions. I know the're very
simplistic ;-), but I need some advice. Also would anybody be willing to look
at the complete driver? Some knowledgeable help now could save me weeks
of time!

Thanks

:-)

Roland.

@CiX


static long
fcon_ioctl(f, mode, buf)
FILEPTR *f; int mode; void *buf;
{

int num = 0;

if (mode == FIONREAD){
if (BCONSTAT(2)){
num=1;
}
*((long *)buf) = num;
return(0);
}
if (mode == FIONWRITE){
if (BCOSTAT(2)){
num=1;
}
*((long *)buf) = num;
return(0);
}
 return(EINVFN);
}


static long
fcon_select(FILEPTR *f, LONG proc, WORD mode)
{
long ret = 0L;

if (mode == O_RDONLY){
if (BCONSTAT(2)){
ret=1L;
}
return(ret);
}
if (mode == O_WRONLY){
if (BCOSTAT(2)){
ret=1L;
}
return(ret);
}
 return(EINVFN);
}