This site will look much better in a browser that supports webstandards , but it is accessible to any browser or Internet device.

Professional Hardwarenear Programming

Linux Driver

© 2009 Peter Thoemmes, 2009-06-16

For developing a Linux kernel driver I go the same way I develop a real-time operating system for an embedded system or a server application for a distributed system or a client application for a remote control system: I do absolutely strict layering. Strict layering means two things:

First of all each header module (.h) does declare exactly one implementation module (.c). Yes this is possible and it is good. If the implementation grows too big, then I may think about a split, which will end up in one more header (.h) and one more implementation file (.c).

Second point is the most important rule of my strict layering: each implementation (.c) and header (.h) can ONLY include headers (.h) from layers below. Any header of the same layer or any layer above are forbidden to be included. Any header from any layer below can be included. There is absolutely NO exclusion from this rule - NEVER!

Layering is done for two projects: for the kernel driver and for the user space application. Both will see a common shared layer on the lowest level: the kernel driver's API.

+-------------------------------+ Layer 3 | CIRCUIT | +-------------------------------+ | | | +-------+ +-------+ +-------+ +--------------------------+ Layer 2 | PART0 | | PART1 | ... | PARTN | | Application | +-------+ +-------+ +-------+ +--------------------------+ | | | | +-------------------------------+ +--------------------------+ Layer 1 | GENERIC DEVICE | | API WRAPPER | +-------------------------------+ +--------------------------+ | | +---------------------------------------------------------------+ Layer 0 | KERNEL DRIVER API | +---------------------------------------------------------------+