一種基于ARM-Linux的FPGA程序加載方法
4、嵌入式 Linux的驅(qū)動(dòng)實(shí)現(xiàn)
本文以模塊形式實(shí)現(xiàn)了運(yùn)行于S3C2410上的linux驅(qū)動(dòng)程序,源文件如下(有關(guān)寄存器
的設(shè)置參考S3C2410的數(shù)據(jù)手冊(cè),以下源代碼未包含頭文件):
#define GPIO_va_base 0x0F6000000
//基于S3C2410 上的Linux內(nèi)核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
//定義主設(shè)備號(hào),和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;
}
linux操作系統(tǒng)文章專題:linux操作系統(tǒng)詳解(linux不再難懂)
評(píng)論