当前位置:网站首页>字符设备注册常用的两种方法和步骤
字符设备注册常用的两种方法和步骤
2022-07-02 23:09:00 【要不要买菜!】

static int __init RK_irq_init(void)
{
/* 1、构建设备号 */
if (RK_irq.major) {
RK_irq.devid = MKDEV(RK_irq.major, 0);
register_chrdev_region(RK_irq.devid, RK_IRQ_CNT, RK_IRQ_NAME);
} else {
alloc_chrdev_region(&RK_irq.devid, 0, RK_IRQ_CNT, RK_IRQ_NAME);
RK_irq.major = MAJOR(RK_irq.devid);
RK_irq.minor = MINOR(RK_irq.devid);
}
/* 2、注册字符设备 */
cdev_init(&RK_irq.cdev, &RK_irq_fops);
cdev_add(&RK_irq.cdev, RK_irq.devid, RK_IRQ_CNT);
/* 3、创建类 */
RK_irq.class = class_create(THIS_MODULE, RK_IRQ_NAME);
if (IS_ERR(RK_irq.class)) {
return PTR_ERR(RK_irq.class);
}
/* 4、创建设备 */
RK_irq.device = device_create(RK_irq.class, NULL, RK_irq.devid, NULL, RK_IRQ_NAME);
if (IS_ERR(RK_irq.device)) {
return PTR_ERR(RK_irq.device);
}
/* 5、始化按键 */
atomic_set(&RK_irq.keyvalue, INVAKEY);
atomic_set(&RK_irq.releasekey, 0);
keyio_init();
return 0;
}
边栏推荐
- 多进程编程(一):基本概念
- NC50528 滑动窗口
- 洛谷_P1149 [NOIP2008 提高组] 火柴棒等式_枚举打表
- Practical series - free commercial video material library
- TypeError: Cannot read properties of undefined (reading ***)
- NC50965 Largest Rectangle in a Histogram
- NC24325 [USACO 2012 Mar S]Flowerpot
- TypeError: Cannot read properties of undefined (reading ***)
- JS interviewer wants to know how much you understand call, apply, bind no regrets series
- Improvement of RTP receiving and sending PS stream tool (II)
猜你喜欢

哪些软件可以整篇翻译英文论文?

開源了 | 文心大模型ERNIE-Tiny輕量化技術,又准又快,效果全開

What are the projects of metauniverse and what are the companies of metauniverse

Where can I find the English literature of the thesis (except HowNet)?

Understanding and application of least square method

Feature Engineering: summary of common feature transformation methods

Matlab 信号处理【问答笔记-1】

Architecture: database architecture design

Is the multitasking loss in pytoch added up or backward separately?

Explain in detail the process of realizing Chinese text classification by CNN
随机推荐
Andorid 获取系统标题栏高度
Multiprocess programming (I): basic concepts
Which websites can I search for references when writing a thesis?
[shutter] shutter open source project reference
開源了 | 文心大模型ERNIE-Tiny輕量化技術,又准又快,效果全開
NC17059 队列Q
Blue decides red - burst CS teamserver password
大学生课堂作业2000~3000字的小论文,标准格式是什么?
来自数砖大佬的 130页 PPT 深入介绍 Apache Spark 3.2 & 3.3 新功能
多进程编程(三):消息队列
Xcode real machine debugging
Markdown使用教程
Bigder: how to deal with the bugs found in the 32/100 test if they are not bugs
Install docker and use docker to install MySQL
What are the projects of metauniverse and what are the companies of metauniverse
Analyze ad654: Marketing Analytics
What website can you find English literature on?
MySQL advanced learning notes (4)
毕业总结
论文的英文文献在哪找(除了知网)?