当前位置:网站首页>字符设备注册常用的两种方法和步骤
字符设备注册常用的两种方法和步骤
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;
}
边栏推荐
- Luogu_ P1149 [noip2008 improvement group] matchstick equation_ Enumeration and tabulation
- Go custom sort
- 直击产业落地!飞桨重磅推出业界首个模型选型工具
- Slf4j + logback logging framework
- [shutter] Introduction to the official example of shutter Gallery (learning example | email application | retail application | wealth management application | travel application | news application | a
- How to specify const array in the global scope of rust- How to specify const array in global scope in Rust?
- [shutter] image component (image component introduction | image constructor | image.network constructor | image.asset constructor)
- 【单片机项目实训】八路抢答器
- Matlab 信号处理【问答笔记-1】
- Nc50528 sliding window
猜你喜欢

Cmake basic use

Multiprocess programming (I): basic concepts

UART、RS232、RS485、I2C和SPI的介绍
![Luogu_ P1149 [noip2008 improvement group] matchstick equation_ Enumeration and tabulation](/img/4a/ab732c41ea8a939fa0983fec475622.png)
Luogu_ P1149 [noip2008 improvement group] matchstick equation_ Enumeration and tabulation

Open source | Wenxin big model Ernie tiny lightweight technology, which is accurate and fast, and the effect is fully open

What are the recommended thesis translation software?

RTP 接发ps流工具改进(二)
![[target detection] r-cnn, fast r-cnn, fast r-cnn learning](/img/f0/df285f01ffadff62eb3dcb92f2e04f.jpg)
[target detection] r-cnn, fast r-cnn, fast r-cnn learning
![Luogu_ P2010 [noip2016 popularization group] reply date_ Half enumeration](/img/a3/55bb71d39801ceeee421a0c8ded333.png)
Luogu_ P2010 [noip2016 popularization group] reply date_ Half enumeration

Confluence的PDF导出中文文档异常显示问题解决
随机推荐
开源了 | 文心大模型ERNIE-Tiny轻量化技术,又准又快,效果全开
在线预览Word文档
Analyze ad654: Marketing Analytics
布隆过滤器
Go自定义排序
Many to one, one to many processing
35 pages dangerous chemicals safety management platform solution 2022 Edition
Architecture: database architecture design
CMake基本使用
免费自媒体必备工具分享
How to specify const array in the global scope of rust- How to specify const array in global scope in Rust?
Which software can translate an English paper in its entirety?
form表单实例化
NC50965 Largest Rectangle in a Histogram
Matlab 信号处理【问答笔记-1】
Free we media essential tools sharing
Hit the industry directly! The propeller launched the industry's first model selection tool
JSON conversion tool class
What are the projects of metauniverse and what are the companies of metauniverse
開源了 | 文心大模型ERNIE-Tiny輕量化技術,又准又快,效果全開