Sponsored Content
Operating Systems SCO Any device driver sample for SCO ?! Post 302505033 by k.a.docpp on Wednesday 16th of March 2011 11:32:44 AM
Old 03-16-2011
@lilezek : I think there are some differences between them. Smilie In linux you create a module and load it into kernel space using the 'insmod' command. but there is no such command in unix, as far as I know in sco. You should write your driver and compile it as an object file , put the object file in the directories below /etc/conf and next relink the kernel. I guess there should be some differences in driver overall template. The rest is common between them , yeah both of them use file system to create callbacks between kernel space and user space.
@jgt : Thnx , yes you're right , I don't know if I place the source code in appropriate directories the kernel gets linked but it doesn't matter Smilie I have no sample for a driver written in unix. I think the overall structure for a C written driver is different in unix and linux. I say this based on some linux drivers I've seen before and the sample driver on aplwarence website. I need the template more than anything , the rest can be tested many times Smilie Thnx any way Smilie

---------- Post updated at 10:32 AM ---------- Previous update was at 01:42 AM ----------

This is a sample for a prallel port I've found on the net but unfortunately I can't compile it. I wanna use cc to compile this file , as you can see in the comments.
Any help on this ??!

You can see the actual page here : http://aplawrence.com/Unix/driver.html

Code for Drvier.c :

Code:
 /* Debugging Driver for parallel printer port.
Copyright Anthony Lawrence 10/7/93
Lawrence & Clark, Inc
(617) 762-0707  (206) 323-2864

NOT a drop-in replacement for SCO's lp driver!
Includes ioctl calls to examine & set driver variables.
You can speed it up, slow it down, and generally tune
it to the conditions at hand.  The debugging mode gives
you the clues when something is wrong, and "lp2status"
lets you play.

Does not include the stty's that SCO supports!
Developed and tested on a Dell 486 running 3.2v4.0
To compile and link:

cc -c -Zp4 -K -M3 -DINKERNEL Driver.c
cp Driver.o /etc/conf/pack.d/lp2
cd /etc/conf/cf.d
./link_unix

Yoy will need an entry in /etc/conf/cf.d/mdevice:

lp2     ocIwi   icH             lp2     0       84      1       3       -1

(you can modify the "lp" entry for this purpose)

and in /etc/conf/sdevice.d/lp2:

lp2     Y       1       2       4       7       378     37f     0       0

And of course if your printer is *not* at 378 or at interrupt 7,
you need to change a few things.

The corresponding sdevice entry for "lp" should be marked "N"

Minor node 0 is non-DeBugging.
Minor node 129 is for ioctl; see "lp2status.c".
Minor nodes 1-3 are for DeBugging; 1 is the lowest level, 3 is the highest

(note that when a driver uses printf, as this does in DeBug mode, all output 
is also written to /usr/adm/messages.)


Great fun to play with, and I have been using it for a long time now
as my normal parallel driver, but your mileage may vary, so caveat emptor
and cover your butt and all the other warnings.  This is, after all,
a driver, and in (more than) theory, has the potential to muck your
system up pretty well.  Read and understand *all* the code before
implementing.


Tony

*/
#include <sys/param.h>
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/signal.h>
#include <sys/dir.h>
#include <sys/user.h>
#include <sys/tty.h>
#include <sys/sysmacros.h>
#include <sys/file.h>
#include "lp2status.h"


#define LPPRI PZERO+5

#define LPBASE 0x378
#define LPDATA (LPBASE + 0)
#define LPSTAT (LPBASE + 1)
#define LPCTRL (LPBASE + 2)

#define LPNERR 0x08
#define LPON   0x10
#define LPRDY  0x80

#define LPSTRB 0x01
#define LPLF   0x02
#define LPINIT 0x04
#define LPSEL  0x08
#define LPIENB 0x10

#define TRUE 1


static unsigned short Lpflags=0;
static struct clist Lpqueue;
unsigned short DeBug=0;
unsigned short Ccount=0;
unsigned short Icount=0;
unsigned short spindowns=0;
unsigned short wsleeps=0;
unsigned short spinloop=100;

int Low_water=50;
int Highwater=250;
int Wait_int=HZ/10;

void printflags(char *message);

lp2init()
{
int x=0;
outb(LPCTRL,0);
if ((x=inb(LPCTRL)) != 0xe2)
        {
        printf("Line printer not found!!( %x )!!\n",x);
        return;
        }
outb(LPCTRL,0xfe);
if ((x=inb(LPCTRL)) != 0xfe)
        {
        printf("Line printer not found!!(2: %x )!!\n",x);
        return;
        }
/* These tests work on my particular machine, but you may need
 to modify for your port.  Actually, since the primary purpose
 is debugging, you might even take them out and just assume the
 port is there... */

outb(LPCTRL,0);
printf("Found Line printer at %x\n",LPBASE);
Lpflags=LPEXIST;
}

lp2open(dev,flags,otype)
dev_t dev;
int flags,otype;
{
DeBug=(minor(dev));
Icount=0;
Ccount=0;
spindowns=0;
wsleeps=0;

/* minor #129 is for ioctl, so we don't concern ourselves
   with any error conditions */

if ((Lpflags & LPEXIST) == 0 && DeBug != 129)
        u.u_error = ENODEV;
else if (Lpflags & EXCLOPEN && DeBug != 129)
        u.u_error=EBUSY;
else if (Lpflags & OPEN && DeBug != 129)
{
if (flags & FEXCL)
        u.u_error=EBUSY;
}
else
{
/* again, if doing ioctl, we don't want to mess with anything */
if (DeBug != 129)
        {
        outb(LPDATA,0);
        outb(LPCTRL,LPLF | LPINIT | LPSEL);
        Lpflags |= OPEN;
        if (flags & FEXCL)
         Lpflags |= EXCLOPEN;
        }

}
/* reset if ioctl as nothing else will be called anyway.  If you
   want to, you can reset debug anyway with the ioctl call */
   
if (DeBug == 129)
   DeBug=0;
if (DeBug)
 printflags("Open:");
}

lp2close(dev,flags,otype)
dev_t dev;
int flags,otype;
{
int x;
x=spl5();
while (Lpflags & LPBUSY)
{
Lpflags |= WAIT;
if (DeBug > 1)
 printflags("Sleeping in lp2close");

sleep(&Lpflags,LPPRI);
}
Lpflags=LPEXIST;
outb(LPCTRL,0);
splx(x);
if (DeBug)
 {
 printflags("Close:");
 printf("Close: Interrupts %d\n Characters %d\n Spindowns %d\n Sleeps in lp2write %d\n",Icount,Ccount,spindowns,wsleeps);
 }

}

lp2write(dev)
dev_t dev;
{
char c;
int x;
extern void lpwork();
while (u.u_count)
{
if (copyin(u.u_base, &c,1) == -1)
{
u.u_error=EFAULT;
return;
}
u.u_base++;
u.u_count--;

while (Lpqueue.c_cc > Highwater)
{
x=spl5();
lpwork(0);
if (Lpqueue.c_cc > Highwater)
{
wsleeps++;
if (DeBug > 1)
 printflags("Sleeping in lp2write");

Lpflags |= SLEEP;
sleep(&Lpqueue,LPPRI);
}
splx(x);
}
putc(c, &Lpqueue);
}
x=spl5();
lpwork(0);
splx(x);
}

static void lpwork(where)
int where;
{
int ch;
extern void lprestart();
unsigned short spins=spinloop;

Lpflags |= LPBUSY;

while(1)
{
while (((inb(LPSTAT) & (LPNERR | LPON | LPRDY)) != (LPNERR|LPON|LPRDY)) && --spins) ;
if (spins == 0)
 {
 spindowns++;
 if (DeBug > 2)
   printflags("Spundown"); 
 break;
 }
if ((ch=getc(&Lpqueue)) < 0)
 break;
outb(LPDATA,ch);
Ccount++;
outb(LPCTRL,LPSTRB | LPLF | LPINIT | LPSEL);
outb(LPCTRL,         LPLF | LPINIT | LPSEL);
}
if( Lpqueue.c_cc < Low_water && (Lpflags & SLEEP))
{
        Lpflags &= -SLEEP;
        if (DeBug > 2)
           printflags("Wakeup call");
        wakeup(&Lpqueue);
        
}
if (Lpqueue.c_cc <= 0)
{
Lpflags &= ~LPBUSY;
if (Lpflags & WAIT)
      {
        if (DeBug > 2)
           printflags("Wakeup call");
        wakeup(&Lpflags);
       }
}
else if ((Lpflags & TOPEND) == 0)
{
        if (DeBug > 2)
           printflags("Setting Timeout");
        timeout(lprestart,0,Wait_int);
        Lpflags |= TOPEND;
}
outb(LPCTRL,LPLF | LPINIT | LPSEL | LPIENB);
}


lp2intr(dev)
dev_t dev;
{
Icount++;
if (DeBug > 2)
  printflags("Got interrupt");

if ((Lpflags & LPBUSY) == 0)
        return;
if (Lpqueue.c_cc > 0)
  lpwork(1);
}
static void lprestart()
{
int x;
if (DeBug > 2)
  printflags("Restarting");
Lpflags &= ~TOPEND;
x=spl5();
lpwork(0);
splx(x);
}

void printflags(char *message)
{
printf("(%d) %s",DeBug, message);
if (Lpflags & LPEXIST)
    printf(" LPEXIST");
if (Lpflags & SLEEP)
    printf(" SLEEP");
if (Lpflags & LPBUSY)
    printf(" LPBUSY");
if (Lpflags & WAIT)
    printf(" WAIT");
if (Lpflags & TOPEND)
    printf(" TOPEND");
if (Lpflags & EXCLOPEN)
    printf(" EXCLOPEN");
if (Lpflags & OPEN)
     printf(" OPEN");
printf("\n");

}
int lp2ioctl(dev_t dev, int cmd, struct lp2 *arg, int mode)
{
static short read_it=0;

/* we're enforcing must_read_before_write here, just to keep
   from screwing up too badly :-) */

switch (cmd-MAGIC)
   {
   case 0: 
        arg->Lpflags=Lpflags;
        arg->DeBug=DeBug;
        arg->Ccount=Ccount;
        arg->Icount=Icount;
        arg->spindowns=spindowns;
        arg->wsleeps=wsleeps;
        arg->spinloop=spinloop;
        arg->Low_water=Low_water;
        arg->Highwater=Highwater;
        arg->Wait_int=Wait_int;
        read_it=1;
        break;
   case 1:
     if (read_it)
        {
        /* Lpflags=arg->Lpflags; */
        DeBug=arg->DeBug;
        Ccount=arg->Ccount;
        Icount=arg->Icount;
        spindowns=arg->spindowns;
        wsleeps=arg->wsleeps;
        spinloop=arg->spinloop;
        Low_water=arg->Low_water;
        Highwater=arg->Highwater;
        Wait_int=arg->Wait_int;
        break;
        }
      read_it=0;
    }
        
}


     }
  }
}


Last edited by pludi; 03-16-2011 at 12:53 PM..
 

4 More Discussions You Might Find Interesting

1. Solaris

SUNWglmr -- rasctrl environment monitoring driver for i2c or SCSI device driver ?

I've been researching minimizeing Solaris 8 and found that on the web page http://www.sun.com/bigadmin/content/packagelist/s8u7PkgList/p2.html the package SUNWglmr is listed as "rasctrl environment monitoring driver for i2c, (Root) (32-bit)" while in the document "Solaris 8 minimize-updt1.pdf"... (1 Reply)
Discussion started by: roygoodwin
1 Replies

2. UNIX for Advanced & Expert Users

help regarding device driver

Hi All, I have a device driver that uses UARTserial port to write/read to-from a device. That device driver is working fine on FC3 machine( kernel version 2.6.12)... Now I am switching to FC9 (kernel version 2.6.25.11-97).I have changed the interrupt flag SA_INTERRUPT to IRQF_DISABLED... (0 Replies)
Discussion started by: rajuprade
0 Replies

3. Programming

regarding device driver

Hi All, I have a device driver that uses UARTserial port to write/read to-from a device. That device driver is working fine on FC3 machine( kernel version 2.6.12)... Now I am switching to FC9 (kernel version 2.6.25.11-97).I have changed the interrupt flag SA_INTERRUPT to IRQF_DISABLED... (0 Replies)
Discussion started by: rajuprade
0 Replies

4. UNIX for Advanced & Expert Users

SCSI Command Sample Driver

Can anybody get me some sample driver code of linux block drivers to send request to scsi disks? Basically I need a sample code of linux scsi block driver. I tried googling for sample code but did not find it. (1 Reply)
Discussion started by: rupeshkp728
1 Replies
All times are GMT -4. The time now is 05:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy