通用摄像头驱动源码分析附有详细注释

上传人:飞****9 文档编号:132182360 上传时间:2020-05-13 格式:PDF 页数:42 大小:124KB
返回 下载 相关 举报
通用摄像头驱动源码分析附有详细注释_第1页
第1页 / 共42页
通用摄像头驱动源码分析附有详细注释_第2页
第2页 / 共42页
通用摄像头驱动源码分析附有详细注释_第3页
第3页 / 共42页
通用摄像头驱动源码分析附有详细注释_第4页
第4页 / 共42页
通用摄像头驱动源码分析附有详细注释_第5页
第5页 / 共42页
点击查看更多>>
资源描述

《通用摄像头驱动源码分析附有详细注释》由会员分享,可在线阅读,更多相关《通用摄像头驱动源码分析附有详细注释(42页珍藏版)》请在金锄头文库上搜索。

1、通用摄像头驱动源码分析通用摄像头驱动源码分析 附有详细注释附有详细注释 摄像头驱动实现源码分析 Spac5xx 的实现是按照标准的 USB VIDEO 设备的驱动框架编写 其具体的驱动 框架可参照 usr src linux drivers usb usbvideo c 文件 整个源程序由四 个主体部分组成 设备模块的初始化模块和卸载模块 上层软件接口模块 数据 传输模块 具体的模块分析如下 一 初始化设备模块 该驱动采用了显式的模块初始化和消除函数 即调用 module init 来初始化一 个模块 并在卸载时调用 moduel exit 函数 此二函数在 2 3 13 内核开始支 持 其具

2、体实现如下 1 模块初始化 module init usb spca5xx init static int init usb spca5xx init void ifdef CONFIG PROC FS proc spca50 x create 建立 PROC 设备文件 endif CONFIG PROC FS if usb register spca5xx driver 0 注册 USB 设备驱 动 return 1 info spca5xx driver s registered version return 0 2 模块卸载 module exit usb spca5xx exit ta

3、tic void exit usb spca5xx exit void usb deregister spca5xx driver 注销 USB 设备 驱动 info driver spca5xx deregistered ifdef CONFIG PROC FS proc spca50 x destroy 撤消PROC设备文件 endif CONFIG PROC FS 关键数据结构 USB 驱动结构 即插即用功 能的实现 static struct usb driver spca5xx driver spca5xx spca5xx probe 注册设备自我侦测功能 spca5xx disco

4、nnect 注册设备自我断开功能 NULL NULL 用两个函数调用 spca5xx probe 和 spca5xx disconnect 来支持 USB 设备的 即插即用功能 spca5xx probe 具体实现如下 static void spca5xx probe struct usb device dev unsigned int ifnum const struct usb device id id struct usb interface descriptor interface USB 设备接口描述 符 struct usb spca50 x spca50 x 物理设备数据结构

5、int err probe int i if dev descriptor bNumConfigurations 1 探测设备是不 是可配置 goto nodevice if ifnum 0 goto nodevice interface dev actconfig interface ifnum altsetting 0 MOD INC USE COUNT interface intf altsetting 0 desc if interface bInterfaceNumber 0 goto nodevice if spca50 x kmalloc sizeof struct usb sp

6、ca50 x GFP KERNEL NULL 分配物理地址空间 err couldnt kmalloc spca50 x struct goto error memset spca50 x 0 sizeof struct usb spca50 x spca50 x dev dev if err probe spcaDetectCamera spca50 x 0 具体物理设备查找 匹配厂商号 设备号 在子程序中 err Devices not found goto error PDEBUG 0 Cameratype s Plist spca50 x cameratype name for i 0

7、 i SPCA50X NUMFRAMES i init waitqueue head spca50 x frame i wq 初始化帧 等待队列 init waitqueue head spca50 x wq 初始化驱动 等待队列 if spca50 x configure spca50 x 物理设备配置 主要完成传感器侦测和图形参数配置 主要思想是给控制寄 存器写值 读回其返回值 以此判断具体的传感器型号 spca50 x user 0 init MUTEX spca50 x lock 信号量初始化 init MUTEX spca50 x buf lock spca50 x v4l lock

8、 SPIN LOCK UNLOCKED spca50 x buf state BUF NOT ALLOCATED else err Failed to configure camera goto error Init video stuff spca50 x vdev video device alloc 设备控制块内存 分配 if spca50 x vdev goto error memcpy spca50 x vdev spca50 x template sizeof spca50 x template 系统调用的挂接 在此将驱动实现的系统调用 挂到内核中 video set drvdat

9、a spca50 x vdev spca50 x if video register device spca50 x vdev VFL TYPE GRABBER video nr 0 video 设备注册 err video register device failed goto error spca50 x present 1 if spca50 x force rgb info data format set to RGB spca50 x task sync 0 spca50 x task routine auto bh spca50 x task data spca50 x spca5

10、0 x bh requested 0 MOD DEC USE COUNT 增加模块使用数 return spca50 x 返回数据结构 error 错误处理 if spca50 x vdev if spca50 x vdev minor 1 video device release spca50 x vdev else video unregister device spca50 x vdev spca50 x vdev NULL if spca50 x kfree spca50 x spca50 x NULL MOD DEC USE COUNT return NULL nodevice re

11、turn NULL Spca5xx disconnect 的具体实现如下 static void spca5xx disconnect struct usb device dev void ptr struct usb spca50 x spca50 x struct usb spca50 x ptr int n MOD INC USE COUNT 增加模块使用数 if spca50 x return down spca50 x lock 减 少信号量 spca50 x present 0 驱动卸 载置 0 for n 0 n SPCA50X NUMFRAMES n 标示所有帧 ABORTIN

12、G 状 态 spca50 x frame n grabstate FRAME ABORTING spca50 x curframe 1 for n 0 n SPCA50X NUMFRAMES n 唤醒所有等待进程 if waitqueue active spca50 x frame n wq wake up interruptible spca50 x frame n wq if waitqueue active spca50 x wq wake up interruptible spca50 x wq spca5xx kill isoc spca50 x 子函数终止 URB 包 的传输 PD

13、EBUG 3 Disconnect Kill isoc done up spca50 x lock 增加信号量 while spca50 x user 如果还有进程在 使用 进程切换 schedule down spca50 x lock if spca50 x vdev video unregister device spca50 x vdev 注销 video 设 备 usb driver release interface spca5xx driver 端口释放 spca50 x dev actconfig interface spca50 x iface spca50 x dev NU

14、LL up spca50 x lock ifdef CONFIG PROC FS destroy proc spca50 x cam spca50 x 注销 PROC 文件 endif CONFIG PROC FS if spca50 x spca50 x user 释 放内存空间 spca5xx dealloc spca50 x kfree spca50 x spca50 x NULL MOD DEC USE COUNT 减少模块记数 PDEBUG 3 Disconnect complete 二 上层软件接口模块 该模块通过 file operations 数据结构 依据 V4L 协议规范

15、实现设备的关键系 统调用 实现设备文件化的 UNIX 系统设计特点 作为摄相头驱动 其功能在于 数据采集 而没有向摄相头输出的功能 因此在源码中没有实现 write 系统调用 其关键的数据结构如下 static struct video device spca50 x template owner THIS MODULE name SPCA5XX USB Camera type VID TYPE CAPTURE hardware VID HARDWARE SPCA5XX fops spca5xx fops static struct file operations spca5xx fops o

16、wner THIS MODULE open spca5xx open open 功能 release spca5xx close close 功能 read spca5xx read read功能 mmap spca5xx mmap 内存映射功能 ioctl spca5xx ioctl 文件信息获取 llseek no llseek 文件定位功能未实现 1 Open 功能 完成设备的打开和初始化 并初始化解码器模块 其具体实现如下 static int spca5xx open struct video device vdev int flags struct usb spca50 x spca50 x video get drvdata vdev int err MOD INC USE COUNT 增加模块记数 down spca50 x lock err ENODEV if spca50 x present 检查设备是不是存在 有不有 驱动 是不是忙 goto out err EBUSY if spca50 x user goto out err ENOMEM if spca50

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 其它学术论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号