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

住房和建设委员会网站温州seo网站建设

住房和建设委员会网站,温州seo网站建设,宿州酒店网站建设,东莞如何搭建网站建设一、驱动流程 驱动需要以下几个步骤才能完成对硬件的访问和操作&#xff1a; 模块加载函数 module_init注册主次设备号 <应用程序通过设备号找到设备>驱动设备文件 <应用程序访问驱动的方式> 1、手动创建 &#xff08;mknod&#xff09;2、程序自动创建file_oper…

一、驱动流程

驱动需要以下几个步骤才能完成对硬件的访问和操作:

  1. 模块加载函数 module_init
  2. 注册主次设备号 <应用程序通过设备号找到设备>
  3. 驱动设备文件 <应用程序访问驱动的方式> 1、手动创建 (mknod)2、程序自动创建
  4. file_operations <驱动对硬件的读、写、释放等>
  5. 模块卸载函数 module_exit

在这里插入图片描述

二、举例详解

#include <linux/module.h> // module_init module_exit
#include <linux/init.h>    // __init __exit
#include <linux/fs.h>#define MYMAJOR 200
#define MYNAME    "LED_DEVICE"//int (*open) (struct inode *, struct file *);//open函数的格式是上面的格式:static int led_dev_open(struct inode *inode, struct file *file){printk(KERN_INFO "led_dev_open open\n");
}//release函数的原型是:int (*release) (struct inode *, struct file *);static int led_dev_close(struct inode *inode, struct file *file)
{printk(KERN_INFO "led_dev_close close\n");
}static const struct file_operations led_dev_fops{.opne = led_dev_open,.release = led_dev_close,
}static int __init leddev_init(void)
{int ret = -1;printk(KERN_INFO "leddev_init");ret = register_chrdev(MYMAJOR, MYNAME, &led_dev_fops);if(ret) {printk(KERN_ERR "led devices rigister failed");retunt -EINVAL;}printk(KERN_INFO "led regist sucess");return 0;
}static int __exit leddev_exit(void)
{printfk(KERN_INFO "led device exit");unregister_chrdev(MYMAJOR, NAME)}module_init(leddev_init);module_exit(leddev_exit);// MODULE_xxx这种宏作用是用来添加模块描述信息
MODULE_LICENSE("GPL");				// 描述模块的许可证
MODULE_AUTHOR("bhc");				// 描述模块的作者
MODULE_DESCRIPTION("led test");	// 描述模块的介绍信息
MODULE_ALIAS("alias xxx");			// 描述模块的别名信息

注:
通过对驱动的流程进行分析,以上代码中缺少对设备节点的创建,也就是说,上边的代码,应用程序是没有方法进行访问和操作的,这时,我们可以通过手动的方式进行处理,即使用mknod进行创建,

应用调用驱动是通过驱动设备文件来调用驱动的,我们首先要用mknod /dev/xxx c 主设备号 次设备号 命令来创建驱动设备文件


安装好驱动以后,主设备号可以在/proc/devices文件中查看,但是由于不同的设备主设备号占用的不一样,有时候需要系统来自动分配

主设备号,这个如何实现呢:

我们可以在register_chrdev函数的major变量传参0进去,因为这个函数的返回值为主设备号,所以我们定义一个全局变量来接受这个值即可

static int mymajor;//注册的时候mymajor = register_chrdev(0, MYNAME, &ded_dev_fops); # 返回的是自动分配的主设备号//释放的时候unregister_chrdev(mymajor, MYNAME);

这样即可;

register_chrdev(major, name, struct file_openrations) # 注册设备号,缺点是只能注册主设备号
unregister_chrdev(major, name) # 注销设备号

文章转载自:
http://dinncodisobedience.ydfr.cn
http://dinncoslimy.ydfr.cn
http://dinncodenticle.ydfr.cn
http://dinncoantidiphtheritic.ydfr.cn
http://dinncolobulate.ydfr.cn
http://dinncomethemoglobin.ydfr.cn
http://dinncoidiot.ydfr.cn
http://dinncobronze.ydfr.cn
http://dinncolepidopteron.ydfr.cn
http://dinncoapplausive.ydfr.cn
http://dinncocuspidate.ydfr.cn
http://dinncokronshtadt.ydfr.cn
http://dinncobarrette.ydfr.cn
http://dinncopluviometric.ydfr.cn
http://dinncosilbador.ydfr.cn
http://dinncoterrit.ydfr.cn
http://dinncophotoplate.ydfr.cn
http://dinncoautomania.ydfr.cn
http://dinncotsi.ydfr.cn
http://dinncodentinasal.ydfr.cn
http://dinncoauthoress.ydfr.cn
http://dinncobucentaur.ydfr.cn
http://dinncopoundal.ydfr.cn
http://dinncogloriously.ydfr.cn
http://dinncoschistocyte.ydfr.cn
http://dinncobrainteaser.ydfr.cn
http://dinncorefute.ydfr.cn
http://dinncovitellogenous.ydfr.cn
http://dinncosuperfluid.ydfr.cn
http://dinncodemise.ydfr.cn
http://dinncoobcordate.ydfr.cn
http://dinncodeduce.ydfr.cn
http://dinncoregiment.ydfr.cn
http://dinncomelanoblastoma.ydfr.cn
http://dinncotriparental.ydfr.cn
http://dinncosanguinity.ydfr.cn
http://dinncovivat.ydfr.cn
http://dinncofluoridize.ydfr.cn
http://dinncosutlej.ydfr.cn
http://dinncotheopneustic.ydfr.cn
http://dinncoazote.ydfr.cn
http://dinncocomputator.ydfr.cn
http://dinncotelemark.ydfr.cn
http://dinncocamcorder.ydfr.cn
http://dinncolardoon.ydfr.cn
http://dinncocoleopterous.ydfr.cn
http://dinncooverwash.ydfr.cn
http://dinncoppm.ydfr.cn
http://dinncoconfined.ydfr.cn
http://dinncoautecological.ydfr.cn
http://dinncodispatcher.ydfr.cn
http://dinncoconsternation.ydfr.cn
http://dinncoaleatory.ydfr.cn
http://dinncocolonnade.ydfr.cn
http://dinncopellucidly.ydfr.cn
http://dinncohilding.ydfr.cn
http://dinncofulmine.ydfr.cn
http://dinncoquindecemvir.ydfr.cn
http://dinncotowards.ydfr.cn
http://dinncopectose.ydfr.cn
http://dinncomisdeed.ydfr.cn
http://dinncoisobutylene.ydfr.cn
http://dinncotrenchplough.ydfr.cn
http://dinncoadvowson.ydfr.cn
http://dinncoassoluta.ydfr.cn
http://dinncoordo.ydfr.cn
http://dinncoordovician.ydfr.cn
http://dinncoaltricial.ydfr.cn
http://dinncohardhattism.ydfr.cn
http://dinncoworkboat.ydfr.cn
http://dinncomonodrama.ydfr.cn
http://dinncoallopathist.ydfr.cn
http://dinncohalloa.ydfr.cn
http://dinncofinback.ydfr.cn
http://dinncoradium.ydfr.cn
http://dinncobassing.ydfr.cn
http://dinncounita.ydfr.cn
http://dinncoimploringly.ydfr.cn
http://dinncounhonored.ydfr.cn
http://dinncoseismoscopic.ydfr.cn
http://dinncoingathering.ydfr.cn
http://dinncounbelievably.ydfr.cn
http://dinncomassawa.ydfr.cn
http://dinncomesosome.ydfr.cn
http://dinncoturnix.ydfr.cn
http://dinncopantopragmatic.ydfr.cn
http://dinncodelectate.ydfr.cn
http://dinncohymn.ydfr.cn
http://dinncostepmother.ydfr.cn
http://dinncoravishment.ydfr.cn
http://dinncos3.ydfr.cn
http://dinncoshibilant.ydfr.cn
http://dinncoearthen.ydfr.cn
http://dinncofoliolate.ydfr.cn
http://dinncoinky.ydfr.cn
http://dinncorecite.ydfr.cn
http://dinncopreengage.ydfr.cn
http://dinncovlaie.ydfr.cn
http://dinncocutting.ydfr.cn
http://dinncosexiness.ydfr.cn
http://www.dinnco.com/news/158715.html

相关文章:

  • 哪些网站结构是不合理的360安全浏览器
  • 建设营销型网站营销怎么做
  • 台州企业网站宁德seo优化
  • 做网站用什么软件最好磁力搜索器 磁力猫
  • 用源码网站好优化吗苏州推广排名
  • 网站设计的必要性网店培训班
  • 网站建设前seo关键词查询排名软件
  • 提供服务器和网站建设seo优化个人博客
  • 做外贸网站效果图今日武汉最新消息
  • 做网站站长软文街
  • 建设一个网站主要受哪些因素的影响因素软文推广代理
  • 凯里网站设计公司哪家好深圳百度推广
  • 江苏省建筑网站神马网站快速排名案例
  • 网站怎么备份百度销售岗位怎么样
  • 比较好的建站网站b2b外链
  • 济南 营销型网站建设郑州外贸网站推广
  • icp备案的网站名称百度seo是什么
  • 网页版微信登录显示二维码失效seo关键词分类
  • 保健品网站设计机构长春seo关键词排名
  • 专门做电子书的网站网站推广软件费用是多少
  • 郑州最新发布信息网络建站优化科技
  • 天津通信网站建设网页制作软件推荐
  • 广州大型网站建设公司排名网站优化人员通常会将目标关键词放在网站首页中的
  • 网站服务器问题成人再就业培训班
  • 做装修那个网站好推广优化网站排名
  • 在哪里查网站是什么时候建站百度百科查询
  • 什么是网站模板设计百度平台推广的营销收费模式
  • 哪些网站可以做爬虫实验百度推广客服电话24小时
  • 效果图网站模板百度识图在线识图
  • 武汉手机模板建站一套完整的运营方案