Introduction to the concept of character device drivers (1)

Introduction to the concept of character device drivers (1)

one,

The purpose of Uboot is to start the kernel.

The purpose of the kernel is to start the application.

 

 

two,

Application: read and write files, light up, get keys

 

 

three,

 

1. Frame:

application

open,read,write

C library

system call interface

sytem call interface

 

kernel

VFS virtual file system

sys_open,sys_read,sys_write

 

drive

Led_open,led_read,led_write

 

2. Simple application

intmain()
{
    int fd1,fd2;
    int val = 1;

    fd1=open("/dev/led", O_RDWR); //Open a led program
    write(fd1, &val,4);

    fd2=open("hello.txt", O_RDWR); //Open a text file
    write(fd2, &val, 4);
}


3. Drivers are also part of the kernel.

 

4. How does the C library enter the kernel? What is the essence of the implementation of open, read, and write?

    Execute the swi val (assembly instruction) and raise an exception, which is equivalent to an interrupt. When this exception occurs, it will enter the kernel's exception handling function.

 

5. The role of the system call interface (system call interface):

    In the exception handling function, different handling functions are called according to the cause of the exception.

    For example: using the open function, the incoming value is val1 (swi val1); using the read function, the incoming value is val2 (swi val2); using the write function, the incoming value is val3 (write val3). The system call interface (system call interface) in the kernel will call sys_open, sys_read and sys_write according to the different values ​​passed in.

 

6. In the simple application of 1 above, the behavior of fd1 and fd2 opening is different. sys_open, sys_read and sys_write finally find different drivers according to different files opened, so as to call the driver open, read and write to realize these functions.

 

 

Four,

1. Summary framework:

    The APP1 application program calls the open, read, and write functions, and the open, read, and write functions are implemented in the c library. Execute the instruction swi val, this instruction will trigger an exception, and the exception will enter the kernel space. In the kernel space exception handling function, the sys_open, sys_read, and sys_write functions will be called according to the different values ​​of val passed in. These functions are based on Open different files, the files have different attributes, according to these attributes to find the underlying driver. For example, for led lights, the driver of the led lights will be found. If it is some files, it will find the open, read, and write functions in the Storage drivers storage driver.

 

2、

Application app: open, read, write (standard interface)                     

                                                 How does this process change?

                                                 How to find led_open through open?

                                                 This depends on the driver framework

Drivers: led_open, led_read, led_write

                                                             (operating hardware)


3、



4、

In general,

Sytem call interface The system call interface is to decide which function to use (read(), write(), open()...)

The VFS virtual file system is the open() function that decides which driver to call (led_open(), memdev_open()...)


https://blog.csdn.net/Pris_oner/article/details/51594934

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325608521&siteId=291194637