第一次写驱动,测试read 、write都不好使

我鲁班无敌 2013-10-21 05:24:36
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <asm/irq.h>
//#include <mach/hardware.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/gpio.h>
//#include <plat/gpio-cfg.h>
//#include <mach/regs-gpio.h
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/init.h>
#include <asm/io.h>
#include <asm/system.h>
#include <asm/uaccess.h>


#define FPGA_PHY_START 0x38000000
#define FPGA_PHY_SIZE 2*1024*1024 // 2M
#define FPGA_MAJOR 250
#define FPGA_IO_ADDR 0x0000 //¿¿¿¿
#define DEVICE_NAME "fpga"

static void __iomem *fpga_base;

static ssize_t s3c6410_fpga_read(struct file *filp, char *buf, size_t len, loff_t *off)

{

unsigned long p = *off;
unsigned int count = len;
int ret = 0;
if(count > 0 && count < FPGA_PHY_SIZE)
{
iowrite16(FPGA_IO_ADDR,fpga_base+0x04);
if(copy_to_user(buf,(void *)(fpga_base+p),count))
{
ret = -EFAULT;
}
else
{
*off += count;
ret - count;
}
}
return ret;
}

static ssize_t s3c6410_fpga_write(struct file *filp, char *buf, size_t len, loff_t *off)

{
unsigned long p = *off;
unsigned int count = len;
int ret = 0;
if(count > 0 && count < FPGA_PHY_SIZE)
{
iowrite16(FPGA_IO_ADDR,fpga_base+0x04);
if(copy_from_user(fpga_base+p,buf,count))
{
ret = -EFAULT;
}
else
{
*off += count;
ret - count;
}
}
return ret;

}

static loff_t s3c6410_fpga_llseek(struct file *filp, loff_t offset, int whence)

{

loff_t newpos;
switch(whence) {
case 0: /* SEEK_SET */
newpos = offset;
break;
case 1: /* SEEK_CUR */
newpos = filp->f_pos + offset;
break;
case 2: /* SEEK_END */
newpos = FPGA_PHY_SIZE -1 + offset;
break;
default: /* can't happen */
return -EINVAL;
}
if ((newpos<0) || (newpos>FPGA_PHY_SIZE))
return -EINVAL;
filp->f_pos = newpos;
return newpos;
}

static struct file_operations s3c6410_fpga_fops =

{
.owner = THIS_MODULE,

.read = s3c6410_fpga_read,

.write = s3c6410_fpga_write,

// .open = s3c6410_fpga_open,

.llseek = s3c6410_fpga_llseek,

};



static struct cdev cdev_fpga;



static int __init s3c6410_fpga_init(void)

{ int result;
dev_t devno = MKDEV(FPGA_MAJOR,0);
struct class *fpga_class;
result = register_chrdev_region(devno,1,DEVICE_NAME)
if(result)
{
printk(KERN_NOTICE "Error %d register fpga",result);
return result;
}
cdev_init(&cdev_fpga,&s3c6410_fpga_fops);
result = cdev_add(&cdev_fpga,devno,1);
if(result)
{
printk(KERN_NOTICE "Error %d adding irda",result);
return result;
}
fpga_class = class_create(THIS_MODULE, "fpga_class");
device_create(fpga_class, NULL, devno, "fpga","fpga%d", 0);
fpga_base = ioremap(FPGA_PHY_START,FPGA_PHY_SIZE);
printk ("\n@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
printk (DEVICE_NAME"\tinitialized\n");
printk ("\n@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
return 0;

}
static void __exit s3c6410_fpga_exit(void)

{
cdev_del(&cdev_fpga);
unregister_chrdev_region(MKDEV(FPGA_MAJOR,0),1);
}

module_init(s3c6410_fpga_init);
module_exit(s3c6410_fpga_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("FORLINX Inc.");

这个FPGA要先写一个地址 然后写数据、
...全文
282 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
listen345 2013-11-13
  • 打赏
  • 举报
回复
http://bbs.csdn.net/topics/390641199?page=1#post-396068649 楼主帮我看下这个问题吧,多谢了~
listen345 2013-11-13
  • 打赏
  • 举报
回复
我最近也在做这一块,拿ARM7做前端机,发命令给FPGA并接收数据。 但你的问题我现在回答不了,我也是卡在第一个驱动程序上,现在程序还加载不上。 交个朋友吧,相互交流共同进步。我的QQ:448205180
xiqxin 2013-11-12
  • 打赏
  • 举报
回复
建议楼主去驱动开发网技术论坛问问,那里牛人比较多
rslei 2013-11-02
  • 打赏
  • 举报
回复
看不懂、、找个驱动怎么这么难呢
  • 打赏
  • 举报
回复
把你想要问的问题描述清楚啊!
我鲁班无敌 2013-11-01
  • 打赏
  • 举报
回复
引用 1 楼 oqzuser123456789koo 的回复:
把你想要问的问题描述清楚啊!
主处理器是ARM11。 FPGA通过nCS5连接到arm处理器上处理数据。为了节省电路板连线需要先发地址然后再往这个地址写数据。这样的驱动如何写呢

21,597

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧