Usleep drv
From GumstixDocsWiki
This page presents usleep-drv, a simple kernel module which allows user mode code to utilitze microsecond delays.
Normally, the user mode code could call usleep, but some versions of the kernel only have jiffy resolution (i.e. 10 milliseconds) on this function call.
The usleep-drv module uses an ioctl interface to allow for the kernel mode udelay call to be employed.
Source Files
* usleep-drv.h * usleep-drv.c * usleep-test.c * Makefile
The Makefile assumes that you create a directory parallel to the gumstix-buildroot (i.e. on my system, gumstix-build root can be found at /home/dhylands/gumstix/gumstix-buildroot, so for the usleep-drv example, I'd create /home/dhylands/gumstix/usleep-drv).
Once you've copied source files into the usleep-drv directory, type
make
and the usleep-drv.ko and usleep-test files will be built. Copy both of these file onto the gumstix and use the command:
insmod directory-path/usleep-drv.ko
insmod requires a path to the actual .ko file. A simpler method is to use modpobe, which will also cause any modules that your modules depends on to also be loaded. To use modprobe, copy your usleep-drv.ko file in /lib/modules/2.6.21gum/some-directory. The 2.6.21gum portion will change depending on the version of kernel and exact options selected. It's important that the module be located in a directory under the 2.6.21gum directory (you can create your own). Then type:
/sbin/depmod -a modprobe usleep-drv
The depmod step is normally done as part of booting and only needs to be done when a new module is copied onto the gumstix.
To get your module to load automatically every time the gumstix boots, add a line to the /etc/modules file containing the name of the module as you would pass it to modprobe.
See the Resources section of the Kernel programming page for additional information on writing kernel modules.
Testing the usleep-drv
The usleep-test program can be used to test the usleep-drv module.
usleep-test delay-time num-iterations
will issue the appropriate ioctl call num-ieterations times, and each time will delay for delay-time microseconds. The elapsed time to perform these delays will them be printed.

