|
你好,我最近在作一个视频采集卡的驱动时遇到了些问题,
恳请你伸出援助之手,不盛感激。 我的驱动是基于ARM-LINUX的,数据已经可以采集,但采回来的数据经显示之后全
是彩条,不知是驱动的问题还是应用程序的问题。 本人QQ:599180103 驱动程序如下:
#define MODULE #include <linux/config.h> #include <linux/version.h> #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/types.h> #include <linux/sched.h> #include <linux/errno.h> #include <linux/miscdevice.h> #include <linux/slab.h> #include <linux/fcntl.h>
#include <asm/io.h> #include <asm/uaccess.h> #include <asm/system.h>
#include "mytest.h"
#define DEVICE_NAME "mytest" #define MYTEST_MAJOR 240
#define MAX_SIZE_PER_PICTURE (320*240*2)
#define CAM_PHY_ADDR ((unsigned long)0x24000000)
#define UWORD unsigned short
static int mytest_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg);
static UWORD data[ MAX_SIZE_PER_PICTURE>>1 ];
static int mytest_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg) { UWORD *ptrpic;
switch (cmd) { case MYTEST_Get_data:{ printk("sizeof short = %d \n", sizeof(UWORD)); ptrpic = (UWORD*) __ioremap( CAM_PHY_ADDR,
MAX_SIZE_PER_PICTURE, 0);
if (ptrpic != NULL){
printk("remap phyaddress 0x%X to virtual
address 0x%X \n", CAM_PHY_ADDR, (unsigned long)ptrpic ); if(copy_to_user((char*)arg, ptrpic,
MAX_SIZE_PER_PICTURE) ) { __iounmap(ptrpic); return -1; } __iounmap(ptrpic); } else { printk("remap failed !\n"); }
/* if(copy_to_user((char*)arg, data, 2048) ) return -1;*/ break; }
case MYTEST_Set_Data: { /* if(copy_from_user(data, (char*)arg, 2048)) return -EFAULT;*/ break; } default: return 0; break;
}
return 0;
}
static int mytest_open(struct inode *inode, struct file *file) { return 0; }
static long mytest_read(struct inode *inode, struct file *file, char
*buf, unsigned long count) { return 0; }
/* * The various file operations we support. */
static struct file_operations mytest_fops = { owner: THIS_MODULE, ioctl: mytest_ioctl, open: mytest_open, };
static devfs_handle_t devfs_handle;
static int __init mytest_init(void) { int ret; int i;
ret = register_chrdev(MYTEST_MAJOR, DEVICE_NAME, &mytest_fops); if (ret < 0) { printk(DEVICE_NAME " can't register major number\n"); return ret; } devfs_handle = devfs_register(NULL, DEVICE_NAME,
DEVFS_FL_DEFAULT, MYTEST_MAJOR, 0, S_IFCHR | S_IRUSR |
S_IWUSR, &mytest_fops, NULL);
printk(DEVICE_NAME " initialized\n");
return 0; }
static void __exit mytest_exit(void) { devfs_unregister(devfs_handle); unregister_chrdev(MYTEST_MAJOR, DEVICE_NAME); }
module_exit(mytest_exit); module_init(mytest_init); MODULE_DESCRIPTION("mytest driver"); MODULE_AUTHOR("Supermi <superligen@gmail.com> "); MODULE_LICENSE("GPL");
应用程序如下: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/ioctl.h> #include "mytest.h"
#define MYTEST_Set_Data 1 #define MYTEST_Get_data 2
char Data[2048]={0};
char getData[320*240*2]={0};
FILE *f;
int main(int argc, char **argv) { int fd;
fd = open("/dev/mytest", 0); if (fd < 0) { perror("open device mytest"); exit(1); }
sprintf(Data, "Hello \n"); /*ioctl(fd, MYTEST_Set_Data, Data);*/
ioctl(fd, MYTEST_Get_data, getData);
f = fopen("pic.dat", "wb+");
// fwrite( getData, 320*240*2, 1, f); ////////
for (int y=0;y<320*240;y++) { fwrite( &getData[y*2], 2, 1, f); }
fclose(f);
close(fd);
printf( "%s",getData);
return 0; }
|