Specifications
Comedi
147 / 148
6.5 Device driver caveats
A few things to strive for when writing a new driver:
• Some DAQ cards consist of different ‘layers’ of hardware, which can each be given their own device driver. Examples are:
some of the National Instruments cards, that all share the same Mite PCI driver chip; the ubiquitous parallel port, that can be
used for simple digital IO acquisitions. If your new card has such a multi-layer design too, please take the effort to provide
drivers for each layer separately.
• Your hardware driver should be functional appropriate to the resources allocated. I.e., if the driver is fully functional when
configured with an IRQ and DMA, it should still function moderately well with just an IRQ, or still do minor tasks without
IRQ or DMA. Does your driver really require an IRQ to do digital I/O? Maybe someone will want to use your driver just to do
digital I/O and has no interrupts available.
• Drivers are to have absolutely no global variables (apart from read-only, constant data, or data structures shared by all devices),
mainly because the existence of global variables immediately negates any possibility of using the driver for two devices. The
pointer dev->private should be used to point to a structure containing any additional variables needed by a driver/device
combination.
• Drivers should report errors and warnings via the comedi_error() function. (This is not the same function as the user-space
comedi_perror() function.)
6.6 Integrating the driver in the Comedi library
For integrating new drivers in the Comedi’s source tree the following things have to be done:
• Choose a sensible name for the source code file. Let’s assume here that you call it ‘mydriver.c’
• Put your new driver into comedi/drivers/mydriver.c.
• Edit comedi/drivers/Makefile.am and add mydriver.ko to the module_PROGRAMS list. Also add a line
mydriver_ko_SOURCES = mydriver.c
in the alphabetically appropriate place.
• Run ./autogen.sh in the top-level comedi directory. You will need to have (a recent version of) autoconf and automake installed
to successfully run autogen.sh. Afterwards, your driver will be built along with the rest of the drivers when you run make.
• If you want to have your driver included in the Comedi distribution (you definitely want to :-) ) send it to the Comedi mailing
list for review and integration. See the top-level README for details of the Comedi mailing list.) Note your work must be
licensed under terms compatible with the GNU GPL to be distributed as a part of Comedi.
7 Glossary
Application Program Interface (API)
The (documented) set of function calls supported by a particular application, by which programmers can access the func-
tionality available in the application.
buffer
Comedi uses permanently allocated kernel memory for streaming input and output to store data that has been measured by
a device, but has not been read by an application. These buffers can be resized by the Comedilib functions comedi_se-
t_buffer_size() and comedi_set_max_buffer_size() or the comedi_config utility.
buffer overflow
This is an error message that indicates that the driver ran out of space in a Comedi buffer to put samples. It means that the
application is not copying data out of the buffer quickly enough. Often, this problem can be fixed by making the Comedi
buffer larger. See comedi_set_buffer_size() for more information.