Character Driver - Asynchronous Signal Notification

In order to make the device support the asynchronous notification mechanism, the driver involves the following three tasks:
1. Support the F_SETOWN command, which can set filp->f_owner as the corresponding process ID in this control command processing .
However, this work has been done by the kernel, and the device driver does not need to deal with it.
2. Support the processing of the F_SETFL command, whenever the FASYNC flag changes, the fasync() function in the driver will be
executed. The fasync() function
should be implemented in the driver . 3. When the device resource is available, call the kill_fasync() function to stimulate the corresponding signal Application : fcntl(fd, F_SETOWN, getpid()); // Tell the kernel to whom the application will call " fcntl() " function that tells the driver the PID number of the process. The application also reads " flags " through " F_GETFL "




", set the " FASYNC " bit on flags . Oflags = fcntl(fd, F_GETFL); fcntl(fd, F_SETFL, Oflags | FASYNC); // Change the fasync flag, which will eventually call the driver's faync > fasync_helper : initialization / free fasync_struct


The previous method of character-driven:
First, the application program actively queries or reads .
1. Query method: it takes up a lot of resources.
2. Interrupt mechanism: Although there is sleep, read () will wait all the time and never return when no key is pressed . 3.poll mechanism: specify the timeout period. The above are all "applications" actively reading or querying.

今天学习的方式:
二,异步通知:
有按键按下了,驱动程序来提醒(触发)“应用程序”去读键值。用“signal
进程之间发信号:
kill -9 pid
kill 是信号发送者,
pid 具体进程是信号接收者。
信号值是“9
“信号”与“中断”差不多。注册中断处理函数时是用“request_irq(中断号,处理函数)”。
信号也是有一个“信号”和“处理函数”。
参数是“信号的值”,和要挂接的“信号处理函数”。

测试信号应用程序:

 

kill -9 pid9 这个信号处理函数就是让这个进程退出来。
1,先注册“信号处理函数”。
2,发送信号。
①,谁来发信号。
②,发给谁。
③,怎么发

三,异步通知功能的驱动函数的应用程序:
目标:按下按键时,驱动程序通知应用程序。(以前是应用程序主动读取按键值)
1,应用程序中要注册“信号处理函数”。因为通知它做什么事情,这要一个函数来做。
2,谁发:是驱动程序发送信号。
3,发给谁:信号发送给应用程序。应用程序要告诉驱动程序它自已的 PID
4,如何发:驱动程序中调用某个函数(kill_fasync()

 

 

Guess you like

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