EmbLogic's Blog

parallel port stpper motor via ioctl by zaffer

long scull_ioctl (struct file * filp, unsigned int cmd, unsigned long arg)
{
struct sculldev *lsculldev;
int err=0;
lsculldev=filp->private_data;

#ifdef DEBUG
printk(KERN_INFO”In %s function\n”,__func__);
#endif

#ifdef DEBUG
printk(KERN_INFO”nalue of cmd is %d\n”,cmd);
#endif

if (_IOC_TYPE(cmd) != MAGIC_NUMBER)
{
#ifdef DEBUG
printk(KERN_INFO” MAGIC value of err is %d\n”,err);
#endif
return -ENOTTY;
}
if (_IOC_NR(cmd) > STEPPER_MOTOR_MAX_NR)
{
#ifdef DEBUG
printk(KERN_INFO”STEPPER value of err is %d\n”,err);
#endif
return -ENOTTY;
}

if (_IOC_DIR(cmd) & _IOC_READ){
err = !access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd));
#ifdef DEBUG
printk(KERN_INFO” IOC_READ value of err is %d\n”,err);
#endif
}

else if (_IOC_DIR(cmd) & _IOC_WRITE){
err = !access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd));
#ifdef DEBUG
printk(KERN_INFO”IOC_WRITE value of err is %d\n”,err);
#endif
}
if (err) return -EFAULT;

switch(cmd)
{
case(MOTOR_START):
{
#ifdef DEBUG
printk(KERN_INFO”motor start\n”);
#endif
outb(0×01,DATA);
outb(0×04,DATA);
}
case(MOTOR_STOP):
{
outb(0×00,DATA);
}
case(ANTICLOCKWISE):
{
#ifdef DEBUG
printk(KERN_INFO”anticlockwise\n”);
#endif
outb(0xF1,DATA);
ssleep(300);
outb(0xF2,DATA);
ssleep(300);
outb(0xF4,DATA);
ssleep(300);
outb(0xF8,DATA);
ssleep(300);
}
case(CLOCKWISE):
{
#ifdef DEBUG
printk(KERN_INFO”clockwise\n”);
#endif
outb(0xF8,DATA);
ssleep(300);
outb(0xF4,DATA);
ssleep(300);
outb(0xF2,DATA);
ssleep(300);
outb(0xF1,DATA);
ssleep(300);
}
case(INCREASE_SPEED):
{

#ifdef DEBUG
printk(KERN_INFO”increase speed\n”);
#endif
outb(0xF8,DATA);
ssleep(30000);
outb(0xF4,DATA);
ssleep(30000);
outb(0xF2,DATA);
ssleep(30000);
outb(0xF1,DATA);
}
case(INCREASE_SPEED):
{

#ifdef DEBUG
printk(KERN_INFO”increase speed\n”);
#endif
outb(0xF8,DATA);
ssleep(30000);
outb(0xF4,DATA);
ssleep(30000);
outb(0xF2,DATA);
ssleep(30000);
outb(0xF1,DATA);
ssleep(30000);
}

case(DECREASE_SPEED):
{
#ifdef DEBUG
printk(KERN_INFO”decrease speed\n”);
#endif

outb(0xF8,DATA);
ssleep(3);
outb(0xF4,DATA);
outb(0xF2,DATA);
ssleep(3);
outb(0xF1,DATA);
ssleep(3);
}
default:
{

#ifdef DEBUG
printk(KERN_INFO”value of cmd is %d\n”,cmd);
#endif

}
}

return 0;
}
……………..
when i press any no it reflects the same no in the ioctl but when it goes in switch case the value of cmd is something 0 ………plz explain…..i tested on 2 systems but same result

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>