Linux character device driver development (1)

I. Introduction

The character device is one of the most important devices in the Linux driver, and it can be accessed like a byte stream, that is to say, its operations are performed in units of bytes, such as reading and writing. For example, the most common lighting, buttons, IIC, SPI, LCD, etc. are all character devices, and the drivers of these devices are called character device drivers. The driver of the character device implements system calls such as open, close, read, and write, and the application program can access the character device through the device file (/dev/xxx, where xxx is the character device file, such as /dev/led). In Linux, everything is a file. After the driver is successfully loaded, a corresponding file will be generated in the "/dev" directory. The application program uses this file named "/dev/xxx" (xxx is the specific driver file name) Carry out the corresponding operation to realize the operation of the hardware.

2. Purpose

This article briefly introduces the development steps and process of Linux character device drivers. If you have learned bare metal or STM32, you know that for a certain device module, you need to initialize the relevant peripheral registers, etc. The development of character device drivers under the Linux kernel is still to write the driver according to the steps of initializing the relevant peripheral registers or the framework. The key point is to master its driver development framework.

3. Development process and introduction

Linux device drivers can be roughly divided into the following parts: loading and unloading of driver modules, registration and cancellation of drivers, opening and releasing of devices, read and write operations of devices, control operations of devices, interrupts and rotations of devices query processing, etc. Taking character device driver development as an example, the development process model and work association are shown in the following figure:
Develop process model
job association

1. In the Linux kernel

Guess you like

Origin blog.csdn.net/Youning_Yim/article/details/126404366