Linux Device Control Interface
A basic function of a device driver is to manage and control the device while providing the interface for the user application to manage and control the device. The driver supports the device control interface, which is implemented through the IOCTL function in Linux.
The IOCTL is a function of the device driver to manage the I/O channel of the device. The so-called management of the I/O channel is to control some features of the device, such as the transmission of the serial port baud rate, the speed of the motor and so on. Its number of calls is as follows:
int ioctl (int fd, ind cmd, ...) ;
Where FD is the user program to open the device using the Open function to return the file identifier, CMD is the User Program Control command of the device, as for the following ellipsis, which is a number of supplementary parameters, generally up to one, the parameter has no and the meaning of the CMD is related.
The IOCTL function is an attribute component in the file structure, meaning that if your driver provides support for the IOCTL, the user can use the IOCTL function in the user program to control the I/O channel of the device.
Necessity of the IOCTL
If you don't use the IOCTL, you can also control the device I/O channel, but it's messy. For example, we can implement write in the driver to check if there is a special convention on the flow of data, if any, then followed by the control command (usually in socket programming). But if you do this, it will lead to unclear code division, the program structure is confusing, the programmer will be dizzy. Therefore, we use the IOCTL to achieve the function of control. Keep in mind that the user program simply tells the driver what it wants to do with command code (CMD), as to how to interpret these commands and how to implement them, which is what the driver does.
MSB and LSB
The MSB is the abbreviation for most significant bit, the most significant bit. In binary numbers, the MSB is the highest weighted bit. Similar to the leftmost one in a decimal number. In general, the MSB is on the leftmost side of the binary number, and the LSB is at the far right of the binary number.
LSB (Least significant bit), meaning the least significant bit, the MSB (most significant bit), meaning the most significant bit, if msb=1, the data is negative, if msb=0, it means that the data is positive.
This article is from the "Sun Guodong" blog, make sure to keep this source http://qtlinux.blog.51cto.com/3052744/1752336
Linux Development Notes