Using ioctl to access a real-time clock in Linux

In our preceding recipes, we used MMIO to access peripheral devices from user-space Linux applications. This interface, however, is not the recommended way of communication between user-space applications and device drivers.

In Unix-like operating systems such as Linux, most of the peripheral devices can be accessed in the same way as regular files using so-called device files. When an application opens a device file, it can read from it, fetching data from the corresponding device, or write to it, sending data to the device.

In many cases, device drivers cannot work with unstructured data streams. They expect data exchange organized in the form of requests and responses, where each request and response has a specific and fixed format.

This kind of communication is covered by the ioctl system call. It accepts a device-dependant request code as its parameter. It may also contain other parameters that encode the request data or provide storage for the output data. These parameters are specific to a particular device and request code.

In this recipe, we will learn how to use ioctl in user-space applications for data exchange with device drivers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.71.237