ImageVerifierCode 换一换
格式:PPT , 页数:53 ,大小:1.05MB ,
资源ID:456213      下载积分:12 文钱
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,省得不是一点点
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.wenke99.com/d-456213.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Linux设备驱动程序.ppt)为本站会员(ga****84)主动上传,文客久久仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知文客久久(发送邮件至hr@wenke99.com或直接QQ联系客服),我们立即给予删除!

Linux设备驱动程序.ppt

1、Linux Device Driver,2009/04/08,Reference Book,Another Reference Book,Embedded Linux Primer: A Practical, Real-World Approach By ChristopherHallinan Publisher: Prentice Hall Pub Date: September 18, 2006 Print ISBN-10: 0-13-167984-8 Print ISBN-13: 978-0-13-167984-9 Pages: 576,Website,http:/wiki.openwr

2、t.orghttp:/www.linuxsir.orghttp:/ of Device Driver,Device initializationHardware operation and managementData transfer between kernel space and user spaceData exchange between hardware and kernel space,Function of device driver,Hardware,Device Driver,Application,Buffer,User space,Kernel Space,User s

3、pace vs Kernel Space programFrom the point of view of CPU,mode reg.,memory address mapping,memory access surveillance,Execution core,Memory,address,data,INT,Concept,MMU,User space vs Kernel Space program From the point of view of CPU,用户应用程序,内核程序,Kernel schedule/Kernel API,用户应用程序,用户应用程序,User space pr

4、ogram,内核程序,内核程序,Kernel space program,Mode reg.,Scheduler, change mode reg. to enter different mode,Concept,Soft interrupt,Address Mapping and accessing of the physical address,Physical Address space,User processs1,User processs2,User process 3,Virtual address mapping,user program access virtual usin

5、g pointersphysical address of IO device cannot be accessed by user program directly,Virtual address mapping,Virtual address mapping,Basic operation of device driver,Device controller is often mapped into memory address,D Q,D Q,D Q,Device circuits,Data bus,Address matching circuit,Address bus,CPU,Bas

6、ic operation of device driver,D Q,D Q,D Q,Data bus,Address matching circuit,Address bus,CPU,Device circuits,User space vs Kernel Space program,User space programLimited priorityVirtual run environmentLogic addressKey resource access is difficultUser invoke function directly,Kernel Space programHighe

7、st priorityPhysical run environmentVirtual addressAccess all resourceKernel invoke function,Direct memory access(/dev/kmem),kmfd=open(/dev/kmem,O_RDONLY);lseek(kmfd,offset,SEEK_SET);read(kmfd,byteArray,byteArrayLen);close(kmfd);,memory is mapped into device file, and can be accessed by file read/wri

8、teCan access kernel address(virtual address of kernel)Most started from 0xC0000000,memory,offset,Access Physical address directly(/dev/mem),mem_fd=open(/dev/mem,O_RDONLY);b=mmap(0, 0x10000, PROT_READ|PROT_WRITE,MAP_SHARED, mem_fd,0xA0000)close(memfd);,0xA0000,0xB0000,Pointer b,mmap mapping data in f

9、ile into arrayPhysical memory(accessed by special file /dev/mem)s mapped into array pointed by bNote that value of B may not be 0xA0000, its value is a virtual address coressponding to the physical address 0xA0000under Linux, /dev/mem is for special memory access, such as video memory,May not bye me

10、mory device file,Directly access IO port(/dev/port),port_fd=open(/dev/port, O_RDWR);lseek(port_fd,port_addr,SEEK_SET);read(port_fd,);write(port_fd,); close(port_fd);,Note, not use fopen/fread/fwrite/fclose, because data operation by these function is not fulfilled immediately (buffered),outb()/outw(

11、)/inb()/inw() Function,#include #include #include #define BASEPORT 0x378 / printerint main() ioperm(BASEPORT, 3, 1);/ get access permission outb(0, BASEPORT); usleep(100000); printf(status: %dn, inb(BASEPORT + 1); ioperm(BASEPORT, 3, 0);/ give up exit(0);,ioperm(from,num,turn_on) port address that c

12、an be obtained from ioperm is 0x0000x3FF,use iopl() can obtain all port addressmust run as rootuse “gcc -02 o xxx.elf xxx.c” to compile,outb(value, port); inb(port); / 8-bitoutw(value, port); inw(port); / 16-bitaccess time is about 1us,Access memory directly by user space programwhy we need device d

13、river,Share devicesINT management,Safe device access method Using Linux device driver,Device driver can access device address by pointerdevice driver also use virtual address but more real than user application(device address mapping can be found in transplanting Linux Kernel),Physical address space

14、,Device Driver,Virtual address mapping,Device address Space,Device address mapping,Device Driver,Virtual address mapping,Device address mapping,Direct access IO port vs Using device driver,Direct IO AccessUser spacesimplepoll mode, slow (response time)difficult to share devices,Access by device driv

15、erKernel spacedifficult to debug and programmingcan use fast INT mode, realtimeeasy to implement device sharing (managed by OS),Device Classification in Linux,Character deviceMouse、Serial port、joystickBlock devicePrinter , hard diskNetwork deviceAccess by BSD Socket,Character device vs Block device,

16、Character deviceRead/write operation is fulfilled immediatelydata buffer is optionalADC/DAC、button、LED、sensor,Block deviceneed data buffer to reduce device write/read operationFor slow device such as hard disk,Dynamically installable device vs static linked device driver,Static linked device driverC

17、hange configuration file, re-compile and install kernelDynamically instable device driverinsmodinstallrmmodremovallsmodquery,Abstraction of devices under Linux,Device fileOpen/Close/Read/WriteExample/dev/mouse/dev/lp0,universal IF,Device Driver and File,Device driver,DeviceFile,Create by command mkn

18、od,installed by command insmod (or statically compiled into kernel),Application,Access by open/read/write/close API,Find real device river by major device number,Similar method,User space,Device Driver and File,Kernel Space,Deevice Driverread()write()open()close(),User applicationread()write()open()

19、close(),Device File,device ID,device ID,Name of device file,name of vice file,Structure of Device Driver,Register and unregister,device file operation function (API)(*open)()(*write)()(*flush)()(*llseek)(),ISR,Example of LED device driver,CPU,struct file_operations LED_fops = read: LED_read, write:

20、LED_write, open: LED_open, release: LED_release,;int LED_init_module(void) SET_MODULE_OWNER(,Program list (1),pointers of functions,invoked when device is installed,invoked when device is uninstalled,Tell kernel the name of function to be invoked when install or uninstall device driver,program(2),in

21、t LED_open(struct inode *inode, struct file *filp) printk(LED_open()n); MOD_INC_USE_COUNT; return 0;int LED_release(struct inode *inode, struct file *filp) printk(“LED_release()n“); MOD_DEC_USE_COUNT; return 0;,new vision Linux doesnt use this Macro,new vision Linux doesnt use this Macro,Program Lis

22、t(3),ssize_t LED_read (struct file *filp, char *buf, size_t count, loff_t *f_pos) int i; for (i=0; icount; i+) *(char*)(buf+i) = LED_Status; return count;ssize_t LED_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos) int i; for (i=0; i /proc/sys/kernel/printkcat /dev/Lamp cat /de

23、v/Lamp programvoid main() int fd=open(“/dev/Lamp, O_RDWR); write(fd, ,User space,Use of device driver,Kernel Space,Device Driver read() write() open() close(),Device File,void main() int fd=open(“/dev/Lamp, O_RDWR); write(fd, ,Uninstall device,/sbin/rmmod LEDremove device driverrm -f /dev/Lampdelete

24、 device file,Function ofMOD_INC_USE_COUNT;MOD_DEC_USE_COUNT;,User space,Uninstall device,Kernel Space,Device Driverread()write()open()close(),Device File,/sbin/rmmod LED,x,x,rm -f /dev/Lamp,Complex Device Driver,register and unregister(device and INT),Divice operation API(function)(*open)()(*write)(

25、)(*flush)()(*llseek)(),ISR,Kernel space buffer,Data in user space,Complex Device Driver(USB Device),Application of IRQif (request_irq(USB_INTR_SOURCE1, usb_ep1_int, SA_INTERRUPT, USB EP1, 0) i_rdev); filp-private_data=sub_dev_datminor; ssize_t dev_write(struct file *filp, const char *buf, size_t cou

26、nt, loff_t *f_pos) switch(*(filp-private_data) ,Allocate data space for each device,use data space allocated for the opened device,Debug of Character device driver,Kernel,Device Driver,Device Read,Device Write,Device Open,Device Close,Debug Read,Debug Write,Debug Open,Debug Close,设备文件 1,设备文件 2,Application(using device),debug and monitor,Virtual Serial port, canbe access by minicom,

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。