Using the Kernel Driver

Use of the drives will be illustrated by a simple sequence of shell commands in Listing 25.19. There is also a sample C program on the CD-ROM that will execute several moves and then read back the position.

Listing 25.19 Driver Use

# make the devices (once) mknod /dev/stepper c 31 0 mknod /dev/stepper_ioctl c 31 1

#load the driver sync; insmod ./stepper.o port=0x378

#give it something to do cat "X=100,Y=100,Z=100" >/dev/stepper cat "X=300,Y=300,Z=300" >/dev/stepper cat "X=0,Y=0,Z=0" >/dev/stepper

#unload driver sync; rmmod stepper.o

Various variables can be set to modify the operation of the driver. In usermode only, the variable delay sets the number of microseconds to sleep between moves; if fastdelay is set, a delay loop of the specified number of iterations will be used instead. In kernel mode, skipticks can be used to slow movement down by skipping the specified number of timer ticks between moves. The variable debug sets the amount of debugging information printed. The variable verbose_io, if nonzero, will cause a debugging message to be printed each time outb() is called. The variable verbose_move, if nonzero, will cause a

Chapter 25

debugging message to be printed each time the motor(s) are moved. If either verbose_io or verbose_move is set for a kernel mode driver, use a value for skipticks to reduce the rate at which printk() is called. The variable base sets the I/O port address of the parallel interface to use; the values 0x3BC, 0x378, and 0x278 are the most common. If power_down_on_exit is set to a nonzero value, the motors will be shut down when the usermode program exits or the kernel module is removed. The variable do_io, if set to zero, will disable the outb() calls, allowing experimentation (with verbose_io and/or verbose_move set) without a free parallel port. Some of these variables may also be set via ioctls.

Note

If the driver is issuing a large number of printk()s, you may need to type a rmmod stepper command blindly because the kernel messages will cause the shell prompt and input echo to scroll off the screen.

Note that the parallel port must not be in use by another device driver (such as lp0). You may need to unload the printer module or boot the system with the reserve=0x378,4 option at the boot prompt. If you are trying to use interrupts and are having trouble, check for conflicts with other devices (the interrupts on printer cards are usually not used for printers) and check your bios to make sure it is not allocated to the PCI bus instead of the ISA bus or motherboard.

Was this article helpful?

0 0
The Ultimate Computer Repair Guide

The Ultimate Computer Repair Guide

Read how to maintain and repair any desktop and laptop computer. This Ebook has articles with photos and videos that show detailed step by step pc repair and maintenance procedures. There are many links to online videos that explain how you can build, maintain, speed up, clean, and repair your computer yourself. Put the money that you were going to pay the PC Tech in your own pocket.

Get My Free Ebook


Post a comment