当前位置:网站首页>Asynchronous notification mechanism of character device driver
Asynchronous notification mechanism of character device driver
2022-06-11 08:13:00 【Chenhongwei】
1 The concept of asynchronous notification is introduced
Review the previous three key reading methods
- A query : Extreme consumption of resources ,
- Interrupt mode :read Will also sleep , It doesn't consume resources , But if no key is pressed, the interrupt does not occur , that read Never return .
- poll Mechanism : Specify the timeout period , If you haven't pressed the key after the time, you will return to .
The common point of these three methods is that the application actively reads and queries , Is there a way , When a key is pressed , Driver to remind the application , Then the application reads the keys , This method is called asynchronous notification , Use signal signal Realization , Signaling between processes .
2 Example of signal communication between processes
We used kill -9 PID, In fact, that is kill This process sends 9 Give a process , Next, let's write an example of signal communication , We use it man signal Take a look at the use of signal functions .
First, you need to include signal.h This header file , This signal is similar to our interruption , There is also a number and a handler .

We compile this application , function , And then use ps Order to have a look , Found that he had been dormant 
Then we send a signal to him ,kill -USR1 833, Then I found that the application printed out the content

Let's summarize the key points of sending signals
- Register signal processing functions
- Who sends the signal
- To whom is the signal sent
- How to signal
3 Write code
Now our goal is : When you press the key , Drive notification applications ,
- The signal processing function should be registered in the application
- The driver signals
- To the app , Then the application should tell the driver , Application's PID How much is the , Otherwise I don't know what to send to that application
- How to send ,kill_fasync
We don't know kill_fasync How to use it? , Let's see how others use it , Let's search the kernel code , Then copy it to the interrupt service program of the key , We signal in the interrupt service program ,


And then we make changes , Let's see rtc_asynv_queue How to define it , Then define a ,
![]()
To whom , It should be in the structure button_async It defines who to send it to , So let's see how to initialize this structure , Our search found that it was initialized here ,

So we are also adding one in our driver structure

fifth_drv_fasync This function will be used to button_async To initialize , Then, during initialization, there will be an application to be sent to in the structure , So this fifth_drv_fasync When is a function called , Is when our application calls fasync Called on function fifth_drv_fasync, So obviously our application will call fasync To set the structure ,
边栏推荐
- ConstraintLayout中使用Guideline限制控件最大宽度
- Tidb Cloud est en ligne sur le marché Google Cloud pour permettre aux développeurs du monde entier d'utiliser une nouvelle pile de bases de données htap en temps réel
- [transfer] two-way merging and sorting of C language
- SOCKET【5】- struct linger 用法
- Summary of embedded software interview questions
- DAMENG 数据库启停
- Dameng user management
- 学习《缠解论语》
- torch. roll
- Getting started with bladed tutorial (video)
猜你喜欢

Batch splice string

这几个小工具也太好用了

安卓初中级开发基础知识整理(面试自用)

Summary of embedded software interview questions

(the slow download speed of cifar10 in torchvision has been solved) how to download and use torchvision import

How to start participating in the open source community

JS learning basics document Write write a line of text in the page

Study the Analects of entanglement

(resolved) the tqdm progress bar in the Jupiter notebook does not update and display in one line, but scrolls down to output

Detailed explanation of shift operator and bit operator in C language
随机推荐
(the slow download speed of cifar10 in torchvision has been solved) how to download and use torchvision import
Typescript namespace
How CSDN reports plagiarized articles
Typescript enumeration
关于网络知识的50个问答题,你能答对几个?
Getting started with bladed tutorial (video)
Typescript type alias
通过ComponentCallbacks2来接收onTrimMemory等回调,并mock对应的场景
如何做好空状态设计?来看这份全面总结
嵌入式软件面试问题总结
Node error report sorting
2022.6.7 special student simulation
避免list的并发修改异常的几种方式
Use guidelines in constraintlayout to limit the maximum width of controls
SOCKET【5】- struct linger 用法
Typescript distributed condition type
Post - form data of interface test
Solution to the occurrence interval (space) of latex manual numbering documents
Typescript class and interface, class and generic, interface merging
TypeScript-头文件使用细节