当前位置: 首页 > article >正文

ARM驱动学习之4小结

                                ARM驱动学习之4小结

#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/miscdevice.h>
#include <linux/fs.h>

#define DEVICE_NAME "hello_ctl123"

MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("TOPEET");

static long hello_ioctl(struct file *file,unsigned int cmd,unsigned long arg){
	
	printk("cmd is %d,arg is %ld\n",cmd,arg);
	return 0;
}

static int hello_open(struct inode *inode, struct file *file){
	printk(KERN_EMERG "hello_open");
	
	return 0;
}

static int hello_release(struct inode *inode, struct file *file){
	printk(KERN_EMERG "hello_release");
	return 0;
}

struct file_operations hello_ops = {
	.owner = THIS_MODULE,
	.open = hello_open,
	.release = hello_release,
	.unlocked_ioctl = hello_ioctl,
	
	
};



static struct miscdevice hello_dev = {
	.minor = MISC_DYNAMIC_MINOR,
	.name = DEVICE_NAME,
	.fops = &hello_ops,
};


static int hello_init(void)
{
	printk(KERN_EMERG "hello_init enter\r\n");	
	misc_register(&hello_dev);
	return 0;
}

static void hello_exit(void)
{
	printk(KERN_EMERG "hello_exit exit!\n");
	misc_deregister(&hello_dev);
}

module_init(hello_init);
module_exit(hello_exit);

应用部分代码:

/*************************************************************************
> File Name: Invoke.c
> Author: 
> Mail: 
> Created Time: Fri 27 Sep 2019 10:51:55 PM CST
************************************************************************/

#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>

int main(void)
{
    char *fp = "/dev/hello_ctl123";
    int fd; 
    if(fd = open(fp,O_RDWR|O_NDELAY) < 0){
        printf("APP open %s  failed\r\n",fp);
       }
   else{
        printf("\r\n App open  %s success\r\n",fp);
	ioctl(fd,1,6);
    }
	close(fd);
    return 0;
}

总结:

生成设备节点小结
– 设备节点是“对上”,为了让应用程序可以调用
生成节点的代码可以放到任何地方,和驱动注册和设备注册关系不是
那么严密,甚至没有设备注册,也是可以生成设备节点的。


生成设备节点是“ “对上” ”,它提供的是对上的接口。
– 一定要注意,生成设备节点,和设备注册没有关系,而且设备节点名称
不需要和设备名称相同。
– 一般情况下,是将设备节点注册放到probe中,但是放到init函数中的驱动
也是有的。
• Linux设备驱动一般分为:字符设备、块设备和网络设备。
– 杂项设备多数是属于字符设备,后续我们将介绍字符设备,杂项设备可
以理解为挂载在字符设备上的设备。
– 我个人不太习惯使用字符设备、块设备和网络设备来区分Linux设备驱动
,更加倾向于使用“XX子系统”,这种分类方法在网上不是很常见。


http://www.kler.cn/news/304703.html

相关文章:

  • Docker高级管理--Compose容器编排与私有仓库(Docker技术集群与应用)
  • 使用Spring Boot集成Nacos进行配置管理
  • rocky8安装docker步骤
  • Apple Watch Series 10 動手玩:更大、更輕、更薄
  • 华为VRP系统基本操作
  • php 之 php-fpm 和 nginx结合使用
  • 使用Rustup快速无缝升级Rust
  • Mac快速复制和删除命令
  • Gitlab实现多项目触发式自动CICD
  • 时序预测 | Matlab实现GA-CNN遗传算法优化卷积神经网络时间序列预测
  • Java许可政策再变,Oracle JDK 17 免费期将结束!
  • 7.测试用例设计方法 + Bug
  • linux安全软件Hydra使用教程
  • 速盾:cdn节点越多越好吗?
  • 如何优雅的使用 Nacos
  • Go语言现代web开发11 函数
  • git子模块处理的一些方法
  • 2024年华为9月4日秋招笔试真题题解
  • WalkMe的数字用户体验到底是啥
  • APP广告变现流量售卖,选择API还是SDK对接?
  • 前端Excel热成像数据展示及插值算法
  • DAY 9 - 10 : 树
  • 海量智库第31期 | 自治事务原理与应用解析
  • C++生成唯一值的五种方法
  • 【机器学习(六)】分类和回归任务-LightGBM算法-Sentosa_DSML社区版
  • 前端项目node版本问题导致依赖安装异常的处理办法
  • 网络安全实训七(MSF与CS互相连接)
  • “AI大语言模型+”助力大气科学相关交叉领域实践技术应用
  • ubuntu20.4安装Qt5.15.2
  • SQL案例分析:计算延迟法定退休年龄