一种基于ARM-Linux的FPGA程序加载方法
置参考S3C2410的数据手册,以下源代码未包含头文件):
#define GPIO_va_base 0x0F6000000
//基于S3C2410 上的Linux内核IO控制寄存器首地址映射后的虚拟地址
#define ARM_GPDCON PIO_va_base+0x30);
#define ARM_GPDUP PIO_va_base+0x38);
#define ARM_port_wr(addr,value) *(volatile unsigned int*)(addr)=value)
//定义输出
#define FPGA_CS 8
#define FPGA_RW 9
#define FPGA_PROG 12
#define FPGA_CCLK 14
//定义操作
#define ARM_GPDDAT (*(volatile u32 *)(GPIO_va_base+0x34))
#define set_register_bit(x) ARM_GPDDAT=(1x)|ARM_GPDDAT
#define clear_register_bit(x) ARM_GPDDAT=(~(1x))ARM_GPDDAT
//定义输入
#define FPGA_INIT ((ARM_GPDDAT>>10)1)
#define FPGA_BUSY ((ARM_GPDDAT>>11)1)
#define FPGA_DONE ((ARM_GPDDAT>>13)1)
#define FPGA 211
//定义主设备号,和mknod /dev/fpga c 211 0匹配
typedef char fpga_device_t;
static fpga_device_t fpga_devices[257];
char buf[1000000];
int fpga_open(struct inode *, struct file *);
ssize_t fpga_write(struct file *,const char *,size_t ,loff_t *);
int fpga_release(struct inode*, struct file *);
//初始化ARM的D组通用IO管脚
void init_fpga(void){
ARM_port_wr(GPIO_va_base+0x30,0x55555555);
//FPGA_BUSY FPGA_DONE FPGA_INIT be set input
ARM_port_wr(GPIO_va_base+0x34,0xFFFF);
ARM_port_wr(GPIO_va_base+0x30,0x51055555);
ARM_port_wr(GPIO_va_base+0x38,0);// put up
set_register_bit(FPGA_CCLK);//set GCLK
}
static struct file_operations fpga_ctl_fops= {
open: fpga_open,
write: fpga_write,
release: fpga_release,};
int init_module(void) {
printk("Hello,word,Now preparing FPGA......");
printk("register FPGA......");
register_chrdev(FPGA, "fpga", fpga_ctl_fops);
printk("Done!");
printk("Hello,word,success!");
return 0;
}
int fpga_open(struct inode *inode, struct file *filp){
int minor;
minor = MINOR(inode->i_rdev);
init_fpga();
fpga_devices[minor]++;
printk("FPGA is ready.");
return 0;
}
ssize_t fpga_write(struct file *flip,const char *buffer,size_t count,loff_t
*ppos){
int i;
if(copy_from_user(buf,buffer,count)){
printk("error ");
return -EFAULT;
}
printk("%d numbers have been received!",count);
printk("The number is:%d",count);
for(i=0;icount;i++){
ARM_GPDDAT=(ARM_GPDDAT0x3F00)|buf[i];
set_register_bit(FPGA_CCLK);
}
printk("data write finished");
for(i=0;i4;i++){
set_register_bit(FPGA_CCLK);
clear_register_bit(FPGA_CCLK);
}
return count;
}
int fpga_release(struct inode *inode, struct file *filp){
int minor;
minor = MINOR(inode->i_rdev);
if (fpga_devices[minor])
fpga_devices[minor]--;
printk("Goodbye cruel world");
return 0;
}
void cleanup_module(void){
printk("Goodbye cruel world");
}
5、结束语
本文的创新点:基于ARM-Linux平台,实现了一种FPGA的程序加载模式,加载速度快,灵活高效。
- Linux嵌入式系统开发平台选型探讨(11-09)
- 基于ARM体系的嵌入式系统BSP的程序设计方案(04-11)
- 在Ubuntu上建立Arm Linux 开发环境(04-23)
- 达芬奇数字媒体片上系统的架构和Linux启动过程(06-02)
- SQLite嵌入式数据库系统的研究与实现(02-20)
- 革新2410D开发板试用手记(04-21)